code1
stringlengths 54
12k
| code2
stringlengths 65
12k
| similar
int64 0
1
| __index_level_0__
int64 45
101M
|
---|---|---|---|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
ll r, d, x;
cin >> r >> d >> x;
ll ans = r * x - d;
for (int i = 0; i < 10; i++)
{
cout << ans << endl;
ans = r * ans - d;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define print(i) cout << i << endl
#define all(i) (i).begin(),(i).end()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
int main(void)
{
int a[101] = {};
int mx = 0;
int x;
while (scanf("%d", &x) != EOF){
a[x]++;
if (mx < a[x]) mx = a[x];
}
FOR(i, 1, 101){
if (a[i] == mx){
cout << i << endl;
}
}
return 0;
}
| 0 | 99,256,263 |
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
int ans = 0;
REP(i,n){
cin >> a[i];
if(i != 0){
ans = gcd(gcd(a[i],a[i-1]),ans);
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
int H, W, A, B;
cin >> H >> W >> A >> B;
if (A == 0 && B == 0) {
for (int j = 0; j < H; j++) {
for (int i = 0; i < W; i++) {
cout << 0;
}
cout << endl;
}
return 0;
}
if (A == 0) {
for (int j = 0; j < B; j++) {
for (int i = 0; i < W; i++) {
cout << 1;
}
cout << endl;
}
for (int j = B; j < H; j++) {
for (int i = 0; i < W; i++) {
cout << 0;
}
cout << endl;
}
return 0;
}
if (B == 0) {
for (int j = 0; j < H; j++) {
for (int i = 0; i < A; i++) {
cout << 1;
}
for (int i = A; i < W; i++) {
cout << 0;
}
cout << endl;
}
return 0;
}
vector<vector<int>> ans(H, vector<int>(W));
for (int i = 0; i < H - B; i++) {
for (int j = 0; j < W - A; j++) {
ans[i][j] = 1;
}
}
for (int i = H - B; i < H; i++) {
for (int j = W - A; j < W; j++) {
ans[i][j] = 1;
}
}
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cout << ans[i][j];
}
cout << endl;
}
return 0;
}
| 0 | 64,520,949 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
const int MAX_FRAME = 10000;
int makeLinerCongRand(int a, int b, int c, int x) {
return (a * x + b) % c;
}
int main(void) {
int n, a, b, c, x;
while (cin >> n >> a >> b >> c >> x, n) {
vector<int> reel(n);
for (int i = 0; i < n; i++) {
cin >> reel[i];
}
int frame = 0;
int nowReel = 0;
while (true) {
if (reel[nowReel] == x) {
nowReel++;
if (nowReel == n) {
break;
}
}
if (++frame > MAX_FRAME) {
break;
}
x = makeLinerCongRand(a, b, c, x);
}
cout << (frame <= MAX_FRAME ? frame : -1) << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>
#include <iomanip>
using namespace std;
long long par[2001000];
long long ranks[2001000];
long long diff_weight[2001000]={};
void init(long long n){
for(long long i=0;i<n;i++){
par[i]=i;
ranks[i]=0;
}
}
long long find(long long x){
if(par[x]==x){
return x;
}else{
int r=find(par[x]);
diff_weight[x]+=diff_weight[par[x]];
return par[x]=r;
}
}
long long weight(long long x){
find(x);
return diff_weight[x];
}
void unite(long long x,long long y,long long dist){
dist-=weight(y);
dist+=weight(x);
x=find(x);
y=find(y);
if(x==y){
return ;
}
if(ranks[x]<ranks[y]){
par[x]=y;
diff_weight[x]=(-dist);
}
else{
par[y]=x;
diff_weight[y]=dist;
}
if(ranks[x]==ranks[y]){
ranks[x]++;
}
}
bool same(long long x,long long y){
return find(x)==find(y);
}
int main(){
long long N,M;
cin>>N>>M;
bool judge=true;
long long L,R,D;
init(200020);
for(long long i=0;i<M;++i){
cin>>L>>R>>D;
if(same(L,R)){
if(weight(R)-weight(L)!=D){
judge=false;
break;
}
}
else{
unite(L,R,D);
}
}
if(judge){
cout<<"Yes"<<"\n";
}
else{
cout<<"No"<<"\n";
}
return 0;
}
| 0 | 79,339,619 |
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <stack>
using namespace std;
#define INF 1e18
#define int long long
signed main() {
string s; cin >> s;
string substr4 = s.substr(0, 4);
string substr8 = s.substr(4, 8);
string ans = substr4 + " " + substr8;
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
char col[2][3] = { "RY", "GB" };
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int H, W, d;
cin >> H >> W >> d;
vector<string> S(H, string(W, ' '));
rep(y, H)rep(x, W) {
int Y = x + y;
int X = x - y;
Y = Y % (2 * d) / d;
X = X % (2 * d);
if (X < 0)X += 2 * d;
X /= d;
S[y][x] = col[Y][X];
}
rep(y, H)cout << S[y] << endl;
}
| 0 | 89,092,633 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int flag = 1;
if (s.size() + 1 == t.size()) {
for (int i = 0; i < s.size(); i++) {
if (s[i] != t[i]) {
flag = 0;
}
}
}
flag == 1 ? cout << "Yes" : cout << "No";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define _USES_MATH_DEFINES
#define x first
#define y second
int main() {
int n; cin >> n;
vector< pair<int, int> > P (n, {0, 0});
for(int i = 0; i < n; i++) {
cin >> P[i].x >> P[i].y;
}
sort(P.begin(), P.end(), [](auto a, auto b) -> int { return atan2l(a.y, a.x) < atan2l(b.y, b.x); } );
long long answer = 0;
for( int L = 0; L < n; L++ ) {
long long X = P[L].x, Y = P[L].y;
answer = max(answer, X*X + Y*Y);
for(int i = 1; i < n; i++) {
int R = (L + i) % n;
X += P[R].x;
Y += P[R].y;
answer = max(answer, X*X + Y*Y);
}
}
cout << fixed << setprecision(50) << sqrtl(answer);
}
| 0 | 12,909,510 |
#define DEBUG
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#ifdef DEBUG
#define dbg(s) {s;}
#endif
#ifndef DEBUG
#define dbg(s)
#endif
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) {
return uniform_int_distribution<int>(0, x - 1)(rng);
}
#define int ll
#define i32 int32_t
#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update>
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
int getInt () {
bool minus = false;
int result = 0;
char ch;
ch = getchar();
while (true) {
if (ch == '-') break;
if (ch >= '0' && ch <= '9') break;
ch = getchar();
}
if (ch == '-') minus = true; else result = ch-'0';
while (true) {
ch = getchar();
if (ch < '0' || ch > '9') break;
result = result*10 + (ch - '0');
}
if (minus)
return -result;
else
return result;
}
ll gcd(ll x, ll y) {
if (x < y) return gcd(y, x);
if (y == 0) return x;
return gcd(y, x % y);
}
const ll mod = 1e9 + 7;
ll modexp(ll x, ll ex) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll) ans = (ans * x) % mod;
ex >>= 1ll;
x = (x * x) % mod;
}
return ans;
}
const int maxn = 1e6 + 7;
const ll inf = 1e9 + 7;
i32 main() {
IOS;
int n; cin >> n; n += n;
string s; cin >> s; int t = 1, op = 0, cur = 0;
for (int j = 0; j < n; j++) {
int d = (s[j] == 'B');
if (d == cur) { t *= op; op--; cur ^= 1; }
else { op++; cur ^= 1; }
t %= mod;
}
if (op > 0) { cout << 0 << endl; return 0; }
for (int j = 1; j <= n/2; j++) t = (t * j) % mod;
cout << t << endl;
}
|
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cassert>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define FOR(j,k,n) for (int j = k; j < (int)(n); j++)
#define MAXN 100000000000000000
#define newl printf("\n")
#define test(t) int t; cin>>t; for(int tes = 0; tes < t; tes++)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
const int MM = 120000;
lli m,n,k,p1,p,p2,p3,f,a[MM],v[MM];
vector<lli> gr[MM];
lli dfs(lli s)
{
v[s] = 1;
lli cnt = 1;
for(lli u : gr[s])
{
if(!v[u])
{
p = dfs(u);
if(p==-1)
{
return -1;
}
cnt += p%2;
}
}
if(cnt == 2)
{
return 0;
}
else if(cnt == 1)
{
return 1;
}
else
{
return -1;
}
}
int main(){
fio;
lli q;
cin>>n;
for (int i=1; i<n; i++) {
cin>>p1>>p2;
p1--; p2--;
gr[p2].push_back(p1);
gr[p1].push_back(p2);
}
if(dfs(0) != 0)
cout<<"First";
else
cout<<"Second";
return 0;
}
| 0 | 93,951,577 |
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#define PI (3.1415926535898)
int main(void) {
double a, b, C, rad;
double S, L, h;
scanf("%lf %lf %lf", &a, &b, &C);
rad = C * PI / 180.0;
h = b * sin(rad);
S = a * h / 2.0;
L = a + b + sqrt((h * h) + ( (a - b * cos(rad)) * (a - b * cos(rad))));
printf("%10.8lf\n", S);
printf("%10.8lf\n", L);
printf("%10.8lf\n", h);
}
|
#include<iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
bool num[1000000] = { false };
void primNumberCheck(){
num[2] = true;
int i, j, k;
for (i = 3; i <= 1000000; i += 2)
{
k = 0;
for (j = 3; j <= sqrt((double)i); j += 2)
{
if (i%j == 0)
{
k = 1;
break;
}
}
if (k == 0)
{
num[i] = true;
}
}
}
int main()
{
primNumberCheck();
int n;
while (cin>>n)
{
int result = 0;
for (int i = 0; i <= n; i++)
{
if (num[i] == true)result++;
}
cout << result << endl;
}
return 0;
}
| 0 | 45,069,728 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,s,n) for(int i=s;i<n;++i)
#define FORR(i,s,n) for(int i=n-1;i>=s;--i)
#define ALL(c) (c).begin(),(c).end()
#define CLEAR(v) memset(v,0,sizeof(v))
#define MP(a,b) make_pair((a),(b))
#define ABS(a) ((a)>0?(a):-(a))
#define F first
#define S second
int main(int argc, char **argv) {
string s;
cin >> s;
ll a = 0, b = 0;
REP(i, s.length()) if (s[i] == '0') ++a; else ++b;
cout << (min(a, b) * 2) << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define DFS_WHITE -1
#define DFS_BLACK 1
vector<vi> AdjList;
vi dfs_num;
vi dfs_discover;
int numCC;
int count = 0;
int dfs(int u) {
dfs_num[u] = DFS_BLACK;
int ans = 1;
for (int j = 0; j < (int)AdjList[u].size(); j++) {
int v = AdjList[u][j];
if (dfs_num[v] == DFS_WHITE)
ans += dfs(v);
}
return ans;
}
int main(){
int n, m;
cin>>n>>m;
AdjList.assign(n + 1, vi());
dfs_num.assign(n + 1, DFS_WHITE);
for (int i=0; i<m; i++){
int x, y;
cin>>x>>y;
AdjList[x].push_back(y);
AdjList[y].push_back(x);
}
int ans = 0;
for (int i=1; i<=n; i++){
if(dfs_num[i] == DFS_WHITE){
ans = max(ans,dfs(i));
}
}
cout<<ans;
}
| 0 | 14,755,261 |
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
typedef long long int lli;
lli n,k,s,m,t,a,b,l,r,v,h,u,temp1,temp2,x,y,temp,q,d,mod=1e9+7,w,p,c,z;
lli grid[2000][2000],dp[2000][2000];
lli rec(lli i,lli j)
{
if(grid[i][j]==1)
{
dp[i][j]=0;
}
if(i==1&&j==1)
{
dp[i][j]=1;
}
if(dp[i][j]!=-1)
{
return dp[i][j];
}
dp[i][j]=(rec(i-1,j)%mod+rec(i,j-1)%mod)%mod;
return dp[i][j];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
char ch;
for(int i=1;i<=n;i++)
{
for(int j =1;j<=m;j++)
{
cin>>ch;
if(ch=='.')
{
grid[i][j]=0;
}
else
{
grid[i][j]=1;
}
dp[i][j]=-1;
}
}
rec(n,m);
cout<<dp[n][m]<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, tot = 0;
cin >> n;
map<string, int> prefix;
for (int i = 0; i < n; i++)
{
int val;
string s;
cin >> s >> val;
tot += val;
prefix[s] = tot;
}
string s;
cin >> s;
cout << tot - prefix[s] << "\n";
}
| 0 | 68,735,996 |
#include<iostream>
using namespace std;
class Dice {
public:
int D1;
int D2;
int D3;
int D4;
int D5;
int D6;
Dice(int d1, int d2, int d3, int d4, int d5, int d6);
void Rotate_E();
void Rotate_N();
void Rotate_S();
void Rotate_W();
};
Dice::Dice(int d1, int d2, int d3, int d4, int d5, int d6) {
D1 = d1;
D2 = d2;
D3 = d3;
D4 = d4;
D5 = d5;
D6 = d6;
}
void Dice::Rotate_E() {
int tmp;
tmp = D3;
D3 = D1;
D1 = D4;
D4 = D6;
D6 = tmp;
}
void Dice::Rotate_N() {
int tmp;
tmp = D5;
D5 = D1;
D1 = D2;
D2 = D6;
D6 = tmp;
}
void Dice::Rotate_S() {
int tmp;
tmp = D5;
D5 = D6;
D6 = D2;
D2 = D1;
D1 = tmp;
}
void Dice::Rotate_W() {
int tmp;
tmp = D3;
D3 = D6;
D6 = D4;
D4 = D1;
D1 = tmp;
}
int main () {
int d1, d2, d3, d4, d5, d6;
cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6;
Dice Dice1(d1, d2, d3, d4, d5, d6);
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int a, b;
cin >> a >> b;
if (Dice1.D3 == b || Dice1.D4 == b) {
Dice1.Rotate_E();
}
while (Dice1.D2 != b) {
Dice1.Rotate_N();
}
while (Dice1.D1 != a) {
Dice1.Rotate_E();
}
cout << Dice1.D3 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int N;
cin >> N;
int A[N];
int B[N];
for(int i = 0; i < N; i++){
cin >> A[i];
B[i] = A[i];
}
sort(B,B + N);
int max_v = B[N-1];
int sec_max_v = B[N-2];
int max_idx = -1;
int sec_max_idx = -1;
for(int i = 0; i < N; i++ ){
if(A[i] == max_v) max_idx = i;
if(A[i] == sec_max_v) sec_max_idx = i;
}
for(int i = 0; i < N; i++){
if(i != max_idx) cout << A[max_idx] << endl;
else if(i == max_idx) cout << A[sec_max_idx] << endl;
}
return 0;
}
| 0 | 62,502,097 |
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
ll a,b,c,k;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>a>>b>>c>>k;
if(k&1){
cout<<-1*(a-b)<<endl;
}
else cout<<a-b<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for (int i = (int)(n - 1); i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
template<typename T> inline bool chmax(T &a, T &b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T> inline bool chmin(T &a, T &b) {if (b < a) {a = b; return 1;} return 0;}
template<typename T> T pow(T a, ll n) {T r(1); while(n) {if (n & 1) r *= a; a *= a; n >>= 1;} return r;}
struct faster_io {faster_io() {cin.tie(0); ios_base::sync_with_stdio(false);}} faster_io_;
struct edge {int to, cost;};
struct graph {
int n;
vector<vector<edge>> G;
vector<int> d, pre;
graph(int i) : n(i), G(n), pre(n), d(n,INF) {}
void add_edge(int s, int t, int cost) {
edge e; e.to = t; e.cost = cost;
G[s].push_back(e);
}
void dijkstra(int s) {
rep(i,n) {d[i] = INF; pre[i] = 0;}
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> que;
que.push(P(0,s));
while(!que.empty()){
P p = que.top(); que.pop(); int v = p.second;
if(d[v] < p.first) continue;
for(auto e : G[v]) if(d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost; pre[e.to] = v;
que.push(P(d[e.to],e.to));
}
}
}
};
signed main() {
int n, m; cin >> n >> m;
map<P,int> edge_list;
graph g(n);
rep(i,m) {
int a, b, c; cin >> a >> b >> c;
a--; b--;
edge_list[P(min(a,b),max(a,b))]++;
g.add_edge(a,b,c);
g.add_edge(b,a,c);
}
rep(i,n) {
g.dijkstra(i);
rep(f,n) {
if (f == i) continue;
int t = g.pre[f];
edge_list[P(min(f,t),max(f,t))]++;
}
}
int ans = 0;
for (auto p : edge_list) if (p.second == 1) ans++;
cout << ans << endl;
return 0;
}
| 0 | 17,564,819 |
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline long long read() {
long long f = 0;
char c;
while (!isdigit(c = getChar())) {}
do
f = f * 10 + (c ^ 48);
while (isdigit(c = getChar()));
return f;
}
const int maxN = 100003;
long long d[maxN];
map<long long, int> mp;
int ind[maxN];
inline bool cmp(int x, int y) { return d[x] > d[y]; }
int siz[maxN];
vector<int> g[maxN];
long long dfs(int x) {
long long o = 0;
for (int y : g[x])
o += dfs(y) + siz[y];
return o;
}
int main() {
int n = read(), i, x, y;
long long tmp;
for (i = 1; i <= n; ++i)
d[i] = read(), mp[d[i]] = i, ind[i] = i, siz[i] = 1;
sort(ind + 1, ind + n + 1, cmp);
for (i = 1; i < n; ++i) {
x = ind[i], tmp = d[x] - n + (siz[x] << 1);
if (mp.find(tmp) == mp.end() || siz[x] << 1 == n) {
printf("-1\n");
return 0;
}
y = mp[tmp], g[y].push_back(x), siz[y] += siz[x];
}
if (dfs(ind[n]) == d[ind[n]])
for (x = 1; x <= n; ++x)
for (int y : g[x])
printf("%d %d\n", x, y);
else
printf("-1\n");
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,double> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
ll dp[100005][2];
int main() {
string s;cin>>s;
int n = s.size();
dp[0][1] = 1;
rep(i,n) {
dp[i+1][0] += dp[i][0] * 3;
dp[i+1][0] %= MOD;
if(s[i]=='1') {
dp[i+1][0] += dp[i][1];
dp[i+1][0] %= MOD;
dp[i+1][1] += dp[i][1] * 2;
dp[i+1][1] %= MOD;
} else {
dp[i+1][1] += dp[i][1];
dp[i+1][1] %= MOD;
}
}
cout << (dp[n][0] + dp[n][1]) % MOD <<endl;
}
| 0 | 54,822,031 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
int main() {
int A, B; cin >> A >> B;
vector<string> C(100);
for (int i = 0; i < 50; ++i) {
C[i] = string(100, '.');
}
for (int i = 50; i < 100; ++i) {
C[i] = string(100, '#');
}
--A, --B;
for (int i = 0; i < 50 && B > 0; i += 2) {
for (int j = 0; j < 100 && B > 0; j += 2) {
C[i][j] = '#'; --B;
}
}
for (int i = 99; i > 50 && A > 0; i -= 2) {
for (int j = 0; j < 100 && A > 0; j += 2) {
C[i][j] = '.'; --A;
}
}
cout << 100 << " " << 100 << endl;
for (auto s : C) cout << s << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
#define ll long long int
int main(){
int n,m;
cin>>n>>m;
ll s[n],t[m];
for(int i=0;i<n;i++) cin>>s[i];
for(int i=0;i<m;i++) cin>>t[i];
ll dp[3000][3000];
memset(dp,0,sizeof dp);
dp[0][0]=1;
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i<n && j<m && s[i]==t[j]) dp[i+1][j+1]+=dp[i][j];
dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MAX;
dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MAX;
dp[i+1][j+1]=(dp[i+1][j+1]-dp[i][j])%MAX;
}
}
if(dp[n][m]<0) dp[n][m]+=MAX;
cout<<dp[n][m];
}
| 0 | 51,769,116 |
#include <stdio.h>
int main ()
{
int x, y;
while (1)
{
{scanf("%d%d",&x,&y);
if(x==0&&y==0)
break;}
if(x<y) printf("%d %d\n",x,y);
if(y<x) printf("%d %d\n",y,x);
if(x==y) printf("%d %d\n",x,y);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define optimize() ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
int main()
{
int n,l;
cin>>n>>l;
string bal[n];
for(int i=0;i<n;i++){
cin>>bal[i];
}
string mn=bal[0];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(bal[j]<bal[i]){
mn=bal[j];
bal[j]=bal[i];
bal[i]=mn;
}
}
}
for(int i=0;i<n;i++){
cout<<bal[i];
}
return 0;
}
| 0 | 73,435,209 |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repd(i,n) for(ll i = n - 1; i >= 0; i--)
#define all(x) x.begin(), x.end()
ll n, k, m, M = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
ll f;
for(ll i = 1; i * i <= n; i++) {
if(n % i == 0) f = i;
}
f = n / f;
ll num = 0, prd = 1;
while(prd <= f) {
prd *= 10;
num++;
}
cout << num << endl;
}
|
#include<iostream>
using namespace std;
#define rep(i,j) for(i=0;i<j;i++)
int main()
{
int n;
while(cin>>n)
{
int a,b,c,d;
int cnt=0;
rep(a,10)rep(b,10)rep(c,10)rep(d,10)
{
if(a+b+c+d==n)cnt++;
}
cout << cnt<<endl;
}
return 0;
}
| 0 | 98,247,244 |
#include<bits/stdc++.h>;
using namespace std;
typedef long long ll;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#else
fastIO;
#endif
int n,l;
cin>>n>>l;
vector<string> v(n);
for(int i=0;i<n;i++){
string s;
cin>>s;
v.push_back(s);
}
sort(v.begin(),v.end());
for(auto &x:v){
cout<<x;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
clock_t startTime;
long double getTime(){
return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
ll* bun;
ll* paty;
int n;
ll x;
ll f(int a, ll b){
if(a==0) return 1;
if(b==1) return (a==0)? 1: 0;
ll m=bun[a-1];
if(b <=m+1) return f(a-1,b-1);
else if(b == m+2) return f(a-1,b-1)+1;
else return paty[a-1]+1+f(a-1,b-m-2);
}
int main(){
startTime=clock();
cin >> n >> x;
bun=new ll[n+1];
paty=new ll[n+1];
bun[0]=1;
paty[0]=1;
for(int i=1;i < n+1;i++){
bun[i]=bun[i-1]*2+3;
paty[i]=paty[i-1]*2+1;
}
cout << f(n,x);
return 0;
}
| 0 | 24,679,914 |
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
int main(){
ll n;
cin >> n;
ll ans=0;
sqrep(i, 1, n){
if(n%i==0){
ll a = i;
ll m = n/i -1;
if(m>a)ans += m;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string S;
int K;
ll ans = 0;
bool flag = false;
cin >> S >> K;
int left = 1, right = 1;
for (int i = 0; i < S.size() - 1; i++) {
if (S.at(i) != S.at(i + 1)) {
flag = true;
break;
} else
left++;
}
if (!flag) {
cout << (S.size() * K) / 2 << endl;
return 0;
}
for (int i = S.size() - 1; i > 0; i--) {
if (S.at(i) != S.at(i - 1)) {
break;
} else
right++;
}
for (int i = 0; i < S.size() - 1; i++) {
if (S.at(i) == S.at(i + 1)) {
S.at(i + 1) = '0';
ans++;
}
}
ans *= K;
if (S.at(0) == S.at(S.size() - 1))
ans -= ((left / 2) + (right / 2) - ((left + right) / 2)) * (K - 1);
cout << ans << endl;
}
| 0 | 33,534,912 |
#include <bits/stdc++.h>
using namespace std;
vector<string>v;
vector<int>ansl;
string s;
int ary[100005] = {0};
int main(){
int N,flgL = 0,flgR = 0, prc = 0;
string lu = "lu",ru = "ru", ld = "ld",rd = "rd";
cin >>N;
while(N != 0){
int cnt = 0;
flgL = 0,flgR = 0, prc = 0;
for(int i = 0;i<N;i++){
string foot;
int nwp = prc;
cin >>foot;
if(foot == "lu")flgL = 1;
if(foot == "ru")flgR = 1;
if(foot == "ld")flgL = 0;
if(foot == "rd")flgR = 0;
if((flgL == 1)&&(flgR == 1))prc = 1;
if((flgL == 0)&&(flgR == 0))prc = 0;
if(nwp != prc)cnt++;
}
ansl.push_back(cnt);
cin >>N;
}
for(int i = 0;i<(int)ansl.size();i++){
cout <<ansl[i]<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define spc ' '
#define endl '\n'
using namespace std;
string check(string s1, string s2){
string ans = "";
int n1 = s1.size(), n2 = s2.size();
for(int i = 0; i < n1; i++){
for(int j = 0; j < n2; j++){
if(s1[i]==s2[j]){
s2[j] = '?';
ans+=s1[i];
break;
}
}
}
return ans;
}
int main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
string ans,s;
unordered_map<int, int> m;
for(int i = 0; i < n; ++i){
cin >> s;
if(i==0){
ans = s;
}
else{
ans = check(ans, s);
}
}
sort(ans.begin(), ans.end());
cout << ans;
return 0;
}
| 0 | 66,931,178 |
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
const ll INF = 1LL << 60;
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
};
signed main() {
int a, b, x;
cin >> a >> b >> x;
if (x <= a + b && a <= x) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
using namespace std;
int CalcSumOfDigit(int n);
int getDigit(int n);
string upper(string str);
string lower(string str);
class Combi
{
public:
Combi();
long long Combination(long long n, long long k);
private:
vector<vector<long long>> memo;
long long n_num;
long long k_num;
void Resize(long long n, long long k);
};
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(a) int((a).size())
#define rep(i,n) for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n) for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v) sort((v).begin(),(v).end())
#define rvsort(v) sort(rall((v)))
#define vi vector<int>
#define GCD(a,b) __gcd((a),(b))
#define LCM(a,b) (a)/GCD((a),(b))*(b)
#define kiriage(a,b) ((a)+(b)-1)/(b)
const int INF = 1e9;
typedef long long ll;
typedef unsigned long long ull;
int main() {
ll n,p;
cin >> n >> p;
ll odd = 0,even = 0;
rep(i,n)
{
ll buf;cin >> buf;
(buf % 2 == 0 ? even : odd) += 1;
}
Combi *combi = new Combi;
ll ans = 0;
for(ll i = 0; i <= even; ++i)
{
ans += combi->Combination(even, i);
}
ll st;
if(p == 1)
{
st = 1;
}
else
{
st = 0;
}
ll odd_c = 0;
for(ll i = st; i <= odd; i = i + 2)
{
odd_c += combi->Combination(odd, i);
}
cout << ans * odd_c << endl;
return 0;
}
int getDigit(int n)
{
int i = 1;
while(1)
{
n = n / 10;
if(n == 1)
break;
i++;
}
return i;
}
int CalcSumOfDigit(int n)
{
int s = 0;
while(n)
{
s += n % 10;
n = n / 10;
}
return s;
}
string upper(string str)
{
for(auto itr = str.begin();itr != str.end() ; itr++)
{
if(97 <= *itr && *itr <= 122)
{
*itr = *itr - 32;
}
}
return str;
}
string lower(string str)
{
for(auto itr = str.begin();itr != str.end() ; itr++)
{
if(65 <= *itr && *itr <= 90)
{
*itr = *itr + 32;
}
}
return str;
}
Combi::Combi(){
n_num = -1;
k_num = -1;
};
ll Combi::Combination(ll n, ll k)
{
Resize(n,k);
ll ret;
if(memo[n][k] != 0)
{
ret = memo[n][k];
}
else if(n == k || k == 0)
{
memo[n][k] = 1;
ret = 1;
}
else
{
ret = Combination(n - 1, k - 1) + Combination(n - 1, k);
memo[n][k] = ret;
}
return ret;
}
void Combi::Resize(ll n, ll k)
{
if(n_num <= n || k_num <= k)
{
n_num = (n + 1) * 2;
k_num = (k + 1) * 2;
memo.resize(n_num);
for(auto itr = memo.begin(); itr != memo.end(); ++itr)
{
itr->resize(k_num);
}
}
}
| 0 | 73,014,025 |
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ll N; cin>>N;
vector<vector<ll>> S(N,vector<ll>(3,0));
for(ll i=0; i<N; i++){
ll a,b; cin>>a>>b;
S[i][0]=a;
S[i][1]=b;
S[i][2]=a+b;
}
sort(S.begin(), S.end(), [](auto& x, auto& y){return x[2] > y[2];});
ll asum=0,bsum=0;
for(ll i=0; i<N; i++){
if(i%2==0) asum+=S[i][0];
else bsum+=S[i][1];
}
cout<<asum-bsum<<endl;
}
|
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
#define endl "\n"
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
long long MOD = 1e9+7;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
bool isCubic(long long x) {long long f = cbrt((long double)x + 0.5); return f*f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
vector<long long> divVec(long long x){vector<long long> tmp;for(long long i = 1;1LL*i*i <= x;i++){if(x % i == 0){tmp.push_back(i);if(x / i != i)
tmp.push_back(x / i);}}return tmp;}
long long invMod(long long x){return fastpow(x,MOD - 2) % MOD;}
int main() {
IO;
int n;
cin >> n;
cout << (n-2) * 180;
return 0;
}
| 0 | 17,409,110 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N_MAX = 100002;
int n;
ll L, t;
ll x[N_MAX];
int w[N_MAX];
vector <int> v1, v2;
int ans[N_MAX];
int last1 (int pos)
{
int l = 0, r = (int)v1.size() - 1;
while(l < r)
{
int mid = ((l + r + 1) >> 1);
if(x[v1[mid]] > pos)
r = mid - 1;
else
l = mid;
}
return l;
}
int last2 (int pos)
{
int l = 0, r = (int)v2.size() - 1;
while(l < r)
{
int mid = ((l + r + 1) >> 1);
if(x[v2[mid]] > pos)
r = mid - 1;
else
l = mid;
}
return l;
}
int cnt1 (int l, int r)
{
l = (l % L + L) % L;
r = (r % L + L) % L;
if(l <= r)
return last1(r) - last1(l - 1);
else if(l - r > 1)
return (int)v1.size() - 1 - cnt1(r + 1, l - 1);
return 0;
}
int cnt2 (int l, int r)
{
l = (l % L + L) % L;
r = (r % L + L) % L;
if(l <= r)
return last2(r) - last2(l - 1);
else if(l - r > 1)
return (int)v2.size() - 1 - cnt2(r + 1, l - 1);
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> L >> t;
v1.push_back(0);
v2.push_back(0);
for(int i = 1; i <= n; i++)
{
cin >> x[i] >> w[i];
if(w[i] == 1)
v1.push_back(i);
else
v2.push_back(i);
}
for(int i = 1; i <= n; i++)
if(w[i] == 1)
{
int pos = (x[i] + 2LL * t) % L;
int c = (cnt2(x[i], pos) + (2LL * t / L) * ((int)v2.size() - 1) % n) % n;
int j = ((i - 1 + c) % n + n) % n + 1;
ans[j] = ((pos - t) % L + L) % L;
}
else
{
int pos = ((x[i] - 2LL * t) % L + L) % L;
int c = (cnt1(pos, x[i]) % n + (2LL * t / L) * ((int)v1.size() - 1) % n) % n;
int j = ((i - 1 - c) % n + n) % n + 1;
ans[j] = (pos + t) % L;
}
for(int i = 1; i <= n; i++)
cout << ans[i] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
if(M >= mod) M %= mod;
else if(M < 0){
M += (abs(M)/mod + 1)*mod;
M %= mod;
}
}
ll modpow(ll x, ll n){
if(n==0) return 1;
ll res=modpow(x, n/2);
if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
if (b == 0) return a;
else return GCD(b, a % b);
}
using namespace std;
int main()
{
string S;
cin >> S;
int N = S.length();
if (N == 3) {cout << "Yes" << "\n";}
else {
string S_1 = S.substr(0, (N-1)/2);
string S_2 = S.substr(((N+1)/2), (N-1)/2);
cerr << S_1 << " " << S_2 << "\n";
bool check_1 = true, check_2 = true, check_3 = true;;
int N_1 = S_1.size();
int N_2 = S_2.size();
for(int i = 0; i < N_1; i++) {
cerr << S_1[i] << " " << S_1[(((N-1)/2) - 1) - i] << "\n";
if (S_1[i] != S_1[(((N-1)/2) - 1) - i]) {
check_1 = false;
break;
}
}
for(int i = 0; i < N_2; i++) {
if (S_2[i] != S_2[(((N-1)/2) - 1) - i]) {
check_2 = false;
break;
}
}
for(int i = 0; i < N; i++) {
if (S[i] != S[N-1-i]) {
check_3 = false;
break;
}
}
cerr << check_1 << " " << check_2 << "\n";
if(check_1==1 && check_2==1 && check_3==1) cout << "Yes" << "\n";
else cout << "No" << "\n";
}
}
| 0 | 54,318,411 |
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<int, int> mp;
for(int i = 0; i < n; i++) {
int _;
cin >> _;
mp[_]++;
}
int ans = 0;
for(auto m: mp) {
int num = m.first;
int freq = m.second;
if(num > freq) ans += freq;
else ans += freq-num;
}
printf("%d", ans);
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
int main(void){
ll n;
cin >> n;
ll s = 0;
ll e = n;
ll m = 0;
bool f[n];
string tmp;
rep(i, 0, 20){
if(i == 0){
cout << 0 << endl;
cin >> tmp;
if(tmp == "Male"){
rep(i, 0, n){
if(i % 2 == 0){
f[i] = true;
}else{
f[i] = false;
}
}
}else if(tmp == "Female"){
rep(i, 0, n){
if(i % 2 == 0){
f[i] = false;
}else{
f[i] = true;
}
}
}else{
return 0;
}
}else{
m = (s + e) / 2;
cout << m << endl;
cin >> tmp;
if(tmp == "Male"){
if(f[m] == true){
s = m;
}else{
e = m;
}
}else if(tmp == "Female"){
if(f[m] == true){
e = m;
}else{
s = m;
}
}else{
return 0;
}
}
}
}
| 0 | 19,597,042 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N;
cin >> N;
ll A[100000];
rep(i, N) cin >> A[i];
ll sum = 0;
rep(i, N) sum += A[i];
int OK = 1;
if (sum % (N * (N + 1) / 2)) OK = 0;
else {
ll k = sum / (N * (N + 1) / 2);
rep(i, N) A[i] -= k * (i + 1);
ll kazu = 0;
rep(i, N - 1) {
if ((A[i] - A[i + 1]) % N || A[i] < A[i + 1]) OK = 0;
else kazu += (A[i] - A[i + 1]) / N;
}
if (kazu > k) OK = 0;
}
if (OK) co("YES");
else co("NO");
Would you please return 0;
}
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include<functional>
#define INF 1000000000
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using P = pair<long, long>;
bool IsPrime(int num)
{
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
int main() {
int n, h;
cin >> n >> h;
vector<int> a(n), b(n);
vector<pair<int, int>> v;
int i;
int ma = 0;
for(i = 0; i < n; i++){
cin >> a[i] >> b[i];
v.push_back({a[i], 0});
v.push_back({b[i], 1});
ma = max(a[i], ma);
}
sort(v.begin(), v.end(), greater<pair<int, int>>());
int cnt = 0;
int sum = 0;
for(i = 0; i < n; i++){
if(v[i].first < ma) break;
sum += v[i].first;
cnt ++;
if(sum >= h){
cout << cnt << endl;
return 0;
}
}
if((h-sum)%ma == 0) cnt += (h-sum)/ma;
else cnt += (h-sum)/ma + 1;
cout << cnt << endl;
}
| 0 | 62,737,724 |
#include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
if (a < 1200)
cout << "ABC" << endl;
else if ( 2800 >a)
cout << "ARC" << endl;
else
cout << "AGC" << endl;
}
|
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
if(a==b && b==c && c==a){
printf("Yes\n");
}
else{
printf("No\n");
}
return 0;
}
| 0 | 10,812,752 |
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
int n;
cin>>n;
cout<<(n-2)*180<<endl;
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
string s, t; cin >> s >> t;
int dp[1001][1001] = {0};
int ls = s.size(), lt = t.size();
for (int i = 0; i <= ls; i++)
dp[i][0] = i;
for (int j = 0; j <= lt; j++)
dp[0][j] = j;
for (int i = 0; i < ls; i++) {
for (int j = 0; j < lt; j++) {
if (s[i] == t[j])
dp[i+1][j+1] = min(dp[i][j], min(dp[i][j+1]+1, dp[i+1][j]+1));
else
dp[i+1][j+1] = min(dp[i][j], min(dp[i][j+1], dp[i+1][j])) + 1;
}
}
cout << dp[ls][lt] << endl;
return 0;
}
| 0 | 25,024,482 |
#include<iostream>
int main(){
int n;
std::cin >> n;
for (int i = 0; i < n; i++){
float x1, y1, x2, y2, x3, y3, x4, y4;
std::cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
if (((y2 - y1) / (x2 - x1)) == ((y4 - y3) / (x4 - x3)))std::cout << "YES" << std::endl;
else std::cout << "NO" << std::endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;
ll dp[2002][2002];
int main()
{
int N, M;
cin >> N >> M;
vector<int> S(N), T(M);
rep(i, N) cin >> S[i];
rep(i, M) cin >> T[i];
dp[0][0] = 1;
rep(i, N + 1) {
rep(j, M + 1) {
if (i >= 1 && j >= 1 && (S[i - 1] == T[j - 1])) {
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= MOD;
}
if (i >= 1) {
dp[i][j] += dp[i - 1][j];
dp[i][j] %= MOD;
}
if (j >= 1) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
if (i >= 1 && j >= 1) {
dp[i][j] -= dp[i - 1][j - 1];
dp[i][j] %= MOD;
}
if (dp[i][j] < 0) dp[i][j] += MOD;
}
}
cout << dp[N][M] << endl;
return 0;
}
| 0 | 64,684,799 |
#include <bits/stdc++.h>
using namespace std;
#define maxn 100002
#define FOR(i, l, r) for (int i=l; i<=r; ++i)
#define FORD(i, r, l) for (int i=r; i>=l; --i)
#define REP(i, r) for (int i=0; i<(int)r; ++i)
#define REPD(i, r) for (int i=(int)r-1; i>=0; --i)
#define fi first
#define se second
#define mk make_pair
#define nil NULL
#define y0 y902
#define y1 y232
#define x0 x92
#define x1 x899
#define next asdfa
#define sz size
#define Debug(X) {cerr << #X << " = " << X << '\n';}
#define PR(A, n) {cerr << #A << " = "; FOR(i, 1, n) cerr << A[i] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; REP(i, n) cerr << A[i] << ' '; cerr << '\n';}
typedef long long ll;
typedef double db;
typedef pair<db, db> dd;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int inf = 1e9;
template<class T> int getbit(T x, int pos) {return (x>>(pos-1)) & 1;}
template<class T> void turn_on(T &x, int pos) {x = x | ((T)1<<(pos-1));}
template<class T> void turn_off(T &x, int pos) {x = x & ~((T)1<<(pos-1));}
template<class T> T sqr(T a) {return a*a;}
int n, d[maxn];
set<int> a[maxn];
priority_queue<ii, vector<ii>, greater<ii> > pq;
int main() {
scanf("%d", &n);
FOR(i, 1, n-1) {
int u, v; scanf("%d%d", &u, &v);
a[u].insert(v);
a[v].insert(u);
}
FOR(u, 1, n) {
int cnt = 0;
for (set<int>::iterator it=a[u].begin(); it!=a[u].end(); ++it) {
int v = *it;
if (a[v].sz()==1) ++cnt;
}
if (cnt>1) {
printf("First");
return 0;
}
}
FOR(i, 1, n) pq.push(ii(d[i]=a[i].sz(), i));
while (pq.sz()) {
ii u = pq.top(); pq.pop();
if (d[u.se]!=u.fi) continue;
if (d[u.se]==0) {
printf("First\n");
return 0;
}
int v = *a[u.se].begin();
d[v] = -1;
for (set<int>::iterator it=a[v].begin(); it!=a[v].end(); ++it) {
a[*it].erase(a[*it].find(v));
d[*it]--;
if (*it!=u.se) pq.push(ii(d[*it], *it));
}
}
printf("Second");
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define endl "\n"
#define pb push_back
ll N,S;
vec v,sum;
int judge(ll K,ll x){
ll i=lower_bound(all(v),x)-v.begin();
K-=S-i;
if(!i||K<=0)return 1;
if(sum[i-1]/K>=x){
return 1;
}
return 0;
}
int main(){
ll i,N,cnt=1;
cin>>N;
vec a(N);
rep(i,N)cin>>a[i];
vsort(a);
rep1(i,N){
if(a[i]==a[i-1]){
cnt++;
}else{
v.pb(cnt);
cnt=1;
}
}
v.pb(cnt);
vsort(v);
S=v.size();
sum.resize(S);
sum[0]=v[0];
rep1(i,S)sum[i]=sum[i-1]+v[i];
rep1(i,N+1){
if(i>S){
cout<<0<<endl;
continue;
}
ll ng=N/i+1,ok=0,mid;
while(ng-ok>1){
mid=(ok+ng)/2;
if(judge(i,mid)){
ok=mid;
}else{
ng=mid;
}
}
cout<<ok<<endl;
}
return 0;
}
| 0 | 89,491,690 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string o , e;
cin>>o>>e;
string ans;
int index1 =0 , index2 =0;
int len = o.length() + e.length();
for(int i=1;i<=len;i++)
{
if( i%2==1)
{
ans.push_back(o[index1]);
index1++;
} else
{
ans.push_back( e[index2]);
index2++;
}
}
cout<<ans;
}
|
#include<iostream>
using ll = long long;
using namespace std;
int main()
{
ll a, b;
cin >> a >> b;
if(a == 0){
switch(b % 4){
case 0:
cout << b << endl;
break;
case 1:
cout << 1 << endl;
break;
case 2:
cout << b+1 << endl;
break;
case 3:
cout << 0 << endl;
break;
}
} else{
switch(b % 4){
case 0:
switch((a-1) % 4){
case 0:
cout << ((a-1) ^ b) << endl;
break;
case 1:
cout << (1 ^ b) << endl;
break;
case 2:
cout << (a ^ b) << endl;
break;
case 3:
cout << b << endl;
break;
}
break;
case 1:
switch((a-1) % 4){
case 0:
cout << ((a-1) ^ 1) << endl;
break;
case 1:
cout << (1 ^ 1) << endl;
break;
case 2:
cout << (a ^ 1) << endl;
break;
case 3:
cout << 1 << endl;
break;
}
break;
case 2:
switch((a-1) % 4){
case 0:
cout << ((a-1) ^ (b+1)) << endl;
break;
case 1:
cout << (1 ^ (b+1)) << endl;
break;
case 2:
cout << (a ^ (b+1)) << endl;
break;
case 3:
cout << b+1 << endl;
break;
}
break;
case 3:
switch((a-1) % 4){
case 0:
cout << a-1 << endl;
break;
case 1:
cout << 1 << endl;
break;
case 2:
cout << a << endl;
break;
case 3:
cout << 0 << endl;
break;
}
break;
}
}
return 0;
}
| 0 | 89,270,919 |
#include "bits/stdc++.h"
using namespace std;
int main() {
long long N;
cin >> N;
vector<pair<long long, long long> > D(N);
vector<long long> E(N);
vector<long long> COUNT(N, 1);
vector<pair<long long, long long> > ANS;
for (int i = 0; i < N; i++) cin >> D[i].first, D[i].second = i, E[i] = D[i].first;
sort(D.begin(), D.end());
sort(E.begin(), E.end());
for (int i = N - 1; i > 0; i--) {
long long C = COUNT[D[i].second];
long long ND = D[i].first - (N - C * 2);
long long it = lower_bound(E.begin(), E.end(), ND) - E.begin();
if (D[it].first != ND || i <= it) {
cout << -1 << endl;
return 0;
}
ANS.push_back({ D[i].second, D[it].second });
COUNT[D[it].second] += COUNT[D[i].second];
}
vector<vector<long long> > V(N);
for (int i = 0; i < N - 1; i++) {
V[ANS[i].first].push_back(ANS[i].second);
V[ANS[i].second].push_back(ANS[i].first);
}
vector<long long> Dists(N, -1);
Dists[D[0].second] = 0;
queue<long long> Q;
Q.push(D[0].second);
while (!Q.empty()) {
long long P = Q.front();
Q.pop();
for (long long NP : V[P]) {
if (Dists[NP] == -1) {
Dists[NP] = Dists[P] + 1;
Q.push(NP);
}
}
}
long long SUM = 0;
for (int i = 0; i < N; i++) SUM += Dists[i];
if (SUM != D[0].first) cout << -1 << endl;
else for (int i = 0; i < N - 1; i++) cout << ANS[i].first + 1 << " " << ANS[i].second + 1 << endl;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
cin >> s;
int ans = s.length()-1;
for(; ; ans--){
if(ans % 2 != 0) continue;
bool isok = true;
for(int i = 0; i < ans/2; i++){
if(s[i] != s[ans/2+i]) isok = false;
}
if(isok) break;
}
cout << ans << endl;
return 0;
}
| 0 | 51,810,908 |
#include<bits/stdc++.h>
using namespace std;
vector<int> adj[100001];
bool visited[100001];
int ans[100001];
void bfs(){
queue<int> q;
q.push(1);
visited[1] = true;
while(q.size()){
int cur = q.front(); q.pop();
for(auto i : adj[cur]){
if(!visited[i]){
ans[i] = cur;
q.push(i);
visited[i] = true;
}
}
}
}
int main()
{
memset(visited,false,sizeof(visited));
memset(ans,0,sizeof(ans));
int nodes,edges;
cin >> nodes >> edges;
for(int i=0;i<edges;i++)
{
int u,v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
bfs();
cout << "Yes\n";
for(int i=2;i<=nodes;i++)
cout << ans[i] << "\n";
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
const int maxn = 1e5 + 5;
int dp[maxn][21] , a[maxn] , n , L;
int ask (int x , int c)
{
int pos = x;
if (dp[pos][0] == -1) return 1e9;
for (int i = 20 ; i >= 0 ; i--){
if (c & (1 << i)){
if (pos == -1 || dp[pos][i] == -1) return 1e9;
pos = dp[pos][i];
}
}
if (pos == -1) return 1e9;
return pos;
}
void solve ()
{
for (int i = 1 ; i <= n ; i++) {
int l = 1 , r = n , mid;
while (l <= r){
mid = l + r >> 1;
if (a[mid] <= a[i] + L) l = mid + 1;
else r = mid - 1;
}
dp[i][0] = r;
}
dp[n][0] = -1;
for (int i = 1 ; i <= 20 ; i++)
for (int j = 1 ; j <= n; j++){
if (dp[j][i - 1] == -1) dp[j][i] = -1;
else dp[j][i] = dp[dp[j][i - 1]][i - 1];
}
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
cin >> L;
solve ();
int q;cin >> q;
while (q--){
int x , y; cin >> x >> y;
if (x > y) swap(x , y);
int l = 1 , r = n;
while (l <= r){
int mid = l + r >> 1;
if (ask(x , mid) > y) r = mid - 1;
else l = mid + 1;
}
if (ask(x , r) < y) r++;
cout << r << endl;
}
return 0;
}
| 0 | 28,053,770 |
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
int main(){
int n,j,knum;
string s;
string c[10] = {"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
cin >> n;
while(n){
cin >> s;
for(int i = 0;i<s.size();i++){
if(s[i] == '0')continue;
for(j=0;j<s.size();j++)
if(s[i+j+1] == '0')break;
knum = j%c[s[i]-'0'].size();
cout << c[s[i]-'0'][knum];
i += j;
}
cout << "\n";
n--;
}
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100001
struct Node{
int num;
struct Node *parent;
struct Node *left_child;
struct Node *right_bro;
};
struct Node node[MAX];
int calc_depth(int num){
if (node[num].parent == NULL){
return 0;
}
return calc_depth(node[num].parent->num) + 1;
}
void calc_type(int num, char* s){
if(node[num].parent == NULL){
strcpy(s, "root");
return;
}
if(node[num].left_child == NULL){
strcpy(s, "leaf");
return;
}
strcpy(s, "internal node");
return;
}
void print_children(int num){
struct Node *nd = node[num].left_child;
bool is_first = true;
while(nd){
if(is_first){
printf("%d", nd->num);
is_first = false;
}else{
printf(", %d", nd->num);
}
nd = nd->right_bro;
}
}
void output(int n){
for(int i = 0; i < n; i++){
printf("node %d: ", i);
if(node[i].parent != NULL){
printf("parent = %d, ", node[i].parent->num);
}else{
printf("parent = -1, ");
}
printf("depth = %d, ", calc_depth(i));
char s[30];
calc_type(i, s);
printf("%s, ", s);
printf("[");
print_children(i);
printf("]\n");
}
return;
}
int main(void){
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++){
node[i].num = i;
node[i].parent = NULL;
node[i].left_child = NULL;
node[i].right_bro = NULL;
}
for(int i = 0; i < n; i++){
int num;
scanf("%d", &num);
int left_child_node_num = -1;
int child_node_num;
int node_num;
scanf("%d", &node_num);
for(int j = 0; j < node_num; j++){
scanf("%d", &child_node_num);
if (j == 0){
node[num].left_child = &(node[child_node_num]);
}
if(left_child_node_num != -1){
node[left_child_node_num].right_bro = &(node[child_node_num]);
}
node[child_node_num].parent = &(node[num]);
left_child_node_num = child_node_num;
}
}
output(n);
return 0;
}
| 0 | 97,199,683 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, s1 = 0, s2 = 0, diff = 10007, dif;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 1; i < n; i++)
{
s1 = s2 = 0;
for (int j = 0; j < i; j++)
{
s1 = s1 + a[j];
}
for (int k = i; k < n; k++)
{
s2 = s2 + a[k];
}
if ((s1 - s2) < 0)
{
dif = s2-s1;
}
else
{
dif = s1 - s2;
}
diff = min(diff, dif);
}
cout << diff ;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void){
int k,s;
int ans = 0;
cin >> k >> s;
for(int i=0;i<=k;i++) {
for(int j=0;j<=k;j++) {
int z=s-i-j;
if(0<=z && z<=k) ans++;
}
}
cout << ans << endl;
return 0;
}
| 0 | 46,523,049 |
#include"bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
int main() {
string s,ss;
cin >> s;
ss = s.substr(0, 4) + s.substr(5, 2) + s.substr(8, 2);
int day = stoi(ss);
int v = 20190430;
if (v >= day)cout << "Heisei" << endl;
else cout << "TBD" << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
long a[n + 1];
for (long i = 1; i <= n; i++) cin >> a[i];
if (n % 2 == 0)
{
for (long i = n; i >= 2; i = i - 2) cout << a[i] << ' ';
for (long i = 1; i < n; i = i + 2) cout << a[i] << ' ';
}
else
{
for (long i = n; i >= 1; i = i - 2) cout << a[i] << ' ';
for (long i = 2; i < n; i = i + 2) cout << a[i] << ' ';
}
}
| 0 | 94,384,662 |
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 10000+2;
long long cnt[111];
long long m,n,a=0,b,W;
const int INF = 1e9+1;
const int mod = 1e9 + 7;
string s1,s2;
long dist[max_n],s[max_n],w[max_n],v[max_n];
long long dp[max_n][max_n];
vector<vector<int> > G;
bool isprime(long long xx){
if(xx == 2) return true;
if(xx % 2==0 || xx<2) return false;
long long ii = 3;
while(ii*ii <= xx){
if(xx %ii == 0) return false;
ii += 2;
}
return true;
}
long long gcd(long long xx, long long yy){
if(yy == 0) return xx;
long long k = xx/yy;
long long c = xx - k*yy;
return gcd(yy, c);
}
void solve(){
for(int i=1 ; i<=s1.size() ; i++){
dp[i][0] = i;
}
for(int j=1 ; j<=s2.size() ; j++){
dp[0][j] = j;
}
for(int i=1 ; i<=s1.size() ; i++){
for(int j=1 ; j<=s2.size() ; j++){
long long x = min(dp[i-1][j]+1, dp[i][j-1]+1);
if(s1[i-1] == s2[j-1]){
x = min(x,dp[i-1][j-1]);
dp[i][j] = x;
}else{
x = min(x, dp[i-1][j-1]+1);
dp[i][j] = x;
}
}
}
cout << dp[s1.size()][s2.size()] << endl;
}
int main(){
cin >> s1 >> s2;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define float long double
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define endl '\n'
#define pii pair<int, int>
#define min3(a,b,c) min(a, min(b, c))
#define max3(a,b,c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mex 1000005
int sei[mex],vis[mex];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin>>n;
int arr[n],gcd=0;
for(int i=0;i<n;i++){
cin>>arr[i];
gcd=__gcd(gcd,arr[i]);
}
if(gcd!=1){
cout<<"not coprime"<<endl;
return 0;
}
for(int i=0;i<mex;i++) sei[i]=i;
sei[0]=sei[1]=-1;
for(int i=0;i<mex;i++){
if(sei[i]==i){
for(int j=2*i;j<mex;j+=i) sei[j]=i;
}
}
for(int i=0;i<n;i++){
while(arr[i]!=1){
int x=sei[arr[i]];
if(vis[x]==1){
cout<<"setwise coprime"<<endl;
return 0;
}
vis[x]=1;
while(arr[i]%x==0) arr[i]/=x;
}
}
cout<<"pairwise coprime"<<endl;
}
| 0 | 20,389,433 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
map<int,int> mi,me,md;
set<int> s;
rep(i,n) {
cin >> a[i];
mi[a[i]+1]++;
me[a[i]]++;
md[a[i]-1]++;
s.insert(a[i]+1);
s.insert(a[i]);
s.insert(a[i]-1);
}
int ans = 0;
for (auto si:s) {
int cnt = 0;
if (mi.count(si)) cnt += mi[si];
if (me.count(si)) cnt += me[si];
if (md.count(si)) cnt += md[si];
ans = max(cnt, ans);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
int main(int argc, const char * argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
int h,w;
cin>>h>>w;
char maze[h][w];
vector<vector<int>>black(h,vector<int>(w,-1));
queue<p>que;
rep(i,h){
rep(j,w){
cin>>maze[i][j];
if(maze[i][j]=='#'){
que.emplace(i,j);
black[i][j]=0;
}
}
}
int ans=0;
while(!que.empty()){
int x,y;
tie(y,x)=que.front();
que.pop();
ans=black[y][x];
rep(i,4){
int a=x+dx[i];
int b=y+dy[i];
if(a<0||a>=w||b<0||b>=h)continue;
if(black[b][a]!=-1)continue;
black[b][a]=black[y][x]+1;
que.emplace(b,a);
}
}
cout<<ans<<endl;
return 0;
}
| 0 | 61,583,383 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
long long a[n];
for(int i = 0; i < n; i++){
cin >> a[i];
}
sort(a,a+n);
unsigned long long p = 0,q = 0;
for(int i = 1;i < n; i++ ){
if(a[i-1] == a[i]){
p = q;
q = a[i];
a[i-1] = 0;
a[i] = 0;
}
}
cout << p*q << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2*1e18;
vector<long long> A,Al,Ar;
void regist(vector<long long> D){
A=D;
Al=D;
for(long long i=0;i<((long long)D.size())-1;i++){
Al[i+1]=Al[i]+D[i+1];
}
Ar=D;
for(long long i=((long long)D.size())-2;i>=0;i--){
Ar[i]=Ar[i+1]+D[i];
}
}
long long accu(long long l,long long r){
if(l<=r){
if(l==0){
return Al[r];
}else{
return Al[r]-Al[l-1];
}
}else{
return Al[r]+Ar[l];
}
}
long long sum(void){
return Ar[0];
}
signed main(void){
long long N,K,a;
vector<long long> P,C;
cin >> N >> K;
for(int i=0;i<N;i++){
cin >> a;
a--;
P.push_back(a);
}
for(int i=0;i<N;i++){
cin >> a;
C.push_back(a);
}
vector<bool> visited(N,false);
long long Ans = -INF;
for(int i=0;i<N;i++){
if(visited[i])continue;
long long k = i;
vector<long long> now={};
while(1){
if(visited[k])break;
visited[k]=true;
now.push_back(C[k]);
k = P[k];
}
if(now.size()==0)continue;
regist(now);
long long S = sum();
if(S<=0){
long long num=-INF;
long long L = now.size();
for(long long i=0;i<L;i++){
for(long long j=0;j<L;j++){
long long s;
if(i<=j){
s = j-i+1;
}else{
s = L-(i-j-1);
}
if(s<=K){
num = max(num,accu(i,j));
}
}
}
Ans = max(Ans,num);
}else{
long long num = -INF;
long long L = now.size();
for(long long i=0;i<L;i++){
for(long long s=max(1ll,K-L+1);s<=K;s++){
long long temp = accu(i,(i+s-1)%L);
temp += S*((s-1)/L);
num = max(num,temp);
}
}
Ans = max(Ans,num);
}
}
cout << Ans << endl;
return 0;
}
| 0 | 90,468,269 |
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
using namespace std;
map< char, int > m;
map< int, string > mm;
int sToi(string s){
int ret = 0;
REP(i,0,s.size()){
int tmp = 1;
if(isdigit(s[i])){
ret += (s[i] - '0') * m[s[i+1]];
i++;
}else{
ret += m[s[i]];
}
}
return ret;
}
string iTos(int num){
string s = "";
int tmp = 1000;
REP(i,0,4){
if(num / tmp > 1) s += to_string(num / tmp) + mm[tmp];
else if(num / tmp == 1) s += mm[tmp];
num %= tmp;
tmp /= 10;
}
return s;
}
int main() {
int n;
cin>>n;
m['i'] = 1;
m['x'] = 10;
m['c'] = 100;
m['m'] = 1000;
mm[1] = "i";
mm[10] = "x";
mm[100] = "c";
mm[1000] = "m";
REP(i,0,n){
string s1, s2;
cin>>s1>>s2;
cout<<iTos(sToi(s1) + sToi(s2))<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
int n;
cin >> n;
vector<ll> a(n+1);
vector<ll> b(n);
rep(i,n+1) cin >> a[i];
rep(i,n) cin >> b[i];
ll ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] >= b[i]) {
ans += b[i];
}
else {
ans += a[i];
b[i] -= a[i];
if (a[i+1] >= b[i]) {
ans += b[i];
a[i+1] -= b[i];
}
else {
ans += a[i+1];
a[i+1] = 0;
}
}
}
cout << ans << endl;
return 0;
}
| 0 | 40,521,814 |
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(){
int R, G, B, N;
cin >> R >> G >> B >> N;
int ans = 0;
rep(r, N+1){
rep(g, N/G+1){
double tmp = (double)(N - R*r - G*g)/B;
if(tmp == (int)tmp ){
if(tmp >= 0)
ans++;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
while(1){
int n,k,b[100100]={},sum=0,sum1=0,ans=0,j=0;
cin>>n>>k;
if(n==0) break;
for(int i=0;i<n;i++){
cin>>b[i];
if(i<k){
sum+=b[i];
}else{
ans=max(ans,sum);
sum=sum-b[j]+b[i];
j++;
}
}
cout<<ans<<endl;
}
return 0;
}
| 0 | 12,650,859 |
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;
ll gcd(ll a, ll b) {
if (a == 0)return b;
return gcd(b % a, a);
}
bool isperfect(ll n) {
ll y = sqrt(n);
if (n % y == 0 && y * y == n)return true;
return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
if(a.first == b.first) return a.second>b.second;
return a.first < b.first;
}
ll powi(ll a, ll b) {
ll ans = 1;
while (b > 0) {
if (b & 1)ans = (ans * a);
b = b >> 1;
a = (a * a);
}
return ans;
}
bool isprime(ll n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)return false;
}
return true;
}
bool prime[10000000];
void seive() {
prime[1] = true;
for (int i = 2; i * i < 10000000; i++) {
if (prime[i])continue;
for (int j = i * i; j < 10000000; j += i) {
prime[j] = true;
}
}
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n,m;
cin>>n>>m;
ll sum=0;
for(int i=0;i<m;i++){
ll x;cin>>x;
sum+=x;
}
ll ans=n-sum;
if(ans<0) ans=-1;
cout<<ans;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
const int MOD = 998244353,MAX = 1e6+5;
ll powN(ll a,ll p)
{
if(p==0) return 1;
ll z=powN(a,p/2);
z=(z*z)%MOD;
if(p%2) z=(z*a)%MOD;
return z;
}
vector<bool> is_prime(MAX, true);
vector<int> MinDiv(MAX);
void Sieve()
{
is_prime[0] = is_prime[1] = false;
int i,j;
for (i = 2; i*i <= MAX; i++)
{
if (is_prime[i])
{
MinDiv[i]=i;
for (j = i * i; j <= MAX; j += i)
{
is_prime[j] = false;
MinDiv[j]=i;
}
}
}
for(int i=2;i<=MAX;i++) if(is_prime[i]) MinDiv[i]=i;
}
int main()
{
int n,k;
cin>>n>>k;
vi A(n);
take(A,0,n);
sort(all(A));
int gcd = 0;
for(int i=0;i<n;i++) gcd = __gcd(gcd,A[i]);
bool can=false;
for(int i=n-1;i>=0;i--)
{
if(A[i]>=k&&(A[i]-k)%gcd==0) can=true;
}
if(can) cout<<"POSSIBLE"<<endl;
else cout<<"IMPOSSIBLE"<<endl;
}
| 0 | 69,921,944 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int n;
cin>>n;
int sum = 0;
vector<int> l(n),r(n);
rep(i,n){
cin>>l.at(i)>>r.at(i);
sum += r.at(i)-l.at(i)+1;
}
cout<<sum<<endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M = 0;
cin >> N;
vector<int> x(N);
for (int i = 0; i < N; ++i)
cin >> x[i];
while (N >> M)
M++;
int L;
cin >> L;
vector<vector<ll>> nxt(M, vector<ll>(N, N - 1));
for (int i = 0; i < N; ++i)
nxt[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
for (int i = 0; i + 1 < M; ++i)
for (int j = 0; j < N; ++j)
nxt[i + 1][j] = nxt[i][nxt[i][j]];
int Q;
cin >> Q;
for (int i = 0; i < Q; ++i) {
int a, b, res = 0;
cin >> a >> b;
a--, b--;
if (a == b) {
cout << res << '\n';
continue;
}
if (a > b)
swap(a, b);
for (int j = M - 1; j >= 0; --j) {
if (nxt[j][a] < b) {
a = nxt[j][a];
res += (1 << j);
}
}
cout << res + 1 << '\n';
}
return 0;
}
| 0 | 79,144,326 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
int M;
cin >> M;
vec<ll> d(M), c(M);
rep(i,M){
cin >> d[i] >> c[i];
}
ll sumdc = 0;
ll sumc = 0;
ll ans = 0;
rep(i,M){
sumdc += d[i] * c[i];
sumc += c[i];
}
ans = sumc - 1 + (sumdc - 1)/9;
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using ll = long long;
using namespace std;
const int N = 2e9;
void solveCase() {
string s;
cin >> s;
if(s.length() < 25) {
cout << s;
for(char c = 'a'; c <= 'z'; c++) {
if(s.find(c) == string::npos) {
cout << c;
break;
}
}
cout << endl;
} else if(s == "zyxwvutsrqponmlkjihgfedcba") {
cout << -1 << endl;
} else {
string t = s;
next_permutation(s.begin(), s.end());
for(int i = 1; i <= 26; i++) {
if(s.substr(0, i) > t) {
cout << s.substr(0, i) << endl;
return;
}
}
}
}
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int testcase = 1;
for(int i = 0; i < testcase; i++) {
solveCase();
}
return 0;
}
| 0 | 15,389,480 |
#include <iostream>
using namespace std;
int dp[21][50010], c[21];
const int INF = 1e9;
int main(void) {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> c[i];
for (int i = 0; i < m; i++) {
for (int j = 1; j <= n+1; j++) {
if (!i) dp[i][j] = dp[i][j - c[i]] + 1;
else {
if (j - c[i] >= 0) dp[i][j] = min(dp[i-1][j], dp[i][j - c[i]] + 1);
else dp[i][j] = dp[i-1][j];
}
}
}
cout << dp[m-1][n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
ll n;
cin >> n;
vector<ll> a(n), b(n);
rep(i, n) cin >> a[i] >> b[i];
ll ans = 0;
for (ll i = n - 1; i >= 0; i--) {
if ((a[i] + ans) % b[i] == 0) continue;
ll r = (ans + a[i]) / b[i];
ll toadd = ((r + 1) * b[i]) - (ans + a[i]);
ans += toadd;
}
cout << ans << endl;
}
| 0 | 100,651,097 |
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if( a % b == 0 )
cout << 0;
else cout << 1;
}
|
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n=1):n(n), f(n+1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i]) continue;
primes.push_back(i);
f[i] = i;
for (ll j = i*i; j <= n; j += i) {
if (!f[j]) f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x;}
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<ii> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0) return {};
vector<ii> res(1, ii(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
vector<pair<ll,int>> factor(ll x) {
vector<pair<ll,int>> res;
for (int p : primes) {
int y = 0;
while (x%p == 0) x /= p, ++y;
if (y != 0) res.emplace_back(p,y);
}
if (x != 1) res.emplace_back(x,1);
return res;
}
};
int main() {
int n; cin >> n;
Sieve sieve(n+2);
map<int, int> primes;
for (int i=1; i<=n; i++) {
vii vec = sieve.factor(i);
for (auto p: vec) {
primes[p.first] += p.second;
}
}
auto num = [&](int n) {
int ret = 0;
for (auto p: primes) {
if (p.second >= n-1) ++ret;
}
return ret;
};
ll ans = num(75) + num(25) * (num(3)-1) + num(15) * (num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)/2;
printf("%lld\n", ans);
return 0;
}
| 0 | 49,010,279 |
#include<bits/stdc++.h>
#define int long long
#define fi first
#define si second
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)
#define done(i) cout<<"done = "<<i<<endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
main()
{
fast
string s;
cin>>s;
map<char,bool>vis;
string chk="";
for(char ch='z';ch>='a';ch--)chk+=ch;
for(char x:s)
{
vis[x]=true;
}
if(s==chk)
{
cout<<"-1"<<endl;
}
if(s.size()==26)
{
for(int i=25;i>=0;i--)
{
int flag=0;
char ok;
for(int j=i+1;j<26;j++)
{
if(s[j]>s[i])
{
if(flag==0)ok=s[j];
else if(s[j]<ok)ok=s[j];
flag=1;
}
}
if(flag==1)
{
string ses=s.substr(0,i);
ses+=ok;
cout<<ses<<endl;
return 0;
}
}
}
else
{
for(char ch='a';ch<='z';ch++)
{
if(vis[ch]!=true)
{
s+=ch;
break;
}
}
cout<<s<<endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)
int main() {
int N, M, K;
cin >> N >> M >> K;
bool ans = false;
rep(i, M+1) {
rep(j, N+1) {
if (i*N+j*M-2*i*j == K) {
ans = true;
break;
}
}
}
if (ans) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}
| 0 | 3,329,210 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
int main(){
int x,y,a,b,c;
cin>>x>>y>>a>>b>>c;
vi p(a), q(b), r(c);
rep(i,a)cin>>p[i];
rep(i,b)cin>>q[i];
rep(i,c)cin>>r[i];
sort(p.rbegin(), p.rend());
sort(q.rbegin(), q.rend());
rep(i,x)r.push_back(p[i]);
rep(i,y)r.push_back(q[i]);
sort(r.rbegin(), r.rend());
ll ans = 0;
rep(i,x+y)ans += r[i];
cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
long long int min = 0;
for (long long int i = 0; i < s1.size(); i++) {
if (s1[i] != s2[i]) min++;
}
cout << min;
return 0;
}
| 0 | 78,981,715 |
#include<stdio.h>
int main(){
int h,n;
scanf("%d%d",&h,&n);
int a[n];
int i,j;
int tmp;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
h=h-a[i];
}
if(h<=0){
printf("Yes");
}else{
printf("No");
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#define DEBUG if(false)
using namespace std;
int main(){
int N, K;
cin >> N >> K;
vector<int> A(N, 0);
int which_1 = -1;
for(int i = 0; i < N; i++){
cin >> A[i];
if(A[i] == 1){
which_1 = i;
}
}
int K_left = (which_1-K+1>0)?which_1-K+1:0;
DEBUG printf("K_left : %d\n", K_left);
int minimum = INT_MAX;
for(int i = 0; i < K; i++){
int l_left = K_left + i;
int r_left = l_left + K-1;
if(r_left > N-1) break;
DEBUG printf("l_left : %d\n", l_left);
DEBUG printf("r_left : %d\n", r_left);
int count = 1;
count += (l_left + K-2)/(K-1);
count += (N-1 - r_left + K-2)/(K-1);
DEBUG printf("%d\n", count);
if(minimum > count){
minimum = count;
}
}
cout << minimum << endl;
return 0;
}
| 0 | 2,537,931 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long S,C;
cin >> S >> C;
if(S * 2 >= C)cout << C/2 <<endl;
else{
cout << S+(C-2*S)/4 <<endl;
}
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
long long A, B;
cin >> A >> B;
vector<long long> usea(40, 0), useb(40, 0);
long long t = 1;
long long ans = 0;
long long cnt = 0;
while(B >= t){
long long syo = B / (t * 2);
long long m = B % (t * 2);
if(m >= t - 1) m -= t - 1;
else m = 0;
useb[cnt] += syo * t + m;
t *= 2;
cnt++;
}
t = 1;
cnt = 0;
A--;
while(A >= t){
long long syo = A / (t * 2);
long long m = A % (t * 2);
if(m >= t - 1) m -= t - 1;
else m = 0;
usea[cnt] += syo * t + m;
t *= 2;
cnt++;
}
for(int i = 0; i < 40; i++){
if((useb[i] - usea[i]) % 2 == 1) ans += (1LL << i);
}
cout << ans << endl;
}
| 0 | 25,547,524 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll h1,m1,h2,m2,k;
cin>>h1>>m1>>h2>>m2>>k;
ll remind=(h2-h1)*60+m2-m1;
ll ans=remind-k;
cout<<ans<<endl;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int gcd(int a, int b) {
if(a % b == 0) {
return b;
}
else {
return(gcd(b, a % b));
}
}
int main() {
int w, h, n;
cin >> w >> h >> n;
vector<int> x(n);
vector<int> y(n);
vector<int> a(n);
rep(i, n) cin >> x.at(i) >> y.at(i) >> a.at(i);
vector<vector<bool>> white(h, vector<bool> (w, true));
rep(i, n) {
if (a.at(i) == 1) {
rep(k, x.at(i)) {
rep(j, h) {
white.at(j).at(k) = false;
}
}
}
else if (a.at(i) == 3) {
rep(k, y.at(i)) {
rep(j, w) {
white.at(k).at(j) = false;
}
}
}
else if (a.at(i) == 2) {
for (int k = x.at(i); k < w; k++) {
rep(j, h) {
white.at(j).at(k) = false;
}
}
}
else if (a.at(i) == 4) {
for (int k = y.at(i); k < h; k++) {
rep(j, w) {
white.at(k).at(j) = false;
}
}
}
}
int count = 0;
rep(i, h) {
rep(j, w) {
if (white.at(i).at(j)) {
count++;
}
}
}
cout << count << endl;
}
| 0 | 57,714,250 |
#include <iostream>
using namespace std;
int main() {
int A,B;
cin >> A>> B;
if(A%3==0&&A!=0){
cout <<"Possible"<<endl;
return 0;
}
if(B%3==0&&B!=0){
cout <<"Possible"<<endl;
return 0;
}
if((A+B)%3==0&&(A+B)!=0){
cout <<"Possible"<<endl;
return 0;
}
if(A%3!=0&&B%3!=0&&(A+B)%3!=0){
cout <<"Impossible"<<endl;
}
if(A==0&&B==0){
cout <<"Impossible"<<endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(){
long long H,W;
cin >> H >> W;
long long S = H * W;
long long res=LONG_LONG_MAX;
for(int i=1;i<W;i++){
long long S1 = H*i;
long long ma=S1,mi=S1;
long long S2 = (H/2) * (W-i);
ma=max(ma,S2),mi=min(mi,S2);
long long S3 = S - S1 - S2;
ma=max(ma,S3),mi=min(mi,S3);
res=min(res,ma-mi);
ma=S1,mi=S1;
S2 = ((W-i)/2) * H;
ma=max(ma,S2),mi=min(mi,S2);
S3 = S - S1 - S2;
ma=max(ma,S3),mi=min(mi,S3);
res=min(res,ma-mi);
}
swap(W,H);
for(int i=1;i<W;i++){
long long S1 = H*i;
long long ma=S1,mi=S1;
long long S2 = (H/2) * (W-i);
ma=max(ma,S2),mi=min(mi,S2);
long long S3 = S - S1 - S2;
ma=max(ma,S3),mi=min(mi,S3);
res=min(res,ma-mi);
ma=S1,mi=S1;
S2 = ((W-i)/2) * H;
ma=max(ma,S2),mi=min(mi,S2);
S3 = S - S1 - S2;
ma=max(ma,S3),mi=min(mi,S3);
res=min(res,ma-mi);
}
cout << res << endl;
return 0;
}
| 0 | 1,038,287 |
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
ll dp[1000][1000];
int main(){
int n,K;
cin >> n >> K;
ll h[n+1]={};
rep(i,n)cin >> h[i+1];
rep(i,500)rep(j,500)dp[i][j]=longinf;
dp[0][K]=0;
ll ans=longinf;
for(int i=0;i<=n;i++){
for(int j=0;j<=K;j++){
if(dp[i][j]<longinf){
if(j>=n-i) ans=min(ans,dp[i][j]);
for(int k=i+1;k<=min(n,i+j+1);k++){
dp[k][j-(k-i-1)]=min(dp[k][j-(k-i-1)],dp[i][j]+max(0LL,h[k]-h[i]));
}
}
}
}
cout << ans << endl;
return 0;}
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
cin.tie(0);ios::sync_with_stdio(false);
ll N;
string S;
cin >> N >> S;
ll ans = 0;
reps(i,0,9){
reps(j,0,9){
reps(k,0,9){
string t = to_string(i) + to_string(j) + to_string(k);
int pt = 0;
bool flag = false;
rep(i,0,N){
if(pt >= 3){
flag = true;
break;
}
if(S[i] == t[pt]) pt++;
}
if(pt >= 3) flag = true;
if(flag) ans++;
}
}
}
cout << ans << enld;
return 0;
}
| 0 | 68,599,460 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int numbers[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << numbers[k-1];
}
|
#include<bits/stdc++.h>
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define lll long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read freopen("input.txt", "r", stdin)
#define Write freopen("output.txt", "w", stdout)
#define INF 99999999999999
void solve()
{
int n;
cin>>n;
while(n>0)
{
if(n%10==7)
{
cout<<"Yes"<<endl;
return;
}
n/=10;
}
cout<<"No"<<endl;
}
int main()
{
fast
#ifndef ONLINE_JUDGE
#endif
solve();
}
| 0 | 1,345,153 |
#include <stdio.h>
int main(){
int count,i,cc;
char data[33];
while(1){
for(i=0;i<32;i++){
data[i]='0';
}
scanf("%s",data);
if(data[0]=='#') break;
if(data[0]=='q'||data[0]=='w'||data[0]=='e'||data[0]=='r'||data[0]=='t'||data[0]=='a'||data[0]=='s'||data[0]=='g'||data[0]=='z'||data[0]=='x'||data[0]=='c'||data[0]=='v'||data[0]=='b'||data[0]=='d'||data[0]=='f'){
cc=1;
}else if(data[0]=='y'||data[0]=='u'||data[0]=='i'||data[0]=='o'||data[0]=='p'||data[0]=='h'||data[0]=='j'||data[0]=='k'||data[0]=='l'||data[0]=='n'||data[0]=='m'){
cc=2;
}
count=0;
for(i=1;i<32;i++){
if(data[i]=='q'||data[i]=='w'||data[i]=='e'||data[i]=='r'||data[i]=='t'||data[i]=='a'||data[i]=='s'||data[i]=='g'||data[i]=='z'||data[i]=='x'||data[i]=='c'||data[i]=='v'||data[i]=='d'||data[i]=='b'||data[i]=='f'){
if(cc==2){
count++;
cc=1;
}
}else if(data[i]=='y'||data[i]=='u'||data[i]=='i'||data[i]=='o'||data[i]=='p'||data[i]=='h'||data[i]=='j'||data[i]=='k'||data[i]=='l'||data[i]=='n'||data[i]=='m'){
if(cc==1){
count++;
cc=2;
}
}
}
printf("%d\n",count);
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};
class AHaiku {
public:
void solve(istream& in, ostream& out) {
string s; in >> s;
rep(i,5) out << s[i];
out << " ";
for(int i = 6; i < 13; i++) out << s[i];
out << " ";
for(int i = 14; i < 19; i++) out << s[i];
out << endl;
}
};
int main() {
AHaiku solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 0 | 78,867,661 |
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ull unsigned long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define mod (1000*1000*1000+7)
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
ll modPow(ll x,ll n,ll m)
{
if(n==0)
return 1%m;
ll u = modPow(x,n/2,m);
u=u*u%m;
if(n%2==1)
u=u*x%m;
return u;
}
ll gcd(ll a,ll b)
{
if(b==0)
return a;
return gcd(b,a%b);
}
ll seive[1000000];
void seiveForm()
{
ll i,j;
seive[0]=seive[1]=1;
f(i,2,100000)
{
if(seive[i]==0)
for(j=i*i;j<1000000;j+=i)
seive[j]=1;
}
}
bool isPerfectSquare(ll num)
{
double n = sqrt(num);
return n==(ll)n?true:false;
}
ll countSetbits(ll num)
{
ull temp=0;
while(num){
num=num&(num-1);
temp++;
}
return temp;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll w,h,n,i,j,k,l,temp,t1,t2,ans;
temp=t1=t2=ans=0;
cin>>w>>h>>n;
ll x[n],y[n],a[n];
rep(i,n)
cin>>x[i]>>y[i]>>a[i];
rep(i,n)
{
if(a[i]==1)
t1=max(x[i],t1);
else if(a[i]==2)
w=min(x[i],w);
else if(a[i]==3)
t2=max(y[i],t2);
else
h=min(y[i],h);
}
if((w-t1)<0 || (h-t2)<0)
cout<<"0\n";
else
cout<<(w-t1)*(h-t2)<<endl;
return 0;
}
|
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>
#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
const ll inf = 1LL << 60;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll N, L, Q;
cin >> N;
vector<ll> x(N+1);
x[N] = inf;
Rep (i, N) cin >> x[i];
cin >> L >> Q;
vector<ll> a(Q), b(Q);
Rep (i, Q) {
cin >> a[i] >> b[i];
a[i]--; b[i]--;
}
vector<vector<ll>> dpi(20, vector<ll>(N, 0)), dpd(20, vector<ll>(N, 0));
Rep (i, N) {
dpi[0][i] = upper_bound(x.begin(), x.end(), x[i]+L) - x.begin() - 1;
}
Rep (i, 19) {
Rep (j, N) {
dpi[i+1][j] = dpi[i][dpi[i][j]];
}
}
Rep (i, Q) {
if (a[i] > b[i]) swap(a[i], b[i]);
ll day = 0;
for (ll j = 19; j >= 0; j--) {
if (dpi[j][a[i]] < b[i]) {
a[i] = dpi[j][a[i]];
day += 1 << j;
}
}
cout << day + 1 << "\n";
}
}
| 0 | 86,013,761 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
char ch;
cin>>a>>ch>>b;
switch(ch)
{
case '+':
cout<<a+b;
break;
case'-':
cout<<a-b;
break;
}
}
|
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> l[101];
int matrix[100][100];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int u,k;
cin>>u>>k;
for(int j=0;j<k;j++)
{
int tmp;
cin>>tmp;
l[u].push_back(tmp);
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
matrix[i][j]=0;
}
}
for(int i=1;i<n+1;i++)
{
for(int j=0;j<l[i].size();j++)
{
matrix[i-1][l[i][j]-1]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(j!=0)
cout<<" ";
cout<<matrix[i][j];
}
cout<<endl;
}
}
| 0 | 100,811,390 |
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
using Weight = int;
struct Edge {
int src, dst;
Weight weight;
Edge(const int s = 0, const int d = 0, const Weight w = 0) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;
class Graph {
std::vector<Edges> g;
using iterator = std::vector<Edges>::iterator;
using const_iterator = std::vector<Edges>::const_iterator;
public:
Graph(const int size = 0) : g(size) {}
size_t size() const { return g.size(); }
const Edges &operator[](const int i) const { return g[i]; }
void addArc(const int src, const int dst, const Weight w = 1) { g[src].emplace_back(src, dst, w); }
void addEdge(const int node1, const int node2, const Weight w = 1) {
addArc(node1, node2, w);
addArc(node2, node1, w);
}
iterator begin() { return g.begin(); }
const_iterator begin() const { return g.begin(); }
iterator end() { return g.end(); }
const_iterator end() const { return g.end(); }
};
std::vector<int> tsort(const Graph &g) {
int n = g.size(), k = 0;
std::vector<int> ord(n), in(n);
for (auto &es : g) {
for (auto &e : es) in[e.dst]++;
}
std::queue<int> q;
rep(i, n) if (in[i] == 0) q.push(i);
while (q.size()) {
int v = q.front();
q.pop();
ord[k++] = v;
for (auto &e : g[v])
if (--in[e.dst] == 0) q.push(e.dst);
}
return *std::max_element(in.begin(), in.end()) == 0 ? ord : std::vector<int>();
}
main {
int n, m;
cin >> n >> m;
Graph g(n);
while (m--) {
int s, t;
cin >> s >> t;
g.addArc(s, t);
}
vi v = tsort(g);
for (auto &x : v) cout << x << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(a) a.begin(),a.end()
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
const char* comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1;
ZZ(comma, args...);
}
const ll MOD = 1e9 + 7;
void solve() {
int n;
cin >> n;
vl a(n + 1);
rep(i, 1, n + 1)cin >> a[i];
ll ans = 0ll;
for (ll i = 0; i < 61; i++) {
ll z = 0ll, o = 0ll;
ll k = (1ll << i);
rep(j, 1, n + 1) {
if (k & a[j])o++;
else z++;
}
ll kk = k;
k %= MOD;
k = (((k * z) % MOD) * o) % MOD;
ans = (ans + k) % MOD;
ans %= MOD;
}
cout << ans << endl;
}
int main() {
fast_io;
int t = 1;
while (t--) {
solve();
}
return 0;
}
| 0 | 86,179,456 |
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<string>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef long long ll;
const ll MAXN = 1e6+1;
ll factor[MAXN];
void slove(){
int n;
cin>>n;
vector<ll> arr(n);
for(int i = 0; i < n; ++i){
cin>>arr[i];
}
memset(factor,0,sizeof(factor));
for(ll i = 2; i <= MAXN; ++i){
if(factor[i] != 0) continue;
factor[i] = i;
for(ll j = i*i; j < MAXN; j += i){
if(factor[j] == 0) factor[j] = i;
}
}
unordered_set<int> exists;
bool pairwise = true;
ll setwise = 0;
for(int i = 0; i < n; ++i){
vector<ll> curFact;
ll now = arr[i];
while (now > 1) {
ll sml = factor[now];
if (curFact.empty() || curFact.back() != sml) curFact.push_back(sml);
now /= sml;
}
for (auto f: curFact) {
if (exists.count(f)) pairwise = false;
exists.insert(f);
}
setwise = __gcd(setwise,arr[i]);
}
if(pairwise){
cout << "pairwise coprime\n";
}else if(setwise == 1){
cout << "setwise coprime\n";
}else{
cout << "not coprime\n";
}
}
int main(){
slove();
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};
int main(){
int n, h;
cin >> n >> h;
vector<int> a(n), b(n);
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
int mxa = a[0];
int nh = 0, cnt = 0;
for(int i = 0; i < n; i++) {
if(mxa > b[i]) break;
nh += b[i];
cnt++;
if(nh >= h) {
cout << cnt << endl;
return 0;
}
}
cnt += (h-nh+mxa-1)/mxa;
cout << cnt << endl;
}
| 0 | 19,359,150 |
#include <cstdio>
#include <queue>
using namespace std;
#define EMPTY '.'
#define OBSTACLE 'X'
#define INF 0x7fffffff
typedef pair<int, int> Coor;
int h, w, n;
char map[1000][1000];
int cost[1000][1000];
int bfs(Coor start, Coor end) {
queue<Coor> q;
fill((int*)cost, (int*)(((char*)cost)+sizeof(cost)), INF);
cost[start.second][start.first] = 0;
q.push(start);
while (!q.empty()) {
Coor c = q.front();q.pop();
int x = c.first;
int y = c.second;
int dx[] = {-1, 0, 1, 0};
int dy[] = { 0, -1, 0, 1};
for (int i=0; i<4; i++) {
int x2 = x + dx[i];
int y2 = y + dy[i];
if (x2 < 0 || w <= x2 || y2 < 0 || h <= y2) continue;
if (map[y2][x2] == 'X') continue;
if (cost[y2][x2] != INF) continue;
cost[y2][x2] = cost[y][x] + 1;
if (make_pair(x2, y2) == end) return cost[y2][x2];
q.push(make_pair(x2, y2));
}
}
}
int main() {
Coor start[10];
unsigned int sum = 0;
scanf("%d %d %d", &h, &w, &n);
for (int i=0; i<h; i++) {
for (int j=0; j<w; j++) {
char c;
scanf(" %c", &c);
if (c == 'S') {
start[0].first = j;
start[0].second = i;
} else if (c != 'X' && c != '.') {
int ind = c - '0';
start[ind].first = j;
start[ind].second = i;
}
map[i][j] = c;
}
}
for (int i=0; i<n; i++) {
sum += (unsigned int)bfs(start[i], start[i+1]);
}
printf("%u\n", sum);
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int K, S;
cin >> K >> S;
int count = 0;
for (int x = 0; x <= K; x++) {
for (int y = 0; y <= K; y++) {
int num = S - (x + y);
if (0 <= num && num <= K) {
count++;
}
}
}
cout << count << endl;
return 0;
}
| 0 | 40,452,481 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector< int > a(n);
for (auto& e:a)cin >> e;
ll curr = 1000;
for (int i=0;i+1<n;i++) {
ll s = 0;
if (a[i] < a[i+1]) s=curr/a[i];
curr += ((ll)a[i+1]-a[i])*s;
}
cout << curr << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var) do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};
int main(){
int a, b;
cin >> a >> b;
cout << max(0, a-b) << endl;
}
| 0 | 77,668,566 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll res(ll x){
if(x%4==0) return x;
if(x%4==1) return 1;
if(x%4==2) return x+1;
if(x%4==3) return 0;
}
int main() {
ll a,b;
cin >> a >> b;
ll ansa=0,ansb=0;;
ll now=1;
a--;
ansa=res(a);
ansb=res(b);
ll ans=ansa^ansb;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
char s[N];
int a[N], sum[N];
int n, m;
const int mod = 1e9 + 7;
int main() {
scanf("%d %s", &n, s);
m = strlen(s);
int cur = 0;
for (int i = m-1; i >= 0; i --) {
int t = (s[i] == 'B');
if (cur ^ t) a[i] = -1;
else a[i] = 1;
cur ^= 1;
}
sum[0] = a[0];
bool flag = 0;
flag |= (sum[0] < 0);
for (int i = 1; i < m; i ++) {
sum[i] = sum[i-1] + a[i];
flag |= (sum[i] < 0);
}
int ans = 1, g = 0;
for (int i = 0; i < m; i ++) {
if (a[i] == 1) {
g ++;
continue;
}
if (g == 0) {ans = 0; break;}
ans = 1ll * ans * g % mod;
g --;
}
if (g) ans = 0;
if (ans) {
for (int i = 1; i <= n; i ++) ans = 1ll * ans * i % mod;
}
printf("%d\n", ans);
return 0;
}
| 0 | 51,420,691 |
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;
const int mod = 1e9 +7;
int main(){
int n;
cin >> n;
vector<ll> a(n);
rep(i,n){
cin >> a[i];
}
ll res = 0;
rep(d, 60){
ll n0 = 0, n1 = 0;
rep(i,n){
if((a[i]>>d)&1){
n1++;
}
else{
n0++;
}
}
ll tmp = (1ll << d) % mod;
ll n = n0 * n1 % mod;
tmp = tmp * n %mod;
res = (res + tmp) % mod;
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;
using namespace std;
signed main() {
bool ok = true;
ll N;
cin>>N;
vector<ll> K(N+1);
vector<ll> L(N+1), R(N+1);
for(ll i=1; i<=N; i++)
cin>>K[i];
L[N] = R[N] = 2;
for (ll i=N-1; i>=0; i--) {
ll l = ((L[i+1] + K[i+1] - 1) / K[i+1]) * K[i+1];
ll r = (R[i+1] / K[i+1]) * K[i+1];
L[i] = l;
R[i] = r + K[i+1]-1;
if (L[i] > R[i])
ok = false;
}
if(ok)
cout << L[0] << " " << R[0] << endl;
else
cout << -1 << endl;
return 0;
}
| 0 | 12,900,578 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll h, w;
cin >> h >> w;
ll ans = ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2);
if (h == 1 || w == 1) ans = 1;
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);
int main(){
int H,W,M;
cin >> H >> W >> M;
vector<vector<int>> Ah(H,vector<int> (2));
vector<vector<int>> Aw(W,vector<int> (2));
rep(i,H) {
Ah[i][1] = i;
}
rep(i,W) {
Aw[i][1] = i;
}
set<pair<int,int>> S;
rep(i,M) {
int h,w;
cin >> h >> w;
h--,w--;
Ah[h][0]++;
Aw[w][0]++;
S.insert(make_pair(h,w));
}
sort(Ah.begin(),Ah.end());
sort(Aw.begin(),Aw.end());
int h_max = Ah.back()[0];
int w_max = Aw.back()[0];
set<int> Sh,Sw;
int idx = H-1;
while(1) {
if (Ah[idx][0] == h_max) {
Sh.insert(Ah[idx][1]);
}
else {
break;
}
idx--;
if (idx<0) break;
}
idx = W-1;
while(1) {
if (Aw[idx][0] == w_max) {
Sw.insert(Aw[idx][1]);
}
else break;
idx--;
if(idx<0) break;
}
int ans = h_max + w_max - 1;
int tmp = Sh.size()*Sw.size();
for (auto s:S) {
int h = s.first;
int w = s.second;
if (Sh.count(h) && Sw.count(w)) {
tmp--;
}
}
if (tmp!=0) ans++;
cout << ans << endl;
}
| 0 | 23,321,499 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
int a, b, c;
cin >> a >> b >> c;
int maxi = max(a, max(b, c));
cout << 10 * maxi + a + b + c - maxi << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
#define pln(x) cout << (x) << endl
#define gcd __gcd
using namespace std;
template <class T> constexpr T lcm(T m, T n){return m*n/gcd(m,n);}
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}
template <typename Iter> ostream& out_container(ostream &os, Iter first, Iter last){
os << "{"; auto itr = first; while(itr != last){if(itr != first) os << ","; os << *itr; ++itr;} os << "}"; return os;
}
template <typename T> ostream& operator<<(ostream &os, const vector<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const deque<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const set<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const unordered_set<T> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const unordered_map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}
template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}
bool is_included_in(int a, int b){
return (a&(~b)) == 0;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;
while(cin >> N >> K){
vector<int> A(N);
vector<LLI> B(N);
REP(i,N) cin >> A[i] >> B[i];
LLI ans = 0;
dump(bitset<30>(K));
REP(i,N){
if(is_included_in(A[i],K)) ans += B[i];
}
REP(i,30){
if(!(K & (1<<i))) continue;
int p = (K >> (i+1)) << (i+1);
dump(bitset<30>(p));
LLI t = 0;
REP(j,N){
if(is_included_in((A[j]>>i)<<i,p)){
t += B[j];
}
}
chmax(ans, t);
}
cout << ans << endl;
}
return 0;
}
| 0 | 1,847,808 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;
using ll = long long;
using ld = long double;
const double PI = 3.14159265358979323846;
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
int main()
{
string s;
cin >> s;
string ans = "No";
sort(ALL(s));
if (s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) ans = "Yes";
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int a[100][100];
int N,u,k,col;
int main() {
cin >> N;
for(int i=0; i<N; ++i) {
cin >> u >> k;
for(int l=0; l<k; ++l) {
cin >> col;
a[u-1][col-1] = 1;
}
cout << a[i][0];
for(int l=1; l<N; ++l) {
cout << " " << a[i][l];
}
cout << endl;
}
}
| 0 | 25,921,537 |
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main() {
int n, k;
cin >> n >> k;
int ans = 1;
for (int i = 0; i < n; i++) {
if (ans + k * (n - i - 1) < k * (n - i))
ans <<= 1;
else
ans += k;
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
int h,w,k;
cin>>h>>w>>k;
int x[h*w+1],y[h*w+1];
for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
int ch;
cin>>ch;
x[ch]=i;
y[ch]=j;
}
int d[h*w+1];
memset(d,0,sizeof(d));
for(int i=k+1;i<=h*w;i++)
d[i]=d[i-k]+abs(x[i]-x[i-k])+abs(y[i]-y[i-k]);
int q;
cin>>q;
for(int i=0;i<q;i++)
{
int l,r;
cin>>l>>r;
cout<<d[r]-d[l]<<endl;
}
}
| 0 | 23,156,481 |
#include<iostream>
using namespace std;
int main(){
int a,N,ans=0;
string S,T;
cin >> S >> T;
for(int i = 0; i < 3; i++){
if(S[i] == T[i]) ans++;
}
cout << ans << endl;
}
|
#include<bits/stdc++.h>
#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007ll
#define PI 3.14159
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define in(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define print(x) for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x) for(auto it:x) cout<<it.F<<' '<<it.S<<'\t'; cout<<endl;
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
using namespace std;
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
clock_t time_p=clock();
void TimeTaken()
{
time_p=clock()-time_p;
cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void solve() {
}
int main(){
int n,s=0,k,t,d=0;
cin>>n>>k;
s=k;
vi v(n);
REP(i,0,n-1){
cin>>v[i];
}
REP(i,0,n-2){
d=v[i+1]-v[i];
t=std::min(d,k);
s+=t;
}
cout<<s;
return 0;
}
| 0 | 76,825,140 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
if(a.first != b.first){
return a.first < b.first;
}else{
return a.second < b.second;
}
}
bool In_map(ll y,ll x,ll h,ll w){
if(y<0 || x<0 || y>=h || x>=w){
return 0;
}else{
return 1;
}
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
int main() {
ll N;
cin >>N;
vector<ll>A(N);
rep(i,N){
cin>>A[i];
}
ll ans =0;
ll now=0;
ll r=0;
rep(l,N){
while(r<N){
if((now&A[r])==0){
ans+=(r-l+1);
now += A[r];
r++;
}else{
now -=A[l];
break;
}
}
if(r==N){
break;
}
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
vector<pair<string,int>>v;
int n;
cin>>n;
int total_time=0;
for(int i=0;i<n;i++){
string play_list;
int time;
cin>>play_list>>time;
v.push_back(make_pair(play_list,time));
total_time+=time;
}
string s=v[0].first;
string target;
cin>>target;
if(s==target)
cout<<total_time - v[0].second<<endl;
else{
int res=0;
int i;
for(i=0;i<v.size();i++){
if(v[i].first!=target){
res+=v[i].second;
}
else
break;
}
cout<<total_time-res-v[i].second<<endl;
}
}
| 0 | 44,792,203 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n, l;
cin >> n >> l;
vector < ll > a(n + 1);
for(int i = 1; i <= n; i++) cin >> a[i];
int j = 0;
for(int i = 1; i < n; i++){
if(a[i] + a[i + 1] >= l) j = i;
}
if(j == 0) cout << "Impossible\n";
else{
cout << "Possible\n";
for(int i = 1; i < j; i++) cout << i << '\n';
for(int i = n - 1; i > j; i--) cout << i << '\n';
cout << j << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
int n;
ll d,a;
ll x[200001],h[200001],s[200002];
pll xh[200001];
int main(){
cin>>n>>d>>a;
rep(i,n){
cin>>x[i]>>h[i];
xh[i]={x[i],h[i]};
}
sort(xh,xh+n);
rep(i,n) x[i]=xh[i].first,h[i]=xh[i].second;
ll cnt=0;
int l=0,r=0,px;
ll cur=0;
while(l<n){
px=lower_bound(x,x+n,x[l]-d*2)-x;
cur+=-s[px];
ll nx=max(0ll,(h[l]+a-1)/a-cur);
cnt+=nx;
s[l+1]=s[l]+nx;
cur=s[l+1];
++l;
}
cout<<cnt<<endl;
return 0;
}
| 0 | 11,481,235 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> &a, pair<int, int> &b) {
return atan2(a.second, a.first) < atan2(b.second, b.first);
}
int main ()
{
int n;
cin >> n;
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x || y) {
a.emplace_back(x, y);
}
}
long double ans = 0.0;
sort(a.begin(), a.end(), cmp);
for (int i = 0; i < (int) a.size(); i++) {
long double curX = 0.0, curY = 0.0;
for (int j = 0; j < (int) a.size(); j++) {
int ind = (i + j) % a.size();
curX += a[ind].first;
curY += a[ind].second;
ans = max(ans, sqrt(curX * curX + curY * curY));
}
}
cout << setprecision(15) << fixed << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const int INF = 1e9;
const double pi=acos(-1);
int main(){
int n;
cin >>n;
vector<string>s(n);
rep(i,n)cin >> s[i];
ll ans=0;
rep(k,n){
vector<string>t(n,string(n,' '));
rep(i,n){
rep(j,n){
t[i][(j+k)%n]=s[i][j];
}
}
bool ok=true;
rep(i,n){
rep(j,n){
if(t[i][j]!=t[j][i])ok=false;
}
}
if(ok)ans++;
}
cout << ans*n << endl;
return 0;
}
| 0 | 39,411,635 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
int b;
cin >> a >> b;
if((a+b) % 2 != 0) {
cout << ((a+b) / 2) + 1<< endl;
} else {
cout << (a+b) / 2 << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << "\t";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}
int main()
{
int n, k;
cin >> n >> k;
vector<ll> a;
vector<ll> sum;
ll sum_cnt = 0;
sum.push_back(0);
rep(i, n){
int tmp; cin >> tmp;
a.push_back(tmp);
sum_cnt += a[i];
sum.push_back(sum_cnt);
}
vector<ll> sum_list;
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n+1; j++)
{
sum_list.push_back(sum[j]-sum[i]);
}
}
vector<bool> use(sum_list.size(), false);
int max_bit = 0;
for(int bit = 40; bit >= 0; bit--){
int cnt = 0;
int cnt_true = 0;
rep(i, sum_list.size()){
if (((sum_list[i]>>bit)&1) == 1) {
cnt++;
if (use[i]) cnt_true++;
}
}
if (cnt < k){
continue;
} else {
if (max_bit == 0){
max_bit = bit;
rep(i, sum_list.size()){
if ((sum_list[i]>>bit)&1 == 1) use[i] = true;
}
} else {
if (cnt_true >= k){
rep(i, sum_list.size()){
if ((((sum_list[i]>>bit)&1) == 0) && use[i]) use[i] = false;
}
}
}
}
}
ll sum_bit = (1ll<<40) - 1;
rep(i, sum_list.size()){
if (use[i]) sum_bit&=sum_list[i];
}
cout << sum_bit << endl;
}
| 0 | 67,350,809 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll powM(ll a,ll b,ll m )
{
a%=m;
ll ans=1;
while(b>0)
{
if(b&1)ans=ans*a%m;
a=a*a%m;
b>>=1;
}
return ans;
}
ll pow(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b&1)ans=ans*a;
a=a*a;
b>>=1;
}
return ans;
}
ll dp[105][1005];
char ch[105][1005];
int main()
{fast
ll n;cin>>n;
string s,t;
cin>>s>>t;
ll ans=0;
for(ll i=0;i<n;i++)
{
string t1=t.substr(0,i+1);
string s1=s.substr(n-i-1,i+1);
if(s1==t1)
{
ans=max(ans,i+1);
}
}
cout<<2*n-ans<<"\n";
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
const double PI = acos(-1.0);
const long mod = 1000000007;
const long INF = 1e9 + 1;
int main() {
int n,m,x;
cin >> n >> m >> x;
int c[n],a[n][m];
for(int i = 0; i < n; i++) {
cin >> c[i];
for(int j = 0; j < m; j++)
cin >> a[i][j];
}
int mi = INF;
for(int bit = 0; bit < (1 << n); bit++) {
int num = 0,sum[m];
for(int i = 0; i < m; i++) sum[i] = 0;
for(int i = 0; i < n; i++) {
if(bit & (1 << i)) {
num += c[i];
for(int j = 0; j < m; j++) sum[j] += a[i][j];
}
}
bool flag = 1;
for(int j = 0; j < m; j++) {
if(sum[j] < x) {
flag = 0; break;
}
}
if(flag) mi = min(mi,num);
}
if(mi == INF) cout << -1 << endl;
else cout << mi << endl;
}
| 0 | 14,791,366 |
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define ll long long int
#define ull unsigned long long int
#define veci vector<int>
#define vecc vector<char>
#define vecs vector<string>
#define vecl vector<long long int>
#define vecp vector< pair<int,int> >
#define mapstrint map< string , int >
#define mapstrstr map< string , string >
#define mapint map< int, int >
#define pb push_back
#define newline cerr << endl
#define pob pop_back
#define mp make_pair
#define pii pair<int, int>
#define F first
#define S second
#define sc(x) scanf("%d",&x)
#define sc2(xx,zz) scanf("%d %d",&xx,&zz)
#define scl(x) scanf("%lld",&x)
#define scl2(xx,zz) scanf("%lld %lld",&xx,&zz)
#define pf printf
#define min3(a,b,c) min(a,b<c?b:c)
#define max3(a,b,c) max(a,b>c?b:c)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " = " << x << endl
#define debug2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define debug3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define debug4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define mx9 1000000007
#define mx7 10000007
#define mx6 2000006
#define mx5 200005
#define inf 1<<30
#define eps 1e-9
#define mod mx9
long double PI = acosl(-1);
bool compare_int(int a, int b){return (a>b);}
bool compare_string (string a, string b){return a.size()<b.size();}
bool compare_pair(const pair<int,int> &a,
const pair<int,int> &b){if(a.second==b.second)return a.first<b.first; else return (a.second > b.second);}
bool cmp(pair<string ,int > x , pair<string ,int > y){return (x.S < y.S);}
void NA(){printf("NO\n");exit(0);}
void YA(){printf("YES\n");exit(0);}
int32_t main()
{
FastIO;
int n, k;
cin >> n >> k;
int a[n+1], ans[n+2]={0};
for(int i=0; i<n; i++) cin >> a[i];
for(int i=n-2; i>=0; i--)
{
int val = inf;
for(int j=i+1; j<=min(n-1, i+k); j++)
{
val = min(val, abs(a[i]-a[j])+ans[j]);
}
ans[i] = val;
}
cout << ans[0] << endl;
}
|
#include<iostream>
#include <cstdio>
#include<cctype>
using namespace std;
int main(){
char ch;
ch = getchar();
while( ch != EOF)
{
if(islower(ch))
ch = toupper(ch);
else
ch = tolower(ch);
cout << ch;
ch = getchar();
}
return 0;
}
| 0 | 83,833,028 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, K = 0;
cin >> A >> B >> K;
for (int i=0; i < K; i++) {
if (i%2 == 0) {
A /= 2;
B += A;
} else {
B /= 2;
A += B;
}
}
cout << A << ' ' << B << endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define ci(m) for(int i=0;i<m;i++)
#define cj(m) for(int j=0;j<m;j++)
#define ck(m) for(int k=0;k<m;k++)
#define gcd __gcd
#define endl "\n"
#define pb emplace_back
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define mod2 998244353
#define maxe *max_element
#define mine *min_element
#define inf 1e18
#define deci(x, y) fixed<<setprecision(y)<<x
#define w(t) int t; cin>>t; while(t--)
#define nitin ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI 3.141592653589793238
using namespace std;
int32_t main() {
nitin;
int s;
cin>>s;
cout<<0<<" "<<0<<" ";
cout<<1000000000<<" "<<1<<" ";
int p=(1000000000-s%1000000000)%1000000000;
int x=p;
int y=(s+x)/1000000000;
cout<<x<<" "<<y;
return 0;
}
| 0 | 90,609,771 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x;
cin>>x;
(x<1200)?cout<<"ABC":cout<<"ARC";
}
|
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>
using namespace std;
class Solution {
public:
vector<pair<int,int>> solve(vector<long long>& W) {
int n = W.size();
vector<pair<long long,int>> P;
for (int i = 0; i < n; ++i) {
P.emplace_back(W[i], i);
}
sort(P.begin(), P.end());
vector<long long> sums(n, 0);
vector<int> sizes(n, 1);
vector<int> pars(n, -1);
for (int i = n - 1; i > 0; --i) {
int u = P[i].second;
long long sum = P[i].first;
long long tar = sum - (n - 2 * sizes[u]);
if (tar == sum) {
return {};
}
auto it = lower_bound(P.begin(), P.end(), make_pair(tar, -1));
if (it == P.end()) {
return {};
}
if (it->first != tar || it->second == u) {
return {};
}
int p = it->second;
sums[p] += sums[u] + sizes[u];
sizes[p] += sizes[u];
pars[u] = p;
}
if (sums[P[0].second] != P[0].first) {
return {};
}
vector<pair<int,int>> res;
for (int i = 0; i < n; ++i) {
if (pars[i] >= 0) {
res.emplace_back(pars[i], i);
}
}
return res;
}
};
int main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> W(n, 0);
for (int i = 0; i < n; ++i) {
cin >> W[i];
}
Solution sol;
auto res = sol.solve(W);
if (res.size() != n - 1) {
cout << "-1\n";
} else {
for (auto& e : res) {
cout << e.first + 1 << " " << e.second + 1 << "\n";
}
}
return 0;
}
| 0 | 42,617,896 |
#include <iostream>
#include <set>
#include <map>
using namespace std;
int main(){
int n,a,b,c,x;
while(cin >> n >> a >> b >> c >> x && n){
int key[100];
for(int i = 0 ; i < n ; i++) cin >> key[i];
int t = 0 , T = 0;
if(x == key[0]) t++;
while(t < n && ++T <= 10000){
x = (a * x + b) % c;
if(x==key[t]){t++;}
}
if(T == 10001) cout << -1 << endl;
else cout << T << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long mod = 1e9 + 7;
long long phi[N] = {};
bool isp[N] = {};
int n, k;
void init() {
isp[1] = true;
for (int i = 1; i <= k; i++)
phi[i] = i;
for (int i = 2; i <= k; i++)
if (!isp[i]) {
phi[i]--;
for (int j = i << 1; j <= k; j += i) {
isp[j] = true;
phi[j] = phi[j] / i * (i - 1);
}
}
for (int i = 1; i <= k; i++)
phi[i] = (phi[i] + phi[i - 1]) % mod;
}
long long ksm(long long a, long long b) {
if (b == 1) return a % mod;
else if (b & 1) return a * ksm(a * a % mod, b >> 1) % mod;
else return ksm(a * a % mod, b >> 1);
}
int main() {
cin >> n >> k;
init();
long long ans = 0, t, l = k, r;
while (l) {
t = k / l;
l = k / (t + 1);
r = k / t;
ans = (ans + (phi[r] - phi[l]) * ksm(t, n)) % mod;
}
cout << ans << '\n';
return 0;
}
| 0 | 25,468,157 |
#include <iostream>
#include <fstream>
#include <string>
#include <map>
using namespace std;
int main(){
#ifdef DEBUG
ofstream fout("output.txt");
ifstream fin("input.txt");
if(!fout || !fin){
cout << "Can't open the file.\n";
return;
}
#endif
string word;
int max_length;
int max_appear;
string max_string;
string max_word;
map<string,int> appear;
max_length = 0;
max_appear = 0;
while(1){
cin >> word;
if(cin.eof()) break;
if(appear.find(word) == appear.end()){
appear[word] = 1;
}else
appear[word]++;
if(appear[word] > max_appear){
max_appear = appear[word];
max_word = word;
}
if(word.length() > max_length){
max_length = word.length();
max_string = word;
}
}
cout << max_word << " " << max_string << endl;
#ifdef DEBUG
fout.close();
fin.close();
#endif
return 0;
}
|
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
using namespace std;
const int mod=1e9+7;
void run();
void init() {
ios::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(12);
}
signed main(){
init();
run();
return 0;
}
void run(){
int n;
cin>>n;
vi t(n),a(n);
rep(i,n)cin>>t[i];
rep(i,n)cin>>a[i];
vi y(n);
y[0]=t[0];
Rep(i,1,n){
if(t[i]!=t[i-1])y[i]=t[i];
}
if(y[n-1]!=0&&y[n-1]!=a[n-1]){
cout<<0<<endl;
return;
}
y[n-1]=a[n-1];
for(int i=n-2;i>=0;i--){
if(a[i]!=a[i+1]){
if(y[i]!=0&&y[i]!=a[i]||y[i]==0&&a[i]>t[i]){
cout<<0<<endl;
return;
}
y[i]=a[i];
}
}
int ans=1;
rep(i,n){
if(y[i]==0)ans=ans*min(t[i],a[i])%mod;
}
cout<<ans<<endl;
}
| 0 | 94,188,931 |
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>
#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>
#define cauto const auto&
#else
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;
#define VV(T) vector<vector< T > >
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t){
stringstream ss;
ss << f;
ss >> t;
}
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
struct mint{
ll x;
mint():x(0){}
mint(ll x):x((x%MOD+MOD)%MOD){}
mint operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
mint operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
mint operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
mint operator+(const mint& a)const{ return mint(*this) += a;}
mint operator-(const mint& a)const{ return mint(*this) -= a;}
mint operator*(const mint& a)const{ return mint(*this) *= a;}
bool operator==(const mint& a)const{ return x == a.x;}
friend ostream& operator<<(ostream& os, const mint& mi)
{
os << mi.x;
return os;
}
};
mint func(int n){
ll x;
cin>>x;
mint suf,sum;
rep(i,n-1){
ll t;
cin>>t;
suf += mint(t-x)*mint(i+1);
sum += suf;
x = t;
}
return sum;
}
void mainmain(){
int n,m;
cin>>n>>m;
mint a = func(n);
mint b = func(m);
cout<<a*b<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout<<fixed<<setprecision(20);
mainmain();
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
T GCD(T a, T b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
return (a * b) / GCD(a, b);
}
using namespace std;
signed main() {
int a, b, c;
cin >> a >> b >> c;
if (c % GCD(a, b) == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| 0 | 54,469,106 |
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)
template<class T>
T GCD(T a, T b){
if(a<b){
T temp=a;
a=b;
b=temp;
}
T res=a%b;
while(res!=0){
a=b;
b=res;
res=a%b;
}
return b;
}
template<class T>
T LCM(T a, T b){
T res=GCD(a,b);
return a*b/res;
}
int main(int argc,char* argv[]){
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll a,b,c,d;
cin >> a >> b >> c >> d;
ll cdlcm=LCM(c,d);
ll csum=b/c-(a-1)/c;
ll dsum=b/d-(a-1)/d;
ll cdsum=b/cdlcm-(a-1)/cdlcm;
cout << (b-a+1)-(csum+dsum-cdsum) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
vector<string> a, b;
int n, m;
bool checker(int r, int c) {
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
if(a[r + i][c + j] != b[i][j])
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n);
b.resize(m);
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < m; i++)
cin >> b[i];
for(int i = 0; i <= n - m; i++) {
for(int j = 0; j <= n - m; j++) {
if(checker(i, j)) {
cout << "Yes";
return 0;
}
}
}
cout << "No";
}
| 0 | 46,808,547 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()
template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;
ll dp[10][100];
int main() {
ll K;
cin >> K;
ll tmp;
queue<ll> que;
for (ll i = 1; i < 10; ++i) {
que.emplace(i);
}
for (int i = 0; i < K; ++i) {
tmp = que.front();
que.pop();
if (tmp % 10 != 0)
{
que.emplace(10 * tmp + tmp % 10 - 1);
}
que.emplace(10 * tmp + tmp % 10);
if (tmp % 10 != 9) {
que.emplace(10 * tmp + tmp % 10 + 1);
}
}
cout << tmp << endl;
}
|
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define ct ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first
#define se second
#define foe(i,a,b) for(ll i=a;i<b;i++)
#define rfoe(i,a,b) for(ll i=a;i>=0;i--)
#define sz(s) s.size()
#define mem(a,s) memset(a,s,sizeof(a))
#define all(v) v.bi,v.ei
#define MAX 8000000000000000064LL
#define MIN -8000000000000000064LL
ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
ll fact[1000007]={0};
ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
y=y>>1;x=(1ll*x*x)%MOD;} return res;}
void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
int const N=2e5+9;
ll const INF = 2e9+5;
ll n;
void solve()
{
ll n;
cin>>n;
string s;
cin>>s;
if(n%2==1)
{
cout<<"No\n";
return;
}
foe(i,0,n/2)
{
if(s[i]!=s[i+n/2])
{
cout<<"No\n";
return;
}
}
cout<<"Yes\n";
}
int main()
{
fast
{
solve();
}
}
| 0 | 924,293 |
#include <bits/stdc++.h>
using namespace std;
int main(void){
int n, k;
cin >> n >> k;
cout << (n-2) / (k-1) + 1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int h, w, d;
cin >> h >> w >> d;
map<int, pair<int, int>> a;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
int x;
cin >> x;
a.insert({x, {i, j}});
}
}
vector<ll> memo(h * w + 1);
for (int i = 1; i < memo.size(); ++i) {
if (memo[i] == 0) {
for (int j = i + d; j < memo.size(); j += d) {
int x = abs(a[j].first - a[j - d].first);
int y = abs(a[j].second - a[j - d].second);
memo[j] = memo[j - d] + x + y;
}
}
}
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int l, r;
cin >> l >> r;
ll ans = memo[r] - memo[l];
cout << ans << endl;
}
}
| 0 | 8,070,977 |
#include <iostream>
#include <vector>
using namespace std;
int main() {
int H, W, A, B;
cin >> H >> W >> A >> B;
vector<vector<bool>> ans(H, vector<bool>(W));
for (int i = 0; i < A; i++) {
for (int j = 0; j < B; j++) ans[j][i] = true;
}
for (int i = A; i < W; i++) {
for (int j = B; j < H; j++) ans[j][i] = true;
}
for (vector<bool>& i : ans) {
for (bool j : i) cout << j;
cout << endl;
}
}
|
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
using G = vector<map<int, int>>;
void
dfs(int node, ll count, G &arr, vector<bool> seen, vector<long> &to_K)
{
seen[node] = true;
for(auto child: arr[node]){
if(seen[child.first]) continue;
to_K[child.first] = count + child.second;
dfs(child.first, count + child.second, arr, seen, to_K);
}
}
int
main() {
int N; cin >> N;
G arr(N + 1);
rep(i, 0, N - 1){
int a, b, c; cin >> a >> b >> c;
arr[a][b] = c;
arr[b][a] = c;
}
vector<long> to_K(N + 1);
int Q, K; cin >> Q >> K;
vector<pair<int, int>> q(Q);
rep(i, 0, Q){
cin >> q[i].first;
cin >> q[i].second;
}
vector<bool> seen(N + 1, false);
queue<int> que;
que.push(K);
seen[K] = true;
to_K[K] = 0;
while(!que.empty()){
int node = que.front();
que.pop();
for(auto child : arr[node]){
if(seen[child.first]) continue;
to_K[child.first] = arr[node][child.first] + to_K[node];
seen[child.first] = true;
que.push(child.first);
}
}
rep(i, 0, Q){
cout << to_K[q[i].first] + to_K[q[i].second] << endl;
}
}
| 0 | 30,276,869 |
#include<iostream>
#include<cmath>
using namespace std;
const int M = 2e5;
long long a[M];
long long sum[M];
int main()
{
int n;
while (cin >> n)
{
long long s = 0;
sum[0] = 0;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
s += a[i];
}
long long Min = abs(2 * sum[1] - s);
for (int i = 1; i<n; i++)
{
if (Min > abs(2 * sum[i] - s))
Min = abs(2 * sum[i] - s);
}
cout << Min << endl;
}
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ull = unsigned long long;
ull C(int size, int count) {
ull x = 1;
ull y = 1;
for(int i = 0; i < count; ++i) {
x *= (size - i);
y *= (i + 1);
if(x % y == 0) {
x /= y;
y = 1;
}
}
return x / y;
}
int main() {
int n, p;
cin >> n >> p;
int even = 0;
int odd = 0;
for(int i = 0; i < n; ++i) {
int a;
cin >> a;
if(a % 2 == 0)
even++;
else
odd++;
}
ull answer = 0;
if(p == 0) {
for(int i = 0; i <= even; ++i)
answer += C(even, min(i, even - i));
ull evenC = answer;
if(evenC != 0) {
for(size_t i = 2; i <= odd; i+=2)
answer += evenC * C(odd, min(i, odd - i));
}
}
else {
for(size_t i = 1; i <= odd; i+=2)
answer += C(odd, min(i, odd - i));
ull oddC = answer;
if(oddC != 0) {
for(size_t i = 1; i <= even; ++i)
answer += C(even, min(i, even - i)) * oddC;
}
}
cout << answer << endl;
return 0;
}
| 0 | 99,844,101 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+5;
int n;
int main()
{
scanf("%d",&n);
int ans=0,l=0,r=0,flag=false;
for(int i=1;i<=n;i++)
{
char s[15];
scanf("%s",s+1);
int m=strlen(s+1);
if(s[1]=='B') l++;
if(s[m]=='A') r++;
if(!(s[1]=='B'&&s[m]=='A')&&(s[1]=='B'||s[m]=='A')) flag=true;
for(int i=1;i<m;i++)
if(s[i]=='A'&&s[i+1]=='B') ans++;
}
ans+=min(l,r);
if(!flag&&min(l,r)>0) ans--;
printf("%d\n",ans);
}
|
#include <iostream>
#include <string>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;
int main(){
int n;
string s;
cin >> n >> s;
int num[1000]{};
rep(i,1000){
string strint = to_string(i);
if(i<10){
strint[2] = strint[0];
strint[0] = strint[1] = '0';
}else if(i<100){
strint[2] = strint[1];
strint[1] = strint[0];
strint[0] = '0';
}
bool flag[3] {};
int j=0;
rep(k, n){
if(s[k]==strint[j]){
flag[j] = 1;
j++;
}
}
if(flag[0]==1 && flag[1]==1 && flag[2]==1){
num[i] =1;
}
}
int ans=0;
rep(i,1000){
if(num[i]==1) ans++;
}
cout << ans << endl;
return 0;
}
| 0 | 88,574,872 |
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF 1e18
#define INF 1e9
using namespace std;
#define fs first
#define sc second
using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;
const ll MOD = 1e9+7;
signed main(){
ll n,k;
cin >> n >> k;
ll ans = 0;
rep(i,0,n){
ll h;
cin >> h;
if(h >= k) ans++;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
using namespace std;
ll gcd(ll a,ll b) {
if(a%b==0) return b;
return gcd(b,a%b);
}
int main() {
ll N,X;
cin>>N>>X;
vec A(N+1);
rep(i,0,N) {
cin>>A[i];
}
A[N]=X;
sort(A);
ll C=A[1]-A[0];
rep(i,1,N) {
ll D=A[i+1]-A[i];
C=gcd(C,D);
}
cout<<C<<endl;
}
| 0 | 98,108,665 |
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef long double lld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
#define MOD 1000000007
int main() {
string s,t;
cin >> s >> t;
int ma = 0;
int sa = s.size() - t.size();
for(int i=0;i<sa+1;i++){
int cnt = 0;
for(int j=0;j<t.size();j++){
if(s.at(i+j) == t.at(j)) cnt++;
}
ma = max(ma,cnt);
}
cout << t.size() - ma << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;
int main(){
int n;
cin >> n;
vector<int> h(n);
rep(i,n) cin >> h[i];
int ans=0;
int active=0;
rep(i,n){
if(active >= h[i]){
active = h[i];
}
else{
ans += h[i]-active;
active=h[i];
}
}
cout << ans << endl;
}
| 0 | 75,626,461 |
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;}
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;}
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}
int main()
{
int n, m, a, b;
vector<int> one_to;
vector<int> to_last;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
cin >> a >> b;
if (a == 1)
one_to.push_back(b);
if (b == n)
to_last.push_back(a);
}
if (one_to.size() == 0 || to_last.size() == 0)
{
cout << "IMPOSSIBLE" << endl;
return (0);
}
sort(one_to.begin(), one_to.end());
sort(to_last.begin(), to_last.end());
int j = 0;
for (int i = 0; i < to_last.size(); i++)
{
while (j < one_to.size() && one_to[j] < to_last[i])
j++;
if (one_to[j] == to_last[i])
{
cout << "POSSIBLE" << endl;
return (0);
}
}
cout << "IMPOSSIBLE" << endl;
}
|
#include<bits/stdc++.h>
#include<string.h>
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
using namespace std;
int nxt() {
int x;
cin >> x;
return x;
}
ll nxtl(){
ll x;
cin>>x;
return x;
}
void SieveOfEratosthenes(int n,vector <int> &primes)
{
bool prime[n+1];
memset(prime, true, sizeof(prime));
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for (int i=p*p; i<=n; i += p)
prime[i] = false;
}
}
for (int p=2; p<=n; p++)
if (prime[p])
primes.push_back(p);
}
ll max(ll a,ll b)
{
if(a>b)
return a;
return b;
}
ll power(ll x, ll y,ll mod)
{
ll temp;
if( y == 0)
return 1;
temp = power(x, y/2,mod);
if (y%2 == 0)
return (temp*temp)%mod;
else
return (((x*temp)%mod)*temp)%mod;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n=nxt(),m=nxt();
vector <vector <int> > edges;
vector <int> row(3);
edges.resize(m,row);
vector <vector <int> > dist;
vector <int> r2;
r2.resize(n+1,1e8);
dist.resize(n+1,r2);
for(int i=1;i<=n;i++)
dist[i][i]=0;
for(int i=0;i<m;i++)
{
int u=nxt(),v=nxt(),c=nxt();
edges[i][0]=u;
edges[i][1]=v;
edges[i][2]=c;
dist[u][v]=c;
dist[v][u]=c;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
for(int k=1;k<=n;k++)
if(dist[j][k]>dist[j][i]+dist[i][k])
dist[j][k]=dist[j][i]+dist[i][k];
int test=0;
for(int i=0;i<m;i++)
{
if(edges[i][2]>dist[edges[i][0]][edges[i][1]])
test++;
}
cout<<test<<endl;
return 0;
}
| 0 | 51,222,409 |
#include<bits/stdc++.h>
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
using namespace std;
using Graph = vector<vector<lli>>;
using P = pair<int, int>;
int main(){
int h1, m1, h2, m2, k;
cin >> h1 >> m1 >> h2 >> m2 >> k;
int ans = (60*h2+m2) - (60*h1+m1) - k;
if(ans < 0) ans = 0;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.141592653
#define oo 1000000007
#define loo 10000000000000007
#define prime 1000000007
#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;
int v[5050], u[5050];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
queue<ll> q;
vl ans;
for (ll i = 1; i < 10; ++i){
q.push(i);
ans.pb(i);
}
while((int)ans.size() < n){
ll aux = q.front();
q.pop();
ll d = aux%10;
ll at = 10*aux+d-1;
if(d > 0){
q.push(at);
ans.pb(at);
}
at = 10*aux+d;
q.push(at);
ans.pb(at);
if(d < 9){
at = 10*aux+d+1;
q.push(at);
ans.pb(at);
}
}
cout << ans[n-1] << endl;
return 0;
}
| 0 | 75,330,711 |
#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int>> graph[n + 1];
int deg[n + 1] = {}, x[n + 1];
fill(x, x + n + 1, -1);
for (int l, r, d; cin >> l >> r >> d; ) {
graph[l].emplace_back(r, d);
deg[r]++;
}
string result = "Yes";
stack<int> stack;
for (int i = 1; i <= n; i++) {
if (deg[i] == 0) {
stack.emplace(i);
x[i] = 0;
}
}
while (!stack.empty()) {
auto top = stack.top();
stack.pop();
for (auto& p : graph[top]) {
if (deg[p.first] > 0) {
deg[p.first]--;
if (deg[p.first] == 0) {
stack.emplace(p.first);
}
}
if (x[p.first] != -1 && x[p.first] - x[top] != p.second) {
result = "No";
} else {
x[p.first] = x[top] + p.second;
}
}
}
for (int i = 1; i <= n; i++) {
if (deg[i] > 0) {
result = "No";
}
}
cout << result;
return 0;
}
|
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
void solve(int N, int Q, vector<int> t, vector<int> u, vector<int> v)
{
dsu d(N);
for (int i = 0; i < Q; i++)
{
if (t.at(i) == 0)
{
d.merge(u.at(i), v.at(i));
}
else
{
cout << ((d.same(u.at(i), v.at(i))) ? 1 : 0) << endl;
}
}
}
int main()
{
int N;
cin >> N;
int Q;
cin >> Q;
vector<int> t(Q);
vector<int> u(Q);
vector<int> v(Q);
for (int i = 0; i < Q; i++)
{
cin >> t.at(i);
cin >> u.at(i);
cin >> v.at(i);
}
solve(N, Q, move(t), move(u), move(v));
return 0;
}
| 0 | 10,910,118 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s,w;
cin >> s >> w;
if(s>w)cout << "safe" << "\n";
else cout << "unsafe" << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;
int main() {
int N, M; cin >> N >> M;
vector<ll> X(N), Y(N), Z(N);
REP(i, 0, N) cin >> X[i] >> Y[i] >> Z[i];
ll ans = 0;
for (int bit = 0; bit < (1 << 3); bit++) {
vector<ll> V(N);
REP(i, 0, N) {
V[i] += ((bit & 1) ? -X[i] : X[i]);
V[i] += ((bit & 2) ? -Y[i] : Y[i]);
V[i] += ((bit & 4) ? -Z[i] : Z[i]);
}
sort(ALL(V), greater<>());
ll total = 0;
REP(i, 0, M) total += V[i];
ans = max(ans, total);
}
cout << ans << endl;
return 0;
}
| 0 | 79,832,292 |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
int qpow(int b,int e){
if( !e ) return 1;
if( e & 1 ) return qpow(b,e-1) * b % mod;
int pwur = qpow(b,e>>1);
return (pwur * pwur) % mod;
}
int modinv(int x){
return qpow(x,mod-2);
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(0);
srand(time(NULL));
string s,t;
cin >> s >>t;
if(t.size()>s.size()){
cout << "UNRESTORABLE" << endl;
return 0;
}
string ans="{";
for(int i = 0; i < s.size()-t.size()+1; i++) {
bool a=true;
for(int j = 0; j < t.size(); j++) {
if(s[i+j]!=t[j] && s[i+j]!='?'){
a=false;
}
}
if(a){
vector<char> y(s.size());
for(int j = 0; j < s.size(); j++) {
y[j]=s[j];
}
for(int j = i; j < i+t.size() ; j++) {
y[j]=t[j-i];
}
for(int j = 0; j < s.size(); j++) {
if(y[j]=='?') y[j]='a';
}
string q;
for(int j = 0; j < s.size(); j++) {
q += y[j];
}
if(ans>q) ans=q;
}
}
if(ans=="{") cout << "UNRESTORABLE" << endl;
else cout << ans << endl;
return 0;
}
|
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#include <utility>
#include <iomanip>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
int n, m;
cin >> n >> m;
vector<int> p(m), y(m);
rep(i, m) {
cin >> p[i] >> y[i];
p[i]--; y[i]--;
}
vector<vector<pair<int, int>>> dat(n);
rep(i, m) {
dat[p[i]].push_back(make_pair(y[i],i));
}
vector<pair<int, int>> ans(m);
rep(i, n) {
sort(dat[i].begin(), dat[i].end());
rep(j, dat[i].size()) {
ans[dat[i][j].second] = make_pair(i, j);
}
}
rep(i, m) {
printf("%06d%06d\n", ans[i].first+1, ans[i].second+1);
}
}
| 0 | 5,739,926 |
#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
char s[105];
bool cput(LL x) {
printf("? %lld\n",x);
fflush(stdout);
scanf("%s",s);
return s[0] == 'Y';
}
int main() {
int i,l = 0,r;
bool vis = 1;
for(i = 1000000000; i > 0; i /= 10) {
if(cput(i)) {
vis = vis & 1;
if(l == 0) l = i;
} else vis = 0;
}
if(vis) {
for(i = 1; i <= 1000000000; i *= 10) {
if(cput(i * 10LL - 1)) {
printf("! %d\n",i);
fflush(stdout);
return 0;
}
}
}
r = l * 10 - 1;
l =l + 1;
while(l < r) {
int mid = (l + r) >> 1;
if(cput(mid * 10LL + 1)) r = mid;
else l = mid + 1;
}
printf("! %d\n",r);
fflush(stdout);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
int main(){
string n; cin>>n;
int N=n.size();
int k; cin>>k;
vector<vector<int>> dpv(N,vector<int>(k+1,0)),dpi(N,vector<int>(k+1,0));
dpv[0][1]=1; dpi[0][1]=n[0]-'0'-1; dpi[0][0]=1;
for(int i=1;i<N;i++){
if(n[i]=='0'){
rep(j,k+1){
dpv[i][j]=dpv[i-1][j];
if(j==0){
dpi[i][0]=dpi[i-1][0];
continue;
}
dpi[i][j]=dpi[i-1][j-1]*9+dpi[i-1][j];
}
}
else{
rep(j,k+1){
if(j==0){
dpi[i][0]=dpi[i-1][0];
continue;
}
dpv[i][j]=dpv[i-1][j-1];
dpi[i][j]=dpi[i-1][j]+dpi[i-1][j-1]*9;
dpi[i][j]+=dpv[i-1][j-1]*(n[i]-'0'-1)+dpv[i-1][j];
}
}
}
cout<<dpi.back()[k]+dpv.back()[k]<<endl;
}
| 0 | 85,134,156 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool compare(pair<int, int> a, pair<int, int> b)
{
return a.second < b.second;
}
int main()
{
int N, M;
cin >> N >> M;
vector<int> cnt;
cnt.resize(N);
for (int i = 0; i < M; ++i)
{
int a, b;
cin >> a >> b;
--a, --b;
++cnt[a], ++cnt[b];
}
for (int i = 0; i < N; ++i)
{
if (cnt[i] % 2 == 1)
{
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;
using Graph = V<V<int>>;
Graph g;
V<bool> seen;
int n, m;
int ans = 0, cnt = 0;
void dfs(int v) {
seen[v] = true;
cnt++;
if(cnt == n) ans++;
for (auto next_v : g[v]) {
if (seen[next_v]) continue;
dfs(next_v);
}
cnt--;
seen[v] = false;
}
int main() {
cin >> n >> m;
g.resize(n);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
g[a].push_back(b);
g[b].push_back(a);
}
seen.resize(n);
dfs(0);
cout << ans << endl;
return 0;
}
| 0 | 83,582,930 |
#include <bits/stdc++.h>
using namespace std;
#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int N = 1e5+1;
int n, a[N], val[N], b[N];
long res[N];
vector <int> pos[N];
int main()
{
fastio;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++){
int x = lower_bound(a + 1, a + 1 + n, b[i]) - a;
val[x] = b[i];
pos[x].push_back(i);
}
int pre = -INF, x = INF;
long cnt = 0;
for (int i = n; i >= 0; i--){
if (i == 0){
res[x] += cnt * pre;
break;
}
if (pos[i].size() == 0) continue;
if (pre == -INF){
x = pos[i][0];
pre = val[i];
cnt += pos[i].size();
}
else {
res[x] += cnt * (pre - val[i]);
if (pos[i][0] < x) x = pos[i][0];
cnt += pos[i].size();
pre = val[i];
}
}
for (int i = 1; i <= n; i++) cout << res[i] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecd vector<double>
#define vecst vector<string>
#define vecb vector<bool>
#define v2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vb2(v,n,m,init) vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>> v(n, vector<ll>(m, init))
#define rep(i,n) for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n) vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n) vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n) vecst var(n); rep(i,n){cin >> var[i];}
#define all(var) (var).begin(), (var).end()
#define sortall(var) sort(all(var))
#define uniqueall(v) v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var) push_back(var)
#define prt(var) cout << (var) << "\n"
#define prtd(n, var) cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var) cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2) cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v) rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
int main(void){
ll a, b, k;
cin >> a >> b >> k;
if(a>=k){
prt2(a-k, b);
} else {
prt2(0, max(0ll, b-(k-a)));
}
}
| 0 | 58,505,252 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++) cin>>a[i];
if(*min_element(a.begin(),a.end()) != 1) {
cout<<"-1";
return 0;
}
vector<int> p;
int k=1;
for(int i=0;i<n;i++)
{ int j=i;
for( j=i;j<n;j++)
{
if(a[j]==k)
{ k++;
p.push_back(j);
break;
}
}
i=j;
}
cout<<n-p.size()<<endl;
}
|
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>
using namespace std;
#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")
using ll = long long int;
ll gcd(ll a, ll b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
ll beki(ll a, ll b) {
ll tmp = 1;
rep(i, b) tmp *= a;
return tmp;
}
ll modPow(ll x, ll a) {
if (a == 1) return x;
if (a % 2) return (x * modPow(x, a - 1)) % MOD;
ll t = modPow(x, a / 2);
return ((t % MOD) * (t % MOD)) % MOD;
}
ll modInv(ll x) {
return modPow(x, MOD - 2);
}
ll N, A, B;
int main() {
cin >> N >> A >> B;
ll tmp = N / (A + B);
cout << A * tmp + min(N - (A + B) * tmp, A) << endl;
}
| 0 | 26,076,052 |
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=9999999999999999;
int main() {
int A,B,C;
cin>>A>>B>>C;
cout<<(A+B+C)-max({A,B,C})<<endl;
return 0;}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
typedef pair<pi,int> pii;
int n;
set <int> coords;
vector <pii> points;
int main() {
FAST
cin >> n;
for (int i =0;i<n;i++) {
int x,y; cin >> x >> y;
points.push_back(pii(pi(x,y),0));
}
for (int i=0;i<n;i++) {
int x,y; cin >> x >> y;
points.push_back(pii(pi(x,y),1));
}
sort(points.begin(),points.end());
int ans = 0;
for (auto cur: points) {
int y = cur.f.s;
if (cur.s == 0) {
coords.insert(y);
} else {
auto it = coords.lower_bound(y);
if (it == coords.begin()) continue;
it--;
coords.erase(it);
ans++;
}
}
cout << ans;
}
| 0 | 800,462 |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sort(a) sort((a).begin(), (a).end());
#define uniq(a) SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
srand((unsigned)time(NULL));
fix(12)
ll n; cin >> n;
if (n < 1200)
outl("ABC")
else
outl("ARC")
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod2=1000000007;
ll mod=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
if(a<b)return b;
else return a;
}
ll lmin(ll a,ll b){
if(a<b)return a;
else return b;
}
int main(){
ll n;cin>>n;
ll a[n];
ll sum=0;
rep(i,0,n){
cin>>a[i];
sum+=a[i];
}
for(ll i=max((ll)0,sum-n*(n-1));i<sum+1;i++){
ll cnt=0;
rep(j,0,n){
ll r=a[j]+i-n+1;
if(r<=0)continue;
cnt+=r/(n+1);
if(r%(n+1)!=0)cnt++;
}
if(cnt==i){
cout<<i<<endl;
return 0;
}
}
}
| 0 | 30,855,904 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
int main() {
ll n,k;
cin>>n>>k;
ll a[n];
ll ok=0,temp1=0;
rep(i,n) cin>>a[i];
rep(i,n){
if(temp1<a[i]) ok++,temp1=a[i];
else break;
}
if(k<=ok){
cout<<0<<endl;
return 0;
}
ll ans=100000000000000000;
for(ll bit=0;bit<(1LL<<(n-ok));bit++){
ll cansee=0;
for(ll i=0;i<n-ok;i++){
if(bit&(1LL<<i)) cansee++;
}
if(cansee>=k-ok){
ll temp2=temp1;
ll yen=0;
for(ll i=0;i<n-ok;i++){
if(bit&(1LL<<i)){
if(temp2==a[i+ok]){
yen++;
temp2++;
}
else if(temp2>a[i+ok]){
yen+=(temp2-a[i+ok]+1);
temp2++;
}
else{
temp2=a[i+ok];
}
}
else{
if(temp2<a[i+ok]) temp2=a[i+ok];
}
}
ans=min(ans,yen);
}
}
cout<<ans<<endl;
}
|
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);
int main()
{
optimize();
int h, w;
cin>> h>> w;
char a[h+10][w+10];
int r[h+1]= {}, c[w+1]={};
for(int i=0; i<h; i++)
{
for(int j=0; j<w; j++)
{
cin>> a[i][j];
if( a[i][j]=='#')
{
r[i]++;
c[j]++;
}
}
}
for(int i=0; i<h; i++)
{
if(r[i]== 0)
continue;
for(int j=0; j<w; j++)
{
if(c[j]== 0)
continue;
cout << a[i][j];
}
nl;
}
return 0;
}
| 0 | 89,055,018 |
#include<iostream>
#include<vector>
using namespace std;
int get_square(int x){
return x*x;
}
int main(){
vector<int> area_anss;
int d;
while(cin>>d){
int area=0;
for(int i=1;i<600/d;i++){
area=area+get_square(i*d)*d;
}
area_anss.push_back(area);
}
for(int i=0;i<area_anss.size();i++){
cout<<area_anss[i]<<endl;
}
}
|
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define inputInt(a) int a; cin >> a;
#define inputInt2(a,b) int a; int b; cin >> a >> b;
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N) for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
#define show(v) FOR(i,v.size()){ cout << v[i] << " "; } cout << endl;
#define showshow(v) FOR(i,v.size()){ FOR(j,v[i].size()){ cout << v[i][j] << " "; } cout << endl; }
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int LIMIT = 1e6;
vector<ll> FacMod(LIMIT), InvMod(LIMIT), FacInvMod(LIMIT);
const int dpComTableLIMIT = 3e3+1;
vector<vector<ll>> Com(dpComTableLIMIT,vector<ll>(dpComTableLIMIT,0));
const int ComKTableLIMIT = 1e7;
vector<ll> ComK(ComKTableLIMIT);
void DPComInit(){
for(int i=0; i<dpComTableLIMIT; i++){ Com[i][0] = 1; }
for(int i=1; i<dpComTableLIMIT; i++){
for(int j=1; j<dpComTableLIMIT; j++){
Com[i][j] = (Com[i-1][j-1]+Com[i-1][j])%MOD;
}
}
}
void ComKInit(ll N){
for(int i=0; i<=ComKTableLIMIT; i++){
if(0<i && i<=N/2){
ComK[i] = (ComK[i-1]*(N-i+1)/i)%MOD;
}else if(i==0){
ComK[i] = 1;
}else if(N/2<i && i<=N){
ComK[i] = ComK[N-i];
}else{
ComK[i] = -1;
}
}
}
void ComInit(){
FacMod[0] = FacMod[1] = 1;
InvMod[0] = 0; InvMod[1] = 1;
FacInvMod[0] = FacInvMod[1] = 1;
for(int i=2; i<LIMIT; i++){
FacMod[i] = FacMod[i-1]*i%MOD;
InvMod[i] = -InvMod[MOD%i]*(MOD/i)%MOD + MOD;
FacInvMod[i] = FacInvMod[i-1] * InvMod[i]%MOD;
}
}
ll ComMod(int n, int k){
if(n>=0 && k>=0 && n>=k){
return FacMod[n]*(FacInvMod[k]*FacInvMod[n-k]%MOD)%MOD;
}else{
return 0;
}
}
ll power(ll x, ll y){
if(y < 0){
return 0;
}else if(y == 0){
return 1LL;
}else if(y%2 == 0){
return power(x,y/2)*power(x,y/2);
}else{
return power(x,y-1)*x;
}
}
ll mpower(ll x, ll y, ll m){
if(y < 0){
return 0;
}else if(y == 0){
return 1LL;
}else if(y%2 == 0){
return mpower(x,y/2,m)*mpower(x,y/2,m)%m;
}else{
return mpower(x,y-1,m)*x%m;
}
}
ll GCD(ll a, ll b){
return b ? GCD(b,a%b) : a;
}
ll LCM(ll a, ll b){
return (a / GCD(a,b))*b;
}
pair<map<ll,ll>,bool> PrimeFactorization(ll N){
pair<map<ll,ll>,bool> ret;
ret.second = true;
if(N != 2){
while(N%2 == 0){
N /= 2;
ret.first[2] ++;
ret.second = false;
}
}
for(ll i=3; i*i<=N; i+=2){
while(N%i == 0){
N /= i;
ret.first[i] ++;
ret.second = false;
}
}
if(N != 1){
ret.first[N] ++;
}
return ret;
}
bool compare_by_second(pair<ll,ll> a, pair<ll,ll> b){
return a.second != b.second ? a.second < b.second : a.first < b.first;
}
class UnionFind {
vector<int> parent;
vector<int> rank;
vector<int> size;
public:
UnionFind(int N);
int root(int x);
void unite(int x, int y);
bool isUnited(int x, int y);
int getRank(int x);
int getSize(int x);
};
UnionFind::UnionFind(int N):parent(N),rank(N,1),size(N,1){
for(int i=0; i<N; i++){parent[i]=i;}
}
int UnionFind::root(int x){
if(parent[x] == x) return x;
return root(parent[x]);
}
void UnionFind::unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry) return;
ll xs = size[root(x)]; ll ys = size[root(y)];
size[root(x)] += ys;
size[root(y)] += xs;
if(rank[x] >= rank[y]){parent[ry] = rx; rank[y]+=1;}
else{parent[rx] = ry; rank[x]+=1;}
}
bool UnionFind::isUnited(int x, int y) {
int rx = root(x);
int ry = root(y);
parent[x]=rx; parent[y]=ry;rank[x]=2;rank[y]=2;
return rx == ry;
}
int UnionFind::getRank(int x){
return rank[x];
}
int UnionFind::getSize(int x){
return size[root(x)];
}
bool isOK(ll condition){
return true;
}
ll binary_search(){
ll ok = 1e18;
ll ng = -1;
while(abs(ok-ng) > 1){
ll mid = (ok+ng)/2;
if(isOK(mid)){
ok = mid;
}else{
ng = mid;
}
}
return ok;
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M; cin >> N >> M;
vector<map<ll,pair<ll,bool>>> graph(N);
vector<vector<ll>> d(N,vector<ll>(N,1e18));
FOR(i,N){ d[i][i] = 0; }
vector<vector<ll>> next(N,vector<ll>(N));
FOR(i,N){ FOR(j,N){ next[i][j] = j; } }
FOR(i,M){
ll a, b, c; cin >> a >> b >> c; a --; b --;
graph[a][b] = mp(c,false);
graph[b][a] = mp(c,false);
d[a][b] = c;
d[b][a] = c;
}
FOR(k,N){
FOR(i,N){
FOR(j,N){
if(d[i][j] > d[i][k]+d[k][j]){
d[i][j] = d[i][k]+d[k][j];
next[i][j] = next[i][k];
}
}
}
}
FOR(s,N){
FOR(g,N){
ll now = s;
while(now != g){
ll nex = next[now][g];
ll c = graph[now][nex].first;
graph[now][nex] = mp(c,true);
graph[nex][now] = mp(c,true);
now = nex;
}
}
}
ll ans = 0;
FOR(i,N){
map<ll,pair<ll,bool>> mp = graph[i];
for(auto itr = mp.begin(); itr != mp.end(); itr ++){
if(!((itr->second).second)) ans ++;
}
}
cout << ans/2 << endl;
return 0;
}
| 0 | 5,098,094 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define vector_rsort(x) sort(all(x));reverse(all(x))
#define array_rsort(x,n) sort(x,x+n);reverse(x,x+n);
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
int n,u,k,v;
int g[105][105];
int main(){
scanf("%d",&n);
rep(i,n){
scanf("%d%d",&u,&k);
rep(i,k){
scanf("%d",&v);
g[u][v]=1;
}
}
REP(i,1,n+1){
printf("%d",g[i][1]);
REP(j,2,n+1){
printf(" %d",g[i][j]);
}
printf("\n");
}
return 0;
}
|
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define dbg(x) cerr << #x << " = " << x << '\n'
#define sz(x) (int)x.size()
#define all(a) (a.begin(),a.end())
#define ff first
#define ss second
#define pii pair<int,int>
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;
inline void solve(){
map <int,int> hash;
int n,m,ans=0; cin>>n>>m;
while (n--){
int a,b;
cin>>a>>b;
hash[a] += b;
}
for (auto &it: hash){
if (it.ss<=m) m -= it.ss,ans += it.ss*it.ff ;
else {
ans += m*it.ff;
break;
}
}
cout << ans << endl;
}
signed main()
{
int n=1;
while (n--) solve();
return 0;
}
| 0 | 58,190,097 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
if (a + b == 15)
cout << '+';
else if (a * b == 15)
cout << '*';
else
cout << 'x';
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9;
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
Int check(vector<vector<Int> > G, Int root,Int d){
function<Int(Int,Int,Int)> dfs = [&](Int pos,Int pre,Int dis){
Int res = dis;
for(Int to:G[pos]){
if(to == pre) continue;
res += dfs(to, pos, dis+1);
}
return res;
};
return dfs(root, -1, 0) == d;
}
signed main(){
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int n;
cin>>n;
vector<P> D(n);
map<Int,Int> num;
for(Int i=0;i<n;i++){
Int d;
cin>>d;
D[i] = P(d, i);
num[d] = i;
}
sort(D.begin(), D.end(), greater<P>());
vector<Int> sz(n, 1);
vector<vector<Int> > G(n);
auto add_edge = [&](Int a,Int b){
G[a].push_back(b);
G[b].push_back(a);
};
for(Int i=0;i<n-1;i++){
Int d, pos; tie(d, pos) = D[i];
Int x = sz[pos];
Int nd = d + x - (n - x);
if(!num.count(nd)){
cout<<-1<<endl;
return 0;
}
Int to = num[nd];
if(d <= nd){
cout<<-1<<endl;
return 0;
}
add_edge(pos, to);
sz[to] += sz[pos];
}
if(!check(G, D[n-1].second, D[n-1].first)){
cout<<-1<<endl;
return 0;
}
for(Int i=0;i<n;i++)
for(Int to:G[i]){
if(i > to) continue;
cout<<i+1<<" "<<to+1<<endl;
}
return 0;
}
| 0 | 85,980,843 |
#include <iostream>
#include <vector>
#include <numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPONE(i, n) for(int i = 1; i < n; i++)
#define ll long long
using namespace std;
int main()
{
int n; cin >> n;
vector<ll> time;
ll t;
REP(i, n) {
cin >> t;
time.push_back(t);
}
ll ans = time[0];
REPONE(i, n) {
ans = ans / gcd(ans, time[i]) * time[i];
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("avx2")
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
int qpow(int b,int e){
if( !e ) return 1;
if( e & 1 ) return qpow(b,e-1) * b % mod;
int pwur = qpow(b,e>>1);
return (pwur * pwur) % mod;
}
int modinv(int x){
return qpow(x,mod-2);
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cout.setf(ios::fixed); cout.precision(0);
srand(time(NULL));
int n;
cin>>n;
map<int,int>mp;
rep(i,n){
int x;
cin>>x;
mp[x]++;
}
int ans=0;
for(auto v:mp){
if(v.f>v.s)ans+=v.s;
else ans+=abs(v.s-v.f);
}
cout<<ans<<enl;
return 0;
}
| 0 | 84,921,808 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.