akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

const int dx[] = {1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1};
const int dy[] = {0, 1, 0, 1,-1, 0, 0, 1, 1, 1, 1,-1,-1};
const int dz[] = {0, 0, 1, 0, 0, 1,-1, 1,-1, 1,-1, 1,-1};

int main()
{
  while(1){
    int n, m, p;
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0) break;
    int b[n][n][n];
    fill(b[0][0], b[n][0], -1);
    string ans_s;
    int ans_t = 0;
    bool flag = true;
    for(int i = 1; i <= p; i++){
      int x, y, z;
      cin >> x >> y;
      if(flag){
        z = 0;
        while(b[x-1][y-1][z] != -1)
          z++;
        b[x-1][y-1][z] = i % 2;
        for(int l = 0; l < n; l++){
          for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
              if(b[l][j][k] != -1){
                for(int c = 0; c < 13; c++){
                  int s = l, t = j, u = k;
                  int d = 0;
                  if(b[s][t][u] == 1){
                    while(s >= 0 && s < n && t >= 0 && t < n && u >= 0 && u < n && b[s][t][u] == 1){
                      s += dx[c];
                      t += dy[c];
                      u += dz[c];
                      d++;
                    }
                    if(d >= m){
                      flag = false;
                      ans_s = "Black";
                      ans_t = i;
                    }
                  }else if(b[s][t][u] == 0){
                    while(s >= 0 && s < n && t >= 0 && t < n && u >= 0 && u < n && b[s][t][u] == 0){
                      s += dx[c];
                      t += dy[c];
                      u += dz[c];
                      d++;
                    }
                    if(d >= m){
                      flag = false;
                      ans_s = "White";
                      ans_t = i;
                    }
                  }
                }
              }
            }
          } 
        }
      }
    }
    if(ans_t != 0)
      cout << ans_s+" " << ans_t << endl;
    else
      cout << "Draw" << endl;
  }
}

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

int main(){
  int N; cin >> N;
  if(N==1){
    cout <<"YES" << endl;
    return 0;
  }
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for(int i=0;i<N-1;i++){
    if(A[i]==A[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
# cording: utf-8

num = int(input())

list = []
scard = []
hcard = []
ccard = []
dcard = []

for i in range(num):
    card = input().rstrip().split(" ")
    list.append(card)

for i in range(num):
    if (list[i][0] == 'S'):
        scard.append(list[i][1])
    elif (list[i][0] == 'H'):
        hcard.append(list[i][1])
    elif (list[i][0] == 'C'):
        ccard.append(list[i][1])        
    else:
        dcard.append(list[i][1])

sscard = sorted([ int(x) for x in scard])
shcard = sorted([ int(x) for x in hcard])
sccard = sorted([ int(x) for x in ccard])
sdcard = sorted([ int(x) for x in dcard])

for i in range(1,14):
    if i not in sscard:
        print("S" + " " + str(i))
for i in range(1,14):
    if i not in shcard:
        print("H" + " " + str(i))
for i in range(1,14):
    if i not in sccard:
        print("C" + " " + str(i))
for i in range(1,14):
    if i not in sdcard:
        print("D" + " " + str(i))

Measured memory_bytes: 7776
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



int main(){
    int k, s, ans = 0,z;
    cin >> k >> s;
    rep(x,k+1){
        rep(y,k+1){
            z = s - x - y;
            if (z>=0&&z<=k){
                // cout << x << "," << y << "," << z << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(int w1,int w2, int s1, int s2, int solute, int volume){
	int WS = w1*100, S = 0;
	int wend = volume/100 + 1;
	double maxper = 0.0;
	rp(iw, 1, wend) rp(jw, 0, wend){
		int w = w1*iw + w2*jw;
		if(w >= wend) break;
		int send = volume - w*100 + 1;
		rp(is, 0, send) rp(js, 0, send){
			int s = s1*is + s2*js;
			if(s >= send) break;
			if(s > solute*w) break;
			int ws = w * 100 + s;
			if(ws > volume) break;
			double per = 100.0*s/ws;
			if(maxper < per){
				maxper = per;
				WS = ws;
				S = s;
			}
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
#define F first
#define S second
typedef pair<int,int> Pi;
#define INF 1 << 29
#define pb push_back

inline void chmin(int &a, int b) {
  a = min(a,b);
}

inline void chmax(int &a, int b) {
  a = max(a,b);
}

int main()
{
  int N, K;
  while(cin >> N >> K,N || K) {
    int Q, A, B, C;
    int path[105][105];
    fill(path[0],path[105],INF);
    Rep(i,105) {
      path[i][i] = 0;
    }
    while(K--) {
      cin >> Q >> A >> B;--A,--B;
      if(Q) {
	cin >> C;
	chmin(path[A][B],C);
	chmin(path[B][A],C);
        Rep(i,N)Rep(j,N) {
	  chmin(path[i][j],min(path[i][A] + path[A][B] + path[B][j],path[i][B] + path[B][A] + path[B][j]));
	  path[j][i] = path[i][j];
	}
      }else {
	if(path[A][B] == INF) {
	  cout << -1 << endl;
	} else {
	  cout << path[A][B] << endl;
	}	
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>

int main(void)
{
	float a,b,c,d,e,f;
	float x,y;
	
	
	while((scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f))!=EOF){
		x = ((c*e-f*b)/(a*e-d*b));
		y = ((a*f-d*c)/(a*e-d*b));
		if(x == -0.000000)
			x=0.000000;
		else if(y==-0.000000)
			y=0.000000;
		else{}
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
template<typename T = int> using V = vector<T>;
template<typename T = int> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  int k; cin >> k;

  if (k == 1) {
    cout << "1\n1\n";
    return 0;
  }

  int n = (k+1)/2;
  if (n&1) ++n;

  auto a = make_vec(n, n, 0);
  rep(i, n) rep(r, n) {
    int j = (i+r) % n;
    a[i][j] = 2*r + j%2 + 1;
  }

  int kr = k%4;
  if (kr == 1) {
    rep(i, n) rep(j, n) {
      if (a[i][j] >= 2*n-5 && a[i][j] <= 2*n-4) a[i][j] = 2*n-5;
      if (a[i][j] >= 2*n-3 && a[i][j] <= 2*n-2) a[i][j] = 2*n-4;
      if (a[i][j] >= 2*n-1 && a[i][j] <= 2*n-0) a[i][j] = 2*n-3;
    }
  }
  if (kr == 2) {
    rep(i, n) rep(j, n) {
      if (a[i][j] >= 2*n-3 && a[i][j] <= 2*n-2) a[i][j] = 2*n-3;
      if (a[i][j] >= 2*n-1 && a[i][j] <= 2*n-0) a[i][j] = 2*n-2;
    }
  }
  if (kr == 3) {
    rep(i, n) rep(j, n) {
      if (a[i][j] >= 2*n-1 && a[i][j] <= 2*n-0) a[i][j] = 2*n-1;
    }
  }

  cout << n << '\n';
  for (auto &e : a) cout << e << '\n';
}


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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.141592653589793238462643383279;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} init;

int N;
int P[220000];
int idx[220000];
set<int> set_hi, set_lo;
signed main() {
    cin >> N;
    reps(i, N) { cin >> P[i], idx[P[i]] = i; }
    int ans = 0;
    set_hi.insert(N + 1), set_lo.insert(0);
    reps(i, N) {
        int cur = idx[i];
        int l = -*set_lo.upper_bound(-cur), r = *set_hi.upper_bound(cur);
        ans += (cur - l) * (r - cur) * i;
        set_hi.insert(cur), set_lo.insert(-cur);
    }
    cout << ans << endl;
}

Measured memory_bytes: 22144
// B - Crane and Turtle
#include <bits/stdc++.h>
using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    bool flag = false;
    for(int i=0; i<=x; i++){
        if(y == 2*i+4*(x-i)) flag = true; 
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;   
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    for(int i=0;i<3;i++) cout<<a[i]<<" ";
    return 0;
}


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

int main(int argc, char* argv[])
{
    int a, b;
    cin >> a >> b;
    if(a>b) cout << "a > b" << endl;
    if(a<b) cout << "a < b" << endl;
    if(a==b) cout << "a == b" << endl;
    return 0;
}



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

int main(){
  long long N, A, B, blue=0,count ,x;
  cin >> N >> A >> B;
  x = N /(A + B);
  blue = A * x;
  count = (A+B)*x;
  if((A + B) * x == N) blue = blue;
  if(count + A > N) blue += N - count;
  else if(count + A + B > N) blue += A;
  cout << blue << endl;
}

Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split()))
for i in reversed(range(n-1)):
    if H[i] <= H[i+1]:
        continue
    elif H[i] == H[i+1]+1:
        H[i] -= 1
    else:
        print('No')
        exit()
else:
    print('Yes')


Measured memory_bytes: 85036
#include <iostream>
#include <map>

using ll = long long;
using namespace std;

int main() {
    string s;
    cin >> s;
    map<char, int> l;
    for (char &a : s) {
        l[a]++;
    }
    for (char i = 'a'; i <= 'z'; ++i) {
        if(!l[i]){
            cout << i << "\n";
            return 0;
        }
    }
    cout << "None" << "\n";
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
    // in;
    // out;
    string s;
    string ss;
    cin>>s>>ss;
    string sss="";
    for(int i=0;i<ss.length()-1;i++){
        sss+=ss[i];
    }
    // cout<<s<<endl;
    // cout<<ss<<endl;
    // cout<<sss<<endl;
    if(sss==s) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=2e5+6;
#define i0(x)(x*2)
#define i1(x)(x*2+1)
vector<int>G[N];
int n,X[N],Y[N],dfn[N],top,SCC,low[N],sta[N],idx,bel[N];
bool vis[N];
pair<int,int>A[N];
inline void addedge(int u,int v){G[u].push_back(v);}
void build(int l,int r,int o){
	const int id=o+n;
	if(l==r){
		addedge(i0(id),A[l].second^1),addedge(A[l].second,i1(id));
	}else{
		const int mid=l+r>>1;
		build(l,mid,o<<1),build(mid+1,r,o<<1|1);
		const int idL=(o<<1)+n,idR=(o<<1|1)+n;
		addedge(i0(id),i0(idL)),addedge(i1(idL),i1(id));
		addedge(i0(id),i0(idR)),addedge(i1(idR),i1(id));
	}
}
void add(int l,int r,int o,const int&L,const int&R,const int&id_){
	if(L<=l&&r<=R){
		const int id=o+n;
		addedge(id_,i0(id)),addedge(i1(id),id_^1);
	}else{
		const int mid=l+r>>1;
		if(L<=mid)add(l,mid,o<<1,L,R,id_);
		if(mid<R)add(mid+1,r,o<<1|1,L,R,id_);
	}
}
void dfs(int now){
	vis[now]=1,sta[++top]=now;
	dfn[now]=low[now]=++idx;
	for(int to:G[now])
	if(!dfn[to]){
		dfs(to);
		low[now]=min(low[now],low[to]);
	}else if(vis[to])low[now]=min(low[now],dfn[to]);
	if(low[now]==dfn[now]){
		++SCC;
		int v;
		do{
			v=sta[top--];
			vis[v]=0;
			bel[v]=SCC;
		}while(v!=now);
	}
}
bool check(int d){
	for(int i=0;i<N;++i)G[i].clear();
	build(0,2*n-1,1);
	for(int i=0;i<2*n;++i){
		int it=lower_bound(A,A+2*n,make_pair(A[i].first-d+1,0))-A;
		if(it<i)add(0,2*n-1,1,it,i-1,A[i].second);
		it=lower_bound(A,A+2*n,make_pair(A[i].first+d,0))-A-1;
		if(i<it)add(0,2*n-1,1,i+1,it,A[i].second);
	}
	memset(dfn,0,sizeof dfn);
	memset(bel,0,sizeof bel);
	idx=SCC=top=0;
	for(int i=0;i<N;++i)if(!dfn[i])dfs(i);
	for(int i=0;i<N/2;++i)
	if(bel[i0(i)]==bel[i1(i)])return 0;
	return 1;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=0;i<n;++i)cin>>X[i]>>Y[i],A[i0(i)]=make_pair(X[i],i0(i)),A[i1(i)]=make_pair(Y[i],i1(i));
	sort(A,A+2*n);
	int l=1,r=A[2*n-1].first-A[0].first,ans=0;
	while(l<=r){
		const int mid=l+r>>1;
		if(check(mid))l=(ans=mid)+1;else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 28032
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;


int main() {
    string s;
    cin >> s;
    int n = s.size();
    // 二文字つながったところがあればそこが答え
    // それ以外の場合
    // abacaのような形しかありない→奇数項がmajor
    // abacaがあればabaもある→これだけ調べればOK

    int a = -1, b = -1;
    for (int i = 0; i < n-1; i++) {
        if (s[i] == s[i + 1]) {
            a = i+1, b = i + 2;
            break;
        }
    }
    if (a == -1 && b == -1) {
        for (int i = 0; i < n - 2; i++) {
            if (s[i] == s[i + 2]) {
                a = i+1, b = i + 3;
                break;
            }
        }
    }
    printf("%d %d\n", a, b);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    
    int n;
    cin >> n;
    vector<int> a(n, 0);
    vector<int> ret;
    
    int sum = 0;
    int tmp = 0;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum += abs(a[i] - tmp);
        tmp = a[i];
    }
    
    sum += abs(tmp);
    
    ret.push_back(sum - abs(a[0]) - abs(a[1] - a[0]) + abs(a[1]));
    
    for (int i = 1; i < n - 1; ++i)
    {
        ret.push_back(sum - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]));
    }
    
    ret.push_back(sum - abs(a[n - 1] - a[n - 2]) - abs(a[n - 1]) + abs(a[n - 2]));
    
    for (int i = 0; i < n; ++i)
    {
        cout << ret[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2168
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    while b:
        a, b = b, a % b
    return a

def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


def multi_lcm(array: list) -> int:
    ans = array[0]
    for i in range(1, len(array)):
        ans = (ans * array[i]) // gcd(ans, array[i])
    return ans


n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

lcm_ = multi_lcm(a) % MOD
ans = 0
for i in range(n):
    ans += lcm_ * pow(a[i], MOD - 2, MOD) 
    ans %= MOD
print(ans)

Measured memory_bytes: 41692
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int a,b,c,k; cin >>a >>b >>c >>k;
  while(b<=a){b*=2; k--;}
  while(c<=b){c*=2; k--;}
  if(k>=0) cout <<"Yes";
  else cout <<"No";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>

struct edge{
  int to;
  int ind;
};

std::vector<std::vector<edge>> G(55);
std::vector<long long> paths(55);
int N,M,U[22],V[22];

long long dfs(int v,int tar,int par,long long path){
  if(v==tar){
    return path;
  }
  for(edge e:G[v]){
    if(e.to==par) continue;
    long long res=dfs(e.to,tar,v,path+(1LL<<e.ind));
    if(res!=-1) return res;
  }
  return -1;
}

void solve(){
  std::cin>>N;
  for(int i=0;i<N-1;i++){
    int A,B;
    std::cin>>A>>B;
    A--,B--;
    G[A].push_back({B,i});
    G[B].push_back({A,i});
  }
  std::cin>>M;
  for(int i=0;i<M;i++){
    std::cin>>U[i]>>V[i];
    U[i]--,V[i]--;
    paths[i]=dfs(U[i],V[i],-1,0);
  }
  
  long long ans=0;
  for(int bit=1;bit<(1<<M);bit++){
    long long orpath=0,bit_popcount=0;
    for(int i=0;i<M;i++){
      if((bit>>i)&1){
        orpath|=paths[i];
        bit_popcount++;
      }
    }
    int path_popcount=0;
    for(int i=0;i<N-1;i++){
      if((orpath>>i)&1) path_popcount++;
    }
    if(bit_popcount%2) ans+=1LL<<(N-1-path_popcount);
    else ans-=1LL<<(N-1-path_popcount);
  }
  std::cout<<(1LL<<(N-1))-ans<<std::endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> pi;
typedef long long int ll;
#define F first
#define S second
#define MP make_pair
const int N=5e5+10;
const ll INF=1LL<<60;
ll dis(pi a,pi b){
    ll x=a.F-b.F,y=a.S-b.S;
    return x*x+y*y;
}
int main(){
    int n,lim;
    ll ans=INF;
    pi a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d%d",&a[i].F,&a[i].S);
    sort(a,a+n);
    lim=min(3,n);
    for(int i=0;i<lim;i++)for(int j=i+1;j<lim;j++)ans=min(ans,dis(a[i],a[j]));
    for(int i=lim;i<n;i++)for(int j=1;j<=lim;j++)ans=min(ans,dis(a[i],a[i-j]));
    printf("%lld\n",ans);
}


Measured memory_bytes: 6596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)

typedef complex<double> P;
#define PI acos(-1)
#define EPS 1e-10
#define INF 1e9

int N;
P p[100][2];

double cross(P a, P b) { return imag(conj(a) * b); }

bool is_crossing(P a1, P a2, P b1, P b2)
{
	bool l = cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1) < EPS;
	bool r = cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1) < EPS;
	return l && r;
}

P intersection_is(P a1, P a2, P b1, P b2)
{
	P b = b2 - b1;
	double d1 = abs(cross(b, a1 - b1));
	double d2 = abs(cross(b, a2 - b1));
	double t = d1 / (d1 + d2);
	return a1 + (a2 - a1) * t;
}

int solve()
{
	int ans = 1;

	rep(i, 0, N)
	{
		ans++;

		vector<double> dist;
		rep(j, i + 1, N) if (is_crossing(p[i][0], p[i][1], p[j][0], p[j][1]))
		{
			P c = intersection_is(p[i][0], p[i][1], p[j][0], p[j][1]);

			if (abs(abs(real(c)) - 100.0) < EPS) continue;
			if (abs(abs(imag(c)) - 100.0) < EPS) continue;

			dist.push_back(abs(p[i][0] - c));
		}

		sort(dist.begin(), dist.end());

		rep(j, 0, dist.size())
		{
			if (j != 0)
			{
				if (abs(dist[j] - dist[j - 1]) < EPS) continue;
			}
			ans++;
		}
	}

	return ans;
}

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

	while (1)
	{
		cin >> N;
		if (N == 0) return 0;

		rep(i, 0, N) rep(j, 0, 2)
		{
			double x, y; cin >> x >> y;
			p[i][j] = P(x, y);
		}

		cout << solve() << endl;
	}
}

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

int main(){
    string n;
    cin >> n;
    int l = n.size(), sum = 0;
    for (int i = 0; i < l; i++){
        sum += n[i] - '0';
        sum %= 9;
    }
    if (sum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3668
<?php
  $n = trim(fgets(STDIN));
  $work = [];
  for($i=0; $i<$n; $i++){
      fscanf(STDIN, "%d%d", $a,$b);
      $work[$b] += $a;
  }
  ksort($work);
//   print_r($work);
  $flag = true;
  $sum = 0;
  foreach ($work as $end => $time){
      $sum += $time;
      if($sum > $end){
          $flag = false;
      }
  }
  if($flag){
      echo "Yes";
  }else{
      echo "No";
  }

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

const int N = 55;

struct Song {
    string title;
    int dur;
} song[N];

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

    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> song[i].title >> song[i].dur;
    }

    string x;
    cin >> x;

    int ans = 0;
    bool isSum = false;

    for (int i = 0; i < n; i++) {
        if (isSum) {
            ans += song[i].dur;
        }

        if (song[i].title == x) {
            isSum = true;
        }
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
         
         
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        ll mod=1e9+7;
        ll mod1=1e9+5;
        ll power(ll a,ll b)
        {
            if(b==0) return 1;
            else if(b%2==0)
                return power((((a%mod)*(a%mod))%mod),b/2)%mod;
            else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        }
       
       
        
        int32_t main()
        {
            IOS
           
             
        
        int n,ans=0;
        cin>>n;
        string s;
        cin>>s;
        for(int i=0;i<n;++i)
        {
            for(int j=i;j<n;++j)
            {
                if(s[i]==s[j])
                {
                    if(j==n-1)
                        i=n-1;
                }
                else
                {
                    i=j-1;
                    break;
                }
            }
            ans++;
        }
        cout<<ans;

        }


Measured memory_bytes: 512
K, N = map(int, input().split())
A = list(map(int, input().split()))
dA = [0] * N
for i in range(N-1):
    dA[i] = A[i+1] - A[i]
dA[N-1] = A[0] + K - A[N-1]
print(K - max(dA))

Measured memory_bytes: 32284
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
void add(int &x,int y){
    x += y;
    x = x >= mod ? x - mod : x;
    return;
}
int mul(int x,int y){
    return (1LL * x * y) % mod;

}
int pow(int val,int idx){
    if(idx == 0) return 1;
    if(idx == 1) return val;
    int k = pow(val, idx >> 1);
    k = mul(k,k);
    if(idx & 1) return mul(val,k);
    return k;
}
int ab(int val){
    while(val < 0) val+=mod;
    if(val > mod) val %= mod;
    return val;
}
int fac[(int)1e5 + 10];
ll a[(int)1e5 + 10];
int ncr(int x,int y){
    int inv1 = pow(fac[x-y],mod - 2),inv2 = pow(fac[y],mod-2);
    return mul(fac[x],mul(inv1,inv2));
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    fac[0] = 1;
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        fac[i] = mul(fac[i-1],i);
    }
    sort(a+1,a+n+1);
    int ans = 0;
    for(int i =2;i<=n;i++) a[i] += a[i-1];
    for(int i = k;i <= n;i++){
        add(ans, mul(ncr(i-2,k-2),(a[n]-a[i-1]-a[n-i+1])%mod));
    }
    printf("%d",ans);
}


Measured memory_bytes: 1408
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

n = max(A)
mid = n / 2
r = float("inf")
for a in A:
    if a == n:
        continue
    if abs(mid - r) > abs(mid - a):
        r = a

print(n, r)

Measured memory_bytes: 19988
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e5+5;
void solve(int tc)
{
    //  cout<<"Case #"<<tc<<": ";
    int n,i,j,p,k,m,q,l,r;
    cin>>n>>k;
    int ar[n];
    rep(i,n)
        cin>>ar[i];
    vector<int> dp(n , inf);
    dp[0] = 0;
    repv(i,1,n-1)
    {
        for(j=1; j<=k; j++)
        {
            if(i-j >= 0)
                dp[i] = min(dp[i] , dp[i-j] + abs(ar[i] - ar[i-j]));
            else
                break;
        }
    }
    cout<<dp[n-1];
}       
signed main()
{
    // ar.cpp
    RAGE;
 //   db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
//    timeit();
    return 0;
}


Measured memory_bytes: 4792
n,*A=map(int,open(a:=0).read().split());A=[0]+sorted(A);S=[0]*(n+1)
for i in range(1,n+1):S[i]=S[i-1]+A[i]
for x,y in zip(A[:0:-1],S[-2::-1]):
  a+=1
  if x>y*2:break
print(a)

Measured memory_bytes: 20296
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void){
  cout << std::fixed << std::setprecision(16);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  std::priority_queue<int64_t> pq;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    pq.push(a);
  }
  for(int i=0;i<m;i++){
    int tgt=pq.top();
    pq.pop();
    pq.push(tgt/2);
  }
  int64_t result=0;
  while(!pq.empty()){
    result+=pq.top();
    pq.pop();
  }
  cout<<result<<endl;





  return 0;
}


Measured memory_bytes: 1400
n = int(input())

from collections import defaultdict
from math import sqrt

A = defaultdict(int)

def factorize(n):    
    i = 2
    
    while n % i == 0:
        n //= i
        A[i] += 1
    i += 1

    while n != 1 and i <= sqrt(n):
        while n % i == 0:
            n //= i
            A[i] += 1
        i += 2
    if n != 1:
        A[n] += 1

    return A

for i in range(1, n+1):
    factorize(i)

ans = 0

c_74 = 0
c_2 = 0
c_24 = 0
c_4 = 0
c_14 = 0

for k, v in A.items():
    if v >= 74:
        c_74 += 1
    if v >= 2:
        c_2 += 1
    if v >= 24:
        c_24 += 1
    if v >= 4:
        c_4 += 1
    if v >= 14:
        c_14 += 1

ans += c_74
ans += max(0, (c_2 - 1) * c_24)
ans += max(0, (c_2 - 2) * c_4 * (c_4 - 1) // 2)
ans += max(0, c_14 * (c_4 - 1))

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  vector<bool> D(101,false);
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> d;
    D[d] = true;
  }
  int answer = 0;
  for(int i = 1;i < 101;i++){
    if(D[i] == true)answer++;
  }
  cout << answer << endl;
}
  


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL MOD = 1e9+7;

int main() {
    int N;
    cin >> N;
    map<string, bool> dic;
    REP(i, N) {
        string s;
        cin >> s;
        dic[s] = true;
    }
    cout << dic.size() << endl;
    return 0;
}


Measured memory_bytes: 19116
#!/usr/bin/env python
# coding: utf-8

# In[6]:


N = int(input())
S = input()


# In[9]:


w = S.count(".")
b = 0
ans = min(w,N-w)
for i in range(N):
    if S[i] == ".":
        w -= 1
    else:
        b += 1
    ans = min(ans, w+b)
print(ans)


# In[ ]:






Measured memory_bytes: 9460
#include <iostream>
#include <algorithm>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int n;
int a[110];
int main()
{
  cin >> n;
  rep(i,n) cin >> a[i];

  double sum = 0;
  rep(i,n) sum += (double)1/a[i];
  
  double res = 1/sum;
  printf("%.9f\n", res);
  return 0;
}


Measured memory_bytes: 256
#import collections
#aa = collections.Counter(a) # list to list
#mod = 10**9 + 7
def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = [readInts() for _ in range(2)]

    #print(*A)
    # 下に行くidxを決めておく
    idx = 0
    # ゆーてnまでしかいけないけど
    ma_ = -1
    while idx < n:
        j = 0
        cnt = 0 # なんぼあるいたか
        dist = 0 #距離
        k = 0
        while k <= idx:
            if cnt <= n:
                dist += A[j][k]
                cnt += 1
            else:
                break
            k += 1
        k -=1
        # ここで下にずらす
        if cnt <= n:
            j += 1
            #print(idx,j,k)
            dist += A[j][k]
            cnt += 1
        k += 1 # 次始まるときはk += 1からだから
        # 右側を探索
        if cnt <= n:
            while k < n:
                if cnt <= n:
                    #print(k)
                    dist += A[j][k]
                    cnt += 1
                else:
                    break
                k += 1
        idx += 1
        #print(dist)
        ma_ = max(ma_,dist)
    print(ma_)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38800
#include <stdio.h>

int main()
{
	int n, l;
	
	scanf("%d %d", &n, &l);
	
	int sum=(n*(2*l+(n-1)))/2;
	
	if(l<0 && (l+(n-1))<0){ sum=sum-(l+(n-1)); }
	else if(l<0 && (l+(n-1))>=0){ sum=sum-0; }
	else{ sum=sum-l; }
	
	printf("%d", sum);
	
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
 
int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
 
    ll straight = min(K, X / D);
    K -= straight;
    X -= straight * D;
 
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        cout << D - X << endl;
    }
 
    return 0;
}

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

struct Node {
	int key;
	Node *prev, *next;
};

Node *nil;

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t) {
	if (t == nil) {
		return;
	}
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deletekey(int key) {
	deleteNode(listSearch(key));
}

void printList() {
	Node *cur = nil->next;
	int i = 0;
	while (1) {
		if (cur == nil) break;
		if (i > 0) printf(" ");
		i++;
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main() {
	int key;
	int n;
	int i;
	char com[20];

	scanf("%d", &n);
	init();

	for (i = 0; i < n; i++) {
		scanf("%s %d", com, &key);
		if (com[0] == 'i') {
			insert(key);
		}
		else if (com[0] == 'd') 
			if (strlen(com) > 6) {
				if (com[6] == 'F') {
					deleteFirst();
				}
				else if (com[6] == 'L') {
					deleteLast();
				}
			}
			else {
				deletekey(key);
			}
	}

	printList();

	return 0;
}

Measured memory_bytes: 32216
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);
const int MAXN = 105;
const int INF = 1e9+7;
int dis[MAXN];
vector<P> v[MAXN];
int n, m;
int d[MAXN][MAXN];
int a[MAXN][MAXN];
int main()
{
    //FIN;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        for(int  j =1; j <= n; j++)
        {
            a[i][j] = d[i][j] = INF;
        }
    }
    for(int i = 0; i <= n; i++)
    {
        d[i][i] = a[i][i] = 0;
    }
    for(int i = 0 ; i< m; i++)
    {
        int u , v, w;
        cin >> u >> v >> w;
        a[u][v] = a[v][u] = d[u][v] = d[v][u] = w;
    }
    for(int k = 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n ; j++)
            {
                if(i != j && i != k)
                {
                    a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
                }
            }
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = i + 1; j <= n ;j++)
        {
            if(d[i][j] < INF && a[i][j] != d[i][j]) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	long long A,B,C;
	cin>>A>>B>>C;
	int sum;
	bool p=false;
	for(int i=0;i<=1000;i++)
	{
		if(A%2==1||B%2==1||C%2==1)
		{
			sum=i;
			p=true;
			break;
		}
		int A1,B1,C1;
		A1=A;
		B1=B;
		C1=C;
		A=B1/2+C1/2;
		B=A1/2+C1/2;
		C=A1/2+B1/2;
	}
	if(p==true)
		cout<<sum<<endl;
	else
		cout<<"-1"<<endl;	
}

Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

#define int long long
ll N;

ll A[100010];
ll B[100010];

signed main(void){
	scanf("%lld", &N);
	rep(i, N)scanf("%lld", &A[i]);
	ll sum = 0;
	rep(i, N) sum += A[i];

	if(sum % (N*(N+1)/2)){
		printf("NO\n"); return 0;
	}

	ll k = sum / (N*(N+1)/2);
	// printf("%lld\n", k);
	rep(i, N) B[i] = A[(i + 1) % N] - A[i % N];
	rep(i, N) B[i] -= k;

	ll cnt = 0;

	rep(i, N){
		if(B[i] > 0){
			printf("NO\n");
			return 0;
		}
		ll t = -B[i];
		if(t % N){
			printf("NO\n");
			return 0;
		}
		// printf("t %lld\n", t);
		cnt += t / N;
	}

	if(cnt == k){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(size_t, N);

    vector<intmax_t> a(N);
    input(a);

    intmax_t res = 0;
    for (const auto e: a) {
        res += __builtin_ctz(e);
    }

    output(res);

    return 0;
}


Measured memory_bytes: 384
//package abc166.D

import java.io.*
import java.math.*
import java.util.*
import kotlin.math.*

var reader: BufferedReader = System.`in`.bufferedReader()
var writer: PrintWriter = PrintWriter(System.`out`)

fun next() = reader.readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextStrings() = next().split(" ")
fun nextInts() = nextStrings().map { it.toInt() }
fun nextLongs() = nextStrings().map { it.toLong() }
fun nextDoubles() = nextStrings().map { it.toDouble() }

fun put(v: Any?) = writer.print(v)
fun puts() = writer.println()
fun puts(v: Any?) = writer.println(v)

var debug = false
fun dp(v: Any?) {
    if (debug) println(v)
}
fun dp() {
    if (debug) println()
}

fun test(case: Int, input: String, expected: String) {
    reader = input.trimIndent().reader().buffered()

    val stringWriter = StringWriter()
    writer = PrintWriter(stringWriter)

    solve()
    writer.flush()

    val actual = stringWriter.toString()

    println("[test $case]")
    if ("${expected}" == actual) {
        println("OK")
    } else {
        println("NG")
        println()
        println("expected: \"${expected}\"")
        println("actual:   \"${actual}\"")
    }
    println()
}

@Suppress("UNUSED_PARAMETER")
fun xtest(case: Int, input: String, expected: String) {}

fun main(args: Array<String>) {
    if ((args.size == 1) && (args[0] == "test")) {
        testAll()
    } else {
        solve()
        writer.flush()
    }
}

///////////////////////////////////////////////////////////

fun testAll() {
    debug = true

    test(1,
    """
    33
    """,
    "2 -1"
    )
    test(2,
    """
    1
    """,
    "0 -1")
    test(3,
    """
    530707531
    """,
    "102 101")
}

fun pow5(value: Long): Long {
    var vv = value*value
    return vv * vv * value
}

fun findB(b5: Long): Long? {
    var l = 1L
    var u = 1L
    while (pow5(u) < b5) {
        //dp("$b5: $u(${pow5(u)})")
        u *= 2
    }

    while (l <= u) {
        var m = l + (u-l)/2
        var m5 = pow5(m)
        //dp("$b5: [$l, $u]: $m($m5)")

        if (m5 == b5) {
            return m
        } else if (m5 < b5) {
            l = m + 1
        } else {
            u = m - 1
        }
    }

    return null
}

fun doSolve(): Pair<Long, Long> {
    val X = nextLong()

    var a = 0L
    while (true) {
        //dp("$a")
        val a5 = pow5(a)

        val b5 = a5 - X
        //dp("$b5")

        if (b5 == 0L) {
            return Pair(a, 0)
        } else if (b5 > 0) {
            val b = findB(b5)
            if (b != null) {
                return Pair(a, b)
            }
        } else {
            val b = findB(-b5)
            if (b != null) {
                return Pair(a, -b)
            }
        }
        ++a
        //dp()
    }
}

fun solve() {
    val (a, b) = doSolve()
    put("$a $b")
}


Measured memory_bytes: 34484
// C - Write and Erase
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define all(x) (x).begin(),(x).end()

int main(){
	int N; cin>>N;
	vi A(N);
	rp(i, 0, N) cin>>A[i];
	sort(all(A));
	int ans = 0;
	int count = 1;
	rp(i, 0, N-1)
		if(A[i] == A[i+1]) count++;
		else{
			if(count&1) ans++;
			count = 1;
		}
	if(count&1) ans++;
	printf("%d\n", ans);
}

Measured memory_bytes: 640
import java.util.* ;
public class Main {
    public static void main(String[] args) {
        Main obj = new Main() ;
        Scanner S = new Scanner( System.in ) ;
        int result = 0 ;
        int n = S.nextInt() ;
        for( int i=1;i<=n;i++ ) {
            int num = S.nextInt() ;
            if( ( i==1 || i%2!=0 ) && num%2!=0 ) result++ ;
        }
        System.out.println( result ) ;
    }
}

Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
using LL = long long;

const LL mod = 1e9 + 7;

map<LL, LL> d;

LL f(LL x) {
  if (x <= 1) return x;
  if (d.count(x)) return d[x];
  LL y = (x - 1) / 2;
  LL a = f(y);
  LL b = f(y + 1);
  LL ret;
  if (x & 1) {
    ret = (a * 3 + (b - a)) % mod;
    if (ret < 0) ret += mod;
  } else {
    ret = (a * 3 + (b - a) * 2) % mod;
    if (ret < 0) ret += mod;
  }
  return d[x] = ret;
}

int main() {
  LL n;
  cin >> n;
  cout << f(n + 1) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919810364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n;
pair<P, P> a[1010];
int d[1010][20010];

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first.second >> a[i].second.first >> a[i].second.second;
		a[i].first.first = a[i].first.second + a[i].second.first;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 20000; j++)d[i + 1][j] = d[i][j];
		for (int j = 0; j <= a[i].second.first; j++)d[i + 1][j + a[i].first.second] = max(d[i + 1][j + a[i].first.second], d[i][j] + a[i].second.second);
	}
	int ans = 0;
	for (int i = 0; i <= 20000; i++)ans = max(ans, d[n][i]);
	cout << ans << endl;
}

Measured memory_bytes: 157824