akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

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; }
const long long INF = 1LL << 60;
typedef pair<int, int> PR;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define fr(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
//cout<<""<<endl;
int N,A,B,C;;
int ans=100000000;
vi l;

void dfs(int d,vi vec){
  if(d==N){
    int a=0,b=0,c=0,cost=0;
    rep(p,N){
      if(vec[p]==1){
        if(a!=0)cost+=10;
        a+=l[p];
      }
      else if(vec[p]==2){
        if(b!=0)cost+=10;
        b+=l[p];
      }
      else if(vec[p]==3){
        if(c!=0)cost+=10;
        c+=l[p];
      }
    }
    if(a!=0&&b!=0&&c!=0)cost+=abs(A-a)+abs(B-b)+abs(C-c);
    else return;
    ans=min(ans,cost);
    return;
  }
  rep(num,4){
    vec.pb(num);
    dfs(d+1,vec);
    vec.pop_back();
  }
}
int main(){
  cin>>N>>A>>B>>C;
  vi z(N);
  rep(i,N){
    cin>>z[i];
  }
  l=z;
  dfs(1,{0});
  dfs(1,{1});
  dfs(1,{2});
  dfs(1,{3});
  cout<<ans<<endl;
}




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

int main() {
    int N;
    bool frag = true;
    cin >> N;
    vector<string> v (N);
    cin >> v.at(0);
    for  (int i = 1; i < N; i++) {
        cin >> v.at(i);
        for (int j = 0; j < i; j++) {
            if (v.at(j) == v.at(i)) {
                cout << "No" << endl;
                frag = false;
                break;
            }
        }

        if (v.at(i).at(0) != v.at(i-1).at(v.at(i-1).size()-1)) {
            cout << "No" << endl;
            frag = false;
            break;
        }
    }

    if (frag) {
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  int i = 0;
  i = 0;
  for(i = 0; i < 120;) {
    if(c < (w + s) * i) {
      c += 60;
    }
    else if(  c <= (w + s) * i + w) break;
    else i++;
  }
  if(i >= 120) cout << "-1" << endl;
  else         cout << c << endl;

  
  return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<queue>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef vector<int> vi;
struct S{
	int s,r; vi his;
	S(int s=0,int r=0,vi p=vi(0)):s(s),r(r),his(p){}
};
int main(){
	int n,m,t1,t2;
	while(cin>>n>>m,n){
		bool ad[15][15]={0},sw[15][15]={0};
		int s=0;
		rep(i,m)cin>>t1>>t2,ad[t1-1][t2-1]=ad[t2-1][t1-1]=1;
		rep(i,n)cin>>t1,t1?s|=1<<i:0;
		rep(i,n){
			cin>>t1; rep(j,t1)cin>>t2,sw[i][t2-1]=1;
		}
		//ツδδつ可サツ探ツ催オ
		queue<S> F; bool V[1<<n][n],g=0,f=0; rep(i,1<<n)rep(j,n)V[i][j]=0;
		F.push(S(s,0,vi(0))); V[s][0]=1; vi ans;
		while(!F.empty()&&!f){
			S cs=F.front(),ns; F.pop();
			//ツ暗堋督ョ
			rep(i,n){
				ns=cs; ns.r=i;
				if(!ad[cs.r][i]||!(cs.s&(1<<i))||V[cs.s][i])continue;
				ns.his.push_back(i),F.push(ns),V[cs.s][i]=1;
				if(ns.r==n-1)g=1;
			}
			//ツ湘鳴セ
			rep(i,n){
				ns=cs; ns.s=cs.s^(1<<i);
				if(!sw[cs.r][i]||cs.r==i||V[ns.s][cs.r])continue;
				ns.his.push_back(i+((ns.s&(1<<i))?100:200)),F.push(ns),V[ns.s][cs.r]=1;
				if(ns.r==n-1&&ns.s==1<<(n-1))f=1,ans=ns.his;
			}
		}
		if(f){
			cout<<"You can go home in "<<ans.size()<<" steps."<<endl;
			rep(i,ans.size())cout<<(ans[i]>99?
				ans[i]>199?"Switch off":"Switch on":
				"Move to")<<" room "<<ans[i]%100+1<<"."<<endl;
		}else cout<<(g?"You can not switch off all lights.":"Help me!")<<endl;
	}
	return 0;
}

Measured memory_bytes: 2456
#include <iostream>

using namespace std;

void exec1()
{
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '1')
			++cnt;
	}
	cout << cnt << endl;
}
int main()
{
	exec1();
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

#define sub(a, b) (a - b > 0 ? a - b : (a - b) * -1)
#define dis(a, b) (sub(a.first, b.first) + sub(a.second, b.second))


using namespace std;

char check(int index, map<int, char> &key){
	for(map<int, char>::iterator it = key.begin(); it != key.end(); it++){
		if(it->first == index) return it->second;
	}
	return 'z';
}

int main(){
	int n, a, b, c, d;
	map<char, pair<int, int> > build;
	map<int, char> key;

	cin >> n >> a >> b >> c >> d;
	key[a] = 'a';
	key[b] = 'b';
	key[c] = 'c';
	key[d] = 'd';

	int x = n + 1, y = 2, min = 1000;

	while(n + 1 != y + 1){
		int index = 1;
		for(int i = 1; i < y; i++){
			for(int j = 1; j < x; j++){
				pair<int, int> tmp(j, i);
				build[check(index, key)] = tmp;
				index++;
			}
		}

		int total = dis(build['a'], build['b']) + dis(build['c'], build['d']);

		if(min > total) min = total;

		x--;
		y++;
	}

	cout << min << endl;

	return 0;
}

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

int main() {
bool a=false;
	int N,tmp;
  cin>>N;
vector<int> B(N+1);
  for(int i=1; i<=N; i++){
    cin>>B.at(i);}
  tmp=B.at(1);
    for(int i=1; i<=N;i++){
    if(tmp==2){cout<<i<<endl;a=true;break;}
	else{tmp=B.at(tmp);}
      
    }if(!a){cout<<-1<<endl;}
}






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

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0;i < n;i++) cin >> vec.at(i);
  int cout_odd = 0;
  for(auto x: vec) if(x % 2 == 1 ) cout_odd++;
  if(cout_odd % 2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 640
from __future__ import print_function

import sys
input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def reverse_range(Large_a, Small_b, i):  # b < a ,  get [b, a)
    return range(Small_b, Large_a, -i)  # range(a, b+1, -1)


def crange(a, b, i):
    return range(a, b + 1, i)


def reverse_crange(Large_a, Small_b, i):
    return range(Small_b, Large_a, -i)


# import math
# import string
# import fractions
# from fractions import Fraction
# from fractions import gcd

# def lcm(n,m):
#     return int(n*m/gcd(n,m))

# import re
# import array
# import copy
# import functools
# import operator

# import collections
# import itertools
# import bisect
# import heapq

# from heapq import heappush
# from heapq import heappop
# from heapq import heappushpop
# from heapq import heapify
# from heapq import heapreplace

# from queue import PriorityQueue as pq

# def reduce(p, q):
#     common = fractions.gcd(p, q)
#     return (p//common , q//common )
# from itertools import accumulate
# from collections import deque

# from operator import mul
# from functools import reduce

# def combinations_count(n, r):
#     r = min(r, n - r)
#     numer = reduce(mul, range(n, n - r, -1), 1)
#     denom = reduce(mul, range(1, r + 1), 1)
#     return numer // denom

# import random
# import time


def main():
    s = input().strip()
    lll = [i for i in crange(len(s) - 2, 0, -2)]
    for i in crange(len(s) - 2, 0, -2):
        i=i-1
        eprint("crange", end=": ")
        eprint(lll)
        s = s[0:i]
        if s[0:i // 2] == s[i // 2 + 1:i]:
            print(i+1)
            return
        else:
            eprint("debug ", end=": ")
            eprint("false this time")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
#include <iostream>
using namespace std;
int main(){
    int W, H, x, y, cnt=0;
    cin >> W >> H >> x >> y;
    double S = double(W) * H /2;
    if(2*x==W && 2*y==H) cnt = 1;
    cout << S << " " << cnt <<endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> c(10,vector<int>(10,0));
    rep2(i,1,N+1){
        int num=i;
        int num_top,num_end;
        num_top=num%10;
        num_end=num_top;
        while(num>0){
            num_top=num%10;
            num/=10;
        }
        c[num_top][num_end]++;
    }
    ll ans=0;
    rep(i,10){
        rep(j,10){
            ans+=(c[i][j]*c[j][i]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> v;
    rep(i, 0, n) {
        string s;
        int p;
        cin >> s >> p;
        p = p * (-1);
        v.push_back(make_tuple(s, p, i));
    }

    sort(all(v));

    rep(i, 0, n) {
        cout << get<2>(v[i]) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,s,i,j;
  cin >> n >> s;
  vector<long long> a(n);
  vector<vector<long long>> x(n,vector<long long>(s+1,0));
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  x.at(0).at(0)=2;
  for(j=1;j<=s;j++){
    if(j==a.at(0)){
      x.at(0).at(j)=1;
    }else{
      x.at(0).at(j)=0;
    }
  }
  
  for(i=1;i<n;i++){
    for(j=0;j<=s;j++){
      if(a.at(i)<=j){
        x.at(i).at(j)=(x.at(i-1).at(j)*2+x.at(i-1).at(j-a.at(i)))%998244353;
      }else{
        x.at(i).at(j)=(x.at(i-1).at(j)*2)%998244353;
      }
    }
  }
  
  cout << x.at(n-1).at(s) << endl;
}

Measured memory_bytes: 73744
n = int(input())
k = int(input())
x = [int(i) for i in input().split()]

d = []
for ball in x:
   robot_a = 2 * ball
   robot_b = 2 * (k - ball)
   if(robot_a <= robot_b):
      d.append(robot_a)
   else:
      d.append(robot_b)
print(sum(d))



Measured memory_bytes: 2940
#include<stdio.h>

int int_comp(const void *_a, const void *_b)
{
  int a = *(int *)_a;
  int b = *(int *)_b;
  if (a < b) {
    return -1;
  } else if (a > b) {
    return 1;
  } else {
    return 0;
  }
}

int main() {
  int V,d,count=0;
  while(scanf("%d%d",&V,&d) != EOF) {
    int i,fib[V];
    fib[0]=2,fib[1]=3;
    for(i=2; i<V; i++) fib[i] = ((fib[i-1]+fib[i-2])>1001)? (fib[i-1]+fib[i-2]-1001):(fib[i-1]+fib[i-2]);
    qsort(fib,V,sizeof(int), int_comp);
    for(i=1; i<V; i++)
      if((fib[i] - fib[i-1]) >= d) count++;
    printf("%d\n",++count);
    count=0;
  }
  return 0;
}

Measured memory_bytes: 0
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int n,x;
  cin >> n >> x;

  vector<int> tmp(51), sum(51);
  tmp[0] = 1;
  sum[0] = 1; 
  REP(i,50){
    tmp[i+1] = tmp[i]*2+3;
    sum[i+1] = sum[i]*2+1;
  }

  int ans = 0;
  RREP(i,n+1){
    if(x < tmp[i]){
      x--;
      continue;
    }
    x -= tmp[i];
    ans += sum[i];
    if(x == 0) break;
    
    x--;
    ans++;
    i++;
  }


  cout << ans << endl;

  return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;

    int x = 0;
    int ans = x;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I') {
            x++;
            ans = max(ans, x);
        } else {
            x--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

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

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

ll dp[3001][3001][4];

int main()
{
	int R, C, k; cin >> R >> C >> k;
	vector<vector<ll>> g(3001, vector<ll>(3001));
	rep(i, k)
	{
		int r, c; cin >> r >> c;
		ll v; cin >> v;
		--r, --c;
		g[r][c] = v;
	}
	rep(i, 3001)rep(j, 3001)rep(k, 4)dp[i][j][k] = 0;
	rep(i, R)rep(j, C)rep(k, 4)
	{
		if (i != R - 1)
		{
			chmax(dp[i + 1][j][0], dp[i][j][k]);
			if (k <= 2)chmax(dp[i + 1][j][0], dp[i][j][k] + g[i][j]);
		}
		if (j != C - 1)
		{
			chmax(dp[i][j + 1][k], dp[i][j][k]);
			if (k <= 2)chmax(dp[i][j + 1][k + 1], dp[i][j][k] + g[i][j]);
		}
	}
	ll res = max({ dp[R - 1][C - 1][0] + g[R - 1][C - 1], dp[R - 1][C - 1][1] + g[R - 1][C - 1], dp[R - 1][C - 1][2] + g[R - 1][C - 1], dp[R - 1][C - 1][3] });
	cout << res << endl;
}

Measured memory_bytes: 355164
N, M = gets.split.map(&:to_i)
shops = []
N.times do
  a, b = gets.split.map(&:to_i)
  shops << [a, b]
end
shops.sort_by! {|s| s[0]}
num = 0
money = 0
shops.each do |shop|
  if M <= num + shop[1]
    money += (M - num) * shop[0]
    num += M - num
    break
  else
    num += shop[1]
    money += shop[1] * shop[0]
  end
end
puts money


Measured memory_bytes: 14712
#include<iostream>
#include<cstdio>
using namespace std;
const int N = 1e5+5;
int a[N];
int b[N];
int main()
{
	int n; cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),b[a[i]] = i;
	for(int i=1;i<=n;i++)
	{
		if(i<n)
			printf("%d ",b[i]);
		else
			printf("%d\n",b[i]);
	}
	return 0;
 } 

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

vector<int> dp(100000, -1);
int minCost(vector<int> &stones, int dest){
	if(dest == 1){
      return abs(stones[1] - stones[0]);
    }
	if(dest == 0){
      return 0;
    }
  	if(dp[dest-1] == -1){
      dp[dest-1] = minCost(stones, dest-1);
    }
  	if(dp[dest-2] == -1){
      dp[dest-2] = minCost(stones, dest-2);
    }
  	return min(abs(stones[dest] - stones[dest-1]) + dp[dest-1],
               abs(stones[dest] - stones[dest-2]) + dp[dest-2]);
}



int main(){
  int n;
  cin>>n;
  vector<int> vec;
  for(int i=0;i<n;i++){
    int temp;
    cin>>temp;
    vec.push_back(temp);
  }
  vector<int> dp(vec.size(), -1);
  cout<<minCost(vec, vec.size()-1)<<endl;
}

Measured memory_bytes: 9196
N = int(input())
A = list(map(int,input().split()))
G = {0:0,1:0,2:0}
for i in range(N):
    if A[i]%2==1:
        G[0] += 1
    else:
        a = A[i]//2
        if a%2==1:
            G[1] += 1
        else:
            G[2] += 1
if G[1]>0:
    if G[2]>=G[0]:
        print("Yes")
    else:
        print("No")
else:
    if G[2]>=G[0]-1:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
n=int(input())
t,a=map(int,input().split())
res_diff=666
res_idx=0
for i,x in enumerate(map(int,input().split())):
  if(abs(a-t+0.006*x)<res_diff):
    res_diff=abs(a-t+0.006*x)
    res_idx=i+1
print(res_idx)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;    
    int a = n%10;
    if(a == 2|| a == 4|| a== 5||a == 7|| a== 9) puts("hon");
    else if(a == 3) puts("bon");
    else puts("pon");
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
using namespace std;

int N, A[305], sum[305][305], dp[305][305];

void update(int a, int b){
  for(int i=a;i<=b;i++) sum[a][b] += A[i];
}

int cal(int a, int b, int c, int d){
  
  int X = sum[a][b], Y = sum[c][d];
  int xprev = 0, yprev = 0, cprev = 0;
  int res = 0,cnt=0;
  while(1){

    if(X==0&&Y==0) cnt++;

    if( xprev + yprev + cprev < 10 ) cprev = 0;
    else cprev = 1;
    
    int xi = X % 10, yi = Y % 10, ci = cprev;
    
    xprev = xi, yprev = yi;
    
    X /= 10, Y /= 10;
    
    res += xi * yi + ci;

    if(cnt)break;
    
  }
  
  return res;
}

int dfs(int l,int r){
  if(l==r)return 0;
  if(dp[l][r]!=-1)return dp[l][r];
  int res=1e9;
  for(int i=l+1;i<=r;i++){
    res=min(res,dfs(l,i-1)+dfs(i,r)+cal(l,i-1,i,r));
  }
  return dp[l][r]=res;
}

signed main(){

  cin>>N;

  for(int i=0;i<N;i++) cin>>A[i];

  for(int i=0;i<N;i++){
    
    for(int j=i;j<N;j++){
      
      update( i, j );
      
    }
    
  }
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,N-1)<<endl;
}


Measured memory_bytes: 4564
A,B,K = gets.chomp.split(" ").map(&:to_i)

require 'prime'

class Integer
  def my_divisor_list
    divisors = [1]
    primes = []
    Prime.prime_division(self).each do |prime|
      prime[1].times {primes << prime[0]}
    end

    1.upto(primes.size) do |i|
      primes.combination(i) do |prime|
        divisors << prime.inject{|a,b| a *= b}
      end
    end

    divisors.uniq!
    divisors.sort!
    return divisors
  rescue ZeroDivisionError
    return
  end
end
puts ((A.my_divisor_list & B.my_divisor_list)[-K])

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

dic = {}

for i in range(n):
  s = input()
  tmp = dic.get(s, 0)
  dic[s] = tmp + 1
  
max_num = max(dic.values())

array = []

for key in dic.keys():
  if max_num == dic.get(key):
    array.append(key)
    
for s in sorted(array):
  print(s)

Measured memory_bytes: 32988
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
#include <queue>
#define lengthof(x) (sizeof(x) / sizeof(*(x)))

using namespace std;

int MOD = 998244353;
int N, S;
int cache[3000+1][3000+1];
int A[3000+1];

int f(int s, int i) {
  if(s < 0) {
    return 0;
  }
  if(i == N) {
    if(s == 0) {
      return 1;
    }
    return 0;
  }
  if(cache[i][s] != -1) {
    return cache[i][s];
  }
  cache[i][s] = (2 * f(s, i+1) % MOD + f(s-A[i], i+1)) % MOD;
  return cache[i][s];
}

int main(){
  std::fill((int*) cache, (int*) (cache + lengthof(cache)), -1);
  cin >> N >> S;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  cout << f(S, 0) << endl;
  return 0;
}


Measured memory_bytes: 38968
let () =
  let c1s = read_line () in
  let c2s = read_line () in
  Array.init 3 (fun i -> c1s.[i] = c2s.[2 - i])
  |> Array.fold_left ( && ) true
  |> (function true -> "YES" | false -> "NO")
  |> print_endline

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

int n, a, b, c;
int l[10];

int dfs(int k, int x, int y, int z) {
	if (k == n)
		if (x > 0 && y > 0 && z > 0) {
			return(abs(a - x) + abs(b - y) + abs(c - z)) - 30;
		}
		else {
			return(100000000);
		}
	else {
		int add0, adda, addb, addc;
		add0 = dfs(k + 1, x, y, z);
		adda = dfs(k + 1, x + l[k], y, z) + 10;
		addb = dfs(k + 1, x, y + l[k], z) + 10;
		addc = dfs(k + 1, x, y, z + l[k]) + 10;
		return(min(min(add0, adda), min(addb, addc)));
	}
}

int main()
{
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	cout << dfs(0, 0, 0, 0) << endl;
}

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

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+key%(M-1); }

int find(char str[]){
  int i,j;
  long long k;
  k=getKey(str);
  for(i=0;i<M;i++)
    {
      j=(h1(k)+i*h2(k))%M;
      if(H[j][0]=='\0') return 0;
      else if(strcmp(H[j],str)==0) return 1;
    }

  return 0;
}

int insert(char str[]){
  int i,j;
  long long k;
  k=getKey(str);
  for(i=0;i<M;i++)
    {
      j=(h1(k)+i*h2(k))%M;
      if(H[j][0]=='\0')
	{
	  strcpy(H[j],str);
	  break;
	}
    }

  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 14280
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        K: usize,
        S: chars,
    }
    let mut prev = 'Z';
    let mut LR = Vec::new();
    let mut count = 0;
    for i in 0..N {
        if i != 0 && prev != S[i] {
            if prev == 'L' {
                LR.push(('L', count));
            } else {
                LR.push(('R', count));
            }
            count = 0;
        }
        count += 1;
        prev = S[i];
    }
    LR.push((prev, count));
    let mut score = 0;
    for &(_, t) in &LR {
        if t > 1 {
            score += t - 1;
        }
    }
    let ans = min(score+2*K, N-1);
    println!("{}", ans);
}


Measured memory_bytes: 8444
//#define M_PI 3.14159265358979323846
#define _USE_MATH_DEFINES

//#define _GLIBCXX_DEBUG
//#define all(x) (x).begin(),(x).end()

#include <bits/stdc++.h>

#define TASK ""
#define sqr(x) ((x)*(x))
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const ll INFLL = numeric_limits<int>::max();
const ll INFINT = numeric_limits<int>::max();
const ld EPS = 1e-7;
const ll MOD = 1000000000;
const ll MAXN = 123456;

void run()
{
    ll n;
    cin >> n;
    vector<ll> mas(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> mas[i];
    }
    sort(mas.begin(), mas.end());
    ll ans = INFLL;
    for (int i = -101; i < 101; i++)
    {
        ll ans2 = 0;
        for (int j = 0; j < n; j++)
        {
            ans2 += sqr(i - mas[j]);
        }
        ans = min(ans, ans2);
    }
    cout << ans;
}

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

#ifdef LOCAL
//#define STRESS
#ifdef STRESS
    freopen("input.txt", "w", stdout);
    cout << "1000 50\n";
    for (int i = 0; i < 999; i++)
    {
        for (int j = 0; j < 999; j++) cout << ".";
        cout << "X\n";
    }
    for (int j = 0; j < 1000; j++)
        if (j != 1000 / 50)cout << "X";
        else cout << ".";
    return 0;

#endif
    if (strcmp(TASK, "-") != 0)
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#else
    if (strcmp(TASK, "")   != 0)
    {
        freopen(TASK".in", "r", stdin)  ;
        freopen(TASK".out", "w", stdout)  ;
    }
#endif
    run();

    return 0;
}

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

using namespace std;

int main(){
  string s;
  cin >> s;
  bool yymm = false, mmyy = false;
  std::regex yymm_regex("[0987654321][0987654321]([1][012]|[0][987654321])");
  std::regex mmyy_regex("([1][012]|[0][987654321])[0987654321][0987654321]");

  yymm = std::regex_match(s,yymm_regex);
  mmyy = std::regex_match(s,mmyy_regex);

  if(yymm && mmyy){
    cout << "AMBIGUOUS";
  }else if( yymm ){
    cout << "YYMM";
  }else if( mmyy ){
    cout << "MMYY";
  }else{
    cout << "NA";
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
namespace I_am_the_brown_coder{
    class ABC10000000{
        static void Main(){
            string[] n_m = Console.ReadLine().Split();
            int n = int.Parse(n_m[0]);
            int m = int.Parse(n_m[1]);
            List<int>[] sw = new List<int>[n];
            for(int i=0;i<n;i++){
                sw[i] = new List<int>();
            }
            for(int i=0;i<m;i++){
                string[] input = Console.ReadLine().Split();
                for(int j=0;j<int.Parse(input[0]);j++){
                    sw[int.Parse(input[j+1])-1].Add(i);
                }
            }
            string[] ps = Console.ReadLine().Split();
            int[] p = new int[m];
            for(int i=0;i<m;i++){
                p[i] = int.Parse(ps[i]);
            }
            int ons = 0;
            bool[] dnonoff = new bool[m];
            for(int i =0;i<m;i++){
                if(p[i]==0){
                    dnonoff[i] = true;
                    ons ++;
                }
            }
            int ans = 0;
            Stack<int[]> st = new Stack<int[]>();
            st.Push(new int[]{0,1});
            st.Push(new int[]{0,0});
            while(st.Count>0){
                int[] ima = st.Pop();
                if(ima[1]>0){
                    foreach(int i in sw[ima[0]]){
                        dnonoff[i] = !dnonoff[i];
                        if(dnonoff[i]){
                            ons ++;
                        }else{
                            ons --;
                        }
                    }
                }
                if(ima[0]==n-1){
                    if(ons==m){
                        ans += 1;
                    }
                    if(ima[1]>0){foreach(int i in sw[ima[0]]){
                        dnonoff[i] = !dnonoff[i];
                        if(dnonoff[i]){
                            ons ++;
                        }else{
                            ons --;
                        }
                    }}
                }else{
                    st.Push(new int[]{ima[0]+1,1});
                    st.Push(new int[]{ima[0]+1,0});
                    
                }
                
            }

            Console.WriteLine(ans);
        }

    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

bool comp(P &a, P&b){
    return a.second < b.second;
}

int main(){
    int N; cin >> N;
    int X[200200];
    vector<P> vec(0);
    for(int i=0; i<N; i++){
        cin >> X[i];
        vec.push_back( P(X[i],i) );
    }
    sort(vec.begin(),vec.end());
    int middle = vec[N/2-1].first;
    int middle1 = vec[N/2].first;
    for(int j=0; j<N; j++){
        if(vec[j].first <= middle){
            vec[j].first=middle1;
        }
        else{
            vec[j].first=middle;
        }
    }
    sort(vec.begin(),vec.end(),comp);
    for(int i=0; i<N; i++){
        cout << vec[i].first << endl;
    }

}

Measured memory_bytes: 4720
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int> vi;
const int mod = 1000000007;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,cx,cy;
    cin>>n;
    int t[n],x[n],y[n];
    for(int i =0;i<n;i++){
        cin>>t[i]>>x[i]>>y[i];
    }
    int time =0;
    cx=0,cy=0;
    for(int i =0;i<n;i++){
        if(abs(x[i]-cx)+abs(y[i]-cy)>t[i]-time){
            cout<<"No"<<endl;
            return 0;

        }
        else if(((abs(x[i]-cx)+abs(y[i]-cy))%2==0 && (t[i]-time)%2!=0)||((abs(x[i]-cx)+abs(y[i]-cy))%2!=0 && (t[i]-time)%2==0)){
             cout<<"No"<<endl;
            return 0;
        }
        else{
            time = t[i];
            cx=x[i];
            cy=y[i];
        }



    }
    cout<<"Yes"<<endl;








}








Measured memory_bytes: 1408
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto a = readln.chomp.split.to!(int[]);
  a.sort();
  writeln(abs(a[$-1] - a[0]));
}


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

int main()
{
	vector<int> a = {0, 0, 0};
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
	return 0;
}

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

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll a,b;
    cin >> a >> b;
    ll ans=0;
    while(1){
        if(ans*(a-1)+1>=b){
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
    return 0;
}











Measured memory_bytes: 256
N, M = map(int, input().split())

par = [i for i in range(N)]

def find(x):
  if par[x] == x:
    return x
  else:
    par[x] = find(par[x])
    return par[x]
    

def unite(x, y):
  x = find(x)
  y = find(y)
  if x > y:
    par[x] = y
    find(x)
  else:
    par[y] = x
    find(y)
if M > 0:  
  for i in range(M):
    a, b = map(int, input().split())
    unite(a - 1, b - 1)
  
  ans = [0] * N
  Max = 0
  for i in range(N):
    find(i)
  for i in par:
    ans[i] += 1
  for i in ans:
    if i > Max:
      Max = i
  
  print(Max)
else:
  print(1)


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

typedef pair<int, int> p;

int n, m;
int a[202020], b[202020];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];
	
	priority_queue<p> pq;
	for(int i=0; i<n; i++) pq.push({b[i], i});
	
	long long ans = 0;
	while(pq.size()){
		int i = pq.top().second; pq.pop();
		int st =  b[(i+1)%n] + b[(i+n-1)%n];
		
		if((b[i] - a[i]) % st == 0){
			ans += (b[i] - a[i]) / st;
			b[i] = a[i];
			continue;
		}
		if(st >= b[i]){
			cout << -1; return 0;
		}
		
		ans += b[i] / st;
		b[i] %= st;
		if (b[i] < a[i]) {
			cout << -1; return 0;
		}
		pq.push({b[i], i});
	}
	cout << ans;
}

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

using namespace std;

typedef long long ll;

const int MAXN=3e5+7;

ll from[MAXN],to[MAXN];

map<ll,ll> Map;

ll n;
ll a[MAXN],b[MAXN],siz[MAXN],sum[MAXN];

bool cmp(const ll &A,const ll &B){return a[A]>a[B];}
bool cmp2(const ll &A,const ll &B){return A>B;}

ll minn1=1e18,minn2;

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		b[i]=i;
		Map[a[i]]=i;
		siz[i]=1;
		if(minn1>a[i]) {
			minn1=a[i];
			minn2=i;
		}
	}
	sort(b+1,b+1+n,cmp);
	sort(a+1,a+1+n,cmp2);
	for(ll i=1,i2;i<n;i++) {
		i2=Map[a[i]-abs(n-2*siz[b[i]])];
		if(i2!=0&&a[i]-abs(n-2*siz[b[i]])!=a[i]) {
			siz[i2]+=siz[b[i]];
			sum[i2]+=sum[b[i]]+siz[b[i]];
			from[i]=i2;
			to[i]=b[i];
		}
		else {
			cout<<-1<<endl;
			return 0;
		}
	}
	if(minn1!=sum[minn2]) {
		cout<<-1<<endl;
		return 0;
	}
	for(int i=1;i<n;i++) {
		cout<<from[i]<<" "<<to[i]<<endl;
	}
}


Measured memory_bytes: 14604
#include<cmath>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<functional>
#define INF 1e16
#define N (1000000007)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> Q;


ll sum[200010];

int main(void){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n+1);
    for(int i=0;i<n;i++)cin>>a[i+1];
    for(int q=0;q<k;q++){
        for(int i=1;i<=n;i++){
            sum[max(1LL,i-a[i])]++;
            sum[min(n+1,i+a[i]+1)]--;
        }
        for(int i=1;i<=n+1;i++){
            sum[i]+=sum[i-1];
        }
        for(int i=1;i<=n;i++){
            a[i]=sum[i];
        }
        bool flag = true;
        for(int i=1;i<=n;i++){
            if(a[i]!=n)flag = false;
        }
        if(flag)break;
        for(int i=0;i<=n+1;i++)sum[i]=0;
    }
    for(int i=1;i<=n;i++){
        if(i==n)cout<<a[i]<<endl;
        else cout<<a[i]<<" ";
    }
    return 0;
}



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

int N;
int a[100000001];

int gcd(int a, int b) {
    if (a%b == 0) return b;
    else gcd(b, a%b);
}

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

    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];

    int l[100001], r[100001];
    l[0] = a[0]; r[N-1] = a[N-1];
    for (int i = 1; i < N; i++) {
        l[i] = gcd(l[i-1], a[i]);
        r[N-i-1] = gcd(r[N-i], a[N-i-1]);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i == 0) ans = max(ans, r[i+1]);
        else if (i == N-1) ans = max(ans, l[i-1]);
        else ans = max(ans, gcd(l[i-1], r[i+1]));
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let aa = read_line () |> split_string ~pattern:" " |> List.map int_of_string

let all = List.fold_left (lxor) (List.hd aa) (List.tl aa)

let () = aa |> List.map (fun i -> all lxor i) |> List.map string_of_int |> String.concat " " |> print_endline

Measured memory_bytes: 33628
#include <bits/stdc++.h>
using namespace std;
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
char s[100];
int a[100];
int main(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    if (n<26){
	for (int i=1; i<=n; ++i)
	    a[s[i]-'a']=1;
	cout<<s+1;
	for (int i=0; i<26; ++i)
	    if (!a[i]){
		putchar('a'+i);
		break;
	    }
	return 0;
    }
    s[0]='z'+1;
    for (int i=n-1; i; --i){
	int id=0;
	for (int j=i+1; j<=n; ++j)
	    if (s[j]>s[i]&&s[j]<s[id])
		id=j;
	if (id){
	    for (int j=1; j<i; ++j)
		putchar(s[j]);
	    putchar(s[id]);
	    return 0;
	}
    }
    cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string abc[3];
	rep(i, 0, 3)cin >> abc[i];
	int num = 0;
	char ans[] = { 'A','B','C' };
	while (1) {
		if (abc[num].empty()) {
			cout << ans[num] << "\n";
			return 0;
		}
		int x = num;
		num = abc[num][0] - 'a';
		abc[x].erase(0, 1);
	}

	return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  int num, tarou = 0, hanako = 0, j;
  string tru, hnk;
  char t, h;
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> tru; cin >> hnk;
    for(j = 0; j < tru.length(); j++){
      if(j > hnk.length() - 1){
        tarou += 3;
        break;
      }
      t = tru[j];
      if(isupper(t)) { tolower(t); }
      h = hnk[j];
      if(isupper(h)) { tolower(h); }
      if(t > h){
        tarou += 3;
        break;
      } else if(t < h){        
        hanako += 3;
        break;
      }
    }
    if(j == tru.length()){
      if(hnk.length() > tru.length()){
        hanako += 3;
      } else {
        hanako++; tarou++;
      }
    }
  }
  cout << tarou << " " << hanako << endl;
  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;


int main() {
	map<int, int> mp;
	long long int a,b=0,c[1600];
	string str;
	cin >> a;
	for (int i = 0; i < 2*a; i++) {
		cin >> c[i];
	}
	sort(c, c + 2*a);
	for (int i = 0; i < a; i++) {
		b += c[2 * i];
	}
	cout << b;
}


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

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

	int result = 0;

	for (int i=0; i<s.length()-1 ; ++i) {
		if (s[i] != s[i+1]) {
			result++;
		}
	}

	cout << result << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#define MAX 60000

int num[MAX];

int main(void){
	int i, j;
	int in, big, small;
	for(i = 2; i < sqrt(MAX); i++){
		for(j = i; i * j < MAX; j++)	num[i*j] = 1;
	}
	while(scanf("%d", &in) != EOF){
		for(i = 2; i < MAX; i++){
			if((num[i] == 0) && (i > in))	break;
		}
		big = i;
		for(i = i; i > 2; i--){
			if((num[i] == 0) && (i < in))	break;
		}
		small = i;
		printf("%d %d\n", small, big);
	}
  return 0;
}

Measured memory_bytes: 828
#include<bits/stdc++.h>
using namespace std;
int m,p,ans,res,x,n,q,fi,ti,rev=0;
string s,t;
char c;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
    cin>>s>>q;
    while(q--){
        cin>>ti;
        if (ti==1)
            rev++;
        else{
            cin>>fi>>c;
            if(rev%2==0){
            	if(fi==1) s.insert(s.begin(),c);
            	else s.insert(s.end(),c);
        	}
        	else{
            	if(fi==1) s.insert(s.end(),c);
            	else s.insert(s.begin(),c);
        	}
        }
    }
    if (rev%2==1)
        reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}


Measured memory_bytes: 912
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;
int l1,l2,a,b,c,n,T,v[200005],i;
long long sol;

int main()
{
    cin>>n>>T;
    for(i=1;i<=n;i++) cin>>v[i];
    sort(v+1,v+n+1);
    sol+=T;
    for(i=1;i<n;i++)
    {
        sol+=min(T,v[i+1]-v[i]);
    }
    cout<<sol<<'\n';
}


Measured memory_bytes: 1024
<?php
/**
 * Created by PhpStorm.
 * User: wahho
 * Date: 2016/08/28
 * Time: 20:56
 */
fscanf(STDIN, "%s", $in_w);
$arr_w = array();
for($i = 0; $i < strlen($in_w); $i++){
    $arr_w[] = substr($in_w, $i, 1);
}
// echo "test: $arr_w[0] $arr_w[1] $arr_w[2]";
sort ($arr_w);

$ans_b = "Yes";
$kazu = 0;
$mae = "null";
foreach ($arr_w as $w){
//    echo "test: $ans_b $kazu $mae $w\n";
    if($mae == $w){
        $kazu++;
    }elseif(($kazu % 2) == 0){
        $mae = $w;
        $kazu = 1;
    }else{
//        $ans_b = "No";
        break;
    }
}
if(($kazu % 2) != 0){
    $ans_b = "No";
}

echo "$ans_b\n";
?>

Measured memory_bytes: 2936
#include <iostream>
using namespace std;
const int Max = 200;

int a[Max], Count = 0;
void SelectSort(int a[], int N)
{
      for(int i=0; i<N-1; i++)
      {
          int minj = i;
          for(int j=i+1; j<N; j++)
          {
              if(a[j] < a[minj])
                minj = j;
          }
          if(i!=minj)
          {
              int temp = a[i];
              a[i] = a[minj];
              a[minj] = temp;
              Count++;
          }
      }
}

int main()
{
    int N;
    cin >> N;
    for(int i=0; i<N; i++)
    {
        cin >> a[i];
    }
    SelectSort(a, N);
    for(int i=0; i<N-1; i++)
        cout << a[i] << " ";
     cout << a[N-1] << endl;
     cout << Count << endl;
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int n, k, m;
vector<int> a;

bool possible( int d ){
	vector<int> b(a);
	for( auto &x : b ) x %= d;
	sort( b.begin(), b.end() );
	vector<int> sum(n+1);
	sum[0] = 0;
	for( int i = 0; i < n; ++i ){
		sum[i+1] = sum[i] + b[i];
	}
	int res = inf;
	for( int l = 0; l <= n; ++l ){
		if( d*(n-l) - (sum[n]-sum[l]) == sum[l] ){
			res = min(res, sum[l]);
		} 
	}
	return ( k >= res );
}

int main(){
	cin >> n >> k;
	int sum = 0;
	for( int i = 0; i < n; ++i ){
		int tmp; cin >> tmp;
		sum += tmp;
		a.push_back(tmp);
	}
	vector<int> dv;
	int sz = 0;
	for( int k = 1; k*k <= sum; ++k ){
		if( sum%k == 0 ){
			dv.push_back(k);
			++sz;
			if( sum/k != k ){
				dv.push_back( sum/k );
				++sz;
			}
		}
	}
	int ans = 0;
	for( auto &x : dv ){
		if( possible(x) ) ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0){
        return a;
    }
    return mygcd(b,a%b);
}

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

    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

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

    vector<vector<ll>> dp(n+1,vector<ll>(2,0));

    dp[0][0] = a[0];
    dp[0][1] = a[0];
    
    for(int i = 1; i < n; i++){
        dp[i][0] = mygcd(dp[i-1][0],a[i]);
        dp[i][1] = mygcd(dp[i-1][1],a[i]);
        dp[i][1] = max(dp[i][1],dp[i-1][0]);
    }

    ll r = a[1];
    for(int i = 2; i < n; i++){
        r = mygcd(r,a[i]);
    }

    cout << max(dp[n-1][0],max(dp[n-1][1],r)) << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long

int cmpfunc(const void *a, const void *b){
    return (*(int*)a - *(int*)b);
}

int max(int a,int b){
    return (a>b)?a:b;
}

int main(void){
    int a,b,i;
    scanf("%d %d",&a,&b);
    if(a+b>=10) printf("error\n");
    else printf("%d\n",a+b);


    return 0;
}


Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10000000)
input = sys.stdin.readline

N, Q = map(int, input().split())

tree = [[0] * 1 for i in range(N)]


tree_list = [0] * N
end = [0] * N

for index in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)

for index in range(Q):
    a, b = map(int, input().split())
    a -= 1
    tree_list[a] += b


def iter(node):
    end[node] = -1
    child = tree[node]
    for c in child:
        if end[c] == 0:
            tree_list[c] += tree_list[node]
            iter(c)


iter(0)

print(*tree_list)


Measured memory_bytes: 234484