akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int h, w, k;
string s[6];


int main(){

 
  cin >> h >> w >> k;
  REP(i,h){
    cin >> s[i];
  }

  llong ans = 0;
  for(int maskR = 0; maskR < (1 << h); ++maskR){
    for(int maskC = 0; maskC < (1 << w); ++maskC){
      int black = 0;
      REP(i,h){
        REP(j,w){
          if(s[i][j] == '#' && ((maskR >> i) & 1) == 0 && ((maskC >> j) & 1) == 0) black++;
        }
      }
      if(black == k) ans++;
    }
  }
  cout << ans << endl;
  return 0;

}





Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

int main() {
    long a, b, x;
    cin >> a >> b >> x;
    if (x >= a && x <= a + b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,i,j,l=0;
    scanf("%d",&N);
    for(j=1;j<=9;j++)
    {
        for(i=1;i<=9;i++)
            {


         if(N==j*i)
            {
                l=1;
         }
            }}
            if(l==1){
            printf("Yes");
         }
         else{
            printf("No");
         }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,x,y;
    cin >> x >> y;
    string ans ="No";
    if(2*x <= y && y<=4*x){
        if(y%2==0){
            ans = "Yes";
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long n = sc.nextLong();
			double sq = Math.sqrt((double) n);
			int sqrt = (int) sq;
			long ans = 1;

			for (int i = 2; i <= sqrt; i++) {
				if (n % i == 0) {
					ans = i;
				}
			}
			long other = n / ans;
			System.out.println((ans + other - 2));
		}
	}
}


Measured memory_bytes: 23764
def solve(d, n):
    return (100**d) * (n + (n==100))

assert solve(0, 5) == 5
assert solve(1, 11) == 1100
assert solve(2, 85) == 850000
assert solve(0, 100) == 101
assert solve(1, 100) == 10100
assert solve(2, 100) == 1010000

d, n = map(int, raw_input().split())
print solve(d, n)

Measured memory_bytes: 2568
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

int dp[2][101][5];

signed main() {
  string S;cin>>S;
  int k;cin>>k;

  dp[0][0][0] = 1;

  rep(i, sz(S)){  //桁数
    rep(leq, 2){  //未満確定フラグ
      int lim = leq ? 9 : S[i]-'0';
      rep(d, 0, lim+1){
        rep(j, 4) dp[leq || d<lim][i+1][j+(d==0?0:1)] += dp[leq][i][j];
      }
    }
  }

  cout << dp[0][sz(S)][k]+dp[1][sz(S)][k] << endl;
  return 0;
}


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

#define pb(s) push_back(s)
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PI 3.14159265358979323846264338327950L


typedef long long ll;

void calculate(vector<int> vi, int p,int x)
{
    int sum=0;
    for(int i=0;i<vi.size();++i){
        if(i==p-1){
            sum+=x;
            continue;
        }
        sum+=vi[i];
    }
    cout<<sum<<endl;
}

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

    int N;
    cin>>N;
    vector<int> vi(N);
    for(int i=0;i<N;++i){
        cin>>vi[i];
    }
    int M;
    cin>>M;
    for(int i=0;i<M;++i){
        int p,x;
        cin>>p>>x;
        calculate(vi,p,x);
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long


signed main(void)
{
	int n; cin >> n;
	int a[n], b[n];
	rep (i, n) cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n);
	double ac, bc;
	if (n % 2) ac = a[(n+1)/2-1], bc = b[(n+1)/2-1];
	else ac = (a[n/2-1]+a[n/2]) / 2.0, bc = (b[n/2-1]+b[n/2]) / 2.0;
	int ans;
	if (n % 2) ans = bc - ac + 1;
	else ans = (bc - ac) * 2 + 1;
	cout << ans << endl;
}



Measured memory_bytes: 6752
#include <stdio.h>
 
int main(void)
{
  long int n,k;
  
  do{
    scanf("%ld %ld",&n,&k);
  } while((n<0 || n>1000000000000000000) || (k<1 || k>1000000000000000000));
  
  if(n>=k){
    n %= k; 
    if(n>k-n)
      n = k-n;
  }
  else
    while(n>k-n)
      n = k-n;
  
  printf("%ld\n",n);
  
  return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

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

  int ans = 0;
  rep(i, N)
  {
    while (i < N - 1 && A[i] == A[i + 1])
      i++;

    if (i < N - 1 && A[i] < A[i + 1])
    {
      while (i < N - 1 && A[i] <= A[i + 1])
        i++;
    }
    else if (i < N - 1 && A[i] > A[i + 1])
    {
      while (i < N - 1 && A[i] >= A[i + 1])
        i++;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 200005
using namespace std;
typedef long long ll;
typedef double db;
int n,a[N],tmp;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	if(a[n]==a[1]&&a[1]==1){printf("1 1\n");return 0;}
	printf("%d ",a[n]);
	for(int i=0;i<=n;++i)
	{
		if(a[i]<=a[n]/2&&a[i+1]>a[n]/2)
		{
			if(a[n]/2-a[i]<a[n]/2-(a[n]-a[i+1])) printf("%d\n",a[i]);
			else
			{
				if(a[i+1]==a[n]) printf("%d\n",a[i]);
				else printf("%d\n",a[i+1]);
			}
			break;
		}
	}
	return 0;
}


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

int main() {
  int p,q,r;
  cin >> p >> q >> r;
  if (((p+q) < (q+r)) && ((p+q) < (r+p))) cout << (p+q);
  else if ((q+r) < (r+p)) cout << (q+r);
  else cout << (r+p);
}


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

int main() {
  int n; string s;
  cin >> n >> s;
  int open = 0, close = 0;
  rep(i,n) {
    if (s[i] == '(') close++;
    else if (close > 0) close--;
    else open++;
  }
  rep(i,open) cout << '(';
  cout << s;
  rep(i,close) cout << ')';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  if((s[0] == s[1] && s[1] == s[2]) || (s[2] == s[3] && s[1] == s[2]))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 2010
using namespace std;
struct edge{ int v,nt; } G[N<<1];
int n,m,cnt,h[N],d[N],f[N],sz[N],A=0;
inline int dfs(int x,int p){
	d[x]=d[p]+1; int c=0;
	for(int v,i=h[x];i;i=G[i].nt)
		if((v=G[i].v)!=p){
			c+=dfs(v,x);
			sz[x]+=sz[v]; 
		}
	if(d[x]<=(m>>1)) ++c; return c;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int x,y,i=1;i<n;++i){
		scanf("%d%d",&x,&y);
		G[++cnt]=(edge){y,h[x]}; h[x]=cnt;
		G[++cnt]=(edge){x,h[y]}; h[y]=cnt;
	}
	if(m&1){
		for(int x=1;x<=n;++x)
			for(int y,i=h[x];i;i=G[i].nt){
				d[G[i].v]=-1; y=dfs(x,G[i].v);
				d[x]=-1; y+=dfs(G[i].v,x);
				A=max(A,y);
			}
	} else for(int x=1;x<=n;++x){
		d[0]=-1;
		A=max(A,dfs(x,0));
	}
	printf("%d\n",n-A);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
}

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

int main(){
    string s;
    cin >> s;
    REP(i, s.size() - 1){
        if(s[i] == 'A' and s[i + 1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 */
int main()
{
    int n;
    cin >> n;
    vector<int> a(1000000, 0);
    a.at(0) = n;
    FOR(i, 1000000, 1) {
        if(a.at(i-1) % 2 == 0) {
            a.at(i) = a.at(i - 1) / 2;
        } else {
            a.at(i) = a.at(i - 1) * 3 + 1;
        }
    }
    REP(i, 1000000) {
        if(a.at(i) == 0) {
            break;
        }
        FOR(j, 1000000, i+1) {
            if(a.at(j) == 0) {
                break;
            }
            if (a.at(i) == a.at(j))
            {
                cout << j+1 << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main() {
  int D, N;
  cin >> D >> N;
  
  if( N == 100 ){
    if( D == 0 )cout << 101 << endl;
    else if( D == 1 ) cout << 101 * 100 << endl;
    else if( D == 2 ) cout << 101 * 100 * 100 << endl;
      return 0;
  }
  if( D == 0 ){
    cout << N << endl;
  }else if( D == 1){
    cout << N * 100 << endl;
  }else if( D == 2){
    cout << N * 100 * 100 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n, temp;
    cin>>n;
    vector <int> v;
    for (int i=0; i<n; i++){
        cin>>temp;
        v.push_back(temp);
    }

    bool approved=true;
    for (int i=0; i <n; i++)
    {
        if (v[i]%2==0 && v[i]%3!=0 && v[i]%5!=0)
        {
            approved =false;
            break;
        }
    }

    if (approved)
        cout<<"APPROVED";
    else
        cout<<"DENIED";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [0]
A += list(map(int, input().split()))
A += [0]
cost = [abs(A[i] - A[i+1]) for i in range(N+1)]
sumcost = sum(cost)
for i in range(1, N+1):
    print(sumcost - (cost[i-1] + cost[i]) + abs(A[i+1] - A[i-1]))


Measured memory_bytes: 14044
#include <stdio.h>

int selectionSort(int *arr, int size) {
  int cnt=0;
  for (int i=0; i<size; i++) {
    int minj=i, tmp;
    for (int j=i+1; j<size; j++) {
      if (arr[minj]>arr[j]) {
        minj=j;
      }
    }
    if (minj!=i) {
      tmp=arr[i];
      arr[i]=arr[minj];
      arr[minj]=tmp;
      cnt++;
    }
  }
  return cnt;
}

int main() {
  int n;
  scanf("%d", &n);
  int arr[n];

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

  int cnt = selectionSort(arr, n);

  for (int i=0; i<n; i++) {
    if (i<n-1) {
      printf("%d ", arr[i]);
    } else {
      printf("%d\n", arr[i]);
    }
  }

  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename T>
vector<T> divisor(T n)
{
    vector<T> res;
    for(T i=1;i*i<=n;i++){
        if(n%i==0){
            res.pb(i);
            if(i != n/i){
                res.pb(n/i);
            }
        }
    }
    sort(all(res));
    return res;
}

ll mod_pow(ll a,ll b)
{
    a %= MOD;
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

map<int,int> mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vi res = divisor(n);
    int m = len(res);
    rep(i,m){
        int val = mod_pow(K,(res[i]+1)/2);
        rep(j,i){
            if(res[i] % res[j] == 0){
                val = sub(val,mp[res[j]]);
            }
        }
        mp[res[i]] = val;
    }
    int ans = 0;
    rep(i,m){
        if(res[i] % 2){
            ans = add(ans,mul(mp[res[i]],res[i]));
        }else{
            ans = add(ans,mul(mp[res[i]],res[i]/2));
        }
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
  int D;
  cin >> D;
  if(D == 22){
    cout << "Christmas Eve Eve Eve";
  }else if(D == 23){
    cout << "Christmas Eve Eve";
  }else if(D == 24){
    cout << "Christmas Eve";
  }else if(D == 25){
    cout << "Christmas";
  }
}


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

int main() {
    int N, C, K;
    cin >> N >> C >> K;

    vector<int> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    sort(T.begin(), T.end());

    int idx = 0,
        num = 0,
        ans = 0;
    while (idx < N) {
        int start = T[idx++];
        num = 1;
        ans++;

        while (idx < N && num < C && T[idx] <= start + K) {
            idx++;
            num++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h> 
int n,a,ans=0,i=0;;
int main()
{
	scanf("%d",&n);
	while (n--)
	{
		i++;
		scanf("%d",&a);
		if (i%2==1&&a%2==1) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vector<vector<int>> to(n);
    vector<vector<int>> cost(n);
    rep(i, n-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        to[u].pb(v);
        cost[u].pb(w);
        to[v].pb(u);
        cost[v].pb(w);
    }
    vi ans(n, -1);
    queue<int> q;
    q.push(0);
    ans[0] = 0;
    while (!q.empty()) {
        int p = q.front(); q.pop();
        rep(i, sz(to[p])) {
            int t = to[p][i], nc = cost[p][i];
            if (ans[t] != -1) continue;
            int col = (nc%2==0?ans[p]:1-ans[p]);
            q.push(t);
            ans[t] = col;
        }
    }
    rep(i, n) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 14520
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
// Int MOD = 998244353;


int main() {
    ios::sync_with_stdio(false);
    Int k, a, b;
    cin >> k >> a >> b;
    if (a + 2 >= b) {
        dump(k + 1);
        return 0;
    }
    if (k < a + 1) {
        dump(k + 1);
        return 0;
    }
    Int res = b;
    k -= (a - 1) + 2;
    res += (k / 2) * (b - a);
    if (k % 2 == 1) res++;
    dump(res);
    return 0;  
} 

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

int main(){

    size_t n, l;

    std::cin >> n >> l;

    std::vector<std::string> s(n);

    for(auto&& e : s){
        std::cin >> e;
    }

    std::sort(s.begin(), s.end());

    for(const auto& e : s){
        std::cout << e;
    }std::cout << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
n,m = (int(i) for i in input().split())
x = []
for _ in range(n):
    a,b = (int(i) for i in input().split())
    x.append((-b,a))
c,v,x,ans = [int(i) for i in range(m+1)],[1]*(m+1),sorted(x),0
for i in range(n):
    num,y = x[i][1],[x[i][1]]
    while num<=m and num!=c[num]:
        num = c[num]
        y.append(num)
    if num<=m:
        for j in y: c[j] = num+1
        ans-=x[i][0]
print(ans)

Measured memory_bytes: 22492
#include <stdio.h>
#include <string.h>
#include <iostream>


main(){
  char name[10];
  int  AA, BB;

  std::cin >> AA >> name >> BB;
  if(!strcmp(name, "+")) std::cout<< AA + BB <<std::endl;
  else if(!strcmp(name, "-")) std::cout<< AA - BB <<std::endl;

  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>

int main(){
   int x, y;
   scanf("%d %d", &x, &y);

   int judge = 0;
   for(int i=0; i<=x; i++){
      if(y == 2*i + 4*(x-i)){
         judge = 1;
      }
   }
   if(judge == 1){
      printf("Yes\n");
   } else {
      printf("No\n");
   }

   return 0;
}



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

int main()
{
    long long l,r;
    cin >> l >> r;
    const int mod = 2019;
    if(r - l >= mod){
        cout << 0 << endl;
        return 0;
    }
    int ans = mod;
    for(int i=l; i<=r; i++){
        for(int j=i+1; j<=r; j++){
            int tmp = (i % mod) * (j % mod);
            tmp = tmp % mod;
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n,m;
int l[20];
int q[200];

bool con(int i,int m){
    if (m ==0) return true;
    else if (i >= n) return false;
    int res = con (i+1,m) || con(i + 1,m -l[i]);
    return res;
}

int main(){
    cin >> n;
    for (int i =0; i<n; i++){
        cin >> l[i];
    }
    cin >> m;
    for (int j =0; j<m; j++){
        cin >> q[j];
    }
    for (int k = 0;k<m; k++){
        if (con(0,q[k])==true){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        } 
    }
    return 0;
}


Measured memory_bytes: 3104
A=[]
B=range(2, 1600)
while(B[0]<40):
    b=B.pop(0)
    A.append(b)
    B=[x for x in B if x%b!=0]
A+=B
C=range(2,1600)
for b in A:
    C=[b if c%b==0 else c for c in C]
N=reduce(lambda a,b: a*b, A)+2
print N
q=int(raw_input())
for i in range(q):
    print C[i]

Measured memory_bytes: 6540
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
n=int(input())
number=[int(input()) for i in range(n)]

ac=[False]*3
bc=[False]*3
cc=[False]*3

for i in number:
    for x in range(3):
        if i==a[x]:
            ac[x]=True
        if i==b[x]:
            bc[x]=True
        if i==c[x]:
            cc[x]=True

if all(ac) or all(bc) or all(cc):
    print('Yes')
    exit()
for i in range(3):
    if ac[i]==True and bc[i]==True and cc[i]==True:
        print('Yes')
        exit()
if ac[0]==True and bc[1]==True and cc[2]==True:
    print('Yes')
    exit()
if ac[2]==True and bc[1]==True and cc[0]==True:
    print('Yes')
    exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf (1e9 + 7)
using namespace std;
typedef long long LL;
const LL mod = (1e9 + 7);

int nexts[200005][27], pos[27], dp[200005], pos2[200005], len;
char ch[200005];

void dfs(int u)
{
    if(dp[u] != -1)
        return;
    dp[u] = inf;
    for(int i = 0;i < 26;i++)
    {
        if(nexts[u][i] == len + 1)
        {
            if(dp[u] > 1)
                dp[u] = 1, pos2[u] = i;
        }
        else
        {
            dfs(nexts[u][i]);
            if(dp[u] > dp[nexts[u][i]] + 1)
                dp[u] = dp[nexts[u][i]] + 1, pos2[u] = i;
        }
    }
}

void pr(int a)
{
    printf("%c", pos2[a] + 'a');
    if(nexts[a][pos2[a]] == len + 1)
        return;
    pr(nexts[a][pos2[a]]);
}

int main()
{
    mem(dp, -1);
    scanf("%s", ch + 1);
    len = strlen(ch + 1);
    for(int i = 0;i < 26;i++)
        pos[i] = len + 1;
    for(int i = len;i >= 1;i--)
    {
        for(int j = 0;j < 26;j++)
            nexts[i][j] = pos[j];
        pos[ch[i] - 'a'] = i;
    }
    for(int i = 0;i < 26;i++)
        nexts[0][i] = pos[i];
    for(int i = 0;i <= len;i++)
    {
        if(dp[i] == -1)
            dfs(i);
    }
    int ans = inf, ans2;
    pr(0);
    puts("");
    return 0;
}


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

int main(void) {

    int N; // 展望台
    int M; // 道

    char tenbodai_yoshi[100000];
    int tenboudai_height[100000];

    scanf("%d %d",&N,&M);

    for(int i = 0;i < N;i++){
        tenbodai_yoshi[i] = 1; //みちがつながってないときは1のままになる
        tenboudai_height[i] = 0;
    }
    int temp_h;

    for(int j = 0;j < N;j++){
        scanf("%d",&tenboudai_height[j]);
    }

    int tembodai_a;
    int tembodai_b;
    for(int i = 0;i < M;i++){
        scanf("%d %d",&tembodai_a,&tembodai_b);
        if(tenboudai_height[tembodai_a - 1] > tenboudai_height[tembodai_b - 1]){
            tenbodai_yoshi[tembodai_b - 1] = 0;
        }else if(tenboudai_height[tembodai_a - 1] < tenboudai_height[tembodai_b - 1]){
            tenbodai_yoshi[tembodai_a - 1] = 0;
        }else if(tenboudai_height[tembodai_a - 1] == tenboudai_height[tembodai_b - 1]){
            tenbodai_yoshi[tembodai_a - 1] = 0;
            tenbodai_yoshi[tembodai_b - 1] = 0;
        }
    }

    // 展望台の数表示
    int count = 0;
    for(int i = 0;i < N;i++){
        if(tenbodai_yoshi[i] == 1)count++;
    }
    printf("%d\n",count);

    return 0;
}

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



int main(){

	int n,k[100],len;
	char s[100];
	int i,j;


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

		if(n == 0){

			exit(0);
		}

		for(i=0; i < n; i++){

			scanf("%d",&k[i]);
		}

		scanf("%s",s);

		for(i = 0; i < strlen( s ); i++){

			for(j = 0;j < k[i%n];j++){
				
				if(s[i] == 'a'){
					s[i] = 'Z';
				}
				else if(s[i] == 'A'){
					s[i] = 'z';
				}
				else{
					s[i]--; 
				}

			}

		}

		printf("%s\n",s);
	}

}

Measured memory_bytes: 592
import java.util.Scanner;
public class Main {
  static Scanner scan=new Scanner(System.in);
  public static void main(String[] args) {
    int N = scan.nextInt();
    int K = scan.nextInt();
    String S = scan.next();

    int cnt = 0;
    for (int i = 0; i < N-1; i++) {
      if (S.charAt(i) != S.charAt(i+1)) {
        ++cnt;
      }
    }

    int ans = N-1 - Math.max(cnt - 2*K, 0);
    System.out.println(ans);
  }
}


Measured memory_bytes: 25928
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

map<lld,lld>cnt;

int main()
{
	fastio
	lld n;
	cin>>n;

	std::vector<lld> v(n);
	lld sum=0;
	for(lld i=0;i<n;i++)
	{
		cin>>v[i];
		cnt[v[i]]++;
		sum+=v[i];
	}	

	lld q;
	cin>>q;

	while(q--)
	{
		lld b,c;
		cin>>b>>c;
		sum=sum+(c-b)*cnt[b];

		if(cnt.find(c)!=cnt.end())
			cnt[c]+=cnt[b];
		else
			cnt[c]=cnt[b];

		cnt[b]=0;

		cout<<sum<<endl;

	}

}

Measured memory_bytes: 10120
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long m=sc.nextLong();
		long l=1;
		int count2=0;
		for(int i=0; i<n; i++){
			long a =sc.nextLong();
			int tmp=0;
			while(a%2==0){
				a/=2;
				tmp++;
			}
			if(i==0){
				count2=tmp;
			}else if(count2!=tmp){
				System.out.println(0);
				return;
			}
			try{
			l=l*a/gcd(l,a);
			}catch(StackOverflowError e){
				System.out.println(00);
				return;
			}
		}
		long two=2;
		count2--;
		while(count2>0){
			if((count2 & 1)==1){
				l*=two;
			}
			two*=two;
			count2>>=1;
		}
		m/=l;
		System.out.println((m+1)/2);
	}
	private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 287632
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type rints []int
func (f rints) Len() int {
	return len(f)
}

func (f rints) Less(i, j int) bool {
	return f[i] > f[j]
}

func (f rints) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func RSortInt(x []int) []int {
	i := rints(x[:])
	sort.Sort(i)
	return i
}

func main() {
	n := nextInt()
	k := nextInt()
	h := make([]int, n)

	for i:=0; i<n ; i++ {
		h[i] = nextInt()
	}

	if k >= n {
		fmt.Printf("0")
		return
	}

	sum := 0
	rh := RSortInt(h)
	for i:=k; i < n ; i++ {
		sum += rh[i]
	}

	fmt.Printf("%d", sum)
}


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

int main(){
    string s;
    ll k;
    cin >> s >> k;
    int n = s.size();
    int a[n], b[n];
    rep(i, n){
        a[i] = ('z' - s[i] + 1) % 26;
    }

    rep(i, n - 1){
        if (k >= a[i]){
            cout << 'a';
            k -= a[i];
        }
        else cout << s[i];
    }
    cout << char('a' + ((s[n - 1] - 'a') + k) % 26) << endl;
    return 0;
}

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

using namespace std;

typedef long long llint;
typedef pair <int, int> pi;

int n, cnt, sol;
string s;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    n = s.size();
    for (int i = 0; i < n; i++) {
        if (s[i] == 'S') {
            cnt++;
        } else if (cnt > 0) {
            cnt--;
            sol++;
        }
    }
    cout << n - 2 * sol;
    return 0;
}


Measured memory_bytes: 3752
"""
AtCoder Beginner Contest 147 D

https://atcoder.jp/contests/abc147/submissions/8876207
https://qiita.com/ZhangChaoran/items/0d59eb5c95cd9414801d


"""

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

# XORではビット毎に計算していくのが基本的な戦略
# 60乗までなので
bits = [0] * 60
for num in A:
    # A_i<2**60なので
    for i in range(60):
        # iビット目に1が立っていたらカウント
        if num & (1<<i):
            bits[i] += 1

"""
pは0からスタート
A_iについて、pビット目に1が立っていたら、i<jを満たすA_jのpビット目に0が立っている個数分2**pをプラスする
また、pビット目に0が立っていたら、i<jを満たすA_jのpビット目に1が立っている個数分2**pをプラスする
i,jのペアを見ていく時に、pビット目の1と0が何回出会うかを考えるとわかりやすいか
配列全体をみて、pビット目に1がa個ある場合、0はN-a個ある。これがΣΣのループで出会うので、
p桁目についてはa*(N-a)回2**pを答えに加えることになる
（a*(N-a)についてはあんまり腑に落ちてないが、例2とかで手を動かしてみるとそうなるので。）

これを全pに対して実施すると良い。
最後にmodを取ると値が大きすぎてあれなので、つどmodを取る
"""



ans = 0
for i, a in enumerate(bits):
    ans += a*(N-a) * 2**i
    ans %= MOD

print(ans)

Measured memory_bytes: 125624
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
}

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

fn main() {
    input!{
        N:i64,
        X:i64,
        T:i64
    }
    println!("{}",T*(N/X+cmp::min(1,N%X)));
}


Measured memory_bytes: 2064
#include <iostream>
#include <cmath>
using namespace std;
int main() {
	long long int h;
	int count;
	cin >> h;
	if(h==1){
		cout << 1 << endl;
	}
	else {
		if (h % 2 != 0) {
			h -= 1;
		}
		count = log2(h);
		cout << (long long int)pow(2, count + 1) - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		if (a < b) {
			cout << a;
			for (int j = a+1; j <= b; j++) {
				cout << " " << j;
			}
			cout << endl;
		} else {
			if (a < 6) {
				cout << a;
				for (int j = a-1; j >= b; j--) {
					cout << " " << j;
				}
				cout << endl;
			} else {
				if (b < 6) {
					cout << a;
					for (int j = a+1; j <= 9; j++) {
						cout << " " << j;
					}
					for (int j = 5; j >= b; j--) {
						cout << " " << j;
					}
					cout << endl;
				} else {
					cout << a;
					for (int j = a+1; j <= 9; j++) {
						cout << " " << j;
					}
					for (int j = 5; j >= 1; j--) {
						cout << " " << j;
					}
					for (int j = 0; j <= b; j++) {
						cout << " " << j;
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
#include<random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<double, lint> Pa;
typedef pair<plint, lint> tlint;
struct edge {
	lint cost;
	lint u, v;
};

vector< int64_t > divisor(int64_t n) {
	vector< int64_t > ret;
	for (int64_t i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}

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

const lint MAX_A = 1000000;
lint N, arr[MAX_A];
bool tbl[MAX_A + 1];
int main() {
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	bool flag = true;
	REP(i, MAX_A + 1) tbl[i] = true;
	REP(i, N) {
		auto vec = divisor(arr[i]);
		REP(j, SZ(vec) - 1) {
			if (!tbl[vec[j + 1]]) {
				flag = false;
				break;
			}
			tbl[vec[j + 1]] = false;
		}
		if (!flag) break;
	}
	if (flag) {
		cout << "pairwise coprime" << endk;
		return 0;
	}

	lint _gcd = arr[0];
	REP(i, N - 1) {
		_gcd = gcd(arr[i + 1], _gcd);
	}
	if (_gcd == 1) {
		cout << "setwise coprime" << endk;
	}
	else {
		cout << "not coprime" << endk;
	}
}


Measured memory_bytes: 12412
s = input()
len = 0
op = []

for i in s:
    if(i == '1'):
        op.append('1')
        len += 1
    elif(i == '0'):
        op.append('0')
        len += 1
    elif(i == 'B'):
        if(len > 0):
            op.pop()
            len = len - 1

for i in op:
    print(i, end = '')

Measured memory_bytes: 3064
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

ll arr[3002][3002];
ll dp[3002][3002][4];

int main()
{
	int r,c,k;
	cin>>r>>c>>k;
	
	for(int i = 0;i<k;i++)
	{
		int x,y;
		ll v;
		cin>>x>>y>>v;
		arr[x-1][y-1] = v;	
	}
	
	for(int row = r-1;row>=0;row--)
	{
		for(int col = c-1;col>=0;col--)
		{
			for(int at = 0;at<=3;at++)
			{
				if(at == 0)
				{
					dp[row][col][at] = dp[row+1][col][3];
				}
				else
				{
					ll val = 0;
					val = max(arr[row][col] + dp[row][col+1][at-1] ,val);
					val = max(dp[row][col+1][at] , val);
					val = max(val , arr[row][col] + dp[row+1][col][3]);
					
					dp[row][col][at] = val;
				}
			}
		}
	}		
	
	cout<<dp[0][0][3]<<endl;
	
	return 0;
}

Measured memory_bytes: 355228
#include <stdio.h>
#include <string.h>
#define len 100005

typedef struct pp
{
    char name[100];
    int t;
}P;

P Q[len];
int head,tail,n;

void enqueue(P x)
{
    Q[tail] = x;
    tail = (tail + 1) % len;
}

P dequeue()
{
    P x = Q[head];
    head = (head + 1) % len;
    return x;
}

int min(int a, int b){ return a < b?a :b;}

int main()
{
    int elaps = 0,c;
    int i, q;
    P u;
    scanf("%d %d",&n,&q);
    for( i = 1;i <= n;i++)
    {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].t);
    }
    head = 1;tail = n + 1;
    while(head != tail)
    {
        u = dequeue();
        c = min(q,u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0)
            enqueue(u);
        else
            printf("%s %d\n",u.name,elaps);
    }
    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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


int main() {
  int a,b,c;cin>>a>>b>>c;
  cout<< max(0,c-(a-b));
}



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


using namespace std;


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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,K,S;
  cin >>N>>K>>S;
  if(S==1000000000){
    rep(i,N){
      if(i<K){
        cout << S;
      }
      else{
        cout << 7;
      }
      if(i!=N-1){
        cout << " ";
      }
      else{
        cout << endl;
      }
    }
  }
  else{
    rep(i,N){
      if(i<K){
        cout << S;
      }
      else{
        cout << 1000000000;
      }
      if(i!=N-1){
        cout << " ";
      }
      else{
        cout << endl;
      }
    }
  }
}

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

using namespace std;
using ll = long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10LL * TEN(n-1); }

using P = pair<int, int>;
bool ok(vector<P> v) {
    for (auto &p: v) {
        if (p.first > p.second) {
            swap(p.first, p.second);
        }
    }
    sort(begin(v), end(v));
    vector<P> st;
    for (auto p: v) {
        while (st.size() && st.back().second < p.first) {
            st.pop_back();
        }
        if (st.size() && st.back().second < p.second) {
            return false;
        }
        st.push_back(p);
    }
    return true;
}

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    int n = h*w;
    int rid[n];
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        rid[a] = i;
    }

    for (int y = 0; y < h; y++) {
        vector<P> v[2];
        for (int x = 0; x < w-1; x++) {
            int id = y*w+x;
            v[x%2].push_back(P(rid[id], rid[id+1]));
        }
        if (!ok(v[0]) || !ok(v[1])) {
            cout << "NO" << endl;
            return 0;
        }
    }

    for (int x = 0; x < w; x++) {
        vector<P> v[2];
        for (int y = 0; y < h-1; y++) {
            int id = y*w+x;
            v[y%2].push_back(P(rid[id], rid[id+w]));
        }
        if (!ok(v[0]) || !ok(v[1])) {
            cout << "NO" << endl;
            return 0;
        }        
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 4200
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e18
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    string s = to_string(i);
    if(s.size()==1)
      s = "00" + s;
    if(s.size()==2)
      s = "0" + s;
    int idx = 0;
    for (int j = 0; j < N; j++) {
      if(S[j]==s[idx])
        idx++;
      if(idx==3){
        ans++;
        //cout << s << endl;
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
import numpy as np
mn=min(a)
mx=max(a)

def lambda_d(ii):
  rr=0
  for jj in range(n):
    rr+=(a[jj]-ii)**2
  return rr

r=lambda_d(mn)
for ii in np.arange(mn,mx+1):
  tempr=lambda_d(ii)
  if tempr<r:
    r=tempr
print(r)


Measured memory_bytes: 14440
/* Coached by rainboy */
#include <stdio.h>
#include <stdlib.h>

#define N 100000

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ib - ia;
}

int main() {
	static int aa[N];
	int n, i, j;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	qsort(aa, n, sizeof *aa, compare);
	i = 0;
	while (i + 1 < n && aa[i] != aa[i + 1])
		i++;
	j = i + 2;
	while (j + 1 < n && aa[j] != aa[j + 1])
		j++;
	printf("%lld\n", i + 1 < n && j + 1 < n ? (long long) aa[i] * aa[j] : 0);
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    int x;
    cin >> x;
    if(x>29) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3584
S = input()
T = input()
flg = 0
ans = []

for i in range(len(S)-len(T), -1, -1):
    tmpS = list(S)
    for j in range(len(T)):
        if tmpS[i+j] == "?":
            tmpS[i+j] = T[j]
    
    if "".join(tmpS[i:i+len(T)]) == T:
        ans = tmpS
        flg = 1
        break

ans = "".join(ans)
if flg == 0:
    print("UNRESTORABLE")
else:
    print(ans.replace("?", "a"))


Measured memory_bytes: 3064
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(auto &i:a){cin>>i;}
    vector<ll> dp(n+1,E);
    dp[0]=0;
    for(int i=0;i+1<n;i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
    }
    cout<<dp[n-1]<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792