akhauriyash/Code-Regression huggingface dataset:
//金字塔
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n,a[2000001];
bool check(int x){
	int tmp=0;
	for(int i=1;i<n;i++)
		if(a[i]>=x&&a[i+1]>=x)
			tmp=i+1;
	if(tmp==n)return true;
	if(tmp){
		for(int j=tmp;a[j+2]>=x&&j<=2*n-3;j+=2,tmp++);
		if(tmp>=n)return true;
	} //从左往右
	tmp=0;
	for(int i=2*n-1;i>n;i--)
		if(a[i]>=x&&a[i-1]>=x)
			tmp=i-1;
	if(tmp==n) return true;
	if(tmp){
		for(int j=tmp;a[j-2]>=x&&j>=3;j-=2,tmp--);
		if(tmp<=n) return true;
	} //从右往左
	tmp=0;
	for(int i=1;i<=2*n-1;i+=2)
		if(a[i]<x)tmp=1;
	if(!tmp)return true; //特判10101
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++)
		scanf("%d",&a[i]);
	int l=2,r=2*n-2,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)) l=mid+1;
			else r=mid-1;
	}
	printf("%d\n",l-1);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  int k, n;
  cin >> k >> n;
  for (int i = n - (k - 1); i < n + k; i++) {
    cout << i << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  ll r,D,x;
  cin >> r >> D >> x;
  rep(i,10) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int dist[100010];
int main()
{
	int N, X, Y;
	cin >> N >> X >> Y;
	X--; Y--;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			dist[min(j - i, abs(X - i) + 1 + abs(j - Y))]++;
		}
	}
	for (int i = 1; i < N; i++) {
		cout << dist[i] << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s; cin >> s;
  string t;
  for(int i = 0; i < (s.size() - 1)/2; i++){
    t.push_back(s.at(i));
  }
  string u = t;
  reverse(t.begin(), t.end());
  int f = 1;
  if(u!=t) f = 0;
  string v = s;
  reverse(s.begin(), s.end());
  if(v!=s) f = 0;
  if(f==0){
    cout << "No";
  }else{
    cout << "Yes";
  }
}

Measured memory_bytes: 256
# include <stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
	long long int N;
	long long int x = 1E9+7;
	int i;
	long long int m,b,y,a;
	m = 1;
	b = 1;
	y = 1;
	a = 0;
	scanf("%lld",&N);
	for(i=1;i<=N;i++)
	{
		m = 10*m;
		m = m%x;
	}
	for(i=1;i<=N;i++)
	{
		b = 9*b;
		b = b%x;
	}
	for(i=1;i<=N;i++)
	{
		y = 8*y;
		y = y%x;
	}
	a = m - 2*b + y+2*x;
	a = a%x;
	printf("%lld",a);
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>

#include <stdlib.h>

int main(void){ 

int n,Count=0,count2=0,i,len,kazu[1000],sum=0; 

char x[1000],a; 

while(1){ 

sum=0; 

scanf("%s",x); 

if(x[0]=='0'){ 

break; 

} 

len=strlen(x); //????????°??°??? 

for(i=0;i<len;i++){ 

a=x[i]; 

kazu[i]=atoi(&a); 

sum=sum+kazu[i]; 

} 

printf("%d\n",sum);  

}   

return 0;

}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
 int N;
 string S;
 cin >> N >> S;
  int ans = 0;
  for(int i = 0; i < S.size() - 2; i++) {
    if(S.substr(i, 3) == "ABC") ans++;
  }

  cout << ans;

 return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

bool is_prime(ll n) {
    for (int i = 2; i*i <= n; ++i) {
        if (n % i == 0) return false;
    }
    if(n==1) return false;
    return true;
}

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    cin>>n;
    vector<ll> v;
    for(j=1;j<=100000;j+=2){
            if(is_prime(j)&&is_prime((j+1)/2)) v.push_back(j);
    }

    //rep(i,v.size()) cout<<v[i];
    
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        cout<<upper_bound(v.begin(),v.end(),b)-lower_bound(v.begin(),v.end(),a)<<endl;
    }


    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

#define MAX_N (1<<17)
struct SegTree {
  long long seg[MAX_N*2-1];

  void update(int i, long long x) {
    i += MAX_N-1;
    if (seg[i] >= x) return;
    seg[i] = x;
    while (i > 0) {
      i = (i-1) / 2;
      seg[i] = max(seg[i*2+1], seg[i*2+2]);
    }
  }

  long long query(int a, int b, int k=0, int l=0, int r=MAX_N) {
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return seg[k];
    return max(
      query(a, b, k*2+1, l, (l+r)/2),
      query(a, b, k*2+2, (l+r)/2, r)
    );
  }
};

int N;
int A[100000];
SegTree seg;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) {
    seg.update(A[i], seg.query(0, A[i]) + A[i]);
  }
  long long sum = 0;
  rep(i, N) sum += A[i];
  cout << sum - seg.query(0, N+1) << "\n";
  return 0;
}

Measured memory_bytes: 5132
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, m = map(int, input().split())
    balls = [1] * (n + 1)
    posib = [0] * (n + 1)
    posib[1] = 1
    m = map(int, read().split())
    ab = zip(m, m)
    for x, y in ab:
        if posib[x]:
            posib[y] = 1
        balls[y] += 1
        balls[x] -= 1
        if not balls[x]:
            posib[x] = 0
    r = sum(posib)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 103672
n=int(input())
l=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append((a+b,a,b))
l.sort(reverse=True)
c1=0
c2=0
for i in range(n):
    if i%2==0:
        c1+=l[i][1]
    else:
        c2+=l[i][2]
print(c1-c2)

Measured memory_bytes: 61404
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n;
  int count;
  bool up,leftUp,rightUp;
  string str;
  while(cin>>n,n!=0){
    count=0;
    up=leftUp=rightUp=false;
    REP(i,n){
      cin>>str;
      if(str=="lu"){leftUp=true;}
      else if(str=="ru"){rightUp=true;}
      else if(str=="ld"){leftUp=false;}
      else if(str=="rd"){rightUp=false;}
      if(!up&&leftUp&&rightUp){
	count++;
	up=true;
      }else if(up&&!leftUp&&!rightUp){
	count++;
	up=false;
      }
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1216
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n;
int deg[150005], par[150005];
Ldouble dp[150005], dp2[150005];
Ldouble ans[150005];

vector<int> v[150005];

void dfs(int id, int pv){
	par[id] = pv;
	for(auto to: v[id]){
		if(to == pv) continue;
		dfs(to, id);
		deg[id]++;
		dp[id] += dp2[to] + 1;
	}
	if(deg[id]) dp2[id] = dp[id] / deg[id];
	return;
}

void calc(int id, int pv, Ldouble up){
	
//	printf("%d %d %.10lf\n", id, pv, (double)up);
	
	if(pv == 0) ans[id] = dp2[id];
	else ans[id] = (dp[id] + up) / (deg[id] + 1);
	
	for(auto to: v[id]){
		if(to == pv) continue;
		if(pv == 0){
			if(deg[id] == 1) calc(to, id, 1.0);
			else calc(to, id, (dp[id] - (1 + dp2[to])) / (deg[id] - 1) + 1);
		}
		else calc(to, id, ((dp[id] - (1 + dp2[to])) + up) / deg[id] + 1);
	}
}

int main(){
	scanf("%d", &n);
	FI(i, 2, n){
		int a, b;
		scanf("%d %d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(1, 0);
	calc(1, 0, 0.0);
//	FI(i, 1, n) printf("%d: %.10lf %.10lf\n", i, (double)dp[i], (double)dp2[i]);
	FI(i, 1, n) printf("%.10lf\n", (double)ans[i]);
	return 0;
}

Measured memory_bytes: 25600
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)cout << "Draw" << endl;
	else if (a == 1)cout << "Alice" << endl;
	else if (b == 1)cout << "Bob" << endl;
	else if (a < b)cout << "Bob" << endl;
	else if (a > b)cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 256
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
def comb(n,k,mod):
    c = 1
    for i in range(k):
        c = c*(n-i)%mod
        c = c*mod_inv(i+1,mod)%mod
    return c
n,k = map(int,input().split())
mn = 0
ma = 0
a = list(map(int,input().split()))
a.sort()
mod = 10**9 + 7
c = 1
for i in range(n-k+1):
    mn += a[n-k-i]*c
    ma += a[k-1+i]*c
    c = c*(k+i)%mod
    c = c*mod_inv(i+1,mod)%mod
print((ma-mn)%mod)

Measured memory_bytes: 14416
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int ac=0, wa=0, tle=0, re=0;
  string s;
  for(int i=0;i<n;i++) {
    cin >> s;
    if (s == "AC") ac++;
    else if(s == "WA") wa++;
    else if(s == "TLE") tle++;
    else re++;
  }
  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d", re);
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
//#include <iostream>
// #include <vector>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> B(N-1);
    for (int i=0; i<N-1; ++i){
        cin >> B.at(i);
    }
    vector<int> A(N);
    A.at(0) = B.at(0);
    for(int i=1; i<N-1; ++i){
        if(B.at(i-1) <= B.at(i)){
            A.at(i) = B.at(i-1);
        }
        else{
            A.at(i) = B.at(i); 
        }
    }
    A.at(N-1) = B.at(N-2);

    int sum=0;
    for (int i=0; i<N; i++){
        sum += A.at(i);
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i = 1; i <= (n); ++i)
using ll = long long;
using P = pair<int, int>;

long long MOD = 1e9 + 7;

long long modPow(long long x, long long a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % MOD;
  long long t = modPow(x, a / 2);
  return (t * t) % MOD;
}

long long modInv(long long x) {
  return modPow(x, MOD - 2);
}

long long modPerm(long long n, long long k) {
  long long ret = 1;
  for (long long i = 0; i < k; i++) {
    ret = (ret * (n - i)) % MOD;
  }
  return ret;
}

long long modComb(long long n, long long k) {
  long long a, b;
  a = modPerm(n, k);
  b = modPerm(k, k);
  return (a * modInv(b)) % MOD;
}

ll s, ans;

int main() {
  cin >> s;
  ans = 0;
  rep (k, s/3) {
    ans += modComb(s-2*k-1, k-1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  string w;
  cin >> w;
  vector<int> cnt(26, 0);
  string ab = "";
  for (char c = 'a'; c <= 'z'; ++c) {
    ab += c;
  }
  for (int i = 0; i < w.size(); ++i) {
    for (int j = 0; j < 26; ++j) {
      if (w[i] == ab[j]) {
        ++cnt[j];
        break;
      }
    }
  }
  bool flg = true;
  for (int i = 0; i < 26; ++i) {
    if (cnt[i] % 2 != 0) {
      flg = false;
      break;
    }
  }
  if (flg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INFTY 10000000
 
int n;
int M[N][N];
int color[N], d[N], f[N];
int tt;
int Q[N*2];
int head, tail;

int empty(){
  return head==tail;
}

void bfs(int s){
  int i,u,v;
  head=tail=1;
  Q[tail++]=s;
  for(i=0;i<n;i++){
    d[i]=INFTY;
  }
  d[s]=0;
  while(!empty()){
    u=Q[head++];
    for(v=0;v<n;v++){
      if(M[u][v]==0){
	continue;
      }
      if(d[v]!=INFTY){
	continue;
      }
      d[v]=d[u]+1;
      Q[tail++]=v;
    }
  }
  for (i=0;i<n;i++){
    printf("%d %d\n", i+1,((d[i]==INFTY)?(-1):d[i]));
  }
}

int main(){
  int u,k,v,i,j; 
  scanf("%d", &n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){  
    scanf("%d %d", &u, &k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}
 

Measured memory_bytes: 636
import math
n = int(input())
a = list(map(int,input().split()))
dic_S = {0:[0]}
S = 0
ans = 0
for i in range(n):
    S += a[i]
    if S not in dic_S:
        dic_S[S] = []
    else:
        pass
    dic_S[S].append(a[i])
    

for k in dic_S.keys():
    I = len(dic_S[k])
    if 3 <= I:
        ans += math.factorial(I) // (math.factorial(I-2)*2)
    elif I == 2:
        ans += 1
    else:
        pass
print(ans)


Measured memory_bytes: 54996
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define lowbit(x) x&(-x)
#define _ %Mod
#define __ %=Mod
using namespace std;

const int maxn = 22;
const int maxm = 22;
const int maxk = 1100000;
const ll Mod = 1e9+7;

int n,m,K;
int ci[maxm][maxn];
ll f[2][maxk];

int main()
{
	scanf("%d%d%d",&n,&m,&K); n--;
	memset(ci,-1,sizeof ci);
	for(int i=1;i<=K;i++)
	{
		int x,y,z; scanf("%d%d%d",&x,&y,&z);
		ci[x][y-1]=z;
	}
	
	int al=1<<n;
	int now=0; f[0][0]=1ll;
	for(int i=1;i<=m;i++) for(int j=0;j<n;j++) 
	{
		for(int k=0;k<al;k++) if(f[now][k])
		{
			ll tmp=f[now][k];
			
			if(!(k>>j&1)&&ci[i][j]!=1) (f[!now][k]+=tmp)__;
			if(ci[i][j]==0) continue;
			if(k>>j&1) (f[!now][k]+=tmp)__;
			else
			{
				int lk=k&(1<<j+1)-1,nk=k^lk;
				nk=nk^lowbit(nk)^lk^1<<j;
				(f[!now][nk]+=tmp)__;
			}
		}
		memset(f[now],0,sizeof f[now]); now=!now;
	}
	ll ans=0;
	for(int k=0;k<al;k++) (ans+=f[now][k])__;
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 17408
def ceil(v):
	if v % 10 == 0:
		return v
	else:
		return (v // 10+1) *10

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

times = [A,B,C,D,E]

minMod = 9
last = times[0]
for time in times:
	if minMod > (time+9) % 10:
		minMod = (time+9) % 10
		last = time
		
times.remove(last)

for i,time in enumerate(times):
	times[i] = ceil(time)
	
times.append(last)

print(sum(times))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = LLONG_MAX;
constexpr double DINF = DBL_MAX;
constexpr ll mod = 1e9+7;
constexpr double PI = M_PI;

long long fact(long long n){
  long long x = 1;
  while(n > 1ll){
    x = (x*n) % mod;
    n--;
  }
  return x;
}

long long expo(long long a, long long p){
  if(p == 0ll){
    return 1ll;
  }else if(p%2ll == 0){
    long long cmp = expo(a, p/2ll);
    return (cmp*cmp) % mod;
  }else{
    return (expo(a, p-1)*a) % mod;
  }
}

int main(){
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
 
  long long x, y;
  cin >> x >> y;
  long long h = 1, w = 1;
  while(x > 0 and y > 0){
    if(x > y){
      x -= 2;
      y--;
      w++;
    }else{
      x--;
      y -= 2;
      h++;
    }
  }
  if(x != 0  or y != 0){
    cout << 0 << endl;
    return 0;
  }
  long long ans, tmp;
  ans = fact(w+h-2);
  tmp = (fact(w-1) * fact(h-1)) % mod;
  ans *= expo(tmp, mod-2) % mod;
  cout << ans%mod << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

#define INF (100000000)

int A[1000];
int B[1000];

int dp[1000][10001];

int main()
{
	int H, N;

	cin >> H >> N;
	rep(i, N) cin >> A[i] >> B[i];

	rep(i, N) repc(j, 1, N) dp[i][j] = INF;

	rep(i, N) repc(j, 1, H) {
		if (i == 0) {
			dp[i][j] = B[i] * ((j + A[i] - 1) / A[i]);
		}
		else {
			if (j - A[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i][j - A[i]] + B[i]);
			else dp[i][j] = min(dp[i - 1][j], B[i]);
		}
	}
	
	cout << dp[N - 1][H] << endl;

	return 0;
}


Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

struct UnionFind {
    // 親ノードの番号を持つメンバ変数
    // ただし自分が親の時は-x(xは自身を含めた子ノードの数)
    vector<int> par;
    
    //　コンストラクタでの初期化1(初期値-1を持つn次元配列)
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    // 与えられたノードの親ノードの番号を返すメンバ関数
    int root(int x) {
        // もしも親ノードが0以下なら、それは初期値なので自身が親
        if (par[x] < 0) return x;
        // 親ノードを再帰的に一番上までたどって返す
        // 単にroot(par[x])ではなく代入してるのは、根に直接張り直すため
        else return par[x] = root(par[x]);
    }
    
    // もし根が同じかどうかの判定
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    // ２つの根をマージする処理
    bool merge(int x, int y) {
        // 根をたどって、同じなら何もしない
        x = root(x); y = root(y);
        if (x == y) return false;

        // xもyも今は親ノードなので、子の数を比べる
        if (par[x] > par[y]) swap(x, y); // merge technique

        // 小さい方を親ノードにする
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    // 親ノードに入っている番号*-1 = この木のノード数を返す。
    int size(int x) {
        return -par[root(x)];
    }
};

int main()
{
    cout << fixed << setprecision(15);

    ll N, M;
    cin >> N >> M;

    vector<ll> A(M);
    vector<ll> B(M);

    REP(i, M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    vector<ll> ans;
    ll count = N*(N-1)/2;

    UnionFind uf(N);

    // 辺を1つずつ足していく
    REP(i, M){

        // 現在の非連結ペアの数を格納
        ans.push_back(count);

        ll x = A[M-i-1];
        ll y = B[M-i-1];

        // 同じ木に属すなら処理終了
        if(uf.issame(x, y)) continue;

        // 新たにくっついたときに連結できる様になるペアの数を数える
        ll pairs = uf.size(x) * uf.size(y);

        // 答えからペアの数を引く
        count -= pairs;

        //最後にマージ処理をする
        uf.merge(x, y);
    }

    REP(i, M){
        cout << ans[M-i-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int i = 0;
    while (a > 0 && c > 0) {
        if (i % 2 == 0)
            c -= b;
        else
            a -= d;
        i++;
    }

    if (a > 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
	ll a,b,c,d;
	cin>>a>>b;
	c=(a+b)/2;
	d=c*2;
	if (d==(a+b)) cout<<c<<endl;
	else
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 555;

string s[N];
string a[N];
string b[N];

int main() {
    ios_base::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        cin >> s[i];
    for (int i = 0; i < h; i++) {
        a[i] = s[i];
        b[i] = s[i];
    }
    for (int i = 0; i < h; i++) {
        a[i][0] = '#';
        b[i][w - 1] = '#';
        for (int j = 1; j < w - 1; j++) {
            if (i % 2 == 0)
                b[i][j] = '#';
            else
                a[i][j] = '#';
        }   
    }
    for (int i = 0; i < h; i++)
        cout << a[i] << endl;
    cout << endl;
    for (int i = 0; i < h; i++)
        cout << b[i] << endl;
    return 0;
}


Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int c[11][1010];
int32_t main()
{
	int h=in();int w=in();int k=in();
	vector<string> s(h);
	for(int i=0;i<h;i++)cin>>s[i];
	
	int ans=h*w;
	for(int mask=0;mask<(1<<(h-1));mask++)
	{
		int g=0;
		vector<int> id(h);
		
		//distributing rows in groups
		for(int i=0;i<h;i++)
		{
			id[i]=g;
			if(mask&(1<<i))g++;
		}
		
		for(int i=0;i<=g;i++)
		for(int j=0;j<w;j++)c[i][j]=0;
		
		for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)c[id[i]][j]+=(s[i][j]-'0');
		
		int cut=g;
		
		
		//lambdas help in not passing everything 
		vector<int> cur(g+1);
		auto add=[&](int j)
		{
			for(int i=0;i<=g;i++)
			cur[i]+=c[i][j];
			
			for(int i=0;i<=g;i++)
			if(cur[i]>k)return 0;
			
			return 1;
		};
		
		for(int j=0;j<w;j++)
		{
			if(!add(j))
			{
				cut++;
				cur=vector<int>(g+1);
				if(!add(j))
				{
					cut=1e9;break;
				}
			}
		}
		ans=min(ans,cut);
	}
	cout<<ans;
	
}

Measured memory_bytes: 3788
//“ In order to be irreplaceable, one must always be different”
#include<bits/stdc++.h>
using namespace std;
#define ll long long
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
//assign() assignes new value
//emplace(position,x) inserting
//erase(position) to remove an element
//swap() for swapping
//reverse(position,position) for reversing
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
# define schar set<char>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define mss map<str,str>
# define mci map<char,ll>
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
ll lcm(ll a, ll b)  
{  
    return (a*b)/gcd(a, b);  
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x,y,z;
    cin>>x>>y>>z;
    vll v;
    for(ll i=0;i<y;i++){
       v.pb(z);
    }
   for(ll i=v.size();i<x;i++){
       if(z!=1000000000){
       v.pb(z+1);}
       else{
           v.pb(z-1);
       }
   }
   for(ll i=0;i<v.size();i++){
       cout<<v[i]<<" ";
   }
}
   

		
	
	
	
	
	
	
	
	
	
	
	

Measured memory_bytes: 2292
#include<iostream>
using namespace std;

int main(){
	int r,b,c,d,e,k;
	cin>>r>>b>>c>>d>>e>>k;
	int a[10];
	a[1]=r;
	a[2]=b;
	a[3]=c;
	a[4]=d;
	a[5]=e;
	for(int i=1;i<=4;i++){
		for(int j=i+1;j<=5;j++){
			if(a[i]-a[j]>k or a[j]-a[i]>k){
				cout<<":("<<endl;
				return 0;
			}
		}
	}
	cout<<"Yay!"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#undef DBG

int main()
{
        int  inputc[4];
        int i;

        inputc[0] = getc(stdin);
        inputc[1] = getc(stdin);
        inputc[2] = getc(stdin);
        inputc[3] = getc(stdin);

        for( i; i < 3; i++ ) {
                if( inputc[i] == inputc[i+1] ) {
                        printf("Bad\n");
                        return 0;
                }
        }
        printf("Good\n");
        return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <unordered_map>

using namespace std;

int main()
{	
	int n, m;
	cin >> n >> m;

	unordered_map<int,int> um;

	for (int i = 0; i < n; i++)
	{
		int k;
		cin >> k;
		for (int j = 0; j < k; j++)
		{
			int a;
			cin >> a;

			um[a]++;
		}
	}

	int ans = 0;
	for (auto a : um)
	{
		if (a.second == n)
		{
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
   int a,b ;
   cin >> a>>b ;
  
  if((a+b)%2==0)
    cout << (a+b)/2 << endl;
  else 
    cout << "IMPOSSIBLE" << endl; 
    return 0;
}



Measured memory_bytes: 256
n = int(input())
s = input()
x = 0
if n % 2 == 0:
    for i in range(int(n / 2)):
        if s[i] == s[i + int(n / 2)]:
            x += 1
elif n == 1:
    x = 100000

if x == int(n / 2):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
signed main(){
	ll int n;
	cin>>n;
	int flag=0;
	for(int i=0;i<=n/4;i++){
		if(!((n-i*4)%7)){
			flag=1;
		}
	}
	if(flag)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int a,b;
	cin>>a>>b;
	for(int i=1;i<=100000;i++){
		if((i*10)/125==a&&i/10==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, three, two, flag = 0;
    cin >> n;
    if(n == 19999){
        n++;
        flag = 1;
    }
    if(n == 3){
        cout << "2 5 63" << endl;
    }else if(n == 4){
        cout << "2 5 20 63" << endl;
    }else if(n == 6){
        cout << "2 3 6 9 10 30" << endl;
    }else{
        two = min(n/3*3, 15000);
        int rest = n-two;
        if(rest & 1){
            two -= 3;
            rest += 3;
        }
        three = rest/2*2;

        if(three == 0){
            two -= 6;
            three += 6;
        }
        while(3+6*(three-1) > 30000){
            three -= 6;
            two += 6;
        }

        reppp(i, 1, two+1){
            if(i == 3 && flag) continue;
            cout << 2*i << " ";
        }
        repp(i, three){
            cout << 3+6*i << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    H, W, K = map(int,input().split())
    Tgt = 0 - K
    Ch = [0] * H
    Cw = [0] * W
    Gmap = []
    for h in range(H):
        r = list(map(int, input().replace('.','0').replace('#','1')))
        Gmap.append(r)
        for w in range(W):
            x = Gmap[h][w]
            Ch[h] += x
            Cw[w] += x
            Tgt += x

    ret = 0
    for hs in range(2**H):
        for ws in range(2**W):
            cnt = 0
            for h in range(H):
                if hs >> h & 1:
                    cnt += Ch[h]
            for w in range(W):
                if ws >> w & 1:
                    cnt += Cw[w]
            for h in range(H):
                for w in range(W):
                    if (ws >> w & 1) and (hs >> h & 1):
                        cnt -= Gmap[h][w]
            if cnt == Tgt:
                ret +=1


    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main 
{
	static class C implements Comparator<Entry>
	{
		@Override
		public int compare(Entry o1, Entry o2) 
		{
			return o1.l - o2.l;
		}
	}
	static class C2 implements Comparator<Entry>
	{
		@Override
		public int compare(Entry o1, Entry o2) 
		{
			return o1.l - o2.l;
		}
	}
	
	static class Entry
	{
		int l;
		int r;
		int id;
		
		public Entry(int l0, int r0, int i) 
		{
			l = l0;
			r = r0;
			id = i;
		}
	}

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		C c = new C();
		C2 c2 = new C2();
		PriorityQueue<Entry> q1 = new PriorityQueue<>(c);
		PriorityQueue<Entry> q2 = new PriorityQueue<>(c);
		
		for(int i = 0; i < n; i++)
		{
			String s = sc.next();
			
			int cur = 0;
			int l = 0;
			for(int j = 0; j < s.length(); j++)
			{
				if(s.charAt(j) == '(')
				{
					cur++;
				}
				else
				{
					cur--;
				}
				l = Math.min(l, cur);
			}
			l*=-1; //entry
			int r = cur; //payoff
//			System.out.println(l + " " + r + " " + s);
			
			if(r < 0)
			{ //do these later
				l = 0;
				r = 0;
				cur = 0;
				
				for(int j = s.length()-1; j >= 0; j--)
				{
					if(s.charAt(j) == ')')
					{
						cur++;
					}
					else
					{
						cur--;
					}
					l = Math.min(l, cur);
				}
				l*=-1; //entry
				r = cur;
				
				q2.add(new Entry(l,r, i));
			}
			else
			{ //do these first
				q1.add(new Entry(l,r, i));
			}
		}
		
		long has = 0;
		
		while(!q1.isEmpty())
		{
			Entry en = q1.poll();
//			System.out.println("Consider " + en.l + " " + en.r + ", has " + has);
			//take this
			if(en.l > has)
			{
				System.out.println("No");
				return;
			}
			else
			{
//				System.out.println("Take ");
				has += en.r;
			}
			if(has < 0)
			{
				System.out.println("No");
				return;
			}
		}
		
		long needtoget = has;
//		System.out.println("S2 need " + needtoget);
		has = 0;
		
		while(!q2.isEmpty())
		{
			Entry en = q2.poll();
//			System.out.println("Consider " + en.l + " " + en.r + ", has " + has);
			//take this
			if(en.l > has)
			{
				System.out.println("No");
				return;
			}
			else
			{
//				System.out.println("Take ");
				has += en.r;
			}
			if(has < 0)
			{
				System.out.println("No");
				return;
			}
		}
		
		if(has != needtoget)
		{
			System.out.println("No");
			return;
		}
		
		System.out.println("Yes");
	}
	

}


Measured memory_bytes: 82700
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder.ABC
{
	class QuestionA
	{
		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());

			var a = new int[n];
			var hash = new HashSet<int>();

			for (int i = 0; i < n; i++) {
				a[i] = int.Parse(Console.ReadLine()) - 1;
			}

			var next = 0;
			var count = 0L;

			while (true) {
				if (hash.Contains(next)) {
					Console.WriteLine(-1);
					return;
				}

				hash.Add(next);
				next = a[next];

				count++;

				if (next == 1) {
					break;
				}
			}

			Console.WriteLine(count);
		}
	}
}


Measured memory_bytes: 34516
using System;
    using System.Linq;
    using System.Collections.Generic;
     
    class Program
    {
        static void Main(string[] args)
        {
            string[] balls = Console.ReadLine().Split(' ');
            string[] nums = Console.ReadLine().Split(' ');
            int A = int.Parse(nums[0]);
            int B = int.Parse(nums[1]);
            string U = Console.ReadLine();

            if(U==balls[0]){
                A -= 1;
            }else{
                B -= 1;
            }

            Console.WriteLine("{0} {1}", A, B);
        }
    }

Measured memory_bytes: 13140
n = gets.chomp.to_i
array = gets.split.map(&:to_i)
sortarray = array.sort
count = 0
n.times do |i|
  if array[i] != sortarray[i]
    count += 1
  end
  if count >= 3
    break
  end
end
if count == 2 || count == 0
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1788
def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 1, 0)
        print(num+1)


main()


Measured memory_bytes: 68620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

long long int gcd(long long int a,long long int b){
	long long int p;
	if (b > a){
		p = a;
		a = b;
		b = p;
	}
	while(b != 0){
		p = a % b;
		a = b;
		b = p;
	}
	return a;
}

long long int lcm(long long int a,long long int b){
	long long int p = gcd(a,b);
	long long int ret = a / p * b;
	return ret;
}


int main(){
	int N;
	cin >> N;
	long long int p[N];
	FOR(i,0,N){
		cin >> p[i];
	}

	long long int ret = p[0];
	FOR(i,1,N){
		ret = lcm(ret,p[i]);
	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string S="";

int main(void) {

	int K;
	cin >> K;

	for (int i = 1; i <= K; i++) {
		S += "ACL";
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;

#define LOOP(val,times) for(val = 0;val < (times);++val)

int main(){
    int dp[10010];
    int n,W;
    int i,j;
    int weight,value;
    scanf("%d %d",&n,&W);
    LOOP(i,10010) dp[i] = 0;
    LOOP(i,n){
        scanf("%d %d)",&value,&weight);
        bool flag = 1;
        while(flag){
            flag = 0;
            LOOP(j,W+1){
                if(j >= weight && dp[j] < dp[j-weight] + value){
                        flag = 1;
                        dp[j] = dp[j-weight] + value;
                }
            }
        }
    }
    printf("%d\n",dp[W]);
    int k;cin >> k;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

map<char, int> character_count(string s){
    map<char, int> counter;
    rep(i, s.size()){
        ++counter[s[i]];
    }

    return counter;
}

string nchar(char c, int n){
    string s = "";
    rep(i, n){
        s.push_back(c);
    }

    return s;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    string s[n];
    rep(i, n) cin >> s[i];

    map<char,int> snuke;
    string alp = "abcdefghijklmnopqrstuvwxyz";
    rep(i, n){
        auto cnt = character_count(s[i]);
        rep(j, 26){
            if(i == 0)
                snuke[alp[j]] = cnt[alp[j]];
            else
                snuke[alp[j]] = min(cnt[alp[j]], snuke[alp[j]]);
        }

    }

    for(auto itr = snuke.begin(); itr != snuke.end(); ++itr)
        cout << nchar(itr->first, itr->second);

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);
int main(){
   string s,t;cin>>s>>t;
   int ans = INF;
   int n =s.length(),m=t.length();
   rep(i,n-m+1){
       int sum =0;
       rep(j,m){
           if(s[i+j]!=t[j])sum++;
       }
       ans=min(ans,sum);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3620
/**
*    created: 03.07.2020 15:56:45
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); 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)
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 long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    char a1, a2, a3, b1, b2, b3;
    cin >> a1 >> a2 >> a3 >> b1 >> b2 >> b3;
    if (a1 == b3 && a2 == b2 && a3 == b1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		Restaurant[] r=new Restaurant[N];

		for(int i=0;i<N;i++) r[i]=new Restaurant(sc.next(),sc.nextInt(),i+1);

		Arrays.sort(r);


		for(int i=0;i<N;i++) {
			System.out.println(r[i].row);
		}

		sc.close();

	}

}

class  Restaurant implements Comparable<Object>{

	String name;
	int score;
	int row;

	public Restaurant(String name,int score,int row) {
		this.name=name;
		this.score=score;
		this.row=row;
	}

	public int compareTo(Object object) {

		Restaurant r=(Restaurant)object;

		if(this.name.compareTo(r.name)==0) {
			return r.score-this.score;
		}else {
			return this.name.compareTo(r.name);
		}

	}
}



Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;

int main()
{
	string S;
  	cin>>S;
  	if(S[1]=='R')
  	{
    	cout<<"ABC"<<endl;
    }
  	else
  	{
    	cout<<"ARC"<<endl;
    }


	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;

int main(){
    int H;
    int W;

    cin >> H >> W;

    while(H != 0&&W != 0){
        for(int x=1; x<=H; x++){
             for(int y=1; y <=W; y++){
                 if(x==1 || x==H){
                cout << '#';
                 }else{
                     if(y==1 || y==W){
                     cout << '#';
                     }else{
                         cout << '.';
                     }
                 }  
             }
             
              cout << endl;
         }
         cout << endl;

         cin >> H >> W;
    }

    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <iomanip>

int main()
{
  int L;
  long double N;

  std::cin >> L;

  N = static_cast<long double>(L) / 3.0;

  std::cout << std::fixed << std::setprecision(15) << N * N * N << std::endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  for (int x = 0; x < s.length()-1; x++) {
    if (s[x] == s[x+1])  {
      cout << x+1 << " " << x+2 << '\n';
      return 0;
    }
    if (x < s.length()-2 && s[x] == s[x+2]) {
      cout << x+1 << " " << x+3 << '\n';
      return 0;
    }
  }
  cout << "-1 -1\n";
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,x;
	scanf("%d",&a);
	if(100<=a&&a<=999){
		b=a/100;
		c=(a/10)%10;
		d=a%10;
		x=(d*100)+(c*10)+b;
		if(a==x)
		 cout<<"Yes";
		else
		 cout<<"No"; 
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k, a, b;
	cin>>k>>a>>b;
	int c = a % k;
	int dl = (k-c) % k;
	if(dl <= (b-a))
		cout<<"OK";
	else
		cout<<"NG";
}


Measured memory_bytes: 3628
price,ticket=[],[]
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
for i in range(M):
    ticket.append(list(map(int,input().split())))
price.append(min(a)+min(b))
for i in range(M):
    price.append(a[ticket[i][0]-1]+b[ticket[i][1]-1]-ticket[i][2])
print(min(price))

Measured memory_bytes: 42516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

using vi = vector<int>;
using vl = vector<long long int>;
using vii = vector<vector<int>>;
using vll = vector<vector<long long int>>;
#define pb push_back;
#define mp make_pair;
/*ll powM(ll a,ll b,ll m)
{
    ll ans=1;
    a%=m;
    while(b)
        {
            if(b&1)ans=ans*a%m;
            a=a*a%m;
            b>>=1;
        }
        return ans;
}
*/


int main(){
      ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(2);
cout<<fixed;
ll n;cin>>n;
string s;
set<string>se;
for(int i=0;i<n;i++)
{
cin>>s;
se.insert(s);
} 
cout<<se.size()<<"\n";
return 0;


}

Measured memory_bytes: 19272
-- vim: set fdm=marker : -- {{{
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Control.Monad.Fix (fix)
import Data.Maybe
import Data.Array.Unboxed
import qualified Data.IntMap as IM
import qualified Data.ByteString.Char8 as BS
-- }}}

-- Input functions with ByteString
-- {{{
tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

readInt :: Num a => BS.ByteString -> a
readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntTuple :: Num a => BS.ByteString -> (a, a)
readIntTuple = tuplify2 . map readInt . BS.words
readIntList :: Num a => BS.ByteString -> [a]
readIntList = map readInt . BS.words

getInt :: Num a => IO a
getInt = readInt <$> BS.getLine
getIntList :: Num a => IO [a]
getIntList = readIntList <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents
-- }}}

main = do
    [w,h,x,y] <- getIntList :: IO [Int]
    putStrLn $ solve (w,h,x,y)

solve :: (Int, Int, Int, Int) -> String
solve (w,h,x,y) = show s ++ if c then " 1" else " 0" where
    s = fromIntegral w * fromIntegral h / 2
    c = fromIntegral w / fromIntegral x == 2.0 && fromIntegral h / fromIntegral y == 2.0


Measured memory_bytes: 508
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int calc(int N)//0^1^...^N-1
{
    int cnt[40]={0};
    REP(i,40){
        if(~N>>i&1) continue;
        for(int j=0;j<i;j++) cnt[j]+=1LL<<(i-1);
        for(int j=i+1;j<40;j++) if(N>>j&1) cnt[j]+=1LL<<i;
    }
    int res=0;
    REP(i,40) if(cnt[i]%2==1) res|=1LL<<i;
    return res;
}

signed main()
{
    int A,B; cin>>A>>B;
    cout<<(calc(B+1)^calc(A))<<endl;
}


Measured memory_bytes: 256