akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  vector<char> data(6);
  for(int i=0; i<6; i++){
    cin >> data.at(i);
  }
  if(data.at(2) == data.at(3) && data.at(4) == data.at(5))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from numpy import cumsum

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	n, m = MAP()
	a = cumsum(LIST())
	b = [x % m for x in a]
	b = [0] + b

	#ans = b.count(0)
	ans = 0
	dic = defaultdict(int)
	for x in b:
		dic[x] += 1
	for i in dic.values():
		if i >1:
			ans += i * (i-1) // 2

	print(ans)

if  __name__=='__main__':
    main()


Measured memory_bytes: 24264
/*
*   1. What was the key concept?
*   2. What mistake did I make? (if any)
*   3. Thing to remember from now on.
*/

#include <iostream>
#include <set> 
#include <map>
#include <vector>

using namespace std;

#define INF 0x3f3f3f3f;
#define INFL 0x3f3f3f3f3f3f3f3f;
#define NITRO ios_base::sync_with_stdio(false); cin.tie(false)
#define PRECISE cout << fixed << setprecision(9)

using ll = long long int;
using ld = long double;

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

int main(){

    int h, w, m;
    cin >> h >> w >> m;

    map<int, int> rows, cols;
    set<pair<int, int>> points;

    int rmax = -1, cmax = -1;

    for (int i=0; i<m; i++){

        int r, c;
        cin >> r >> c;

        rows[r]++; cols[c]++;
        rmax = max(rmax, rows[r]);
        cmax = max(cmax, cols[c]);
        points.insert({r, c});
    }

    vector<pair<int, int>> rowCandidates, colCandidates;

    for (auto p: rows) {
        if (p.second == rmax){
            rowCandidates.push_back(p);
        }
    }

    for (auto p: cols){
        if (p.second == cmax){
            colCandidates.push_back(p);
        }
    }

    ll ans = rmax + cmax;

    for (int r=0; r<(int)rowCandidates.size(); r++){
        for (int c=0; c<(int)colCandidates.size(); c++){
            if (!points.count({rowCandidates[r].first, colCandidates[c].first})) {
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << ans - 1 << endl;

    return 0;
}

// Check the corner cases. (n = 1).
// Check overflows. (int vs ll).
// Be consistent.

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

int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  long long i,A,B,C,D,E,m,M;
  char ss[10000];
  cin>>A;
  cin>>B;
  cin>>C;
  cin>>D;
  E=C*D/euclidean_gcd(C,D);
  m=(A-1)/C+(A-1)/D-(A-1)/E;
  m=A-1-m;
  M=B/C+B/D-B/E;
  M=B-M;
  printf("%lld\n",M-m);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[105];
void selection_sort(int a[], int n)
{
	int cnt = 0, i, j, mini;
	bool flag = false;
	for(i = 0; i < n; i++)
	{
		flag= false;
		mini = i;
		for(j = i+1; j < n; j++)
		{
			if(a[j] < a[mini])
			{
				mini = j;
				flag = true;
			}
		}
		if(flag)
		{
			swap(a[i], a[mini]);
			cnt++;
		}
	}
	for(int i = 0; i < n; i++)
	{
		if(i)
			cout << " ";
		cout << a[i];
	}
	cout << endl;
	cout << cnt << endl;
}

int main ()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	selection_sort(a, n);
	return 0;
} 


Measured memory_bytes: 3104
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		char[] input = sc.next().toCharArray();

//		int alpha[] = new int[26];

		int result = Integer.MAX_VALUE;
		for(char c = 'a' ; c < 'z'; c++){
			int n = input.length;

			char str[] = Arrays.copyOf(input, n);
			while(true){
				boolean single = true;
				for(int i = 0; i < n; i++){
					if(i != 0 && str[i] != str[i - 1]){
						single = false;
					}
				}

				if(single){
					result = Math.min(result,str.length - n);
					break;
				}

				for(int i = 0; i < n - 1; i++){
					if(str[i + 1] == c){
						str[i] = c;
					}
				}

//				System.out.println(str);
				n--;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 27508
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    K = int(readline())
    dq = []
    for i in range(1, 10):
        dq.append(i)
    for i in range(K):
        v = dq[i]
        r = v%10
        if r == 9:
            dq.append(v*10+8)
            dq.append(v*10+9)
        elif r == 0:
            dq.append(v*10)
            dq.append(v*10+1)
        else:
            dq.append(v*10+(r-1))
            dq.append(v*10+r)
            dq.append(v*10+(r+1))
    print(dq[K-1])

if __name__ == '__main__':
    main()



Measured memory_bytes: 23796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
#define all(v) v.begin(), v.end()
#define rep(i, from, to) for (ll i = from; i < ll(to); ++i)

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

    ll n;
    cin >> n;
    ll tp = 1;
    ll ap = 1;
    rep(i,0,n) {
        ll t, a;
        cin >> t >> a;
        tp = ((tp-1) / t + 1) * t;
        ap = ((ap-1)/a + 1) * a;
        ll tp1 = (ap / a) * t;
        ll ap1 = (tp / t) * a;
        if (tp1 >= tp) tp = tp1;
        else ap = ap1;
    }

    cout << tp+ap << 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 FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void p(T x){cout << x << endl;}
template<class T>void pvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }
 
int main()
{
    string t; cin >> t;
    rep(i, t.length()){
        if(t[i]=='?') t[i]='D'; 
    }
    p(t);
    return 0;
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  


using namespace std;

typedef long long int ll;

const int precision = 16;
const int modulo =  1000000007; // 10^9 + 7
using ll = long long;
const double EPS = 1e-9;

// ll recV1(int ind, const vector<int> & stones) {
// 	if(ind >= (int)stones.size() - 1) return 0;

// 	int cost1 = ind + 1 < (int)stones.size() ? abs(stones[ind + 1] - stones[ind]) : INT_MAX;
// 	int cost2 = ind + 2 < (int) stones.size() ? abs(stones[ind + 2] - stones[ind]) : INT_MAX;

// 	//cout << ind << " cost1:" << cost1 << " cost2:" << cost2 <<endl;
// 	auto oneJump = recV1(ind + 1, stones) + cost1;
// 	auto twoJumps = recV1(ind + 2, stones) + cost2;
// 	//	cout << ind << " oneJump:" << oneJump <<  " twoJumps:" << twoJumps <<endl;
// 	return min(oneJump, twoJumps);
// }


// ll recV2(int ind, const vector<int> & stones, unordered_map<int, ll> & memo) {
// 	if(ind >= (int)stones.size() - 1) return 0;
// 	if(memo.count(ind)) return memo[ind];

// 	int cost1 = ind + 1 < (int)stones.size() ? abs(stones[ind + 1] - stones[ind]) : INT_MAX;
// 	int cost2 = ind + 2 < (int) stones.size() ? abs(stones[ind + 2] - stones[ind]) : INT_MAX;

// 	//cout << ind << " cost1:" << cost1 << " cost2:" << cost2 <<endl;
// 	auto oneJump = recV2(ind + 1, stones, memo) + cost1;
// 	auto twoJumps = recV2(ind + 2, stones, memo) + cost2;
// 	//	cout << ind << " oneJump:" << oneJump <<  " twoJumps:" << twoJumps <<endl;
// 	memo[ind]  = min(oneJump, twoJumps);
// 	return memo[ind];
// }

ll recV3(const vector<int> & stones) 
{
	vector<int> dp(stones.size());

	for(auto i = 1; i < (int)dp.size(); ++i) {
		
		auto oneJump = i - 1 >= 0? dp[i - 1] + abs(stones[i - 1] - stones[i]) : INT_MAX;
		auto twoJumps =  i - 2 >= 0 ? dp[i - 2] + abs(stones[i - 2]  - stones[i]) : INT_MAX;

		dp[i] = min(oneJump, twoJumps);
	}

	return dp[dp.size() - 1];
}

void solveFrog1() 
{
	int n; cin >> n;
	vector<int> stones(n);
	for(auto &it : stones) {
		cin >> it;
	}
	
	//cout <<  recV1(0, stones) <<endl; 
	//unordered_map<int, ll> memo;
	//cout <<  recV2(0, stones, memo) <<endl; 
	cout << recV3(stones) <<endl;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(precision);
	cout.setf(ios_base::fixed);

	solveFrog1();
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
int main()
{ 
    cool;
    string s;
    cin>>s;
    if(s=="Sunny")
    cout<<"Cloudy";
    else if(s=="Cloudy")
    cout<<"Rainy";
    else if(s=="Rainy")
    cout<<"Sunny";
    return 0;
}

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

int main(){
	int A, B;
	cin >> A >> B;
	
	if(A%3==0 || B%3==0 || (A+B)%3==0){
		cout << "Possible" << endl;
		return 0;
	}
	
	cout << "Impossible" << endl;
	
	return 0;
}


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


int main() {
  string s, t;
  cin >> s >> t;
  bool ans = true;
  rep(i,s.size()){
    if(s[i]!=t[i]) ans = false;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3620
N = int(input())
b = [int(x) for x in input().split()]

ans = 0

for n in range(N):
    if n == 0:
        ans += b[0]
    elif n == N-1:
        ans += b[n-1]
    else:
        ans += min(b[n], b[n-1])

print(ans)

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

using namespace std;
typedef long long ll;

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

int main(void){
    int n, m;
    int a[101], b[101];
    bool flag;
    while(cin >> n >> m && n) {
        rep(i, n) scanf("%d", &a[i]);
        rep(i, m) scanf("%d", &b[i]);
        int suma = 0, sumb = 0;
        rep(i, n) suma += a[i];
        rep(i, m) sumb += b[i];
        flag = false;
        int ans_a = INT_MAX/2, ans_b = INT_MAX/2;
        rep(i, n) {
            rep(j, m) {
                if(suma-sumb == 2*(a[i]-b[j])) {
                    if(ans_a+ans_b > a[i]+b[j]) {
                        ans_a = a[i];
                        ans_b = b[j];
                        flag = true;
                    }
                }
            }
        }
        if(flag) cout << ans_a << " " << ans_b << endl;
        else cout << -1 << endl;
    }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int) (n); i++)
#define rep3(i, s, n) for (int i = (s); i <=(int) (n); i++)
#define chmax(x,y) x = max(x,y)

	int a[3005][3005];
	long long dp[3005][3005][5];


int main() {
	int R,C,n;
	cin >> R >> C >> n;

	rep(i, n) {
	int r,c,v;
		cin >> r >> c >> v;
		a[r-1][c-1]=v;
	}

	rep(i,R){
 		rep(j,C) {
			dp[i][j][3]=max(dp[i][j][3],dp[i][j][2]+a[i][j]);
			dp[i][j][2]=max(dp[i][j][2],dp[i][j][1]+a[i][j]);
			dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+a[i][j]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][2]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][3]);
			dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0]);
			dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][1]);
			dp[i][j+1][2]=max(dp[i][j+1][2],dp[i][j][2]);
			dp[i][j+1][3]=max(dp[i][j+1][3],dp[i][j][3]);
		}
	}
	long long ans =0;
	rep(k,4) chmax(ans,dp[R-1][C-1][k]);

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


Measured memory_bytes: 390912
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
fac_list = factorization(n)
a = [0]*len(fac_list)
for i in range(len(fac_list)):
    a[i] = fac_list[i][1]
t = 0
if n == 1:
        print(0)
else:
    for j, aa in enumerate(a):
        p = 0
        for i in range(1,aa+1):
            p += i
            if p <= aa:
                t += 1
            else:
                break
    print(t)

Measured memory_bytes: 9504
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;
typedef long long ll;
 
int main(){
  int n, ans = 0;
  cin >> n;
  for(int i = 1; i <= n; i += 2){
      int cnt = 0;
      for(int j = 1; j <= i; j++){
          if(i % j == 0)cnt++;
      }
      if(cnt == 8)ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
# a = map(int, sys.stdin.read().split("\n"))
a = map(int, [input() for i in range(n)])

d = dict()
for a_i in a:
	if a_i not in d:
		d[a_i] = 0
	d[a_i] = (d[a_i]+1) % 2

print(sum(d.values()))

Measured memory_bytes: 22160
def nCr(n,r):
    return fact[n]*(inv[n-r]%M)*(inv[r]%M)
M = 1000000007
k = int(input())
s = len(input())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M


res = 0
for i in range(k+1):
    #print(nCr(t,t-i))
    res+=nCr(t,t-i)*p25[i]
    #print(res)
    res%=M
    #print(res)
print(res)

Measured memory_bytes: 205352
import java.util.Scanner;

public class  Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				while (true) {
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if (x != 0) continue;
					else break;
				}
			}
		} while (++i <= n);
		System.out.println();
	}
}

Measured memory_bytes: 28780
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int main()
{
	int n; cin>>n;
	ll ans=1;
	const ll INF=2e18;
	const ll INF1=1e18;
	for(int i=0; i<n; i++){
		ll a; cin>>a;
      if(a==0){
        cout<<0<<endl;
        return 0;
      }
		if(ans>INF/a){
			ans=INF;
		}else{
			ans*=a;
		}
	}
	if(ans>INF1) cout<<"-1"<<endl;
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> dp(h + 1, INF);
  dp[0] = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    rep(j, h) {
      int target = min(j + a, h);
      dp[target] = min(dp[target], dp[j] + b);
    }
  }
  // rep(i, dp.size()) {
  //   cout << i << ": " << dp[i] << endl;
  // }
  cout << dp[h] << endl;
  return 0;
}

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

signed main () {
    int n;
    cin >> n;
    vector < int > a(n + 1, 0);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    vector < int64_t > pref(n + 1, 0);
    int64_t ans_odd = 0;
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + a[i];
        if (i & 1) {
            if (pref[i] == 0) {
                ++pref[i];
                ++ans_odd;
            }
            else if (pref[i] < 0) {
                ans_odd += 1 - pref[i];
                pref[i] = 1;
            }
        }
        else {
            if (pref[i] == 0) {
                --pref[i];
                ++ans_odd;
            }
            else if (pref[i] > 0) {
                ans_odd += 1 + pref[i];
                pref[i] = -1;
            }
        }
    }
    int64_t ans_even = 0;
    for (int i = 1; i <= n; ++i) {
        pref[i] = pref[i - 1] + a[i];
        if (i & 1) {
            if (pref[i] == 0) {
                --pref[i];
                ++ans_even;
            }
            else if (pref[i] > 0) {
                ans_even += 1 + pref[i];
                pref[i] = -1;
            }
        }
        else {
            if (pref[i] == 0) {
                ++pref[i];
                ++ans_even;
            }
            else if (pref[i] < 0) {
                ans_even += 1 - pref[i];
                pref[i] = 1;
            }
        }
    }
    cout << min(ans_odd, ans_even) << '\n';
}


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

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

	for (auto &&c : s)
	{
		cout << char('A' + (c - 'A' + n) % 26);
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
while 1:
	M,T,P,R = map(int,raw_input().split())
	if M == 0: break
	S = [[-1]*P for i in range(T)]
	PN = [[0]*P for i in range(T)]
	for i in range(R):
		m,t,p,j = map(int,raw_input().split())
		if j == 0:
			S[t-1][p-1] = m + PN[t-1][p-1]
		else:
			PN[t-1][p-1] += 20
	A = [[t+1,P-S[t].count(-1),sum(S[t])] for t in range(T)]
	A = sorted(sorted(A[::-1], key = lambda x:x[2]), key = lambda x:x[1], reverse = True)
	ans = str(A[0][0])
	for i in range(1,T):
		if A[i-1][1:] == A[i][1:]:
			ans += "=" + str(A[i][0])
		else:
			ans += "," + str(A[i][0])
	print ans

Measured memory_bytes: 4332
def f(w):
    cnt_dict = {}

    for s in w:
        if s not in cnt_dict.keys():
            cnt_dict[s] = 0
        cnt_dict[s] += 1

    for v in cnt_dict.values():
        if v % 2 != 0:
            print("No")
            return
    print("Yes")


w = input()
f(w)

Measured memory_bytes: 2940
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;

ll dp[3010][3010] = {0};

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

    ll ls = s.size();
    ll lt = t.size();

    rep(i,ls){
        rep(j,lt){
            if(s[i] != t[j])dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
            else dp[i+1][j+1] = dp[i][j] + 1;
        }
    }
    cerr << dp[ls][lt] << endl;

    vector<char> ans;

    ll sp = ls,tp = lt;

    while(1){
        if(dp[sp][tp] != dp[sp-1][tp] && dp[sp][tp] != dp[sp][tp-1]){
            ans.pb(s[sp-1]);
            sp--;
            tp--;
        }else if(dp[sp][tp] != dp[sp-1][tp]){
            tp--;
        }else if(dp[sp][tp] != dp[sp][tp-1]){
            sp--;
        }else{
            sp--;
        }
        if(dp[sp][tp] == 0)break;
    }


    rep(i,ans.size()){
        cout << ans[ans.size()-1-i];
    }cout << endl;

   
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://dp.contest.atcoder.jp/tasks/dp_f

Measured memory_bytes: 70784
list=input()
list=list.split( )
count=0
a,b,c,k=int(list[0]),int(list[1]),int(list[2]),int(list[3])
if a>=k:
    count+=k
else:
    count+=a
    k=k-a
    if b>=k:
        yjsnpi=114514
    else:
        k=k-b
        count-=k
print(count)

Measured memory_bytes: 9140
#include <iostream>
using namespace std;
int mod(int a){
    if(a<0)
        return -1*a;
    else return a;
}
int min(int a,int b){
    if(a>b)
        return b;
    else return a;
}
int main() {
    int n;
    scanf("%d",&n);
    int hight[n+1],i;
    for(i=1; i<=n; i++)
        scanf("%d",&hight[i]);
    int dp[n+1];
    dp[2]=mod(hight[2]-hight[1]);
    if(n>2){
        dp[3]=min(mod(hight[3]-hight[1]),mod(hight[3]-hight[2])+dp[2]);
        for(i=4; i<=n; i++)
            dp[i]=min(mod(hight[i]-hight[i-1])+dp[i-1],mod(hight[i]-hight[i-2])+dp[i-2]);
    }
    printf("%d",dp[n]);
	return 0;
}


Measured memory_bytes: 1024
#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(){
    ll A,V;
    cin >> A >> V;
    ll B,W;
    cin >> B >> W;
    ll T;
    cin >> T;
    
  if(A==B){
    cout << "YES" << endl;
  }
  else{
    if(V<=W){
      cout << "NO" << endl;
    }
    else{
      ll N=(max(A,B)-min(A,B))/(V-W);
      if(N>T){
        cout << "NO" << endl;
      }
      else if(N==T){
        if(N*(V-W)==(max(A,B)-min(A,B))){
          cout << "YES" << endl;
        }
        else if(N*(V-W)<(max(A,B)-min(A,B))){
          cout << "NO" << endl;
        }
      }
      else if(N<T){
        cout << "YES" << endl;
      }
    }
  }
}


Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = input()

    if N[-1] == "3":
        print("bon")
    elif N[-1] in ["0", "1", "6", "8"]:
        print("pon")
    else:
        print("hon")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9048
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
    n = II()
    aa = MII()
    bb = MII()
    dn = sum(bb) - sum(aa)
    if dn < 0:
        print('No')
        return None
    cnta = cntb = 0
    for a,b in zip(aa,bb):
        if a>b: cntb += a-b
        else: cnta += (b-a+1)//2
    if cnta <= dn and cntb <= dn:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 4600
N = int(input())
X = list(map(int, input().split()))

Xsort = sorted(X)
lmedian = Xsort[int(N/2) - 1]
rmedian = Xsort[int(N/2)]

for x in X:
	print (rmedian if x <= lmedian else lmedian)  
    

Measured memory_bytes: 26772
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N int

func main() {
	sc.Split(bufio.ScanWords)

	N = nextInt()
	x4 := 0
	x2 := 0
	for i := 0; i < N; i++ {
		a := nextInt()
		if a%4 == 0 {
			x4++
		} else if a%2 == 0 {
			x2++
		}
	}
	if x4 == N {
		fmt.Println("Yes")
		return
	}
	odd := N - x4 - x2
	if x2 == 0 && absInt(odd-x4) <= 1 {
		fmt.Println("Yes")
		return
	} else if x2 > 0 && x4-odd <= 1 && x4-odd >= 0 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


Measured memory_bytes: 3328
#include<cstdio>
using namespace std;
struct node{
	int str[310];
	int l,r;
	void csh(){
		l=150,r=149;
	}
	void push_back(int x){
		str[++r]=x;
	}
	void push_front(int x){
		str[--l]=x;
	}
	void print(){
		for(int i=l;i<=r;i++)
			printf("%d ",str[i]);
	}
}s1,s2;
int stk[100100],top;
int main(){
//	freopen("C.in","r",stdin);
	long long n;
	scanf("%lld",&n);
	n++;
	s1.csh(),s2.csh();
	while(n){
		stk[++top]=n%2;
		n/=2;
	}
	int num=0;
	for(int i=top-1;i>=1;i--){
		s1.push_back(++num);
		s2.push_back(num);
		if(stk[i]){
			s1.push_back(++num);
			s2.push_front(num);
		}
	}
	printf("%d\n",num*2);
	s1.print(),s2.print();
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> A, B, C;


  cout << C << endl;
  cout << A << endl;

  cout << B << endl;

}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

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

  ll N = s.length();
  ll M = t.length();
  vvi X(N, vi(26, INF));

  {
    vi v(26, INF);
    string u = s + s;
    for (ll i = N * 2 - 1; i >= N; i--) {
      v[u[i] - 'a'] = i;
    }
    for (ll i = N - 1; i >= 0; i--) {
      for (ll j = 0; j < 26; j++) {
        if (v[j] != INF)
          X[i][j] = v[j] - i;
      }
      v[u[i] - 'a'] = i;
    }
  }

  ll pos = N - 1;
  for (char c : t) {
    if (X[pos % N][c - 'a'] == INF) {
      cout << -1 << endl;
      return 0;
    }

    pos += X[pos % N][c - 'a'];
  }

  cout << pos - N + 1 << endl;
}


Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int n, m, a, b, ans;
  scanf("%lld", &n);
  scanf("%lld", &m);
  vector<pair<long long int, long long int>> p;
  ans = 0;

  for(int i=0;i<n;i++){
    scanf("%lld %lld", &a, &b);
    p.push_back(make_pair(a, -b));
  }
  sort(p.begin(), p.end());

  for(int i=0;i<n;i++){
    if(m + p[i].second <= 0){
      ans += p[i].first * m;
      break;
    }
    ans += p[i].first * (-1) * p[i].second;
    m = m + p[i].second;
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 2420
#include <cstdio>
#include <vector>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
using namespace std;
signed main(){
    int n;
    int  a;
    cin>>n;
    long long ans=0;
    long long cnt=1;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        ans+=(a-1)/cnt;
        if(i==0)cnt+=1;
            else{
                if(a==cnt)cnt+=1;}
    }
    cout<<ans;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, readline().split())
ok = [0] * (N + 1)
for _ in range(K):
    d = int(readline())
    A = map(int, readline().split())
    for i in A:
        ok[i] = True

print(N - sum(ok))


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  int A, B,one,ten, hund, thou, tthou,count=0;
  cin >> A >> B;
  for (int i=A; i<=B; i++)
  {
    tthou = i/10000;
    thou = (i - tthou*10000) /1000;
    hund = (i - tthou*10000 - thou*1000) / 100;
    ten = (i - tthou*10000 - thou*1000 - hund*100) / 10;
    one = i - tthou*10000 - thou*1000 - hund*100 - ten*10;
    if (tthou == one && thou == ten)
    {
      count++;
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;
vector<int> edges[2000];
int dfs(int v, int p, int d) {
    if(d < 0) return 0;
    int res = 1;
    for(int nv : edges[v])
      if(nv != p) res += dfs(nv, v, d - 1);
    return res;
}
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    rep(_, N - 1) {
        int A, B; cin >> A >> B;
        --A; --B;
        edges[A].push_back(B);
        edges[B].push_back(A);
    }
    int ans = 0;
    if(1 & K) {
        rep(i, N) for(int to : edges[i]) {
            if(i > to) continue;
            int tmp = dfs(i, to, K / 2) + dfs(to, i, K / 2);
            ans = max(ans, tmp);
        }
    } else {
        rep(i, N) ans = max(ans, dfs(i, -1, K / 2));
    }
    cout << N - ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    println((n-1)*(m-1))
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt()= listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 36208
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
  let n = read::<usize>();
  let m = read::<usize>();
  // let mut graph: HashMap<i64, Vec<i64>> = HashMap::new();

  let mut map: Vec<Vec<usize>> = vec![vec![0; n]; n];
  let mut edges: Vec<Vec<usize>> = vec![];
  let mut cnt = 0;

  for _ in 0..m {
    let a = read::<usize>();
    let b = read::<usize>();
    map[a - 1][b - 1] = 1;
    map[b - 1][a - 1] = 1;
    edges.push(vec![a - 1, b - 1])
  }

  for i in edges {
    let a = i[0];
    let b = i[1];
    // 無効化
    map[a][b] = 0;
    map[b][a] = 0;

    // dfs
    let mut visited: Vec<usize> = vec![];
    let mut stack: Vec<usize> = vec![1];

    dfs(&mut visited, &mut stack, 0, &map);

    // println!("{:?}", visited);
    if visited.len() != n {
      cnt += 1;
    }

    // 戻す
    map[a][b] = 1;
    map[b][a] = 1;
  }

  println!("{:?}", cnt);
}

fn dfs(visited: &mut Vec<usize>, stack: &mut Vec<usize>, node: usize, map: &Vec<Vec<usize>>) {
  if visited.contains(&node) {
    return;
  }
  visited.push(node);
  for (i, v) in map[node].iter().enumerate() {
    if *v == 1 {
      dfs(visited, stack, i, map)
    }
  }
}



Measured memory_bytes: 4352
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());

    let n = scan.read::<usize>();
    let d = scan.readn::<i64>(n);
    let mut ret = 0;
    for i in 0..n { for j in i + 1..n {
        ret += d[i] * d[j];
    }}
    println!("{}", ret);
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
A.sort()
exist_flags = [0] * (10 ** 6)
for a in A:
    if exist_flags[a - 1] > 0:
        exist_flags[a - 1] += 1
    else:
        # for i in range(a, 25, a):
        for i in range(a, 10 ** 6 + 1, a):
            exist_flags[i - 1] += 1


ans = 0
for a in A:
    if exist_flags[a - 1] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 121988
//Rishabh Sethi @lostground97

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define in insert
#define mod 1000000007
#define vpair vector< pair <ll,ll> >

ll modexp(ll x, ll y)
{
	ll ans = 1;
	x = x%mod;
	while(y>0)
	{
		if(y%2==1)
			ans = (ans%mod*x%mod)%mod;
		y = y/2;
		x = (x%mod*x%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<"Hello World\n";
		return 0;
	}
	int a, b;
	cin>>a>>b;
	a = a + b;
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()

mod = 10**9+7
flag = 0
joutai = 0

if S1[0]==S2[0]:
    ans = 3
    joutai = 1
else:
    ans = 6
    flag = 1
    joutai = 2

for i in range(1,N):
    if flag == 0:
        if S1[i]==S2[i]:
            if joutai == 1:
                ans = (ans*2)%mod
            joutai = 1
        else:
            if joutai == 1:
                ans = (ans*2)%mod
            else:
                ans = (ans*3)%mod
            joutai = 2
            flag = 1
    else:
        flag = 0
print(ans)

Measured memory_bytes: 38256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        TreeSet<String> ts = new TreeSet<>();
        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < s.length() - i + 1; j++) {
                ts.add(s.substring(j, j+i));
            }
        }
        List<String> list = new ArrayList<>(ts);
        Collections.sort(list);
        System.out.println(list.get(k-1));
    }
}


Measured memory_bytes: 27800
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val p = readLine()!!.split(" ").map { it.toInt() - 1 }.toIntArray()
    val unionFind = UnionFind(N)
    (1..M).forEach {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        unionFind.merge(x - 1, y - 1)
    }


    var answer = 0
    (0 until N).forEach {i ->
        // i and pi belongs same group, we can place i to the proper position
        if (unionFind.isSame(i, p[i])) {
            answer++
        }
    }
    println(answer)
}
class UnionFind(size: Int) {
    var parent: IntArray
    var height: IntArray
    var size: IntArray

    init {
        this.parent = IntArray(size)
        this.height = IntArray(size)
        this.size = IntArray(size)

        for (i in 0 until size) {
            makeSet(i)
        }
    }

    fun merge(x: Int, y: Int) {
        val rootX = root(x)
        val rootY = root(y)

        if (rootX == rootY) {
            return
        }

        if (height[rootX] > height[rootY]) {
            parent[rootY] = rootX
            size[rootX] += size[rootY]

        } else if (height[rootX] < height[rootY]) {
            parent[rootX] = rootY
            size[rootY] += size[rootX]

        } else {
            parent[rootY] = rootX
            size[rootX] += size[rootY]
            height[rootX]++
        }
    }

    fun isSame(x: Int, y: Int) : Boolean {
        return root(x) == root(y)
    }

    fun size(x: Int): Int {
        val rootX = root(x)
        return size[rootX]
    }

    private fun root(x: Int): Int {
        if (x != parent[x]) {
            parent[x] = root(parent[x])
        }
        return parent[x]
    }


    private fun makeSet(i: Int) {
        parent[i] = i
        height[i] = 0
        size[i] = 1
    }
}


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

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}






int main() {
    
    

    cin.tie(0);
    ios::sync_with_stdio(false);
    
   
    int n; cin >> n;
    vector<vector<int>> field(2);
    rep(i,n) {
        int a; cin >> a;
        field[0].push_back(a);
    }
    rep(i,n) {
        int a; cin >> a;
        field[1].push_back(a);
    }
    
    
    vector<vector<int>> CumulativeSum(2);
    CumulativeSum[0].resize(n);
    CumulativeSum[1].resize(n);
    
    CumulativeSum[0][0] = field[0][0];
    CumulativeSum[1][0] = field[1][0];
    
    rep(i,n-1){
        CumulativeSum[0][i+1] = CumulativeSum[0][i] + field[0][i+1];
        CumulativeSum[1][i+1] = CumulativeSum[1][i] + field[1][i+1];
    }
    
    int ans = 0;
    
    rep(i,n){
        if(i==0) ans = CumulativeSum[0][0]+CumulativeSum[1][n-1];
        else ans = max(ans,CumulativeSum[0][i]+CumulativeSum[1][n-1]-CumulativeSum[1][i-1]);
    }
    
    cout << ans << endl;
    
}



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

int main(void){
	int n;
	while(cin >> n,n){
		bool graph[110][110];
		rep(i,n)rep(j,n) graph[i][j]=false;

		R p[110];
		rep(i,n){
			cin >> p[i];
			int m,tmp;
			cin >> m;
			rep(j,m){
				cin >> tmp;
				graph[i][tmp-1] = true;
			}
		}

		rep(k,n)rep(i,n)rep(j,n) graph[i][j] |= (graph[i][k]&graph[k][j]);

		vector<int> group[110];

		rep(i,n){
			int cmin = i;
			bool ok = true;

			rep(j,n){
				if(j==i) continue;

				if(graph[i][j] == true and graph[j][i] == true) cmin = min(cmin,j);
				if(graph[i][j] == false and graph[j][i] == true) ok = false;
			}

			if(ok){
				group[cmin].push_back(i);
			}
		}

		R ans = 1.0;
		rep(i,n){
			if(group[i].empty()) continue;
			R cur = 1.0;
			for(auto &it:group[i]) cur *= p[it];
			ans *= 1.0 - cur;
		}

		cout.precision(20);
		cout << fixed << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int>>adj(200010);
int vis[300050];
int n;

int main()
{
    ll t=1;
    //cin>>t;
    while(t--)
    {
       
        ll n;
        cin>>n;
        if(n==0)
            cout<<1<<endl;
        else
            cout<<0<<endl;

        cout<<endl;
    }

}



Measured memory_bytes: 7860
N = int(input())
X = []
for i in range(N):
    n = 0
    a = 0
    n = N - i
    while  n % 2 == 0:
        n = n // 2
        a = a + 1
    else:
        X.insert(0, a)
print(X.index(max(X)) + 1)

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

int main() {

	long long N,W;
	
	cin>>N>>W;

	long long v[N], w[N];

	long long vsum=0;

	for (long long i=0;i<N;i++) {

		cin>>w[i]>>v[i];
		vsum+=v[i];

	}

	long long dp[N+1][vsum+1];
	
	for (int i=0;i<=N;i++) {
		dp[i][0] = 0ll;	
	}
	
	for (int i=0;i<=N;i++) {
		for (int j=1;j<=vsum;j++) {

			dp[i][j] = 100000000001ll;

		}
	}

	vsum = 0;

	for (long long i=1;i<=N;i++) {

		vsum += v[i-1];

		for (long long j=0;j<v[i-1];j++) {

			dp[i][j] =  dp[i-1][j];

		}		

		for (long long j=v[i-1];j<=vsum;j++) {

			dp[i][j] = w[i-1] + dp[i-1][j-v[i-1]] < dp[i-1][j] ? w[i-1] + dp[i-1][j-v[i-1]] : dp[i-1][j];

		}

		// for (int j=0;j<=vsum;j++) {
		// 		cout<<dp[i][j]<<" ";	
		// }

		// cout<<endl;

	}

	long long ans = 0;

	for (long long i=0;i<=vsum;i++) {

		if (dp[N][i]<=W) {

			ans = i;
		}

	}

	cout<<ans<<endl;

}

Measured memory_bytes: 79104
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    X = readstr()
    s = sum(tuple(map(int, X)))
    s1 = s + 1
    s2 = s - 1 if s != 1 else 1
    m1 = int(X, 2) % s1
    m2 = int(X, 2) % s2
    t1 = [1]
    t2 = [1]
    for i in range(N):
        t1.append(t1[i] * 2 % s1)
        t2.append(t2[i] * 2 % s2)
    for i in range(N):
        ans = 0
        if X[i] == '0':
            x = (m1 + t1[(N - i - 1)]) % s1
        else:
            if s == 1:
                print(0)
                continue
            else:
                x = (m2 - t2[(N - i - 1)]) % s2
        d = sum(tuple(map(int, bin(x)[2:])))
        ans += 1
        while x:
            x %= d
            d = sum(tuple(map(int, bin(x)[2:])))
            ans += 1
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 30508
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ma 1e18
int main()
{lli n,i,j,k;
 lli dp[100001];
 for(i=3;i<=100000;i++)
 {dp[i]=ma;
 }
 dp[0]=0;
 dp[1]=0;
 cin>>n>>k;
 lli a[n+1];
 for(i=1;i<=n;i++)
 {cin>>a[i];
 }
dp[2]=abs(a[2]-a[1]);
 for(i=3;i<=n;i++)
 {for(j=i-1;j>=1 &&j>=i-k;j--)
 {dp[i]=min(dp[i],dp[j]+abs(a[j]-a[i]));
 }
 }
 cout<<dp[n]<<"\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#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, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;

  int mx = 0;
  int tmp = 0;
  REP(i, S.length()) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      tmp++;
    } else {
      tmp = 0;
    }
    mx = max(mx, tmp);
  }
  cout << mx;
  return 0;
}


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

using namespace std;

void Main() {
    int K, A, B;
    cin >> K;
    cin >> A >> B;

    int i = 1;
    bool ret = false;
    while (i * K <= B) {
        if (A <= i * K && i * K <= B) {
            ret = true;
            break;
        }
        ++i;
    }
    cout << (ret ? "OK" : "NG") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int n ;
    cin >> n ;
    ll a = n%1000;
    if(a==0)cout << 0 << '\n';
    else
    {
        ll curr = 1000 - n%1000;
        cout << curr << '\n';
    }

}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {

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

    int n, m; cin >> n >> m;
    vector<vector<int>> yp(m, vector<int>(3));
    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < m; i++) {
        cin >> yp[i][0] >> yp[i][1];
        yp[i][2] = i;
        cnt[yp[i][0]]++;
    }
    sort(yp.begin(), yp.end());
    
    map<int, string> ID;
    
    int p = 0;
    for (int i = 1; i <= n; i++) {
        string pid = to_string(i);
        pid = string(6 - pid.size(), '0') + pid;
        
        for (int j = 0; j < cnt[i]; j++) {
            string xid = to_string(j + 1);
            xid = string(6 - xid.size(), '0') + xid;
            ID.emplace(yp[p][2], pid + xid);
            p++;
        }
    }
    
    for (auto &iter : ID) {
        cout << iter.second << endl;
    }

    return 0;
}


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

int main()
{
	int a, b, c; cin >> a >> b >> c;
		
	int ans;

	if (a == b) ans = c;
	else if (c == a) ans = b;
	else ans = a;

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

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

using namespace std;

int main(void){

  int a,b,c;

  vector<int> num(3);
  
  int n1,n2;

  cin>>num[0];
  cin>>num[1];
  cin>>num[2];

  sort(num.begin(),num.end());
  
  n1=num[1]-num[0];
  n2=num[2]-num[0];

  if(n1%2==0){
    cout << n2 - n1/2 << endl;
  }
  else{
    cout << n2 - n1/2 + 3/2 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256