akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll H,W,h,w;
    cin>>H>>W>>h>>w;
    cout<<(H-h)*(W-w)<<endl;
}
return 0;
}

Measured memory_bytes: 256
// C - GCD on Blackboard
#include <bits/stdc++.h>
using namespace std;
#define rp(i,n) for(int i=0;i<(n);++i)

int gcd(int a, int b){return b? gcd(b, a%b): a;}

int main(){
	int N; cin>>N;
	vector<int> A(N), L(N), R(N);

	rp(n,N) cin>>A[n];

	rp(l,N-1){
		int r = N - l - 2;
		L[l+1] = gcd(L[l], A[l]);
		R[r] = gcd(R[r+1], A[r+1]);
	}

	int maxi = 1;
	rp(n,N) maxi = max(maxi, gcd(L[n], R[n]));
	cout<< maxi <<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(){
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if(a<b){
    if(b<c){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi h(n);
    rep(i,n) cin >> h[i];

    // dp[i]はi番目の足場に行くまでの最小コスト
    vi dp(n,0);
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2;i < n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
}

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

int main(){
  int X,Y,A,B,C; cin >> X >> Y >> A >> B >> C;
  vector<long long> p(A);
  vector<long long> q(B);
  vector<long long> r(C);
  for(int i=0; i<A; i++) cin >> p[i];
  for(int i=0; i<B; i++) cin >> q[i];
  for(int i=0; i<C; i++) cin >> r[i];
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  
  long long sum=0;
  for(int i=0; i<X; i++) sum+=p[A-1-i];
  for(int i=0; i<Y; i++) sum+=q[B-1-i];
  
  int pi=A-X, qi=B-Y;
  for(int i=C-1; i>=0; i--){
    if(pi>=A){
      if(qi>=B){
        continue;
      }else{
        //qとrの比較
        if(q[qi]<r[i]){
          sum = sum - q[qi] + r[i];
          qi++;
        }
      }
    }else{
      if(qi>=B){
        //pとrの比較
        if(p[pi]<r[i]){
          sum = sum - p[pi] + r[i];
          pi++;
        }
      }else{
        //pとqとrの比較
        if(p[pi]>=q[qi]){
          //qとrの比較
          if(q[qi]<r[i]){
            sum = sum - q[qi] + r[i];
            qi++;
          }
        }else{
          //pとrの比較
          if(p[pi]<r[i]){
            sum = sum - p[pi] + r[i];
            pi++;
          }
        }
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 2688
from collections import deque


def solve():
    N = int(input())
    Ti = tuple(map(int, input().split()))
    M = int(input())

    PXi = deque()
    for _ in range(M):
        PXi.append(tuple(map(int, input().split())))

    # print(N)
    # print(Ti)
    # print(M)
    # print(PXi)

    total = sum(Ti)

    ans = deque()
    for p, x in PXi:
        p -= 1
        before = Ti[p]
        after = x

        if before <= after:
            ans.append(total + abs(before - after))
        else:
            ans.append(total - abs(before - after))

    return ans


if __name__ == '__main__':
    res = solve()
    for r in res:
        print(r)


Measured memory_bytes: 38256
N, K = map(int,input().split())
p = list(map(int,input().split()))

sum_p = 0
sum_p_list =[]

for i in range(K):
    sum_p += p[i]

sum_p_list.append(sum_p)

for j in range(K,N):
    sum_p -= p[j - K]
    sum_p += p[j]
    sum_p_list.append(sum_p)
    

ex = (max(sum_p_list) - K + 2)/2

print(ex + K - 1)

Measured memory_bytes: 25060
//Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 1e5 + 1;

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

    in n;
    cin >> n;
    in a[n];
    in sum = 0;
    rep(i, 0, n)
    {
        cin >> a[i];
        sum = (sum + a[i]) % MOD;
    }

    in ans = 0;
    rep(i, 0, n)
    {
        sum = (sum - a[i] + MOD) % MOD;
        ans = (ans + (a[i] * (sum)) % MOD) % MOD;
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 5176
using System;

namespace ABC096C
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int H = int.Parse(target[0]);
            int W = int.Parse(target[1]);
            char[,] table = new char[H,W];
            for(int i=0;i<H;i++){
                var t1 = Console.ReadLine();
                for(int j=0;j<W;j++)
                    table[i,j] = t1[j];
            }
            int[] step = new int[2]{1,-1};
            bool can = true;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(table[i,j] == '#'){
                        bool isolate = true;
                        foreach(int dx in step){
                            if(j+dx>=W || j+dx<0) continue;
                            if(table[i,j+dx] == '#') isolate = false;
                        }
                        foreach(int dy in step){
                            if(i+dy>=H || i+dy<0) continue;
                            if(table[i+dy,j] == '#') isolate = false;
                        }
                        if(isolate) {can = false; break;}
                    }
                    if(!can) break;
                }
                if(!can) break;
            }
            if(!can) Console.WriteLine("No"); else Console.WriteLine("Yes");
        }
    }
}


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

using i64 = int64_t;

int cumsum[100005]={0};

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> v;
    bool one = true;
    int cnt = 0;
    for(int i=0;i<n;++i){
        if(one){
            if(s[i] == '1')cnt++;
            else{
                one = false;
                v.push_back(cnt);
                cnt = 1;
            }
        }else{
            if(s[i] == '0')cnt++;
            else{
                one = true;
                v.push_back(cnt);
                cnt = 1;
            }
        }
    }
    v.push_back(cnt);
    if(((int)v.size())%2 == 0)v.push_back(0);

    for(int i=0;i<v.size();++i){
        cumsum[i+1] = cumsum[i] + v[i];
    }

    int ans = 0;

    if(2*k+1 >= v.size())ans = cumsum[(int)v.size()];
    else{
        for(int i=2*k+1;i<=v.size();i+=2){
            ans = max(ans, cumsum[i] - cumsum[i-(2*k+1)]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1272
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
  int N;
  std::cin >> N;
  int x;
  std::cin >> x;
  int sum = 0;
  int min;
  std::vector<int> m(N);
  for (int i=0; i < N; i++) {
    std::cin >> m.at(i);
    sum += m.at(i);
    if (i==0) {
      min = m.at(i);
    }
    else {
      min = std::min(min,m.at(i));
    }
  }
  x -= sum;
  std::cout << N + x / min << std::endl;
}
  


Measured memory_bytes: 256
while True:
    n=int(input())
    if n==0:break
    s=str(n)[::-1]
    digi=[int(s[i])*((-1)**i) for i in range(len(s))]if n>=0 else [-int(s[i])*((-1)**i)for i in range(len(s)-1)]
    for i in range(2):digi.append(0) 
    l=len(digi)
    negdec=0
    for k in range(l):
        a=digi[k]
        if a<0:
            negdec+=(10+a)*(10**k)
            digi[k+1]+=1
        elif a>=10:
            negdec+=(a-10)*(10**k)
            digi[k+1]-=1
        else:
            negdec+=a*(10**k)
    print(negdec)

Measured memory_bytes: 7752
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int i,j,k,ex1,ex2,ex3,ex4,n,a,b;
    int dice[101][7];
    int command;

    scanf("%d",&n);

    for(i = 1;i <= n;i++)
        for(j = 1;j <= 6;j++)
            scanf("%d",&dice[i][j]);

    for(i = 1;i <= n;i++){
        for(j = i + 1;j <= n;j++){
            for(k = 0;k < 10000;k++){
            command = rand() % 4;
            if(command == 0){
                ex1 = dice[i][1];
                ex2 = dice[i][2];
                ex3 = dice[i][5];
                ex4 = dice[i][6];
                dice[i][1] = ex3;
                dice[i][2] = ex1;
                dice[i][5] = ex4;
                dice[i][6] = ex2;
            }else if(command == 1){
                ex1 = dice[i][1];
                ex2 = dice[i][2];
                ex3 = dice[i][5];
                ex4 = dice[i][6];
                dice[i][1] = ex2;
                dice[i][2] = ex4;
                dice[i][5] = ex1;
                dice[i][6] = ex3;
            }else if(command == 2){
                ex1 = dice[i][1];
                ex2 = dice[i][3];
                ex3 = dice[i][4];
                ex4 = dice[i][6];
                dice[i][1] = ex3;
                dice[i][3] = ex1;
                dice[i][4] = ex4;
                dice[i][6] = ex2;
            }else if(command == 3){
                ex1 = dice[i][1];
                ex2 = dice[i][3];
                ex3 = dice[i][4];
                ex4 = dice[i][6];
                dice[i][1] = ex2;
                dice[i][3] = ex4;
                dice[i][4] = ex1;
                dice[i][6] = ex3;
            }
            for(a = 1;a <= 6;a++)
                if(dice[i][a] != dice[j][a])
                    break;
            if(a == 7){
                printf("No\n");return 0;
            }
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 584
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
long double dp[3000][3000]={};
int main(){
	int N;
	long double p[3000];
	scan(N);
	rep(i,N){
		scan(p[i]);
	}
	dp[0][0]=1;
	rep(i,N){
		rep(j,N){
			dp[i+1][j]+=dp[i][j]*(1-p[i]);
			dp[i+1][j+1]+=dp[i][j]*p[i];
		}
	}
	long double ans=0;
	for(int j=N/2+1;j<=N;j++){
		ans+=dp[N][j];
	}
	prin(std::setprecision(11)<<ans);
	return 0;
}


Measured memory_bytes: 140928
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin >> n >> k;
	vll p(n),c(n);
	REP(i,n){
		cin >> p[i];
		p[i]--;
	}
	REP(i,n) cin >> c[i];
	ll ans = (-LLINF);
	REP(i,n){
		ll tmp = 0LL;
		ll now = i;
		ll x = 0;
		ll next = -1;
		while(next!=i){
			next = p[now];
			tmp+=c[next];
			now = next;
			x++;
		}
		if(tmp<=0LL||k<=x){
			ll r = min(x,k);
			ll t = 0;
			ll tans = -LLINF;
			now = i;
			REP(j,r){
				ll next = p[now];
				t += c[next];
				tans = max(tans, t);
				now = next;
			}
			ans = max(ans,tans);
		}else{
			ll cy = k/x;
			cy--;
			ll t = cy * tmp;
			ll rk = k - x*cy;
			now = i;
			ll tans = -LLINF;
			if(cy>0LL) tans = t;
			REP(j,rk){
				ll next = p[now];
				t += c[next];
				tans = max(t,tans);
				now = next;
			}
			ans = max(ans,tans);
		}
	}
	cout <<  ans << endl;
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<int> v[2][200005];
int p[20][200005];
int dis[200005];
void dfs(int x,int f, vector<int> *v){
    dis[ x ] = dis[ f ] + 1;
    p[ 0 ][ x ] = f;
    for(auto it : v[x]){
        if(it != f){
            dfs(it, x, v);
        }
    }
}
void build(int n){
    for(int i = 1 ; i < 20 ; i++){
        for(int j = 1 ; j <= n ; j++){
            p[ i ][ j ] = p[ i - 1 ][ p[ i - 1 ][ j ] ];
        }
    }
}
int lca(int x, int y){
    if (dis[ x ] > dis[ y ])swap(x, y);
    int d = dis[ y ] - dis[ x ];
    for(int i = 0 ; i < 20 ; i++ ){
        if( d & (1 << i) ){
            y = p[ i ][ y ];
        }
    }
    if (x == y)
        return x;
    for(int i = 19 ; i >= 0 ; i-- ){
        if( p[ i ][ x ] != p[ i ][ y ] ){
            x = p[ i ][ x ];
            y = p[ i ][ y ];
        }
    } 
    return p[ 0 ][ x ];
}
int getdis(int x, int y){
    return dis[ x ] + dis[ y ] - 2*dis[ lca(x, y) ];
}
int ans;
void dfs2(int x,int f,vector<int> *v,int sum=0){
    if(dis[x]==sum){
        ans=max(ans,dis[x]*2);
    }
    if(dis[x]<=sum)return;
    ans=max(ans,dis[x]*2);
    for(auto it:v[x]){
        if( it != f){
            if(getdis(x,it)>=3&&dis[x] > sum){
                //printf("%d %d %d %d %d\n",x,it,dis[x],sum,getdis(x,it));
                printf("-1\n");
                exit(0);
            }
            dfs2(it, x, v, sum+1);
        }
    }
}
int main(){
    int n, x, y;
    scanf("%d %d %d", &n, &x, &y);
    for(int i = 0 ; i < 2 ; i++ ){
        for(int j = 1 ; j < n ; j++ ){
            int x, y;
            scanf("%d %d", &x, &y);
            v[i][x].pb(y);
            v[i][y].pb(x);
        }
    }
    dis[0]=-1;
    dfs(y, 0, v[1]);
    build(n);
    dfs2(x, 0, v[0]);
    printf("%d\n",ans);
}
/*

b[i]*K!/(i)!*(K-i)!
*/

Measured memory_bytes: 48384
n, m = [int(i) for i in input().split()]

dict = {}

for i in range(n):
    a, b = [int(j) for j in input().split()]
    if  (a in dict):
        dict[a] = b + dict[a]
    else:
        dict[a] = b

sum = m
price = 0

for k, v in sorted(dict.items()):
    if sum > v:
        sum -= v
        price += k * v
    else:
        price += k * sum
        break

print(price)
        

Measured memory_bytes: 23000
// inputに入力データ全体が入る
function Main(input) {
  const array = input.split(' ');
  if(Number(array[1]) >= Number(array[0])){
    console.log('unsafe');
  } else {
    console.log('safe');
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
int n;
vector<int>all;
int l;
int a[200010];
int gtid(int x)
{
	return lower_bound(all.begin(),all.end(),x)-all.begin()+1;
}
int sum[200010];
void add(int x,int v)
{
	for(int i=x;i<=l;i+=i&-i)sum[i]+=v; 
}
int query(int x)
{
	int res=0;
	for(int i=x;i;i-=i&-i)res+=sum[i];
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i),all.push_back(a[i]);
	sort(all.begin(),all.end());
	all.erase(unique(all.begin(),all.end()),all.end());
	l=all.size();
	for(int i=1;i<=n;i++)add(gtid(a[i]),1);
	for(int i=1;i<=n;i++)
	{
		int pos=gtid(a[i]);
		add(pos,-1);
		int le=0,ri=l+1;
		while(le+1<ri)
		{
			int mi=(le+ri)>>1;
			if(query(mi)>=n/2)ri=mi;else le=mi;
		}
		printf("%d\n",all[ri-1]);
		add(pos,1);
	}
	return 0;
} 

Measured memory_bytes: 4596
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

long exp_mod(long long a, long long b, long m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (long)res;
}

long fact_mod(long n, long m) {
	long long res = 1;
	for (long i=n; i>0; --i)
		res = (res * i)%m;
	return (long)res;
}

long comb_mod(long n, long r) {
	long long res = 1;
	for (long i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct Pony
{
    long s, t, x;

    Pony(long s_, long t_, long x_)
    {
        s = s_;
        t = t_;
        x = x_;
    }

    bool operator<(const Pony &another) const
    {
        return x < another.x;
    };
};

long modinv(long a, long m) {
    long b = m, u = 1, v = 0;
    while (b) {
        long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

  int n, k;

  cin >> n >> k;

  if (k == 1) {
    cout << 0 << endl;
  } else {
    cout << n-k << endl;
  }
}


Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll a,b;
  cin >> a >> b;
  pri(6-a-b);
    
  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    ans = 0
    for i in range(1,n):
        if a[i-1] > a[i]:
            ans += a[i-1]-a[i]
            a[i] = a[i-1]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 92000
import java.util.Scanner;
import java.util.HashMap;

public class Main {

    public static void main(String[] args) {
 
      Scanner sc = new Scanner(System.in);
      
      if(sc.nextInt() == 1) {
        System.out.println("Hello World");
      } else {
        System.out.println(sc.nextInt() + sc.nextInt());
      }
    }
}

Measured memory_bytes: 22740
s = input()

dp = [[0]*13 for i in range(len(s)+1)]

dp[0][0] = 1

for i in range(len(s)):
    ch = s[i]
    if ch == '?':
        for j in range(13):
            for k in range(10):
                dp[i+1][(10*j+k)%13] += dp[i][j]
                dp[i+1][(10*j+k)%13] %= 10 ** 9 + 7
    else:
        val = int(ch)
        for j in range(13):
            dp[i+1][(10*j+val)%13] += dp[i][j]
            dp[i+1][(10*j+val)%13] %= 10 ** 9 + 7

print(dp[-1][5])


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

using namespace std;

int main()
{
	int n,c;
	int l[100000];
	int r[100000];

	cin >> n;
	c = n;
	for (int i = 0; i < n; i++)
	{
		cin >> l[i] >> r[i];
		
		if (l[i] > r[i]) {
			c += l[i] - r[i];
		}
		else {
			c += r[i] -l[i];
		}
		
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

int n;
int a[2][101];
int t[2][101];

int main(void)
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[0][i];
    }
    rep(i, n)
    {
        cin >> a[1][i];
    }

    t[0][0] = a[0][0];
    loop(i, 1, n)
    {
        t[0][i] = t[0][i - 1] + a[0][i];
    }

    t[1][0] = t[0][0] + a[1][0];
    loop(i, 1, n)
    {
        t[1][i] = max(t[1][i - 1], t[0][i]) + a[1][i];
    }

    cout << t[1][n - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 5005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n;
vector<int> G[MAXN];
int f[MAXN];
int dp[MAXN][MAXN][2],sz[MAXN];
void add(int &a,int b) {a+=b; if(a>=MOD) a-=MOD;}
void dec(int &a,int b) {a-=b; if(a<0) a+=MOD;}
//dp[i][j][0/1]
//in the subtree of i
//number of matchings if we the connected component with i is j
//such that the parity of removed edges is 0/1
void dfs(int v,int p)
{
    sz[v]=1;
    dp[v][1][0]=1;
    for(auto to:G[v])
    {
        if(to==p) continue;
        dfs(to,v);
        for(int i=sz[v];i>=1;i--)
        {
            int save[2]={0,0};
            for(int j=sz[to];j>=1;j--)
            {
                for(int k1=0;k1<2;k1++)
                {
                    if(!dp[v][i][k1]) continue;
                    for(int k2=0;k2<2;k2++)
                    {
                        if(!dp[to][j][k2]) continue;
                        add(dp[v][i+j][(k1+k2)&1],1LL*dp[v][i][k1]*dp[to][j][k2]%MOD);
                        add(save[(k1+k2+1)&1],1LL*dp[v][i][k1]*dp[to][j][k2]%MOD*f[j]%MOD);
                    }
                }
            }
            dp[v][i][0]=save[0];dp[v][i][1]=save[1];
        }
        add(sz[v],sz[to]);
    }
}
int main()
{
    f[0]=1;
    for(int i=2;i<=5000;i+=2) f[i]=1LL*(i-1)*f[i-2]%MOD;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);G[v].push_back(u);
    }
    memset(dp,0,sizeof(dp));
    dfs(1,0);
    int ans=0;
    for(int i=1;i<=n;i++) add(ans,1LL*dp[1][i][0]*f[i]%MOD);
    for(int i=1;i<=n;i++) dec(ans,1LL*dp[1][i][1]*f[i]%MOD);
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 196736
n=int(input())
d={i:[] for i in range(n)}
c=[-1]*n
for i in range(n-1):
    u,v,w=map(int,input().split())
    d[u-1].append([v-1,w])
    d[v-1].append([u-1,w])
c[0]=0
q=[[0,0]]
while(q):
    p,w=q.pop(0)
    l=d[p]
    for x in l:
        p_=x[0]
        w_=x[1]
        if c[p_]>=0:
            continue
        else:
            w_+=w
            q.append([p_,w_])
            if w_%2==0:
                c[p_]=0
            else:
                c[p_]=1
for i in range(n):
    print(c[i])

Measured memory_bytes: 53764
#include<bits/stdc++.h>
#define dalao main
#define ll long long
#define debug(x) {cerr<<#x<<" = "<<(x)<<endl;}
using namespace std;
int f(int x,int y,int z)
{//f(x,y,z)=f(y,z,x)=f(z,x,y) 即轮换对称性
    return x*x+y*y+z*z + x*y+y*z+z*x;
}
int dif(int x,int y,int z)//x,y,z的组合数
{
    int qwq= (x==y) + (x==z) + (y==z);
    if(qwq==3) return 1; //三个数都相同
    if(qwq==1) return 3; //三个数有俩相同，假如x=1,y=1,z=2,可以有1 1 2/1 2 1/2 1 1三种
    return 6;//三个数都不同，有3!=6种
}
int a[100005],n;
int dalao()
{
    memset(a,0,sizeof(a));
    ios::sync_with_stdio(false);
    cin>>n;
    for(int x=1;x<=sqrt(n);x++)//保证z<=y<=x
        for(int y=1;y<=x;y++)
            for(int z=1;z<=y;z++)
                a[f(x,y,z)]+=dif(x,y,z);
    for(int i=1;i<=n;i++)
        cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3912
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    int a[n],b[100010]={0};
    rep(i,n) cin>>a[i];
    rep(i,n){
        b[a[i]]++;
        b[a[i]+1]++;
        b[a[i]-1]++;
    }
    int maxcount = 0;
    rep(i,100010){
        maxcount = max(b[i],maxcount);
    }
    
    cout<<maxcount<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define maxn 23000000
#define int long long
#define mod 1000000007
int digit[maxn], ans, S;

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

int Qpow(int times)
{
	int x = 10, base = 1;
	for(; times; times >>= 1, x = x * x % mod)
		if(times & 1) base = base * x % mod;
	return base;
}

void Up(int &x, int y) { x = (x + y) % mod; }
signed main()
{
    S = read(); int lim = S / 8, now = 0;
    for(int i = 1; i < maxn; i ++) digit[i] = digit[i / 10] + 1;
    for(int i = 1, now = 0, tem = 0; i < 1e7; i ++)
    {
    	while(tem < S) { tem += digit[now]; now ++; }
		if(tem == S) { ans += 1; if(ans >= mod) ans -= mod; } 
		tem -= digit[i];
    }
    for(int i = 1; i <= lim; i ++)
	{
		if(!(S % i)) 
		{
			int l = S / i, sum = Qpow(l - 1) * 9 % mod;
			Up(ans, (sum - i + 1 + mod) % mod);
		}
		else 
		{ 
			int l = (S - S % i) / i;
			ans += 1; if(ans >= mod) ans -= mod; 
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 179968
#include <stdio.h>
#define N 10000
 
int main( void )
{
    int i, j, c = 0, n, q, s[N], t;
     
    scanf( "%d", &n );
     
    for ( i = 0; i < n; i++ ) {
        scanf( "%d", &s[i] );
    }
     
    scanf( "%d", &q );
     
    for ( i = 0; i < q; i++ ) {
        scanf( "%d", &t );
        for ( j = 0; j < n; j++ ) {
            if ( t == s[j] ) {
                t = -1;
            }
        }
        if ( t == -1 ) {
            c++;
        }
    }
     
    printf( "%d\n", c );
     
    return 0;
}

Measured memory_bytes: 636
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Grid = Tuple!(long, "x", long, "y");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto a = aryread();
    auto b = aryread();
    auto com_a = new long[](n);
    auto com_b = new long[](n + 1);
    com_a[0] = a[0], com_b[1] = b[0];
    foreach (i; iota(1, n))
    {
        com_a[i] += com_a[i - 1] + a[i];
        com_b[i + 1] += com_b[i] + b[i];
    }
    // com_a.writeln();
    // com_b.writeln();
    long moves;
    foreach(i; iota(n))
    {
        auto cost = com_a[i] + com_b[$ - 1] - com_b[i];
        moves = max(cost, moves);
    }
    moves.writeln();
}


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

int main(){
  int N; cin >> N;
  int A[100000]={};
  int k;
  for(int i=0; i<N; i++){
    cin >> k; A[k]++;
  }
  if(N==1){
    if(A[0]==1){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }else if(N%2==0){
    bool istwo=true;
    for(int i=1; i<=N-1; i+=2){
      if(A[i]!=2){
        istwo=false;
        break;
      }
    }
    if(istwo){
      long long res=1;
      for(int i=0; i<N/2; i++){
        res*=2;
        res%=(1000000007);
      }
      cout << res << endl;
    }else{
      cout << 0 << endl;
    }
  }else{
    bool istwo=true;
    for(int i=2; i<=N-1; i+=2){
      if(A[i]!=2){
        istwo=false;
        break;
      }
    }
    if(istwo&&A[0]==1){
      long long res=1;
      for(int i=0; i<N/2; i++){
        res*=2;
        res%=(1000000007);
      }
      cout << res << endl;
    }else{
      cout << 0 << endl;
    }
  }
}

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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
                if (500 * a + 100 * b + 50 * c == X) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
C = [0, 0, 0]  # 同じ帽子をかぶっている人数　降順
B = 10 ** 9 + 7
ans = 1
for i in range(N):
    if A[i] in C:
        ans *= C.count(A[i])
        C[C.index(A[i])] += 1
    else:
        ans = 0
        break
print(ans % B)


Measured memory_bytes: 14020
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = 1e15;
constexpr int MAX = 110;

struct edge{
    int to, rev;
    lint cap;
    edge(int to, lint cap, int rev): to(to), cap(cap), rev(rev){}
};

vector<edge> G[MAX];
int level[MAX], iter[MAX];

void add_edge(int from, int to, lint cap){
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size() - 1);
}

void dinic_bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto &e: G[v]){
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

lint dinic_dfs(int v, int t, lint f){
    if(v == t) return f;
    for(int &i=iter[v]; i<G[v].size(); ++i){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            lint d = dinic_dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

lint max_flow(int s, int t){
    lint flow = 0;
    while(true){
        dinic_bfs(s);
        if(level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        lint f;
        while((f = dinic_dfs(s, t, INF)) > 0) flow += f;
    }
}

int main(){
    int n;
    scanf("%d", &n);
    lint a[n+1];
    For(i, 1, n+1) scanf("%lld", &a[i]);
    int s = 0, t = n+1;
    lint ans = 0;
    For(i, 1, n+1){
        if(a[i] >= 0) add_edge(s, i, a[i]);
        else add_edge(i, t, -a[i]);
        for(int j=2; i*j<=n; ++j) add_edge(i*j, i, INF);
        if(a[i] > 0) ans += a[i];
    }
    ans -= max_flow(s, t);
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
def solve(N, strX):
    def getNum1s(numD):
        num1s = [0] * (1<<numD)
        for S in range(1, 1<<numD):
            num1s[S] = num1s[S ^ (S & -S)] + 1
        return num1s
    num1s = getNum1s(20)

    fs = [0] * (N+1)
    for x in range(1, N+1):
        fs[x] = fs[x%num1s[x]] + 1

    M = strX.count('1')
    M1, M9 = M+1, M-1

    XmodM1 = 0
    for X in strX:
        XmodM1 *= 2
        XmodM1 += int(X)
        XmodM1 %= M1
    XmodM9 = 0
    for X in strX:
        XmodM9 *= 2
        XmodM9 += int(X)
        XmodM9 %= M9

    modM1s = []
    modM1 = 1
    for d in range(N+2):
        modM1s.append(modM1)
        modM1 *= 2
        modM1 %= M1

    modM9s = []
    modM9 = 1
    for d in range(N+2):
        modM9s.append(modM9)
        modM9 *= 2
        modM9 %= M9

    anss = []
    for X, modM1, modM9 in zip(strX[::-1], modM1s, modM9s):
        if X == '0':
            Y2 = (XmodM1 + modM1) % M1
        else:
            Y2 = (XmodM9 - modM9) % M9
        ans = fs[Y2] + 1
        anss.append(ans)

    return anss[::-1]


def solve2(N, strX):
    def getNum1s(numD):
        num1s = [0] * (1<<numD)
        for S in range(1, 1<<numD):
            num1s[S] = num1s[S ^ (S & -S)] + 1
        return num1s
    num1s = getNum1s(20)

    fs = [0] * (N+1)
    for x in range(1, N+1):
        fs[x] = fs[x%num1s[x]] + 1

    M = strX.count('1')
    M1, M9 = M+1, M-1

    XmodM1 = 0
    for X in strX:
        XmodM1 *= 2
        XmodM1 += int(X)
        XmodM1 %= M1

    modM1s = []
    modM1 = 1
    for d in range(N+2):
        modM1s.append(modM1)
        modM1 *= 2
        modM1 %= M1

    anss = []
    for X, modM1 in zip(strX[::-1], modM1s):
        if X == '0':
            Y2 = (XmodM1 + modM1) % M1
            ans = fs[Y2] + 1
        else:
            ans = 0
        anss.append(ans)

    return anss[::-1]


N = int(input())
strX = input().rstrip()

num1 = strX.count('1')

if num1 == 0:
    anss = [1] * N
elif num1 == 1:
    anss = solve2(N, strX)
else:
    anss = solve(N, strX)

print('\n'.join(map(str, anss)))


Measured memory_bytes: 38024
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      char[][] masu = new char[h][w];
      Deque<XY> q = new ArrayDeque<>();
      for(int i = 0; i < h; i++) {
        masu[i] = sc.next().toCharArray();
        for (int j = 0; j < w; j++) {
             if (masu[i][j]=='#') {
               q.add(new XY(i, j, 0));
             }
        }
      }
      int max = 0;
      for (;;) {
        if (q.size() < 1){
          break;
        }
        XY xy = q.poll();
        int x = xy.x;
        int y = xy.y;
        int depth = xy.depth;
        if (depth >= max) {
          max = depth;
        }
        if (x + 1 < w && masu[y][x + 1] == '.') {
          masu[y][x + 1] = '#';
          q.add(new XY(y, x + 1, depth + 1));
        }
        if (x - 1 >= 0 && masu[y][x - 1] == '.') {
          masu[y][x - 1] = '#';
          q.add(new XY(y, x - 1, depth + 1));
        }
        if (y + 1 < h && masu[y + 1][x] == '.') {
          masu[y + 1][x] = '#';
          q.add(new XY(y + 1, x, depth + 1));
        }
        if (y - 1 >= 0 && masu[y - 1][x] == '.') {
          masu[y - 1][x] = '#';
          q.add(new XY(y - 1, x, depth + 1));
        }

      }
        System.out.println(max);
    }
}

class XY {
    int y;
    int x;

    int depth;

    XY(int y, int x, int d) {
        this.x = x;
        this.y = y;
        depth = d;
    }
}

Measured memory_bytes: 79012
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,v;
	while(cin>>N) {
		ll ans = 0;
		REP(i, N) {
			cin>>v;
			while(v%2==0) {
				v/=2;
				ans++;
			}
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

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

dp = defaultdict(int)
d1 = {S[0], S[1], S[2]}
d2 = {S[0:2], S[1:3], S[0] + S[2]}
pin = {S[0:3]}
for i in range(3, N):
    s = S[i]
    for d in d2:
        pin.add(d + s)
    for d in d1:
        d2.add(d + s)
    d1.add(s)
print(len(pin))


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>
#include <complex>

using namespace std;

int main(){
  long long int N;

  cin >> N;

  long long int F_min = INT_MAX;
  for(long long int A = 1; A <= sqrt(N); A++){

    if(N % A == 0){
      string a = to_string(A);
      string b = to_string(N / A);
      long long int f = max(a.size(), b.size());
      if(f < F_min) F_min = f;
    }

  }
  cout << F_min << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int b[N][N],S[N],n,u[N][N],l[N],r[N],flag[N][N];
char A[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9',b[i][j]=A[i][j]-'0';
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=x?b[x][j]:0);
		for (register int j=n+1;j;--j){
			if (flag[x][j]){
				l[j]=j-1;
				r[j]=max(r[j+1],j);
				ans+=b[x][j]*(S[r[j]]-S[l[j]]-b[x][j]);
			}
			else l[j]=1e9,r[j]=-1;
		}
		for (register int i=x-1;i;--i){
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=i?b[x][j]:0);
			for (register int j=n+1;j;--j){
				if (flag[i][j]){
					l[j]=min(l[j+1],l[j]);
					r[j]=max(r[j+1],r[j]);
					if (l[j]<=r[j])ans+=b[i][j]*(S[r[j]]-S[l[j]]);
				}
				else l[j]=1e9,r[j]=-1;
			}
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 15360
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b;
	cin >> a >> b;
	int diff = b - a;
	int bigB = diff * (diff + 1) / 2;
	cout << bigB - b << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

using ll = long long;

ll count_bit(ll n, ll digit) {
  ll base = 2LL << digit;
  ll a = n / base * base / 2;
  ll b = (n % base) - (base / 2 - 1);
  return a + std::max(0LL, b);
}

ll solv(ll A, ll B) {
  A = std::max(0LL, A-1);

  auto ans = std::bitset<50>(0);

  for (size_t d=0; 1LL<<d <= B; d++) {
    auto cnt = count_bit(B, d) - count_bit(A, d);
    ans.set(d, cnt % 2 == 1);
  }

  return ans.to_ullong();
}

int main() {
  ll A, B;

  std::cin >> A >> B;

  std::cout << solv(A, B) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vec tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

ll comb(ll n, ll k) {
  return tfact.at(n)*mpow(tfact.at(k),mod-2)%mod*mpow(tfact.at(n-k),mod-2)%mod;
}

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  fact(h+w);
  vector<pll> a(n+1);
  for(ll i=0;i<n;i++) { 
    ll y,x;
    cin >> y >> x;
    y--,x--;
    a[i]={y,x};
  }
  a[n]={h-1,w-1};
  sort(a.begin(),a.end());
  vec dp(n+1);
  for(ll i=0;i<=n;i++) {
    dp[i]=comb(a[i].first+a[i].second,a[i].first);
    for(ll j=0;j<i;j++) {
      ll dx=a[i].second-a[j].second;
      ll dy=a[i].first-a[j].first;
      if(dx>=0&&dy>=0) dp[i]=(dp[i]-dp[j]*comb(dy+dx,dy)%mod+mod)%mod;
    }
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 78464
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
int main() {
	int n;
	ll ans=0;
	cin>>n;
	rep1(i,1,n) rep1(j,1,n) rep1(k,1,n){
		ans+=__gcd(i,__gcd(j,k));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3568