akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
   ll T;
   cin>>T;
   	bool ok=true;
   	ll a,b,c;
   	a=b=c=0;
   while(T--)
   {
   		ll t,x,y;
   		cin>>t>>x>>y;
   		ll es;
		   es=(t-a)-( abs(x-b)+abs(y-c) );
   		if(ok&&(es<0|| es%2==1))
   			ok=false;	
   		a=t;
   		b=x;
   		c=y;
   }
	if(ok)
	   	puts("Yes");
   	else
		puts("No");
    return 0;
}

    
        


Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A, B = map(int, input().split())

def ok(n):
    s = str(i)
    l = len(s)
    for j in range(l):
        if s[j] != s[-(j + 1)]:
            return False
    return True

ans = 0
for i in range(A, B + 1):
    if ok(i):
        ans += 1

print(ans)


Measured memory_bytes: 3572
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
ll ans;
ll a[100010];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n+1)scanf("%lld",a+i);
	ll ans=0;
	rep(i,0,n+1)ans+=llabs(a[i+1]-a[i]);
	rep(i,1,n+1)printf("%lld\n",ans-llabs(a[i]-a[i-1])-llabs(a[i+1]-a[i])+llabs(a[i+1]-a[i-1]));
	return 0;
}

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

int main() {
  int a;
  cin >> a;
  if (a % 1110 < 10) {
    cout << "Yes" << endl;
  }
  else if ((a % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int n = sc.nextInt();

		int yen = 0;
		double btc = 0;

		for(int i=0;i<n;i++) {
			String x = sc.next();
			String u = sc.next();

			switch(u) {
			case "JPY":
				yen += Integer.parseInt(x);
				break;
			case "BTC":
				btc += Double.parseDouble(x);
			break;
			}
		}

		out.println(BigDecimal.valueOf(yen + (btc*380000)).toPlainString());

		sc.close();
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 22868
#include <iostream>
using namespace std;
 
int main() {
    int S,h,m,s;
    cin>>S;
    h=S/3600;
    int a=S%3600;
    m=a/60;
    s=a%60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }
 

void solve()
{
	string s,t;
	cin>>s>>t;
	ll a=s.sz,b=t.sz;
	// ll a,b;
	// cin>>a>>b;
	if(a>b)
		cout<<"GREATER";
	else if(a<b)
		cout<<"LESS";
	else
	{
		for(ll i=0;i<a;i++)
		{
			if(s[i]>t[i])
			{
				cout<<"GREATER";
				return;
			}	
			else if(s[i]<t[i])
			{
				cout<<"LESS";
				return;
			}
			
		}
		cout<<"EQUAL";
	}
	
	return;	
}
	

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

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

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

    if (S == "Sunny"){
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy"){
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>


int max(int a, int b){
    if(a > b){
        return a;
    }else{
        return b;
    }
}

int main(){
    int i;
    int A, B, C, X, Y;
    scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);

    int tmp;
    int min = A * X + B * Y;
    for(i=0; i<100000+1; i++){
        tmp = i * 2 * C + max(0, X - i) * A + max(0, Y - i) * B;
        if(min > tmp)
            min = tmp;
    }
    
    printf("%d\n", min);

    return 0;
}


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

const int MAX_N = 1e5;
int dp[MAX_N][3];
int main() {
  int n;
  cin >> n;
  vector<vector<int> > v(n);
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    v[i].push_back(a);
    v[i].push_back(b);
    v[i].push_back(c);
  }
  rep(i, n) rep(j, 3) rep(k, 3) { 
    if (j == k) continue;
    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + v[i][k]); 
  }
  int ans = 0;
  rep(j, 3) ans = max(ans, dp[n][j]);
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  long long ans = 1;
  bool ngFlg = false;
  for(int index=0;index<N;index++) {
  	long long A;
 	cin >> A;
    if(A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if(ngFlg || 1000000000000000000/ans < A) {
	  ngFlg = true;
    }
  	ans*= A;
  }
  if(ngFlg){
    cout << -1 << endl;
  }
  else 
    cout << ans << endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;
 class Main {
	public void so() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a < b) {
			if(c < b) {
				if(a < c) {
					System.out.println(a + " " + c + " " + b);
				}else{
					System.out.println(c + " " + a + " " + b);
				}
			} else {
				System.out.println(a + " " + b + " " + c);
			}
		}
		if(b < a) {
			if(c < a) {
				if(c < b) {
					System.out.println(c + " " + b + " " + a);
				}else{
					System.out.println(b + " " + c + " " + a);
				}
			} else {
				System.out.println(b + " " + a + " " + c);
			}
		}
	}
	public static void main(String[] args) {
		new Main().so();
	}
}

Measured memory_bytes: 17324
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<set>
#include<fstream>
#include<map>
#include<string>
#include <stdio.h>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include<climits>
#include<unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef vector<char>vc;
typedef vector<string>vs;
#define MP make_pair
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
const ll OO = (ll)1e18;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
ll gcd(ll a, ll b){ if (b == 0){ return a; }return gcd(b, a % b); }
ll fast_power(double base, ll power){
	if (power == 1) return base;
	if (power % 2 == 0) return fast_power((base*base), power / 2);
	else return(base*fast_power((base*base), power / 2));
}
//#pragma warning (disable : 4996)
void Qalbaz()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(2);
}

int main(){

	Qalbaz();
	
	string str;
	cin >> str;
	ll ans = 0, x = 0; 
	for (int i = str.size() - 1; i >= 0; i--)
	{
		if (str[i] == 'W')
			x++;
		else
			ans += x;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pld pair<long double, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define ff first
#define ss second
#define SZ(x) ((int)(x).size())
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, X, T;
  	cin >> N >> X >> T;
  	cout << (N+X-1) / X * T;
}


Measured memory_bytes: 3636
N = int(input())

A = []
for i in range(N):
    A.append(int(input()))

M1 = 0
M2 = 0

for i in range(N):
    if A[i] > M1:
        M1 = A[i]
    elif A[i] > M2:
        M2 = A[i]


for i in range(N):
    if A[i] == M1:
        print(M2)
    else:
        print(M1)

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

typedef long long ll;

int main()
{
    string S;
    string T;
    cin >> S >> T;
    T.pop_back();
    if (S == T)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3628
// ACM-ICPCアジア地区予選2014 G. Flipping Parentheses

#include <iostream>
#include <cstring>
#include <cstdlib>

using namespace std;

const int N = 1<<19;
int segMin[2*N-1];
int segAdd[2*N-1];
int segSum[2*N-1];

void add(int l, int r, int val, int idx = 0, int rangeL = 0, int rangeR = N){
	if(rangeR <= l || r <= rangeL) return;
	if(l <= rangeL && rangeR <= r){
		segAdd[idx] += val;
		while(idx){
			idx = (idx-1)/2;
			segMin[idx] = min(segMin[2*idx+1]+segAdd[2*idx+1], segMin[2*idx+2]+segAdd[2*idx+2]);
		}
	} else {
		int rangeM = (rangeL+rangeR)/2;
		add(l, r, val, 2*idx+1, rangeL, rangeM);
		add(l, r, val, 2*idx+2, rangeM, rangeR);
	}
}

int getMin(int l, int r, int idx = 0, int rangeL = 0, int rangeR = N){
	if(rangeR <= l || r <= rangeL) return 1000000007;
	if(l <= rangeL && rangeR <= r) return segMin[idx]+segAdd[idx];
	int rangeM = (rangeL+rangeR)/2;
	return min(getMin(l, r, 2*idx+1, rangeL, rangeM), getMin(l, r, 2*idx+2, rangeM, rangeR)) + segAdd[idx];
}

void change(int pos, int val){
	int idx = pos+N-1;
	int add = val-segSum[idx];
	segSum[idx] = val;
	while(idx){
		idx = (idx-1)/2;
		segSum[idx] += add;
	}
}

int getSum(int l, int r, int idx = 0, int rangeL = 0, int rangeR = N){
	if(rangeR <= l || r <= rangeL) return 0;
	if(l <= rangeL && rangeR <= r) return segSum[idx];
	int rangeM = (rangeL+rangeR)/2;
	return getSum(l, r, 2*idx+1, rangeL, rangeM)+getSum(l, r, 2*idx+2, rangeM, rangeR);
}

int main(){
	int n, q;
	while(cin >> n >> q){
		memset(segMin, 0, sizeof(segMin));
		memset(segAdd, 0, sizeof(segAdd));
		memset(segSum, 0, sizeof(segSum));
		string str; cin >> str;
		for(int i=0;i<n;i++){
			if(str[i] == '('){
				add(i, n, 1);
			} else {
				add(i, n, -1);
				change(i, 1);
			}
		}
		for(int i=0;i<q;i++){
			int idx; cin >> idx; --idx;
			if(idx == 0 || idx == n-1){
				cout << idx+1 << endl;
			} else if(str[idx] == '('){
				change(idx, 1);
				add(0, idx, 2);
				str[idx] = ')';
				int L = 0, R = n-1;
				while(R-L>1){
					int mid = (L+R)/2;
					if(getSum(0, mid) > 0) R = mid;
					else                   L = mid;
				}
				change(L, 0);
				add(0, L, -2);
				str[L] = '(';
				cout << L+1 << endl;
			} else {
				change(idx, 0);
				add(0, idx, -2);
				str[idx] = '(';
				int L = 0, R = idx+1;
				while(R-L>1){
					int mid = (L+R)/2;
					if(getMin(mid, idx+1) >= 0) R = mid;
					else                        L = mid;
				}
				change(R, 1);
				add(0, R, 2);
				str[R] = ')';
				cout << R+1 << endl;
			}
		}
	}
}

Measured memory_bytes: 13976
use proconio::input;
use proconio::marker::Chars;
use std::cmp::{max, min};
const alpha: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];

const Alpha: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
fn main() {
    input!(N: usize);
    input!(x: Chars);
    let X: Vec<usize> = x.iter().map(|&c| c.to_digit(2).unwrap() as usize).collect();
    let mut ans = vec![0; N];
    // 最初の割り算を行う
    let pc: usize = X.iter().sum();
    // let mut base = 0;
    // for i in 0..N {
    //     base *= 2;
    //     base += X[i];
    //     base %= pc;
    // }

    // 2回目移行の割り算は再帰関数に任せる！

    for b in 0..2 {
        let mut npc = pc;
        if b == 1 && pc <= 1 {
            continue;
        }
        if b == 0 {
            npc += 1;
        } else {
            npc -= 1;
        }

        let mut base = 0;
        for i in 0..N {
            base = (2 * base) % npc;
            base += X[i];
        }

        let mut k = 1;
        for i in (0..N).rev() {
            if X[i] == b {
                let mut r = base;
                if b == 0 {
                    r = (r + k) % npc;
                } else {
                    r = (r + npc - k) % npc;
                }
                ans[i] = f(r) + 1;
            }
            k = (2 * k) % npc;
        }
    }

    for i in 0..N {
        println!("{}", ans[i]);
    }
}

fn pcnt(x: usize) -> usize {
    (x as u64).count_ones() as usize
}

fn f(x: usize) -> usize {
    if x == 0 {
        0
    } else {
        f(x % pcnt(x)) + 1
    }
}


Measured memory_bytes: 6276
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> P;


int main(){
    int a, b;
    int k;  cin >> k;
    cin >> a >> b;
    if((a-1) / k == b / k){
        cout << "NG" << endl;
    }
    else{
        cout << "OK" << endl;
    }



    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int dp[45];

main(){
  int i;
  dp[0] = dp[1] = 1;
  for(i=2;i<=44;i++) dp[i] = dp[i-1] + dp[i-2];
  scanf("%d", &i);
  printf("%d\n", dp[i]);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

static const int N = 100;

int main(){
  int n, i, j, k, l, p[N + 1], m[N + 1][N + 1];
  scanf("%d", &n);
  for(i = 1 ; i <= n ; i++){
    scanf("%d %d", &p[i - 1], &p[i]);
  }

  for(i = 1 ; i <= n ; i++) m[i][i] = 0;
  for(j = 2 ; j <= n ; j++){
    for(i = 1 ; i <= n - j + 1 ; i++){
      k = i + j - 1;
      m[i][k] = (1 << 21);
      for(l = i ; l <= k - 1 ; l++){
        if(m[i][k] >= m[i][l] + m[l + 1][k] + p[i - 1] * p[l] * p[k]){
          m[i][k] =  m[i][l] + m[l + 1][k] + p[i - 1] * p[l] * p[k];
        }
      }
    }
  }

  printf("%d\n", m[1][n]);

  return 0;
}


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

#define LINE_SIZE 17 //1000000+' '+1000000+\n+\0

char *find_space(char *line, char *buf) {
    int i = 0;
    while (*line != '\0' && *line != ' ' && *line != '\n') {
        buf[i] = *line;
        i++;
        line++;
    }
    buf[i] = '\0';
    return line;
}

int main() {
    char line[LINE_SIZE];
    char *str;
    while (fgets(line, LINE_SIZE, stdin) != NULL) {
        if (*line == '\n')
            continue;
        char buf[LINE_SIZE];
        str = find_space(line, buf);
        long num = atol(buf);
        find_space(str + 1, buf);
        num = num + atol(buf);
        int digit = 1;
        while ((num = num / 10) != 0) {
            digit++;
        }
        printf("%d\n", digit);
    }
    return 0;
}



Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> a(n);
  int tot=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    tot^=a[i];
  }
  for(int i=0;i<n;i++){
    int ans=tot^a[i];
    cout<<ans<<endl;
  }
  return 0;
}


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

int main(){
    while(true){
        int x, y;
        cin >> x >> y;
        if(x || y){
            cout << min(x, y) << " " << max(x, y) << endl;
        }else{
            return 0;
        }
    }
}

Measured memory_bytes: 3084
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;

ll solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}


ll solve(void)
{
	string s[2] = {"RUD", "LUD"};

	string t;
	cin >> t;

	bool ans = true;

	for (ll i = 0; i < t.length(); i++)
	{
		ll j = i % 2;
		ans &= (s[j].find(t[i]) != string::npos);
	}

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

x=sum(B)
for i in range(len(A)-1):
  if A[i+1]==A[i]+1:
    x+=C[A[i]-1]
print(x)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

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



Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
	int i, H, W;
	char S[22][22] = {};
	scanf("%d %d", &H, &W);
	for (i = 1; i <= H; i++) scanf("%s", &(S[i][1]));
	for (i = 0; i <= W + 1; i++) {
		S[0][i] = '#';
		S[H+1][i] = '#';
	}
	for (i = 1; i <= H; i++) {
		S[i][0] = '#';
		S[i][W+1] = '#';
	}

	int j, k, l, k_min, l_min, min, max = 0, dist[22][22], flag[22][22];
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (S[i][j] == '#') continue;
			for (k = 1; k <= H; k++) {
				for (l = 1; l <= W; l++) {
					flag[k][l] = 0;
					dist[k][l] = 10000;
				}
			}
			flag[i][j] = 1;
			dist[i][j] = 0;
			if (S[i][j+1] == '.' && flag[i][j+1] == 0) dist[i][j+1] = (dist[i][j] + 1 < dist[i][j+1])? dist[i][j] + 1: dist[i][j+1];
			if (S[i+1][j] == '.' && flag[i+1][j] == 0) dist[i+1][j] = (dist[i][j] + 1 < dist[i+1][j])? dist[i][j] + 1: dist[i+1][j];
			if (S[i][j-1] == '.' && flag[i][j-1] == 0) dist[i][j-1] = (dist[i][j] + 1 < dist[i][j-1])? dist[i][j] + 1: dist[i][j-1];
			if (S[i-1][j] == '.' && flag[i-1][j] == 0) dist[i-1][j] = (dist[i][j] + 1 < dist[i-1][j])? dist[i][j] + 1: dist[i-1][j];
			
			while (1) {
				k_min = 0;
				l_min = 0;
				min = 9999;
				for (k = 1; k <= H; k++) {
					for (l = 1; l <= W; l++) {
						if (flag[k][l] == 0 && dist[k][l] < min) {
							k_min = k;
							l_min = l;
							min = dist[k][l];
						}
					}
				}
				if (min == 9999) break;
				
				flag[k_min][l_min] = 1;
				if (S[k_min][l_min+1] == '.' && flag[k_min][l_min+1] == 0) dist[k_min][l_min+1] = (dist[k_min][l_min] + 1 < dist[k_min][l_min+1])? dist[k_min][l_min] + 1: dist[k_min][l_min+1];
				if (S[k_min+1][l_min] == '.' && flag[k_min+1][l_min] == 0) dist[k_min+1][l_min] = (dist[k_min][l_min] + 1 < dist[k_min+1][l_min])? dist[k_min][l_min] + 1: dist[k_min+1][l_min];
				if (S[k_min][l_min-1] == '.' && flag[k_min][l_min-1] == 0) dist[k_min][l_min-1] = (dist[k_min][l_min] + 1 < dist[k_min][l_min-1])? dist[k_min][l_min] + 1: dist[k_min][l_min-1];
				if (S[k_min-1][l_min] == '.' && flag[k_min-1][l_min] == 0) dist[k_min-1][l_min] = (dist[k_min][l_min] + 1 < dist[k_min-1][l_min])? dist[k_min][l_min] + 1: dist[k_min-1][l_min];
			}
			
			for (k = 1; k <= H; k++) {
				for (l = 1; l <= W; l++) {
					if (flag[k][l] == 1 && dist[k][l] > max) max = dist[k][l];
				}
			}
		}
	}
	
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)
#define N 1000

int f[N + 1][N + 1] = {0}, n;
string s[N];

int getsum(int l, int r, int t, int b){
  return f[r][b] - f[r][t - 1] - f[l - 1][b] + f[l - 1][t - 1];
}

int solve(){
  int res = 0;
  for(int i = 1;i <= n;++i){
    int l = 0;
    for(int r = 0;r <= n - i;){
      if(getsum(i + l, i + r, 1 + l, 1 + r) == 0){
        r++;
      }else{
        res = max(res, r - l);
        l++;
        if(l > r)r++;
      }
      res = max(res, r - l);
    }
  }
  return res;
}
void change(void){
  for(int i = 1;i <= n;++i)for(int j = i + 1;j <= n;++j)swap(f[i][j], f[j][i]);
  return;
}

signed main(void){
  int i, j;
  for(int testcase = 0;;testcase++){
    sc(n);
    if(n == 0)break;
    rep(i, N + 1)rep(j, N + 1)f[i][j] = 0;

    rep(i, n){
      sc(s[i]);
      rep(j, n)if(s[i][j] == '*')++f[i + 1][j + 1];
    }

    rep1(i, n + 1)rep1(j, n + 1)f[i][j] += f[i][j - 1];
    rep1(i, n + 1)rep1(j, n + 1)f[i][j] += f[i - 1][j];

    int res = solve();
    change();
    res = max(res, solve());
    pri(res);


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 6164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    stack<int> s1;
    stack<pair<int, int>> s2;
    ll allSum = 0;
    rep(j, s.size()){
        if (s[j] == '\\') s1.push(j);
        else if (s[j] == '/' && s1.size() > 0){
            int i = s1.top(); s1.pop();
            allSum += j - i;
            int sum = j - i;
            while(s2.size() > 0 && s2.top().first > i){
                sum += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(i, sum));
        }
    }
    int k = s2.size();
    vector<int> sums(k);
    rep(i,k){
        sums[i] = s2.top().second;
        s2.pop();
    }
    reverse(all(sums));
    cout << allSum << endl;
    cout << k;
    rep(i,sums.size()) cout << " " << sums[i];
    cout << endl;
}


Measured memory_bytes: 3248
N=int(input())
S=input()

MOD = 10**9+7
class Mint:
    def __init__(self, value=0):
        self.value = value % MOD
        if self.value < 0: self.value += MOD

    @staticmethod
    def get_value(x): return x.value if isinstance(x, Mint) else x

    def inverse(self):
        a, b = self.value, MOD
        u, v = 1, 0
        while b:
            t = a // b
            b, a = a - t * b, b
            v, u = u - t * v, v
        if u < 0: u += MOD
        return u

    def __repr__(self): return str(self.value)
    def __eq__(self, other): return self.value == other.value
    def __neg__(self): return Mint(-self.value)
    def __hash__(self): return hash(self.value)
    def __bool__(self): return self.value != 0

    def __iadd__(self, other):
        self.value += Mint.get_value(other)
        if self.value >= MOD: self.value -= MOD
        return self
    def __add__(self, other):
        new_obj = Mint(self.value)
        new_obj += other
        return new_obj
    __radd__ = __add__

    def __isub__(self, other):
        self.value -= Mint.get_value(other)
        if self.value < 0: self.value += MOD
        return self
    def __sub__(self, other):
        new_obj = Mint(self.value)
        new_obj -= other
        return new_obj
    def __rsub__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj -= self
        return new_obj

    def __imul__(self, other):
        self.value = self.value * Mint.get_value(other) % MOD
        return self
    def __mul__(self, other):
        new_obj = Mint(self.value)
        new_obj *= other
        return new_obj
    __rmul__ = __mul__

    def __ifloordiv__(self, other):
        other = other if isinstance(other, Mint) else Mint(other)
        self *= other.inverse()
        return self
    def __floordiv__(self, other):
        new_obj = Mint(self.value)
        new_obj //= other
        return new_obj
    def __rfloordiv__(self, other):
        new_obj = Mint(Mint.get_value(other))
        new_obj //= self
        return new_obj

from collections import Counter
C = Counter(S)
ans = Mint(1)
for c in C.values():
    ans *= c + 1
print(ans - 1)


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

int main(){
  int N;
  int count =0;
  cin >> N;
  for(int i=0; i<N; i++){
    int x;
    int temp=0;
    cin >>x;
    
    if(x%2 ==1){
      count =0;
      	break;
    }
    
    while(x%2 == 0){
      temp+=1;
        x/=2;
    }
    if(count ==0)
      count =temp;
    else if(temp < count)
      count = temp;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(ll i = 0; i < n; i++)


int main(){
  ll n;
  string s;
  cin >>n>>s;
  vector<int> r;
  vector<int> g;
  rep(i,n){
    if(s[i]=='R'){
      r.push_back(i);
    }
    else if(s[i]=='G'){
      g.push_back(i);
    }
  }
  ll sum  = r.size()*g.size()*(n-r.size()-g.size());
  rep(i,r.size()){
    rep(j,g.size()){
      int a1,a2;
      if(r[i]<g[j]){
        a1 = r[i];
        a2 = g[j];
      }
      else{
        a1 = g[j];
        a2 = r[i];
      }

      if((a2+(a2-a1))<n){
        if(s[a2+(a2-a1)]=='B'){
        sum -= 1;
      }
      }
      if((a1-(a2-a1))>=0){
        if(s[a1-(a2-a1)]=='B'){
        sum -= 1;
      }
      }
      if((a2+a1)%2==0&& s[(a1+a2)/2]=='B'){
        sum -= 1;
      }
    }
  }


  cout << sum<< endl;

}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#define INF 9999999
using namespace std;

int main(void){
	int n,s;
	cin>>n>>s;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	int l=0,r=0;
	int sum=a[0];
	int res=INF;
	while(l<=r){
		if(sum<s){
			// sum less than s
			r++;
			if(r>=n)break;
			sum+=a[r];
		}else{
			res=min(res,r-l+1);
			sum-=a[l];
			l++;
		}
	}
	cout<<( (res==INF)?0:res )<<endl;
	return 0;
}

Measured memory_bytes: 3484
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int K,N;
  cin >> K >> N;
  vector<int> a(N);
  vector<int> b(N);
  for(int i = 0; i< N; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i< N-1; i++){
    b.at(i) = a.at(i+1)-a.at(i);
  }
   b.at(N-1) = K -a.at(N-1)+a.at(0);
   sort(b.begin(),b.end());
   int sum = 0;
   for(int i = 0; i < N; i++){
     sum+= b.at(i);
   }
   cout << sum - b.at(N-1)<< endl;
}

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

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization ("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set

const int MOD = 1e9 + 7;

int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n = 0, a = 0, b = 0, c = 1, d = 1; cin >> n;
	if(n <= 2){
		cout << "0\n";
		return 0;
	}
	for(int i = 0; i < n - 3; i ++){
		d = (a + d) % MOD;
		a = b;
		b = c;
		c = d;
	}
	cout << c << endl;
}
/**

*/

Measured memory_bytes: 3620
from collections import deque
h,w=list(map(int, input().split()))
s = [input() for _ in range(h)]

water=[[0]*w for _ in range(h)]
water[0][0]=1
a_index=[]
a_column=[]
a_index.append(0)
a_column.append(0)
b=[]
count=0

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            water[i][j]=3000
            count+=1
while water[h-1][w-1]==0:
    for i,j in zip(a_index,a_column):
        if water[i][j]==1:
            if i>0:
                if water[i-1][j]==0:
                    water[i-1][j]+=1
                    b.insert(0,[i-1,j])
            if i<h-1:
                if water[i+1][j]==0:
                    water[i+1][j]+=1
                    b.insert(0,[i+1,j])
            if j>0:
                if water[i][j-1]==0:
                    water[i][j-1]+=1
                    b.insert(0,[i,j-1])
            if j<w-1:
                if water[i][j+1]==0:
                    water[i][j+1]+=1
                    b.insert(0,[i,j+1])
        water[i][j]+=1

    a_index+=[x[0] for x in b]
    a_column+=[x[1] for x in b]

    if not b:
        print(-1)
        exit()
    b=[]

print(h*w-water[0][0]-count)


Measured memory_bytes: 3436
#[test]
fn test_solve() {
    assert_eq!(solve("3\naab\nccb\n"), "6\n");
    assert_eq!(solve("1\nZ\nZ\n"), "3\n");
    assert_eq!(solve("52\nRvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\nRLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn\n"), "958681902\n");
}

fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let s1: Vec<_> = sc.get().chars().collect();
    let s2: Vec<_> = sc.get().chars().collect();

    let mut a = Vec::new();
    let mut i = 0;
    while i < n {
        if s1[i] == s2[i] {
            a.push(true);
            i += 1;
        } else {
            a.push(false);
            i += 2;
        }
    }

    let mut ptn = Finite(if a[0] { 3 } else { 6 });
    for i in 1..a.len() {
        ptn *= match (a[i-1], a[i]) {
            (true, true) | (true, false) => 2,
            (false, true) => 1,
            (false, false) => 3,
        };
    }

    format!("{}\n", ptn)
}

const MOD: u64 = 1_000_000_007;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
struct Finite(u64);
impl std::fmt::Display for Finite {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
impl std::ops::MulAssign<u64> for Finite {
    fn mul_assign(&mut self, rhs: u64) {
        self.0 = self.0 * rhs % MOD;
    }
}

fn main() {
    let mut buf = String::new();
    use std::io;
    use std::io::{Read, Write};
    io::stdin().read_to_string(&mut buf).unwrap();
    io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}

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

void changePlayer(int& i) {
    i = (i == 0) ? 1 : 0;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* cards = new int [2 * n + 1];
        for (int i = 1; i <= 2 * n; i++) {
            cards[i] = 1;
        }
        for (int i = 0; i < n; i++) {
            int card;
            cin >> card;
            cards[card] = 0;
        }
        int cardNums[2] = {n, n, }, index = 1, player = 0;
        while (cardNums[0] > 0 && cardNums[1] > 0) {
            if (cards[index] == player) {
                cards[index] = -1;
                cardNums[player]--;
                changePlayer(player);
                continue;
            }
            if (index + 1 <= 2 * n) {
                index++;
            } else {
                index = 1;
                changePlayer(player);
            }
        }
        int remains[2] = {};
        for (int i = 1; i <= 2 * n; i++) {
            if (cards[i] == player) {
                remains[player]++;
            }
        }
        cout << remains[1] << endl
             << remains[0] << endl;
        delete[] cards;
    }
}

Measured memory_bytes: 0
def solve():
    N = int(raw_input())
    S = [raw_input() for i in range(N)]
    S.sort()
    curr = S[0]
    count = [[S[0], 1]]
    for i in range(1, N):
        if S[i] == curr:
            count[-1][1] += 1
        else:
            curr = S[i]
            count.append([curr, 1])
    count.sort(key = lambda x:-x[1])
    for i in range(len(count)):
        if count[i][1] == count[0][1]:
            print count[i][0]

if __name__ == '__main__':
    solve()


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

using namespace std;

void hawawa()
{
  unsigned int a, b;
  cin >> a >> b;
  a -= 2;
  b -= 2;
  if (a > b) {
    cout << "Alice\n";
  }
  else if (a < b) {
    cout << "Bob\n";
  }
  else {
    cout << "Draw\n";
  }
}

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

Measured memory_bytes: 384
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll x[5];
    REP(i,5){
        cin >> x[i];
        if(x[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }

    return 0;    
}


Measured memory_bytes: 3592
def examF():
    M, K = LI()
    if K>=(2**M) or (M==1 and K==1):
        ans = -1
    elif K==0:
        ans = []
        s = [i for i in range(2**M)]
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
    else:
        ans = []
        ans.append(K)
        for i in range(2**M):
            if i!=K:
                ans.append(i)
        ans.append(K)
        for i in range(2**M-1,-1,-1):
            if i!=K:
                ans.append(i)
    if type(ans) is int:
        print(ans)
    else:
        print(" ".join(map(str,ans)))

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examF()


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

#define REP(a, n) for (int i = a; i < n; i++)
#define pb(a) push_back(a)

typedef long long ll;
typedef long l;
typedef unsigned long long ull;
typedef vector<int> V;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef map<int,int> Map;

long long  arr[100005];





int main(){

  #ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
  freopen("output1.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
    

   ll a,b;
   cin>>a>>b;

   cout<<a*b<<endl;

  

 }



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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin>>N;
  string s;
  cin>>s;

  vector<LL> x(N);

  bool flag = true;

  REP(i,N){
    x[i] = s[i] - '1';
    if(x[i]==1){
      flag = false;
    }
  }
  
  if(flag){
    // all 0 or 2
    REP(i,N){
      x[i] = x[i] / 2;
    }
  }else{
    REP(i,N){
      x[i] = x[i] % 2;
    }
  }
  
  while(x.size()>=2){
    LL size;
    REP(i, 100000)
    {
      LL hoge = (1 << i) + 1;
      if(hoge<=x.size()){
        
      }else{
        size = (1 << (i - 1));
        break;
      }
    }
    
    vector<LL> newx(x.size()-size);
    REP(i,newx.size()){
      newx[i] = (x[i] + x[i + size]) % 2;
    }
    x = newx;
  }

  if(flag){
    if(x[0]==0){
      cout << 0 << endl;
    }
    else
    {
      cout << 2 << endl;
    }
  }else{
    if(x[0]==0){
      cout << 0 << endl;
    }else{
      cout << 1 << endl;
    }
  }
}


Measured memory_bytes: 12956
#!/usr/bin/env python3

def main():
    a, b, c, d = map(int, input().split())
    while True:
        c -= b
        if c <= 0:
            print("Yes")
            return
        a -= d
        if a <= 0:
            print("No")
            return

if __name__ == "__main__":
    main()


Measured memory_bytes: 9164
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int sum = 1;
        for(int i = 0;i < N;i++){
            if(sum <= K){
                sum = sum * 2;
            }else{
                sum = sum + K;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> ans_small (M);
    vector<int> ans_large (M);
    if (N % 2 == 1){
        rep(i,M){
            ans_small[i] = i + 1;
            ans_large[i] = N - i;
        }
    }
    else{
        rep(i,M){
            ans_small[i] = i + 1;
        }
        int x = N - 1;
        rep(i,M){
            ans_large[i] = ans_small[i] + x;
            if (x + (x - 2) == N || x - 2 == N / 2) x -= 3;
            else x -= 2;
        }
    }
    rep(i,M){
        cout << ans_small[i] << " " << ans_large[i] << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e11;

int main() {
  int n, kk;
  cin >> n >> kk;
  int m = min(n, kk);
  vector<int> v(n);
  ll ans = -INF;
  rep(i, n) cin >> v[i];

  for (int i = 0; i <= m; ++i) {
    for (int j = 0; i + j <= m; ++j) {
      ll ta = 0;
      vector<ll> t;
      int c = kk - i - j;
      for (int k = 0; k < i; ++k) t.push_back(v[k]);
      for (int k = 0; k < j; ++k) t.push_back(v[n - 1 - k]);
      for (auto a : t) ta += a;
      sort(t.begin(), t.end());
      for (int k = 0; k < c && k < t.size() && t[k] < 0; ++k) ta -= t[k];
      ans = max(ans, ta);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,b;
  int a[4][14];
  char s;
  for(i=0;i<=13;i++){
    a[0][i]=0;
    a[1][i]=0;
    a[2][i]=0;
    a[3][i]=0;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %c %d",&s,&b);
    if(s=='S'){
      a[0][b]=1;
    }else if(s=='H'){
      a[1][b]=1;
    }else if(s=='C'){
      a[2][b]=1;
    }else if(s=='D'){
      a[3][b]=1;
    }
  }
  for(i=0;i<4;i++){
    for(j=1;j<=13;j++){
      if(a[i][j]!=1){
	if(i==0){
	  s='S';
	}else if(i==1){
	  s='H';
	}else if(i==2){
	  s='C';
	}else if(i==3){
	  s='D';
	}
	printf("%c %d\n",s,j);
      }
    }
  }
  return (0);
}

Measured memory_bytes: 596
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    op = sum(B) - sum(A)
    D = [(b-a+1)//2 if b > a else 0 for a, b in zip(A, B)]
    print("Yes" if op >= sum(D) else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 41584
import java.io.InputStreamReader;
import java.io.LineNumberReader;

/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_C
 * 
 * @author eitatsuro
 * 
 */
public class Main {
    public static void main(String[] args) {
        try {
            LineNumberReader lineNumReader = new LineNumberReader(
                    new InputStreamReader(System.in));
            
            String inputStr = null;
            double  scores[] = null;
            int studentsNum = 0;
            
            while ((inputStr = lineNumReader.readLine()) != null) {
                
                // ???????????°
                if (lineNumReader.getLineNumber()%2 == 1) {
                    studentsNum = Integer.parseInt(inputStr);
                }
                
                // ???????????¶.
                if (studentsNum == 0) {
                    break;
                }
                
                // ????????¢
                if (lineNumReader.getLineNumber() % 2 == 0) {
                    String[] points = inputStr.split(" ");
                    scores = new double[studentsNum];
                    int i = 0;
                    for (String point : points) {
                        scores[i] = Long.parseLong(point);
                        i++;
                    }
                    
                    // ?????????????¨????
                    double sum = 0;
                    for (double score : scores) {
                        sum += score;
                    }
                    double mean = sum / studentsNum;
                    
                    // ?????£ sig2
                    double sig2 = 0;
                    for (double score : scores) {
                        sig2 += Math.pow(score - mean, 2);
                    }
                    
                    // ?¨?????????? sigma
                    double sigma = Math.sqrt(sig2 / studentsNum);
                    
                    // ????????????.
                    System.out.println(String.format("%.8f", sigma));
                }
            }
            
            lineNumReader.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 25344
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

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

struct data{
	int S;
	int x,y;
	bool operator<(const data &D)const{
		if(S!=D.S) return S<D.S;
		if(x!=D.x) return x<D.x;
		return y<D.y;
	}
};

int n;

data next_state(int S,int x,int y){
	S|=1<<y*n+x;
	int T=0;
	rep(i,n) rep(j,n) {
		int cnt=0;
		rep(k,8){
			int yy=i+dy[k],xx=j+dx[k];
			if(0<=yy && yy<n && 0<=xx && xx<n && S&(1<<yy*n+xx)) cnt++;
		}
		if(S&(1<<i*n+j)){
			if(cnt==2 || cnt==3) T|=1<<i*n+j;
		}
		else{
			if(cnt==3) T|=1<<i*n+j;
		}
	}
	T&=~(1<<y*n+x);
	return (data){T,x,y};
}

int main(){
	for(;scanf("%d",&n),n;){
		data ini={};
		rep(i,n){
			char s[6]; scanf("%s",s);
			rep(j,n){
				if(s[j]=='#') ini.S|=1<<(i*n+j);
				if(s[j]=='@') ini.x=j, ini.y=i;
			}
		}

		int ans=-1;
		set<data> Vis;
		queue< pair<int,data> > Q; Q.push(make_pair(0,ini));
		while(!Q.empty()){
			int t=Q.front().first;
			data D=Q.front().second; Q.pop();

			if(Vis.count(D)>0) continue;
			Vis.insert(D);

			if(D.S==0){ ans=t; break; }

			if(t==10) continue;
			rep(k,8){
				int yy=D.y+dy[k],xx=D.x+dx[k];
				if(0<=yy && yy<n && 0<=xx && xx<n && (D.S&(1<<yy*n+xx))==0){
					Q.push(make_pair(t+1,next_state(D.S,xx,yy)));
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0