akhauriyash/Code-Regression huggingface dataset:
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int N = 1e5 + 10;
const int M = 1e9 + 7;

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

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}


ll ans = 0LL, n;

void test(ll x) {
	ll c = n;
	while (c % x == 0) c /= x;
	if (c%x==1) ans++;
}

void solve() {
	cin >> n;
	for (ll i = 1LL; i * i <= n - 1LL; ++i) {
		if ((n-1LL) % i == 0) {
			if (i > 1) ans++;
			if ((n-1)/i!=i) ans++;
		}
	}
	for (ll i = 1LL; i * i <= n; ++i) {
		if (n % i == 0) {
			if (i > 1LL) test(i);
			if (i != n/i) test(n/i);
		}
	}
	cout << ans << endl;
}

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

	int t = 1;
    //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
   int  n;
cin >> n;
   if(n%2==0)cout<<n;
   else cout <<n*2;
}

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

using namespace std;

//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int N;

	cin >> N;

	vector<int> p(N);

	for (int i = 0; i < N;i++) {
		cin >> p[i];
	}

	int key = 0;
	int keynum;
	int flag = 0;
	int ansflag = 0;

	for (int i = 0; i < N; i++) {
		if (p[i] != i + 1) {
			flag++;
		}

		if (p[i] != i + 1 && flag == 1) {
			key = p[i];
			keynum = i+1;
		}

		if (p[i] != i + 1 && flag == 2 && i+1 == key && p[i] == keynum) {
			ansflag = 1;
		}

		
	}

	if ((flag == 0 || ansflag == 1) && flag < 3) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int m,n,maximum;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= n-1 && col >= 0 && col <= m-1)return true;
	else{
		return false;
	}
}

void recursive(int table[90][90],int row,int col,int sum){
	sum++;

	if(rangeCheck(row-1,col) == true && table[row-1][col] == 1){
		int new_table[90][90];

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++)new_table[i][k] = table[i][k];
		}
		new_table[row][col] = 0;
		recursive(new_table,row-1,col,sum);
	}
	if(rangeCheck(row+1,col) == true && table[row+1][col] == 1){
		int new_table[90][90];

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++)new_table[i][k] = table[i][k];
		}
		new_table[row][col] = 0;
		recursive(new_table,row+1,col,sum);
	}
	if(rangeCheck(row,col-1) == true && table[row][col-1] == 1){
		int new_table[90][90];

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++)new_table[i][k] = table[i][k];
		}
		new_table[row][col] = 0;
		recursive(new_table,row,col-1,sum);
	}
	if(rangeCheck(row,col+1) == true && table[row][col+1] == 1){
		int new_table[90][90];

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++)new_table[i][k] = table[i][k];
		}
		new_table[row][col] = 0;
		recursive(new_table,row,col+1,sum);
	}

	maximum = max(maximum,sum);
}

/*void clearData(int table[90][90],int row,int col){
	table[row][col] = 0;
	if(rangeCheck(row-1,col) == true && table[row-1][col] == 1)clearData(table,row-1,col);
	if(rangeCheck(row+1,col) == true && table[row+1][col] == 1)clearData(table,row+1,col);
	if(rangeCheck(row,col-1) == true && table[row][col-1] == 1)clearData(table,row,col-1);
	if(rangeCheck(row,col+1) == true && table[row][col+1] == 1)clearData(table,row,col+1);
}*/

int main(){

	int table[90][90];

	while(true){
		scanf("%d",&m);
		scanf("%d",&n);

		if(m == 0 && n == 0)break;

		maximum = 0;

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++)scanf("%d",&table[i][k]);
		}

		for(int i = 0; i < n; i++){
			for(int k = 0; k < m; k++){
				if(table[i][k] == 1){
					recursive(table,i,k,0);
					//clearData(table,i,k);
				}
			}

		}

		printf("%d\n",maximum);
	}

	return 0;
}

Measured memory_bytes: 3500
#include <stdio.h>

void solve(int n) {
	int square[n][n];
	int x, y, i;

	for (y = 0; y < n; y++) {
		for (x = 0; x < n; x++) {
			square[y][x] = 0;
		}
	}
	x = n / 2;
	y = x + 1;
	square[y][x] = 1;

	for (i = 1; i < n*n; i++) {
		x = (x+1) % n;
		y = (y+1) % n;
		if (square[y][x]) {
			x = ((x-1) > -1) ? (x-1) : (n-1);
			y = (y+1) % n;
		}
		square[y][x] = i + 1;
	}

	for (y = 0; y < n; y++) {
		for (x = 0; x < n; x++) {
			printf("%4d", square[y][x]);
		}
		putchar('\n');
	}
}

int main(void) {
	int n;

	while (1) {
		scanf("%d ", &n);
		if (!n)
			break;
		solve(n);
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;
const int INF = 0x3f3f3f3f;
//static const auto _____ = []()
//{
//	ios::sync_with_stdio(false);
//	cin.tie(nullptr);
//	return nullptr;
//}();

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    vector<int> height(N + 1, 0);
    for (int i = 1; i <= N; i++) {
        cin >> height[i];
    }
    vector<int> dp(N + 1, 0);
    dp[1] = 0;
    dp[2] = abs(height[2] - height[1]);
    for (int i = 3; i <= N; i++) {
        dp[i] = min(dp[i - 2] + abs(height[i] - height[i - 2]), dp[i - 1] + abs(height[i] - height[i - 1]));
    }
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ship(n, vector<int>());
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        ship[a].push_back(b);
        ship[b].push_back(a);
    }
    vector<int> dist(n, -1);
    queue<int> q;
    dist[0] = 0; q.push(0);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (auto w : ship[v]) {
            if (dist[w] == -1) {
                dist[w] = dist[v] + 1;
                q.push(w);
            }
        }
    }
    if (dist[n-1] == 2) puts("POSSIBLE");
    else puts("IMPOSSIBLE");

    return 0;
}

Measured memory_bytes: 13168
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main(void){
  char s[100];
  int n,i;
  double x,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %s",&x,s);
    if(s[0]=='J') sum+=x;
    else sum+=(380000*x);
  }
  printf("%lf",sum);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) { rep(i, N) par[i] = i; }

    int root(int x) {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    rep(i, N) { cin >> P[i]; }

    UnionFind tree(N);

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        tree.merge(a, b);
    }

    int cnt = 0;
    rep(i, N) {
        if (tree.same(i, P[i] - 1))
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
import math

a, b, h, m = map(int, input().split())

radians = (abs((h * 60 + m) / (60 * 12) * 360 - m / 60 * 360))

cos = math.cos(math.radians(radians))
len = math.sqrt(a ** 2 + b ** 2 - 2 * a * b * cos)

print(len)

Measured memory_bytes: 9508
#include<cstdio>
#include<cstring>

const int mod=1000000007;

int n,f[4001][4001],m,k,l,ans,x;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	l=(n+m-1)/(k-1);
	memset(f,0,sizeof(f)); f[0][0]=1;
	for (int i=1; i<=l; i++)
		for (int j=0; j<k; j++)
			for (int o=0; o<=m; o++)
				f[i][j+o]=(f[i][j+o]+f[i-1][o])%mod;
	ans=0;
	for (int i=m; i>0; i-=(k-1))
	{
		x=(m-i)/(k-1);
		ans=(ans+f[l-x][i])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

int a[3 + 5];

int v[3 + 5];

int ans = 114514;

int main(void){
  // Here your code !
  for (int i = 0; i < 3; ++i) {
    scanf("%d", &(a[i]));
    v[i] = i;
  }

  do {
    for (int i = 0; i < 4; ++i) {
      int bak = a[i];
      ans = min(ans, abs(a[v[0]] - a[v[1]]) + abs(a[v[1]] - a[v[2]]));
    }

  } while( next_permutation(v, v + 3));

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

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


s64 attack(s64 h)
{
    if (h == 1)
    {
        return 1;
    }
    s64 ret = 0;
    ret += 2 * attack(h / 2) + 1;
    return ret;
}

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

    s64 h;
    cin >> h;

    cout << attack(h) << "\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
using ll = long long;
const int INF = 0x3f3f3f3f;
const int MAX_N = 2000006;

int N;

void solve()
{
	int ans = 0;
	for(int i=1;i<=N;++i)for(int j=1;j<=N;++j)for(int k=1;k<=N;++k)ans++;
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	solve();
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) { cin >> v[i]; }

  int gcd = __gcd(v[0], v[1]);
  for (int i = 2; i < n; i++) {
    gcd = __gcd(gcd, v[i]);
  }

  cout << gcd;
}

Measured memory_bytes: 640
# include <iostream>
# include <vector>
# include <limits>
# include <algorithm>
# include <map>
# include <string>
# include <functional>
# include <cmath>
# include <iomanip>
using namespace std;

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	int ans = 0;
	int posx = 1, posy = 1;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (i == 0) {
			posx = x, posy = y;
		}
		if ((posx < x&&posy > y) || (posx > x&&posy < y)) {
			ans += abs(posx - x) + abs(posy - y);
		}
		else {
			ans += max(abs(posx - x), abs(posy - y));
		}
		posx = x, posy = y;
	}
	cout << ans << endl;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
int inf = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b,m; cin >> a >> b >> m;
    int ai[a], bi[b];
    int mina=inf,minb=inf;
    rep(i,0,a){ cin >> ai[i]; mina = min(mina,ai[i]);}
    rep(i,0,b){ cin >> bi[i]; minb = min(minb,bi[i]); }
    int total_min = mina + minb;
    rep(i,0,m){
        int x,y,c;
        cin >> x >> y >> c;
        total_min = min(total_min,ai[x-1]+bi[y-1]-c);
    }
    cout << total_min << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a>b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD =1e9 + 7;



int main(){
	int n;
    vector<P>v[101010];
    cin>>n;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        v[a].push_back(P(b,i));
        v[b].push_back(P(a,i));
    }
    int k=0;
    bool f[101010]={};
    int ans[101010]={};
    queue<P> q;
    q.push(P(1,0));
    while(q.size()){
        P p=q.front();
        q.pop();
        f[p.F]=1;
        MAX(k,v[p.F].size());
        int c=1;
        for(auto au:v[p.F]){
            if(f[au.F])continue;
            if(c==p.S)c++;
            ans[au.S]=c;
            q.push(P(au.F,c));
            c++;
        }

    }
    cout<<k<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;


}

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

#define INF 1000000000000

int main(){
  int n;
  cin>>n;
  int a[n][3];
  int k;
  rep(i,n){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    if(a[i][2]!=0){k=i;}
  }
  for(int i=0;i<=100;i++){
    for(int j=0; j<=100; j++){
      int t=0;
      t=a[k][2]+abs(i-a[k][0])+abs(j-a[k][1]);
      if (t>=0){
        int b=0;
        rep(p,n){
          if(a[p][2]!=0){
          if(t!=a[p][2]+abs(i-a[p][0])+abs(j-a[p][1])){
            b++;
          }
        }
        else{if(t-abs(i-a[p][0])-abs(j-a[p][1])>0){b++;}}
        }
        if(b){continue;}
        else{
          int cx=i; int cy=j; int h=t;
          cout<<cx<<' '<<cy<<' '<<h;
          exit(0);
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  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
import itertools

N,M = map(int,input().split())
Data = []
for _ in range(N+1):
    Data.append([0]*(N+1))
for _ in range(M):
    a,b = map(int,input().split())
    Data[a][b] = 1
    Data[b][a] = 1

ans = 0
for r in itertools.permutations(range(2,N+1)):
    Rlist = list(r)
    a = 1
    b = Rlist[0]
    if Data[a][b] == 0:
        continue
    else:
        flag = True 
        for i in range(len(Rlist)-1):
            a = Rlist[i]
            b = Rlist[i+1]
            if Data[a][b] == 0:
                flag = False
                break
        if flag:
            ans += 1

print(ans)


Measured memory_bytes: 3064
def lam(x,mo):
	ans=1
	for i in range(1,x+1):
		ans*=i
		ans%=mo
	return ans
n,m=map(int,input().split())
n,m=min(n,m),max(n,m)
mod=10**9+7
if n<m-1:
	print(0)
	exit()
if n+1==m:
	print(lam(n,mod)*lam(m,mod)%mod)
else:
	print(2*(lam(n,mod)**2)%mod)


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

using namespace std;
#define int long long
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int u=1;
    int a,b,c;
    int k;
    cin>>a>>b>>c>>k;
    int a1=a;int b1=b;int c1=c;
    for(int i=0;i<k;++i) u*=3;
    for(int i=0;i<u;++i)
    {
        a=a1;b=b1;c=c1;
        vector <int> v;
        int x=i;
        for(int i=0;i<k;++i)
        {
            v.push_back(x%3);
            x/=3;
        }
        for(int i=0;i<v.size();++i)
        {
            if(v[i]==0)
            {
                a*=2;
            }
            else if(v[i]==1)
            {
                b*=2;
            }
            else
            {
                c*=2;
            }
        }
        if(c>b && b>a)
        {
            cout<<"Yes";
            return 0;
        }
        //cout<<a<<" "<<b<<" "<<c<<endl;
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
 int a,b,c,i,x;
 
 x=0;
 
 scanf("%d %d %d",&a,&b,&c);
 
 for(i=a;i<=b;i++){
 
   if(c%i==0){
   
    x++;
    
   }
   
  }
  printf("%d\n",x);
  
  return 0;
  
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int64_t a, b;
    cin >> a >> b;

    if (a * b <= 0) {
        cout << "Zero" << endl;
    } else if (a > 0 || (b - a) % 2 == 1) {
        cout << "Positive" << endl;
    } else {
        cout << "Negative" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main() {
	int n, m[200000], l;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		m[i] = 0;
	}
	for (int i = 1; i < n; i++) {
		scanf("%d", &l);
		m[l-1] = m[l-1] + 1;
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", m[i]);
	}
}

Measured memory_bytes: 2936
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <sstream>
#include <string>
#include <vector>

size_t GetValue(const std::vector<size_t> &v, size_t i) {
  if (i >= v.size()) return 0;
  return v.at(i);
}

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

  size_t x;
  size_t y;
  size_t a;
  size_t b;
  size_t c;

  std::cin >> x;
  std::cin >> y;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;

  std::vector<size_t> p;
  p.reserve(a);

  for (size_t i = 0; i < a; i++) {
    size_t tmp;
    std::cin >> tmp;
    p.push_back(tmp);
  }

  std::vector<size_t> q;
  q.reserve(b);

  for (size_t i = 0; i < b; i++) {
    size_t tmp;
    std::cin >> tmp;
    q.push_back(tmp);
  }

  std::vector<size_t> r;
  r.reserve(c);

  for (size_t i = 0; i < c; i++) {
    size_t tmp;
    std::cin >> tmp;
    r.push_back(tmp);
  }

  std::sort(p.rbegin(), p.rend());
  std::sort(q.rbegin(), q.rend());
  std::sort(r.rbegin(), r.rend());
  p.resize(x);
  q.resize(y);
  std::sort(p.begin(), p.end());
  std::sort(q.begin(), q.end());

  size_t p_cnt = 0;
  size_t q_cnt = 0;

  for (size_t i = 0; i < r.size(); i++) {
    int diff_red = (int)r.at(i) - (int)GetValue(p, p_cnt);
    int diff_grn = (int)r.at(i) - (int)GetValue(q, q_cnt);

    if (p_cnt < x && q_cnt < y) {
      if (diff_red > diff_grn) {
        if (diff_red > 0) {
          p[p_cnt] = r.at(i);
          p_cnt++;
        }
      } else {
        if (diff_grn > 0) {
          q[q_cnt] = r.at(i);
          q_cnt++;
        }
      }
    } else if (p_cnt < x) {
      if (diff_red > 0) {
        p[p_cnt] = r.at(i);
        p_cnt++;
      }
    } else if (q_cnt < y) {
      if (diff_grn > 0) {
        q[q_cnt] = r.at(i);
        q_cnt++;
      }
    }
  }

  size_t sum = 0;

  for (size_t i = 0; i < p.size(); i++) {
    sum += p.at(i);
  }

  for (size_t i = 0; i < q.size(); i++) {
    sum += q.at(i);
  }

  std::cout << sum << "\n";

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main(){
  int a,b,c,n,i,j,k,r,d[1000][4];
  while(cin>>a>>b>>c,a||b||c){
    cin>>n;
    int f[301]={0};
    int g[301]={0};
    for(int p=0;p<n;++p){
      cin>>i>>j>>k>>r;
      d[p][0]=i;d[p][1]=j;d[p][2]=k;d[p][3]=r;
      if(r) g[i]=g[j]=g[k]=1;
    }
    for(int p=0;p<n;++p){
      if(!d[p][3]){
	if(g[d[p][0]]&&g[d[p][1]]) f[d[p][2]]=1;
	else if(g[d[p][0]]&&g[d[p][2]]) f[d[p][1]]=1;
	else if(g[d[p][2]]&&g[d[p][1]]) f[d[p][0]]=1;
      }
    }
    for(int p=1;p<=a+b+c;++p){
      if(g[p]) cout<<1;
      else if(f[p]) cout<<0;
      else cout<<2;
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1176
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int len(int* t, int n)
{
	return *max_element(t, t + n) - *min_element(t, t + n) + 1;
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		int x[256], y[256];
		x[0] = y[0] = 0;
		for (int i = 1; i < n; ++i)
		{
			int id, d;
			cin >> id >> d;
			++d %= 4;
			x[i] = x[id] + dx[d];
			y[i] = y[id] + dy[d];
		}
		printf("%d %d\n", len(x, n), len(y, n));
	}
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> a(H);

  for(int i = 0; i < H; i++) {
    cin >> a.at(i);
  }
  
  for(int i = 0; i < H + 2; i++){
    for(int j = 0; j < W + 2; j++) {
      if(i != 0 && i != H + 1 && j != 0 && j != W + 1){
        cout << a.at(i-1);
        j = W;
      }
      else {
        cout << '#';
        if (j == W + 1){
          cout << endl;
        }  
      }
    }
  }
}

Measured memory_bytes: 256
/*
*                                 Name : chaitanya
*
*                         Institute : ANITS,Visakhapatnam
*   "Don't regret anything you do, because in the end it makes you who you are."
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#include<sstream>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll m = 1000000007;
using namespace std;

int main()
{
    int n,tri = 0;
    cin >> n;
    vector < int > v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i+1; j < n; ++j)
        {
            for (int k = j+1; k < n; ++k)
            {
                if(v[i]!=v[j] && v[i]!=v[k] && v[j]!=v[k])
                {
                    int a = v[i],b = v[j],c= v[k];
                    if( a+b > c && b+c > a && c+a > b)
                    {
                        tri++;
                    }
                }
            }
        }
    }
    cout << tri;
    return 0;    
}

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

int main() {
  int n;
  cin >> n;
  vector<int>b(n);
  vector<int>ans;
  rep(i,0,n){
    cin >> b[i];
    b[i]--;
  }
  rep(i,0,n){
    rep(j,0,b.size()){
      if(b[b.size()-1-j] == b.size()-1-j){
        ans.push_back(b.size()-1-j);
        b.erase(b.begin()+b.size()-1-j);
        break;
      }
      if(j == b.size()-1){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  rep(i,0,n) cout << ans[n-i-1]+1 << endl;
 }

Measured memory_bytes: 256
#include <iostream>

int gcd(int x, int y) {
    if(x<y) { int t{x}; x=y; y=t; }
    return (x%y) ? gcd(x-y,y) : y;
}

int main() {
    int x{}, y{};
    std::cin >> x >> y;
    if(x<1 || y<1) return 1;
    std::cout << gcd(x,y) << std::endl;
}



Measured memory_bytes: 3092
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define REP(i,a,n) for(register int i(a);i<=(n);++i)
#define FEC(i,x,y) for(register int i=head[x],y=g[i].to;i;i=g[i].ne,y=g[i].to)
#define dbg(...) fprintf(stderr,__VA_ARGS__)
const int SZ=(1<<21)+1;char ibuf[SZ],*iS,*iT,obuf[SZ+128],*oS=obuf,*oT=obuf+SZ-1;
#ifdef ONLINE_JUDGE
#define gc() (iS==iT?(iT=(iS=ibuf)+fread(ibuf,1,SZ,stdin),(iS==iT?EOF:*iS++)):*iS++)
#else
#define gc() getchar()
#endif
template<typename I>inline void read(I&x){char c=gc();int f=0;for(;c<'0'||c>'9';c=gc())c=='-'?f=1:0;for(x=0;c>='0'&&c<='9';c=gc())x=(x<<1)+(x<<3)+(c&15);f?x=-x:0;}
inline void flush(){fwrite(obuf,1,oS-obuf,stdout);oS=obuf;}
#define printf(...) (oS>oT&&(flush(),1),oS+=sprintf(oS,__VA_ARGS__))
template<typename A,typename B>inline char SMAX(A&a,const B&b){return a<b?a=b,1:0;}
template<typename A,typename B>inline char SMIN(A&a,const B&b){return a>b?a=b,1:0;}
typedef long long ll;typedef unsigned long long ull;typedef std::pair<int,int>pii;

const int N=2e5+7;
int n;char s[N];ll ans;

int main(){
	scanf("%s",s+1);n=strlen(s+1);
	int cnt=0;
	REP(i,1,n){
		if(s[i]=='W')ans+=cnt;
		else cnt++;
	}printf("%lld\n",ans);return flush(),0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int N = 500500;
int n;
char s[N];
int vis[N], deg[N], val[N];
vector<int> g[N];

void dfs(int u) {
	vis[u] = 1;
	FOR(i,SZ(g[u])) {
		int v = g[u][i];
		if (vis[v]) continue;
		deg[v]--;
		val[v] = max(val[v], val[u]+1);
		if (deg[v] == 0) {
			dfs(v);
		}
	}
}

int main() {
	scanf("%s", s);
	for (n=0; s[n]; n++) ;
	FOR(i,n) if (s[i] == '<') g[i].pb(i+1);
	else g[i+1].pb(i);
	n++;
	FOR(i,n) FOR(j,SZ(g[i])) deg[g[i][j]]++;
	FOR(i,n) if (deg[i] == 0 && vis[i] == 0) dfs(i);
	long long res = 0;
	FOR(i,n) res += val[i];
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 57344
#include<cstdio>
#define ll long long
#define mo 1000000007
using namespace std;
int f[3005][3005][4],p[6005],ans;
int n,m;
inline int get(int x){
	return !x?1:x==n?2:0;
}
inline void upd(int &x,int y){
	x=x+y;
	x=x>=mo?x-mo:x;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=0;i<=n;i++)
		f[0][i][get(i)]=1;
	p[0]=1;
	for (int i=1;i<=2*m;i++) p[i]=p[i-1]*2%mo;
	ans=p[m*2];
	if (n<m){
		for (int i=1;i<=m;i++)
			for (int jzq=0;jzq<4;jzq++)
				for (int R=0;R<=n;R++){
					int B=n-R;
					if (R){
						upd(f[i][R-1][jzq|get(R-1)],f[i-1][R][jzq]);
					upd(f[i][R][jzq|get(R-1)],f[i-1][R][jzq]);
					}
					else if (jzq==3)
						upd(ans,-1ll*f[i-1][R][jzq]*p[2*(m-i)+1]%mo+mo);
					if (B){
						upd(f[i][R+1][jzq|get(R+1)],f[i-1][R][jzq]);
						upd(f[i][R][jzq|get(R+1)],f[i-1][R][jzq]);
					}
					else if (jzq==3)
						upd(ans,-1ll*f[i-1][R][jzq]*p[2*(m-i)+1]%mo+mo);
			}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 140032
#ABC043.B
s = input()
L = []

def kan(a):
    if a =='0':
        L.append('0')
    elif a =='1':
        L.append('1')
    else:
        if L !=[]:
            L.pop()
for b in s:
    kan(b)

c =''
for d in L:
    c +=d
print(c)


Measured memory_bytes: 2940
N = input()
couta = N.count('a')           
coutb = N.count('b')
coutc = N.count('c')
x = abs(couta - coutb)
y = abs(coutb - coutc)
z = abs(couta - coutc)
if max(x,y,z) <= 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  lint n, m, d; cin >> n >> m >> d;
  double res = (d == 0 ? 1.0 : 2.0) * (n - d) / (n * n) * (m - 1);
  cout << fixed << setprecision(10) << res << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
using namespace std;

int main() {
	int n, s = 1000, b = 0;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		s = min(tmp, s);
		b = max(tmp, b);
	}
	cout << b - s << endl;
}

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

using namespace std;

int main(){
	int l[100];
	int n, x, cnt = 0, ans = 1;
	cin >> n >> x;
	for (int i = 0; i < n; i++)cin >> l[i];
	for (int i = 0; i < n; i++){
		cnt += l[i];
		if (cnt <= x){
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

        long X=gl();
        long m=0;
        long t=0;
        for (int i=1; i<=X;i++) {
        	m+=(long)i;
        	if(m>=X) {
        		t=i;
        		break;
        	}
        }
        
        System.out.print(t);

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35560
s = input()
l = len(s)
a = []
for i, ss in enumerate(s):
    if ss == "W":
        a.append(i+1)
w_num = s.count("W")
sum_a = (w_num * (w_num + 1)) // 2
ans = sum(a) - sum_a
print(ans)

Measured memory_bytes: 11368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    vector<vector<int>> ans(H+1, vector<int> (W, 0));
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < W; i++) {
        ans[H][i] = K+1;
    }
    int tmp = 1;
    bool check = false;
    int cnt = 0;
    vector<int> yoko;
    for (int i = 0; i < H; i++) {
        cnt = 0;
        for (int j = 0; j < W; j++) {
            ans[i][j] = tmp;
            if(S[i][j] == '#'){
                check = true;
                cnt++;
            }
        }
        if(check){
            tmp += cnt;
            if(tmp > K){
                tmp -= cnt;
            }
            else{
                yoko.push_back(i);
            }
            check = false;
        }
    }

    // for (int i = 0; i < H; i++) {
    //     for (int j = 0; j < W; j++) {
    //         printf("%d ", ans[i][j]);
    //     }
    //     printf("\n");
    // }

    yoko.push_back(H-1);
    int v, w;
    v = -1; w = -1;
    check = false;
    for (int x : yoko){
        // printf("%d\n", x);
        v = w;
        w = x;
        tmp = ans[x][0];
        for (int j = 0; j < W; j++) {
            for (int i = v+1; i < w+1; i++) {
                ans[i][j] = tmp;
                if(S[i][j] == '#'){
                    check = true;
                }
            }
            if(check){
                if(tmp < ans[x+1][0]-1){
                    tmp++;
                }
                check = false;
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }
    

}

Measured memory_bytes: 4236
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		char[] d = sc.next().toCharArray();
		int count = 0;
		if(d[0] == 'R' && d[1] == 'R' && d[2] == 'R')
		System.out.println("3");
		else if(d[0] == 'S' && d[1] == 'S' && d[2] == 'S')
		System.out.println("0");
		else if(d[0] == 'R' && d[1] == 'R' && d[2] == 'S')
		System.out.println("2");
		else if(d[0] == 'S' && d[1] == 'R' && d[2] == 'R')
		System.out.println("2");
		else
		System.out.println("1");
    }
}

Measured memory_bytes: 35804
#include<bits/stdc++.h>
using namespace std;
int n;
struct Node{
	string s;
	int id;
	int ddd;
}a[110];
bool cmp(Node a,Node b)
{
	return a.s<b.s||(a.s==b.s&&a.id>b.id);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i].s>>a[i].id;
		a[i].ddd=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		cout<<a[i].ddd<<endl;
	return 0;
}


Measured memory_bytes: 256
import collections

n = int(input())
v = list(map(int, input().split()))

v_odd = []
for i in range(0, n, 2):
    v_odd.append(v[i])
v_even = []
for i in range(1, n, 2):
    v_even.append(v[i])

odd_dic = collections.Counter(v_odd)
odd_sort = sorted(odd_dic.items(), key=lambda x: -x[1])
odd_maxkey = odd_sort[0][0]
odd_cnt1 = odd_sort[0][1]
if len(odd_sort) > 1:
    odd_cnt2 = odd_sort[1][1]
else:
    odd_cnt2 = 0

even_dic = collections.Counter(v_even)
even_sort = sorted(even_dic.items(), key=lambda x: -x[1])
even_maxkey = even_sort[0][0]
even_cnt1 = even_sort[0][1]
if len(even_sort) > 1:
    even_cnt2 = even_sort[1][1]
else:
    even_cnt2 = 0

ans = len(v_odd) + len(v_even)
if odd_maxkey == even_maxkey:
    ans -= max(odd_cnt1 + even_cnt2, odd_cnt2 + even_cnt1)
else:
    ans -= odd_cnt1 + even_cnt1


#print(odd_cnt1)
#print(odd_cnt2)
#print(even_cnt1)
#print(even_cnt2)

print(ans)



Measured memory_bytes: 21952
n=int(input())
al=list(map(int,input().split()))
bl=list(map(int,input().split()))
h=0
c=0
minl=[]
for i in range(n):
  a=al[i]
  b=bl[i]
  if a<b:
    h+=b-a
    c+=1
  else:
    minl.append(a-b)
minl.sort()
minl.reverse()
if c==0:
  print(c)
  exit()
if len(minl)==0:
  print(-1)
  exit()
for i in minl:
  h-=i
  c+=1
  if h<=0:
    print(c)
    exit()
print(-1)

Measured memory_bytes: 18356
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x=int(readline())
def a(n):
  for i in range(2, int(n ** 0.5 + 1)):
    if n % i == 0:
      return False
  return True
  

while True:
  if a(x):
    print(x)
    quit()
  x+=1

Measured memory_bytes: 3060
a=['S 1','S 2','S 3','S 4','S 5','S 6','S 7','S 8','S 9','S 10','S 11','S 12','S 13','H 1','H 2','H 3','H 4','H 5','H 6','H 7','H 8','H 9','H 10','H 11','H 12','H 13','C 1','C 2','C 3','C 4','C 5','C 6','C 7','C 8','C 9','C 10','C 11','C 12','C 13','D 1','D 2','D 3','D 4','D 5','D 6','D 7','D 8','D 9','D 10','D 11','D 12','D 13']
x=int(input())
count=0
for i in range(x):
  a.remove(input())
for i in range(52-x):
  print(a[count])
  count+=1


Measured memory_bytes: 5600
using System;
using System.Linq;
using System.Collections.Generic;

public class Prime{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		var primeFactors = PrimeFactors(n);
		//primeFactors.Dump();
		
		string output = primeFactors.Count() == 0 
						? n.ToString() 
						: string.Join(" ", primeFactors.Select (f => f.ToString()).ToArray());
						//:string.Join(" ", primeFactors);
		Console.WriteLine("{0}: {1}", n, output);
	}
	
	public static IEnumerable<int> PrimeFactors(int n)
	{
		int i = 2;
		int tmp = n;
		
		while (i <= n)
		{
			if(n % i == 0){
				n /= i;
				yield return i;
			}else{
				i++;
			}
			
			if(i > Math.Sqrt(tmp)){
				i = int.MaxValue; //???????????????
				yield return n;
			}
		}
	}
}

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) (int)((a).size())
#define all(c) (c).begin(), (c).end()
#define debug(v) {for (auto z : v) {cerr << z << ' ';} cerr << endl;}

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	ll k = n / (a + b);
	ll r = n % (a + b);
	ll ans = k * a;
	ans += r >= a ? a : r;
	cout << ans << endl;
}


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

int main() {
    int third = 100000, second = 200000, first = 300000;
    int reslut_code, result_industry;
    int sum;

    cin >> reslut_code >> result_industry;

    switch (reslut_code)
    {
    case 1:
        sum = first;
        break;
    case 2:
        sum = second;
        break;
    case 3:
        sum = third;
        break;
    
    default:
        sum = 0;
        break;
    }

    switch (result_industry)
    {
    case 1:
        sum += first;
        break;
    case 2:
        sum += second;
        break;
    case 3:
        sum += third;
        break;
    
    default:
        sum += 0;
        break;
    }

    if ((result_industry == 1) && (reslut_code == 1)) {
        sum += 400000;
    }

    cout << sum << endl;

    return 0;
}

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

int main(){
  int r, D;
  int x[11];

  cin >> r >> D >> x[0];

  rep(i, 10){
    x[i+1] = r * x[i] - D;
  }

  rep(i,10){
    cout << x[i+1] << endl;
  }
}

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

int n;
int p[101010];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&p[i]);
        p[i] = i == p[i];
        if(p[i])p[i] = p[i-1]+1;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        if(p[i] != 0 && p[i+1] == 0){
            ans += (p[i]+1)/2;
        }
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n;
	int ans=0;
	cin>>n;
	rep(i,0,n)
	{
		int x=read();
		while(x%2==0)
		{
			ans++;
			x/=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
# -*- coding:utf-8 -*-
"""考え方
・Nが奇数の時、
0が一個と、
2, 4, 6, ..., K (< N)が2個ずつ

・Nが偶数の時、
1, 3, ... K (< N)が2個ずつ

"""
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10**9+7

    dic = {}
    for a in A:
        if not a in dic:
            dic[a] = 0
        dic[a] += 1
    
    if N%2 == 0:
        # Nが偶数のとき
        for i in range(N):
            num = i*2+1
            if num > N:
                break

            if not num in dic:
                print(0)
                return

            if dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**i)%MOD)
        return
    else:
        # Nが奇数のとき
        i = -1
        while True:
            i += 1
            num = i*2
            if num > N:
                break
            
            if not num in dic:
                print(0)
                return
            
            if num == 0 and dic[num] == 1:
                continue
            elif num != 0 and dic[num] == 2:
                continue
            else:
                print(0)
                return
        print((2**(i-1))%MOD)
        return
        

if __name__ == "__main__":
    solve()


Measured memory_bytes: 14324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll i, j;
    ll n;
    cin >> n;
    ll ans = 0;
    for (i = 1; i <= n; i++) {
        ans += i * (i + 1) / 2;
    }
    for (i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (n + 1 - v);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>                                             
#include <cmath>                                                
using namespace std;                                            
                                                                
int main() {                                                    
  int x;                                                        
  cin >> x;                                                     
  int XCubic = pow(x,3);                                        
  cout << XCubic << endl;                                       
  return 0;                                                     
}                         

Measured memory_bytes: 3268
n=int(input())
L=[list(map(int,input().split())) for i in range(n)]
minl=sorted([L[i][0] for i in range(n)])
maxl=sorted([L[i][1] for i in range(n)])
if n%2==1:
    mi=minl[n//2]
    ma=maxl[n//2]
    print(ma-mi+1)
else:
    mi=(minl[(n-1)//2]+minl[n//2])/2
    ma=(maxl[(n-1)//2]+maxl[n//2])/2
    print(int((ma-mi)//0.5+1))

Measured memory_bytes: 50948
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using  namespace std;

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << endl;

using db = long double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
#define scl1(a)             scanf(“%I64d", &a)
#define scl2(a, b)          scanf("%lld %lld", &a, &b)

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;
const int inf = 0x3f3f3f3f;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main(){

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

ll t,i,x,j,y,z,k,n;

cin>>n;	k=0;
rep(i,1,10,1){
	if(n%i)	continue;
	
	k=n/i;
	k=(k<10)?k:0;
	if(k)	break;
}
if(k)	ce("Yes")
else	ce("No")
}


Measured memory_bytes: 256
import math

n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
elif n==m:
    a=math.factorial(n)%1000000007
    b=math.factorial(m)%1000000007
    print(2*a*b%1000000007)
else:
    a=math.factorial(n)%1000000007
    b=math.factorial(m)%1000000007
    print(a*b%1000000007)

Measured memory_bytes: 4108
#include <bits/stdc++.h>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
int MOD = 998244353;


int gcd(int a,int b){
    //if( ar[a][b] != 0 ) return ar[a][b];
    //assume a <= b
    if( b < a ) swap(a,b);
    if( a == 0 ) return b;
    return gcd( b%a, a );
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N;
	cin >> N;
	ll ans = 0;
	for(int i = 1; i <= N; i++){
        for(int j=1; j <= N; j++){
            for(int k=1; k <= N; k++){
                ans += gcd(i, gcd(j,k) );
            }
        }
	}
    cout << ans;




}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
	int m,n,k;
	cin>>n>>k;
	m=1;
	for(int i=0;i<n;i++){
		if(2*m<m+k){
			m*=2;
		}
		else{
			m+=k;
		}
	}
	cout<<m<<endl;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _Ty> static _Ty tp_abs(const _Ty& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _Ty> static _Ty tp_min(_Ty a, _Ty b) {
	return a < b ? a : b;
}
template <class _Ty> static _Ty tp_max(_Ty a, _Ty b) {
	return a > b ? a : b;
}
template<class T> static void getint(T& a) {
	const char* fmt = " %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class T> static void getint(T& a, T& b) {
	const char* fmt = " %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class T> static void getint(T& a, T& b, T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static const int EduDp_INF = 1100000000;
static const int MOD_NUM = 1000000007;
static void S_task();

#if 1
int main()
{
	S_task();
	fflush(stdout);
	return 0;
}
#endif

static void S_task()
{
	std::string orgs;
	std::cin >> orgs;

	int D;
	getint(D);

	int digitCount = orgs.length();
	std::vector<std::vector<std::vector<LLONG>>> dp(digitCount + 1, std::vector<std::vector<LLONG>>(2, std::vector<LLONG>(D, 0)));
	dp[0][0][0] = 1;
	for (int digit = 1; digit <= digitCount; digit++) {
		int digitNum = orgs[digit - 1] - '0';

		for (int sml = 0; sml < 2; sml++) {
			int limit = (sml ? 9 : digitNum);

			for (int d = 0; d < D; d++) {
				for (int k = 0; k <= limit; k++) {
					int nowSurp = (d + k) % D;
					dp[digit][sml || k < digitNum][nowSurp] += dp[digit - 1][sml][d] % (LLONG)MOD_NUM;
					dp[digit][sml || k < digitNum][nowSurp] %= (LLONG)MOD_NUM;
				}
			}
		}
	}
	printf("%lld\n", (dp[digitCount][0][0] + dp[digitCount][1][0] + (LLONG)MOD_NUM - 1LL) % (LLONG)MOD_NUM);
}


Measured memory_bytes: 17024