akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define M int(1e9+7)
#define lli long long int
using namespace std;
int com[22][22],dp[22][(1<<21)+2];
int n;
bool Is_Set(int mask,int j)
{
    return mask&(1<<j);
}
int Set(int mask,int j)
{
    return mask|(1<<j);
}
int solve(int man,int woman)
{
    if(man==n) return __builtin_popcount(woman)==n;
    if(dp[man][woman]!=-1) return dp[man][woman];
    int j;
    lli ways=0;
    for(j=0;j<n;j++)
    {
        if(!Is_Set(woman,j) and com[man][j])
            ways+=solve(man+1,Set(woman,j)),ways%=M;
    }
    return dp[man][woman]=ways;
}
int main()
{
    int i,j;

    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        scanf("%d",&com[i][j]);
    memset(dp,-1,sizeof(dp));
    printf("%d\n",solve(0,0));
    return 0;
}


Measured memory_bytes: 183984
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
strToInt s = (read :: String -> Int) s

main = do
    n <- getLine
    let m = read n :: Int
    let an = sum (map (strToInt . \a -> [a]) n)
    if (mod m an) == 0 then putStrLn "Yes"
                       else putStrLn "No"
                  

Measured memory_bytes: 508
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, M, X, A;
    cin >> N >> M >> X;
    int c1 = 0, c2 = 0;
    REP(i, M) {
        cin >> A;
        if (A < X) {
            c1++;
        } else {
            c2++;
        }
    }
    cout << min(c1, c2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#define MOD 1000000007
using namespace std;

typedef long long ll;


int main(){
    int H,W;
    ll dp[1005][1005];
    cin>>H>>W;
    vector<string> str;
    str.resize(H+1);
    for(int i = 0;i < H;i++){
        str[i].reserve(W+1);
        cin>>str[i];
        str[i].push_back('#');
    }
    str[H] = string(W+1,'#');
    
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){dp[i][j]=0;}
    }
    dp[0][0]=1;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(str[i][j]=='#')
                continue;
            if(str[i][j+1]=='.')
                dp[i][j+1]=(dp[i][j+1]+dp[i][j])%MOD;
            if(str[i+1][j]=='.')
                dp[i+1][j]=(dp[i+1][j]+dp[i][j])%MOD;
        }
    }
    cout<<dp[H-1][W-1]<<endl;
}


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

int main(){
    int n, k; cin >> n >> k;
    long ans = n/k;
    ans = ans*ans*ans;
    if(k % 2 == 0){
        long tmp = n/k;
        if(k/2 <= n%k)tmp++;
        ans += tmp*tmp*tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<climits>
#include<ctime>
#include<complex>
#include<sstream>
#include<cstring>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)
typedef pair<int,pii>piii;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int W,H,N;
char fld[100][100];
int cost[100][100];
int dist[7][7];
vector<pii>pos;

void prp(){
    int dx1[]={-1,0,1,-1},dy1[]={-1,-1,-1,0};
    int dx2[]={1,0,-1,1},dy2[]={1,1,1,0};

    rep(i,H){
        rep(j,W){
            rep(k,4){
                int ty=i+dy1[k],tx=j+dx1[k];
                if(ty<0||tx<0)continue;
                cost[i][j]=max(cost[i][j],cost[ty][tx]-1);
            }
        }
    }

    for(int i=H-1;i>=0;i--){
        for(int j=W-1;j>=0;j--){
            rep(k,4){
                int ty=i+dy2[k],tx=j+dx2[k];
                if(tx>=W||ty>=H)continue;
                cost[i][j]=max(cost[i][j],max(cost[ty][tx]-1,1));
            }
        }
    }
}

void bfs(int s){
    priority_queue<piii,vector<piii>,greater<piii> >Q;
    Q.push(piii(0,pii(pos[s].fi,pos[s].se)));
    int D[100][100];fill_n(*D,10000,1e9);
    while(!Q.empty()){
        piii p=Q.top();Q.pop();
        if(D[p.se.fi][p.se.se]<=p.fi)continue;
        D[p.se.fi][p.se.se]=p.fi;

        rep(i,4){
            int ty=p.se.fi+dy[i],tx=p.se.se+dx[i];
            if(ty<0||ty>=H||tx<0||tx>=W)continue;
            if(cost[ty][tx]==4)continue;
            Q.push(piii(p.fi+cost[p.se.fi][p.se.se],pii(ty,tx)));
        }
    }

    rep(i,N){
        dist[s][i]=D[pos[i].fi][pos[i].se];
    }
}
int main(){
    fill_n(*cost,100*100,1);
    scanf("%d%d",&W,&H);
    rep(i,H)scanf("%s",fld[i]);
    pos.resize(1);
    int sy,sx,gy,gx;
    rep(i,H){
        rep(j,W){
            if(fld[i][j]=='S'){
                sy=i;sx=j;
                pos[0]=pii(i,j);
            }
            else if(fld[i][j]=='G'){
                gy=i;gx=j;
            }
            else if(fld[i][j]=='#')cost[i][j]=4;
            else if(fld[i][j]=='M'){
                pos.pb(pii(i,j));
            }
        }
    }
    pos.pb(pii(gy,gx));

    N=pos.size();

    prp();

    rep(i,N)bfs(i);

    vi perm(N);rep(i,N)perm[i]=i;
    int mi=INT_MAX;
    do{
        int sum=0;
        rep(i,N-1)sum+=dist[perm[i]][perm[i+1]];
        mi=min(mi,sum);

    }while(next_permutation(perm.begin()+1,perm.end()-1));

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


}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	int N, C, K;
	cin >> N >> C >> K;
	int T[100000];
	rep(i, N) {
		cin >> T[i];
	}
	sort(T, T + N);
	int count=0;
	int p = 1;
	int x = 0;
	reps(i, 1, N) {
		if (T[i] - T[x] > K) {
			count++;
			p = 1;
			x = i;
		}
		else {
			p++;
		}
		if (p==C) {
			count++;
			p = 0;
			x = i + 1;
		}else if (i == N - 1) {
			count++;
		}
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define __TRUE "yes"
#define __FALSE "no"

int main() {
  int x,y;
  cin >> x >> y;
  int a[]={0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  cout << (a[x] == a[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long 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;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    ll k;
    cin>>k;
    ll n;
    cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    sort(a.begin(),a.end());
    ll bigdif=a[0]+(k-a[n-1]);
    ll res=bigdif;
    rep(i,0,n-1){
        ll dif=a[i+1]-a[i];
        chmax(bigdif,dif);
        res+=dif;
    }
    cout<<res-bigdif<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    ll n,k; 
    cin >> n >> k;
    if(k % 2 == 1){
        ll a = n / k;
        cout << a * a * a << endl;
    }else{
        ll b = 0, c = 0;
        rep(i,n){
            if((i + 1) % k == k / 2){
                b++;
            }
        }
        c = n / k;
    
    cout << b * b * b + c * c * c << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;
typedef pair<int,int> P;

const long long int mod=1e9+7;



int main(){
	int A,B,C;
	cin >> A >> B >> C;

	if(C-(A-B)>0) cout << C-(A-B) << endl;
	else cout << 0 << endl;


}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cctype>
using namespace std;
typedef long long LL;

const int N = 100010;
int n;
LL a[N];

inline void gg() { puts("-1"); exit(0); }
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
	if(a[n] > 2) gg();
	LL mx = 2, mi = 2;
	for(int i = n; i >= 1; i --) {
		if(mx%a[i]) mx = mx/a[i]*a[i];
		if(mi%a[i]) mi = (mi/a[i]+1)*a[i];
		if(mi > mx) gg();
		mi = mi/a[i]*a[i];
		mx = mx/a[i]*a[i]+a[i]-1;
	}
	printf("%lld %lld\n", mi, mx);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < 3; i++)
    {
        if (n % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;


void solve(long long N, std::vector<long long> A){
    ll sum=0;
    rep(i,N){
        if(i%2)sum-=A[i];
        else sum+=A[i];
    }
    cout<<sum<<" ";
    repf(i,0,N-1){
        
        sum=(A[i]-sum/2)*2;
        if(i==N-2) cout<<sum<<endl;
        else cout<<sum<<" ";
        //sum=(A[i]-sum/2);
    }
    return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2048
import sys
def main():
    input = sys.stdin.readline
    N,M=map(int, input().split())
    *A,=map(int, input().split())
    BC=[tuple(map(int, input().split())) for _ in range(M)]

    A.sort()
    BC.sort(key=lambda x:x[1], reverse=True)
    ans=0
    i=0
    from bisect import bisect_right
    for b,c in BC:
        j = bisect_right(A, c, i, min(N,i+b))
        ans += c*(j-i)
        i=j
    for j in range(i,N):
        ans+=A[j]
    print(ans)

if __name__ == '__main__':
    main()

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

int main()
{
    string s, t ;
    cin >> s >> t ;

    int count = 0 ;
    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i)!=t.at(i))
        {
            count ++ ;
        }
        
    }
    cout << count << endl ;
    
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
#define sc scanf
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;
typedef unsigned long long ull;
typedef long long ll;
template <typename it>int o(it a){cout<<a<<endl;return 0;}
int n,l;
int pie[N]={0};
int sum=0;
int main(){
    cin>>n>>l;
    for(int i=1;i<=n;i++)sum+=pie[i]=l+i-1;
    int res=1e9;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(res>abs(pie[i])){
            res=abs(pie[i]);ans=i;
        }
    }
    o(sum-pie[ans]);
}

Measured memory_bytes: 256
#!/usr/bin/env python
"""AtCoder Grand Contest 046: A - Takahashikun, The Strider
https://atcoder.jp/contests/agc046/tasks/agc046_a
"""


def calc(x):
    mod = 360 % x
    ans = 360 // x
    if mod == 0:
        return ans
    angle = 360 - mod
    while True:
    # for i in range(10):
        # print(angle)
        angle += x
        ans += 1
        if angle % 360 == 0:
            return ans
    # angle = x
    # mod = 360 % x
    # print('x:{}, mod:{}, mod_angle:{}'.format(x, mod, mod))
    # c = 360 - mod
    # ans = 360 // x
    # while True:
    #     print(ans)
    #     if c // 360 == 0:
    #         return ans
    #     ans += 1
    #     c += mod


def main():
    X = int(input())
    # for x in range(1, 180):
    #     print('{} => {}'.format(x, calc(x)))
    # print(calc(7))
    # ans = 0
    # while True:
    #     next = 360 % X
    #     if next == 0:
    #         ans = 360 // X
    #         break
    #     X = next
    print(calc(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9056
#include<iostream>
#include<string>
#include<map>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define cout(x) cout << x << endl;
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<string, int> mapii;

int main () {
    int N;
    cin >> N;
    int A[N];
    long long cost = 0;
    long long min_cost = 100000000000000;
    for (int i = 0; i < N; ++i) cin >> A[i];
    for (int p = 1; p < 100; ++p) {
        long long temp = 0;
        cost = 0;
        for (int i = 0; i < N; ++i){
            temp = (A[i] - p ) *(A[i] - p );
            cost += temp;
        }
        min_cost = min(min_cost,cost);
    }
    cout(min_cost)
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,c,d,roll=0,count=0,xxx=0;

struct Dice{
	int d1;
	int d2;
	int d3;
	int d4;
	int d5;
	int d6;
};

void N(struct Dice *std){
	a=(*std).d1;
	b=(*std).d2;
	c=(*std).d6;
	d=(*std).d5;
	(*std).d1=b;
	(*std).d2=c;
	(*std).d6=d;
	(*std).d5=a;
}
void S(struct Dice *std){
	a=(*std).d1;
	b=(*std).d2;
	c=(*std).d6;
	d=(*std).d5;
	(*std).d1=d;
	(*std).d2=a;
	(*std).d6=b;
	(*std).d5=c;
}
void W(struct Dice *std){
	a=(*std).d1;
	b=(*std).d4;
	c=(*std).d6;
	d=(*std).d3;
	(*std).d1=d;
	(*std).d4=a;
	(*std).d6=b;
	(*std).d3=c;
}
void E(struct Dice *std){
	a=(*std).d1;
	b=(*std).d4;
	c=(*std).d6;
	d=(*std).d3;
	(*std).d1=b;
	(*std).d4=c;
	(*std).d6=d;
	(*std).d3=a;
}

int main(){
	struct Dice da,db;
	string s;
	cin >> da.d1 >> da.d2 >> da.d3 >> da.d4 >> da.d5 >> da.d6;
	cin >> db.d1 >> db.d2 >> db.d3 >> db.d4 >> db.d5 >> db.d6;
	while(xxx!=4){
	while(roll!=4){
	while(count!=4){
		if(da.d1==db.d1&&da.d2==db.d2&&da.d3==db.d3&&da.d4==db.d4&&da.d5==db.d5&&da.d6==db.d6){
		s = "Yes";goto end;
		}else{
			S(&db);
			count++;
		}
	}
		E(&db);
		count=0;
		roll++;
	}
	count=0;
	roll=0;
	N(&db);
	E(&db);
	xxx++;
	}
	s = "No";
	end:
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];

    int res=INF;
    for(int y=-100; y<=100; y++){
        int tmp=0;
        rep(i,n){
            tmp+=abs(a[i]-y)*abs(a[i]-y);
        }
        chmin(res,tmp);
    }
    cout<<res<<endl;
}

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

using namespace std;
#define rep(N) for(int i=0;i<(N);i++)
#define all(A) A.begin(),A.end()

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  vector<int64_t> a(n);
  int64_t s=0;
  rep(n) { int x; cin >> x; a[i] = x-i-1; }
  sort(all(a));
  rep(n) { s += abs(a[i]-a[n/2]); }
  cout << s << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int main( void ) {

    string S;
    cin >> S;
    
    set<char> values;

    for ( int i = 0; i < S.size(); i++ ) {
        values.insert(S[i]);
    }

    if ( values.size() == 26 ) {
        cout << "None" << endl;
        return 0;
    }

    for ( int i = 0; i < S.size(); i++ ) {
        
        if ( values.find('a' + i) == values.end() ) {
            printf("%c", ('a' + i));
            return 0;
        }

    }

    return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
  int n;
  cin>>n;
  int ans=0;

  for(int c=1; c<=n; ++c){
    int x=n-c;
    auto pf=prime_factorize(x);
    ll res=1;
    for(auto p:pf)res*=p.second+1;
    ans+=res;
  }
  cout<<ans-2<<endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define debug(x) cerr <<__LINE__<< ": " <<#x<< " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> X(n);
    rep(i, n) cin >> X[i];
    int ans = INF;
    REP(i, -100, 101) {
        int po = 0;
        rep(j, n) po += (X[j] - i) * (X[j] - i);
        chmin(ans, po);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3624
s=[i for i in input()]
t=[i for i in input()]
if s==t:
  print('No')
else:
  s=sorted(s)
  t=sorted(t,reverse=True)
  s=''.join(s)
  t=''.join(t)
  l=[s,t]
  l2=sorted(l)
  if l==l2:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 38384
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> P;
const long long mod = 1000000007;
int modinv;
int a[2005];

int modpow(int x, int n, int md) {
	if (!n)return 1;
	int res = modpow(x*x%md, n / 2, md);
	if (n & 1)res = res*x%md;
	return res;
}

signed main() {
	int n, k; cin >> n >> k;
	rep(i, n)cin >> a[i];
	int cnt = 0;
	modinv = modpow(2, mod - 2, mod);
	rep(i, n) {
		int cl = 0, cr = 0;
		rep(j, i) {
			if (a[i] < a[j])cl++;
		}
		for (int j = i; j < n; j++) {
			if (a[i] < a[j])cr++;
		}
		int fin = cl + (k - 1)*(cl + cr);
		fin %= mod;
		cnt += (cl + fin)*k %mod*modinv%mod;
		cnt %= mod;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

template<class T = lint>
struct Edge {
	int to;
	T cost;
	Edge() {}
	Edge(int to, T cost) : to(to), cost(cost) {}
	bool operator>(const Edge &r) const { return this->cost > r.cost; }
};

int main() {

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

	int N, M;
	cin >> N >> M;

	vector<lint> visited(N, numeric_limits<lint>::max());
	int u, v, len;
	vector<vector<Edge<int>>> edges(N);
	for (int i = 0; i < M; i++) {
		cin >> u >> v >> len;
		edges[u - 1].emplace_back(v - 1, len);
		edges[v - 1].emplace_back(u - 1, -len);
	}

	auto dfs = [&](auto &&f, int now) -> bool {
		bool flag = true;
		for (const auto &e : edges[now]) {
		
			if (visited[e.to] == numeric_limits<lint>::max()) {
				visited[e.to] = visited[now] + e.cost;
				flag &= f(f, e.to);
			}
			else if (visited[e.to] != visited[now] + e.cost) flag = false;

		}
		return flag;
	};

	bool ans = true;
	for (int i = 0; i < N; i++) {
		if (visited[i] == numeric_limits<lint>::max()) {
			visited[i] = 0;
			ans &= dfs(dfs, i);
		}
		else ans &= dfs(dfs, i);
	}

	if (ans) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 11392
R, C, K = map(int, input().split())

items = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    items[r - 1][c - 1] = v

dp0 = [[0] * (C + 1) for _ in range(R + 1)]
dp1 = [[0] * (C + 1) for _ in range(R + 1)]
dp2 = [[0] * (C + 1) for _ in range(R + 1)]
dp3 = [[0] * (C + 1) for _ in range(R + 1)]

for r in range(R):
    for c in range(C):
        v = items[r][c]
        for fr, to in ((dp2, dp3), (dp1, dp2), (dp0, dp1)):
            to[r][c] = max(to[r][c], fr[r][c] + v)

        for dp in (dp0, dp1, dp2, dp3):
            dp[r][c + 1] = max(dp[r][c + 1], dp[r][c])
            dp0[r + 1][c] = max(dp0[r + 1][c], dp[r][c])

ans = max(
    dp0[R - 1][C], dp0[R][C - 1],
    dp1[R - 1][C], dp1[R][C - 1],
    dp2[R - 1][C], dp2[R][C - 1],
    dp3[R - 1][C], dp3[R][C - 1],
)

print(ans)


Measured memory_bytes: 428756
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define INF 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  string a(ty - sy,'U'),b(tx - sx,'R'),c(ty - sy,'D'),d(tx - sx,'L');
  cout << a << b << c << d;
  cout << "L";
  string e(ty - sy + 1,'U'),f(tx - sx + 1,'R'),g(ty - sy + 1,'D'),h(tx - sx + 1,'L');
  cout << e << f << "D" << "R" << g << h << "U" << endl;
  return 0;
}


Measured memory_bytes: 256
k,a,b=map(int,input().split())
if b<a+2:
    print(1+k)
else:
    if k<=a:
        print(1+k)
    else:
        if (k-a-1)%2==0:
            print(b+(b-a)*((k-a-1)//2))
        else:
            print(b+(b-a)*((k-a-1)//2)+1)

Measured memory_bytes: 3060
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

const int INF = 2e9;
// const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
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> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a <= 0 && 0 <= b) cout << "Zero" << endl;
  else if (a > 0) cout << "Positive" << endl;
  else
  {
    if ((-a+b+1) % 2) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  }

  return 0;
}


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

template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define F first
#define S second
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;
	
	int a, cnt=0;;
	for(int i=1 ; i<=n ; ++i){
		cin >> a;
		
		if(i&1 && a&1)cnt++;
	}
	
	cout << cnt;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cout << 180 * (N - 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 998244353;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 3e2+5;

int a[maxn];
ll dp[2][305][305];

signed main(){
    IOS();
    string s; cin>>s;
    int n0 = 0, n = SZ(s);
    int k; cin>>k;
    int n1 = 0;
    int now = 0;
    int N = 0;
    for (int i = 0; i<n; ++i) {
        (s[i]=='0'?n0:n1)++;
        if (s[i] == '0') {
            a[N++] = now; now = 0;
        }else
            now++;
    }
    if (now) a[N++] = now;
    bug(N);
    for (int i = 0; i<N; ++i) bug(i,a[i]);
    bool dpat = 0;
    dp[dpat][0][0] = 1;
    int befsum1 = 0;
    for (int i = N-1; i>=0; --i) {
        dpat ^= 1;
        memset(dp[dpat],0,sizeof dp[dpat]);
        for (int chg = 0; chg<=min(n1,k); ++chg) {
            for (int def = 0; def <= chg; ++def) {
                for (int j = 0; j<=a[i]; ++j) {
                    if (def-j>=0)
                        dp[dpat][def][chg] += dp[dpat^1][def-j][chg-j];
                    else break;
                }
                for (int j = 1; j+def<=befsum1; ++j) {
                    dp[dpat][def][chg] += dp[dpat^1][def+j][chg];
                }
                dp[dpat][def][chg] %= mod;
            }
        }
        befsum1 += a[i];
    }
    ll sig = 0;
    for (int i = 0; i<=min(k, n1); ++i) {
        sig += dp[dpat][0][i];
        bug(i, dp[dpat][0][i]);
    }
    cout<<sig % mod<<endl;

}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
#define f first 
#define sf second.first 
#define ss second.second 
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P > iP;

int main(){
  int t,p,r;
  while(cin>>t>>p>>r&&t){
    iP a[51];
    int k[11][51]={};
    for(int i=1;i<=t;i++)a[i]=iP(0,P(0,-i));
    for(int i=0;i<r;i++){
      int ti,pi,m;
      string s;
      cin>>ti>>pi>>m>>s;
      if(s=="CORRECT")a[ti].f++,a[ti].sf-=m+k[pi][ti]*1200;
      else k[pi][ti]++;
    }
    sort(a+1,a+t+1);
    for(int i=t;i>0;i--)
      cout<<-a[i].ss<<" "<<a[i].f<<" "<<-a[i].sf<<endl;    
  }
  return 0;
}

Measured memory_bytes: 1220
H,W=map(int,input().split())
S=[list(map(int, input().split())) for i in range(10)]
l=[None]*10
for i in range(10):
    l[i]=S[i][1]
for i in range(6):
    for j in range(10):
        for k in range(10):
            if l[j]>l[k]+S[j][k]:
                l[j]=l[k]+S[j][k]
l.append(0)
a=0
for i in range(H):
    L=list(map(int,input().split()))
    for j in L:
        a+=l[j]
print(a)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    for(int i=0;i<N;i++) cin >> S[i];
    sort(S.begin(), S.end());
    for(int i=0;i<N;i++) cout << S[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long A = Long.parseLong(sc.next());
        long B = Long.parseLong(sc.next());
        long max = Math.max(A,B);
        long min = Math.min(A,B);
        ArrayList<Long> list = new ArrayList<>();
        list.add(1L);
        long sosu = 0;
        for(long i=2; i<=Math.sqrt(min); i++) {
            if(min % i == 0) {
                if(max % i == 0) {
                    if(sosuu(i) && (list.contains(i) == false)) {sosu++;}
                    list.add(i);
                }
                if(max % (min/i) == 0) {
                    if(sosuu(min/i) && (list.contains(min/i) == false)) {sosu++;}
                    list.add(min/i);
                }
            }
        }
        
        if(sosuu(min) && max % min == 0 && list.contains(min) == false) sosu++;
        
        System.out.println(sosu+1);
    }

    public static boolean sosuu(long n) {
        for(long i = 2; i <= Math.sqrt(n); i++) {
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }
}


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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;

int main() {
	string S;
	cin >> S;
	int cnt = 0;
	for (const auto c : S)
	{
		if (c == 'x') 
			cnt++;
	}

	if (cnt < 8) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define REP(i, n) for(int i=1; i<=n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;

int main(){
    str s; cin >> s;
    rep(i, 3){
        if(s[i] == '9') s[i] -= 8;
        else if(s[i] == '1') s[i] += 8;
    }
    cout << s << endl;
    return 0;
}

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

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


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, M, ans = 0;
    	int[][] switches;
    	int[] p;
    	
        void solve(InputReader in, PrintWriter out) {
            // write your code here
        	N = in.nextInt();
        	M = in.nextInt();
        	switches = new int[M][];
        	for (int i = 0; i < M; ++i) {
        		int k = in.nextInt();
        		switches[i] = in.nextIntArray(k);
        	}
        	p = in.nextIntArray(M);
        	
        	for (int i = 0; i < 1 << N; ++i) {
        		boolean flag = true;
        		for (int j = 0; j < M; ++j) {
        			int cnt = 0;
        			for (int sw : switches[j]) {
        				if ((i >> --sw & 1) == 1) cnt++;
        			}
        			flag &= cnt % 2 == p[j];
        		}
        		ans += flag ? 1 : 0;
        	}
        	out.println(ans);
        }
        
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21456
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
//vector<Pll>v;
map<Pll, Pll>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000];
string str, ss;
bool f[200][200];
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
void dfs(LL cur,LL par) {
	rep(i, g[cur].size()) {
		LL v = g[cur][i];
		if (v == par)continue;
		a[v] += a[cur];
		dfs(v,cur);
	}
}
int main() {
	cin >> n >> q;
	g.resize(n);
	rep(i, n - 1) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	rep(i, q) {
		LL x, y;
		cin >> x >> y;
		x--;
		a[x] += y;
	}
	dfs(0,-1);
	rep(i, n) {
		if (i)cout << " ";
		cout << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 24320
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
using namespace std;
#define ll long long

int main(){
  int k, s;
  cin >> k >> s;
  int ans=0;
  for(int i=0; i<=k; i++){
    for(int j=0; j<=k; j++){
      if(s-(i+j) <= k && s-(i+j)>=0){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
  int a,b,c,d;
  int num=0;
  cin >> a >> b >> c >> d;
  while(a>0 && c>0){
    if(num%2==0){
      c-=b;
    }
    else{
      a-=d;
    }
    num++;
  }
  if(a<=0){
    cout << "No";
  }
  else{
    cout << "Yes";
  }
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MOD = 1e9 + 7;

void solve()
{
    string s,t;
    cin>>s>>t;
    ll a = s.size();
    ll b = t.size();
    //cout<<"a = "<<a<<" b = "<<b<<"\n";
    ll dp[a+1][b+1];
   // string ans;
    for(ll i=0;i<=a;i++)
    {
        //cout<<"i "<<i<<"\n";
        for(ll j=0;j<=b;j++)
        {
            //cout<<j<<" ";
            if(i==0 || j==0)
            {
                dp[i][j] = 0;
            }
            else if(s[i-1] == t[j-1])
            {
                //ans.push_back(s[i-1]);
                dp[i][j] = dp[i-1][j-1] + 1;
                
            }
            else
            {
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
        //cout<<"\n";
    }
    //cout<< dp[a][b] <<"\n";
    ll si = dp[a][b];
    ll temp = si;
    char ans[si + 1];
    ans[si] = '\0';
    ll i = a;
    ll j = b;
    while(i>0 && j>0)
    {
        if(s[i-1] == t[j-1])
        {
            ans[si-1] = s[i-1];
            i--;
            j--;
            si--;
        }
        else if(dp[i-1][j] > dp[i][j-1])
        {
            
            i--;
        }
        else
        {
            
            j--;
        }
    }
    cout<<ans;
    cout<<"\n";
}

//MAIN 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 73980
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>

using namespace std;

int main()
{
	vector <int > v;
	int n;
	int a;
	cin >> n;
	for (int i = 0; i<n; i++) 
	{
		cin >> a;
		v.push_back(a);
	}
		
	int c = 0;
	
	
	for (int i = n-1; i>=0; i--)
	{
		int flag = 0; 
		int cur = v[i];
		for (int j = i-1; j>=0; j--)
		{
			if (v[i]<v[j]){
				flag = 1;
				break;
			}
			else {
				continue;
				
			}
		}
		
		if (flag == 0) c++;
	}
	
	cout << c <<endl;
	
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;

int main(){
	ll n ; 
	cin >> n ; 
	vector<ll> v(5) ; 
	ll nax = 1e18 ; 
	for(ll &x : v){
		cin >> x ; 
		nax = min(nax,x);
	}
	ll groups = n / nax ; 
	if ( n % nax != 0 ) groups++ ; 
	debug() << imie(groups) ; 
	//ll ans = groups/5ll * 9ll; 
	ll ans = 5 + (groups - 1) ; 
	cout << ans << endl;
    return 0 ;
}


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

int n, a[100010];
int b[100010];

int main(){
    while(cin >> n){
        rep(i,n) cin >> a[i];

        rep(i,n) b[i] = a[i];
        sort(b, b+n);
        map<int,int> p;
        rep(i,n) p[b[i]] = i&1;
        int ans = 0;
        rep(i,n){
            if(p[a[i]] != (i&1)) ++ans;
        }
        cout << ans/2 << endl;
    }
}


Measured memory_bytes: 5760