akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
char s[10000];
int S,X,Y,dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},dir=0,p,q;
bool f[20000];
vector<int>u,v;
int main(){
	scanf("%s",s),S=strlen(s),scanf("%d%d",&X,&Y);
	for(int i=0,j=0;i<S;){
		while(j<S&&s[j]=='F')j++,p+=dx[dir],q+=dy[dir];
		if(i){
			if(dir==0)u.push_back(i-j);
			if(dir==1)v.push_back(i-j);
			if(dir==2)u.push_back(j-i);
			if(dir==3)v.push_back(j-i);
		}
		j++,i=j;
		dir=(dir+1)%4;
	}
	X-=p,Y-=q;
	if((X&1)||(Y&1)){puts("No");return 0;}
	X>>=1,Y>>=1;
	
	f[S]=true;
	for(int i=0;i<u.size();i++){
		if(u[i]==0)continue;
		if(u[i]>0)for(int j=S-u[i];j>=-S;j--)f[S+j+u[i]]|=f[S+j];
		if(u[i]<0)for(int j=-S-u[i];j<=S;j++)f[S+j+u[i]]|=f[S+j];
	}
	if(!f[S+X]){puts("No");return 0;}
	memset(f,0,sizeof(f));
	f[S]=true;
	for(int i=0;i<v.size();i++){
		if(v[i]==0)continue;
		if(v[i]>0)for(int j=S-v[i];j>=-S;j--)f[S+j+v[i]]|=f[S+j];
		if(v[i]<0)for(int j=-S-v[i];j<=S;j++)f[S+j+v[i]]|=f[S+j];
	}
	if(!f[S+Y]){puts("No");return 0;}
	puts("Yes");
	return 0;
}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(typeof(a))(b))
#define MX(a,b) a = max(a,(typeof(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


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

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

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

const int maxn = 2e5+5;


main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s; cin>>s;
    ll k = 0; cin>>k;
    vector<int> l;
    int n = s.length();
    int c = 0;
    REP(i,n){
        if (i && s[i]!=s[i-1]) {
            l.pb(c); c=0;
        }c++;
    }l.pb(c);
    if (SZ(l)==1){
        ll x = n * k;
        cout<<x/2<<endl; return 0;
    }
    ll re = 0;
    FOR(i,1,SZ(l)-1){
        re += (l[i]/2) * k;
    }
    
    if (s[0]==s[n-1]){
        re += l[0]/2; re += l[SZ(l)-1]/2;
        re += (l[0]+l[SZ(l)-1])/2 * (k-1);
    }else {
        re += (l[0]/2) * k; re += (l[SZ(l)-1]/2)*k;
    }

    cout<<re<<endl;
    
} 

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

using namespace std;

int main(){
  int a, b, c, x, y, min;
  cin >> a >> b >> c >> x >> y;
  if(a+b < 2*c){
    cout << a*x + b*y << endl;
  }
  else {
    if(x>=y){
      if(a>2*c&&a*x+b*y>2*c*x) cout << 2*c*x << endl;
      else if(a*x+b*y>2*c*y+a*(x-y)) cout << 2*c*y+a*(x-y) <<endl;
      else cout << a*x+b*y << endl;
    }
    else{
      if(b>2*c&&a*x+b*y>2*c*x) cout << 2*c*y << endl;
      else if(a*x+b*y>2*c*x+b*(y-x)) cout << 2*c*x+b*(y-x) <<endl;
      else cout << a*x+b*y << endl;
    }
  }
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split(" ").map(&:to_i)

sum = as.reduce(0){|a,e|a+=e}
sunuke_sum = as[0]
a_sum = sum - sunuke_sum
min = (sunuke_sum - a_sum).abs

(1...(n-1)).each do |i|
  sunuke_sum = sunuke_sum + as[i]
  araiguma_sum = sum - sunuke_sum
  min = [min, (sunuke_sum - araiguma_sum).abs].min
end

puts min

Measured memory_bytes: 19204
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

vll par(0);
vll ran(0);
vll si(0);
void init(ll n){
	FOR(i,0,n-1){
		par.pb(i);
		ran.pb(1);
		si.pb(1);
	}
}
ll find(ll t){
	if(par[t]==t){
		return t;
	}else{
		par[t]=find(par[t]);
		return par[t];
	}
}
ll unite(ll p,ll q){
	p=find(p);
	q=find(q);
	if(p==q){
		return 0;
	}else{
		ll a=si[p]*si[q];
		if(ran[p]>ran[q]){
			par[q]=p;
			si[p]+=si[q];
		}else if(ran[p]<ran[q]){
			par[p]=q;
			si[q]+=si[p];
		}else{
			par[q]=p;
			si[p]+=si[q];
			ran[p]++;
		}
		return a;
	}
}

signed main(){
	llin(n);
	llin(m);
	vll a(m);
	vll b(m);
	vll k(m);
	init(n);
	FOR(i,0,m-1){
		cin >>a[i]>>b[i];
	}
	k[m-1]=(n*(n-1))/2;
	rFOR(i,0,m-2){
		k[i]=k[i+1]-unite(a[i+1]-1,b[i+1]-1);
	}
	FOR(i,0,m-1){
		sal(k[i]);
	}
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const ll STOP = 1e10;
int k;
vl lun;
void dfs(ll i){
    //DEBUG(i);
    //if(i==3234566667) cout<<"hit!!!!"<<endl;
    if(i>=STOP) return;

    int digit = i%10;

    dfs(i*10 + digit);
    if(digit < 9) dfs(i*10 + ((digit+1)%10));
    if(digit > 0) dfs(i*10 + ((digit-1)%10));

    lun.emplace_back(i);
}

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

    FOR(i,1,9+1){
        dfs(i);
    }
    sort(ALL(lun));

    cout << lun[k-1] << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
 
using namespace std;
 
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define mp make_pair
#define f first
#define s second
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vpl = vector<pll>;
 
void fio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const long double pi = 3.14159265358979323846;



void solve() {
  char c; cin >> c;
  cout << ('A' <= c && c <= 'Z' ? 'A' : 'a') << '\n';
}
 
int main() {
  fio();
  
  int T = 1;
  // cin >> T;
  while (T--) solve();
} 

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
ll a[55]; ll n, p, ans = 1, cnta = 0, cntb = 0;
signed main() {
	cin >> n >> p;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		if (a[i] % 2 == 0)cnta++;
	}
	for (int i = 1; i < n; i++)ans *= 2;
		if (cnta == n) {
			if (p == 0) {
				cout << ans * 2 << endl;
			}
			else cout << 0 << endl;
		}
		else cout << ans << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class CBuildStairs {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int n;
    cin >> n;
    vector<int> H(n);
    for (auto &h: H) cin >> h;

    int prev = int(1e9) + 1;

    for (int i = n - 1; i >= 0; i--){
        if (H[i] > prev)
            H[i]--;
        if (H[i] > prev){
            cout << "No" << endl;
            return;
        }
        prev = H[i];
    }

    cout << "Yes" << endl;
}
};

int main() {
	CBuildStairs solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=10101;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}

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

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

  int ans = 0;
  rep(i,A+1) rep(j,B+1) rep(k,C+1) {
    if(500*i + 100*j + 50*k == X) ans++;
  }

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


Measured memory_bytes: 256
def main():
    *A, = map(int, open(0).read().split())
    N = A[0]
    D = A[1:N + 1]
    M = A[N + 1]
    T = A[N + 2:]
    # print(N, D, M, T)
    D.sort()
    T.sort()
    di = 0
    for t in T:
        if di >= N:
            print('NO')
            return
        d = D[di]
        while d < t and di < N:
            di += 1
            d = D[di]
        if d != t:
            print('NO')
            return
        di += 1
    print('YES')

if __name__ == '__main__':
    main()


Measured memory_bytes: 48940
#include<iostream>
#include<algorithm>
using namespace std;
int n;
string ta;
int memo[20000][10];
int solve(int day,int f){
	if(memo[day][f]!=0)return memo[day][f];
	if(day==n){
		return memo[day][f]=1;
	}

	int tmp,sum=0;;
	for(int i=0;i<8;i++){
		if(ta[day]=='J')tmp=4;
		else if(ta[day]=='O')tmp=2;
		else if(ta[day]=='I')tmp=1;
			if((i&tmp)!=0&&(i&f)!=0)sum+=solve(day+1,i);
	}

	return memo[day][f]=sum%10007;
}


int main(){
	cin>>n;
	cin>>ta;
	cout<<solve(0,4)<<endl;
	return 0;
}

Measured memory_bytes: 1324
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  [a, op, b] <- words <$> getLine
  let c = read a
      d = read b
  print $ if op == "+" then c + d else c - d


Measured memory_bytes: 508
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int a = 10;
    int i = 1;
    int count = 0;
    while (N >= a) {
      int j = 9;
      for (int k = 1; k < i; k++) j *= 10;
      count += j;
      i += 2;
      a *= 100;
    }
    a /= 10;
    if (N >= a) {
      count += N - a + 1;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
n,a,b=map(int,input().split())
ans=0
def digitsum(n):
  l=len(str(n))
  re=0
  for i in range(l):
    re+=int(str(n)[i])
  return re
for i in range(n+1):
  if a<=digitsum(i)<=b:
    ans+=i
print(ans)


Measured memory_bytes: 3060
N, A, B = list(map(int,input().split()))
S = input()
p = fp = 0
for s in S:
    if s=="a" and p<A+B:
        print("Yes")
        p += 1
    elif s=="b" and p<A+B and fp<B:
        print("Yes")
        p += 1
        fp += 1
    else:
        print("No")

Measured memory_bytes: 4016
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
int calc_times(int i, int times){
    int tmp = i;
    rep(j, times) tmp *= 2;
    return tmp;
}

signed main(){
    int r, g, b;
    cin >> r >> g >> b;
    int k;
    cin >> k;
    bool isOK = false;

    rep(i, k+1){
        int tmpr = r;
        int tmpb = b;
        int tmpg = g;
        int j = k-i;
        if(j > k) continue;
            /* cout << i << " " << j << endl; */
        tmpb = calc_times(tmpb, i); /* 青をi回 */
        tmpg = calc_times(tmpg, j); /* 緑をj回 */
        if((tmpg > tmpr) && (tmpb > tmpg)){
            isOK = true;
            /* cout << i << " " << j << endl;
            cout << tmpr << " " << tmpg << " " << tmpb << endl;
            cout << endl; */
        }
    }

    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k,Q,a,b,c,d,A[N],B[N],C[N],D[N];
char s1[N],s[N];
int main()
{
		scanf("%s",s1+1); n=strlen(s1+1); for (i=1;i<=n;++i) A[i]=A[i-1]+(s1[i]=='A'),B[i]=B[i-1]+(s1[i]=='B');
		scanf("%s",s+1); m=strlen(s+1); for (i=1;i<=m;++i) C[i]=C[i-1]+(s[i]=='A'),D[i]=D[i-1]+(s[i]=='B');
		scanf("%d",&Q);
		for (;Q--;)
		{
				scanf("%d%d%d%d",&a,&b,&c,&d); --a; --c;
				if (abs((A[b]-A[a])*2+B[b]-B[a]-((C[d]-C[c])*2+D[d]-D[c]))%3==0) puts("YES");
				else puts("NO"); 
		}
}


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

int main(){
    string N;
    cin >> N;
    for(int i=0; i<N.size(); i++){
        if( N[i]=='7' ){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3624
def main():
    N,C = map(int,input().split())
    D = [list(map(int,input().split())) for _ in range(C)]
    c = [list(map(int,input().split())) for _ in range(N)]
    mod_0 = [0 for _ in range(C)]
    mod_1 = [0 for _ in range(C)]
    mod_2 = [0 for _ in range(C)]
    for i in range(N):
        for j in range(N):
            if (i+j)%3 == 0:
                mod_2[c[i][j]-1] += 1
            if (i+j)%3 == 1:
                mod_0[c[i][j]-1] += 1
            if (i+j)%3 == 2:
                mod_1[c[i][j]-1] += 1
    INF = 10**10
    ans = INF
    for i in range(C):
        for j in range(C):
            if i == j:
                continue
            for k in range(C):
                if i == k or j == k:
                    continue
                ans = min(ans,sum(mod_0[n]*D[n][i] for n in range(C))+\
                              sum(mod_1[n]*D[n][j] for n in range(C))+\
                              sum(mod_2[n]*D[n][k] for n in range(C)))
    print(ans)

if __name__ == "__main__":
    main()

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

int main(){
  int h,w;
  cin >> h >> w;
  char a[h][w];
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> a[i][j];
  int ans[h][w],flag[h][w]={};
  int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
  queue<P> q;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='#'){
        ans[i][j]=0;
        flag[i][j]=1;
        q.push(P(i,j));
      }
    }
  }
  while(!q.empty()){
    P p=q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int nx=p.first+dx[i];
      int ny=p.second+dy[i];
      if(0<=nx&&nx<h&&0<=ny&&ny<w&&!flag[nx][ny]){
        flag[nx][ny]=1;
        q.push(P(nx,ny));
        ans[nx][ny]=ans[p.first][p.second]+1;
      }
    }
  }
  int res=0;
  for(int i=0;i<h;i++) for(int j=0;j<w;j++) res=max(res,ans[i][j]);
  cout << res << endl;
}


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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), n = sc.nextInt(), c[] = new int[n], a[] = new int[m + 1];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.fill(a, Integer.MAX_VALUE);
        a[0] = 0;
                for (int i = 0; i < n; i++)
                    for (int j = c[i]; j <= m; j++) {
                        a[j] = Math.min(a[j], a[j - c[i]] + 1);
                    }
        System.out.println(a[m]);
    }
}


Measured memory_bytes: 26848
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    ll N;
    cin >> N;

    ll X = N + 1;
    ll val = 1ll;
    deque<int> dq;

    int len = 0;
    for (len = 0; X >> len > 0; len++);

//    for(int i = 0; i < len; ++i){
//
//    }

    int cnt = 1;
    for (int i = len - 1; i >= 0; --i) {
        if (i == 0) {
            if ((X >> i & 1) != (val & 1)) {
                val += 1ll;
                dq.push_front(cnt++);
            }
            break;
        }
        if ((X >> i & 1) == (val & 1)) {
            val <<= 1;
            dq.push_back(cnt++);
        } else {
            val += 1ll;
            dq.push_front(cnt++);

            val <<= 1;
            dq.push_back(cnt++);
        }
    }

    vector<int> ans;
    rep(i, 1, cnt) ans.push_back(i);
    for (auto e : dq) ans.push_back(e);

    cout << ans.size() << endl;
    rep(i, 0, ans.size()) {
        cout << ans[i];
        if (i == ans.size() - 1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

int measure(int x,int y)  
{     
    int z=y;  
    while(x%y!=0)  
    {  
        z=x%y;  
        x=y;  
        y=z;    
    }  
    return z;  
}

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a%b==0&&c%b==0)
		cout<<"YES"<<endl;
	else if((a%b==0)||(c%b==0))
		cout<<"NO"<<endl;
	else
	{
		if(c%measure(a,b)==0)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

string str;
map<char,int> w;

char winner(int &i){
	if(str[i] == '['){
		char l = winner(++i);
		assert(str[i] == '-');
		char r = winner(++i);
		assert(str[i] == ']');
		i++;
//		cerr << l << ":" << w[l] << " , " << r << ":" << w[r] << endl;
		if(l == 0  || r == 0)return 0;
		if(w[l] == 0){
			if(w[r] == 0)return 0;
			w[r]--;
			return r;
		}
		else{
			if(w[r] != 0)return 0;
			w[l]--;
			return l;
		}
	}
	char t = str[i];
	i++;
	return t;
}

signed main(){
	cin >> str;
	int n = 0;
	for(auto e: str){
		if(isalpha(e) && w.find(e) == w.end()){
			n++;
			w[e] = 0;
		}
	}
	for(int i = 0; i < n; i++){
		char a;
		int v;
		cin >> a >> v;
		w[a] = v;
	}
	int tmp = 0;
	int cnt = 0;
	char ret = winner(tmp);
	for(auto e : w){
//		cerr << e.first << "," << e.second << endl;
		if(e.second != 0){
			cnt++;
		}
	}
	if(ret == 0 || cnt != 0){
		cout << "No" << endl;
	}
	else{
		
		cout << "Yes" << endl;
	}

	return 0;
}




Measured memory_bytes: 3232
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $N);
$A[] = explode(" ", trim(fgets(STDIN)));
$A[] = explode(" ", trim(fgets(STDIN)));

$ans = $cur = $A[0][0] + array_sum($A[1]);

for ($i = 0; $i < $N; $i++) {
    $cur = $cur + $A[0][$i+1] - $A[1][$i];
    $ans = max($ans, $cur);
}

echo $ans . PHP_EOL;


Measured memory_bytes: 4728
import sys

a, b, c, d = map(int, sys.stdin.readline().split())
l = a + b
r = c + d

def main():
    if l > r: ans = 'Left'
    elif l == r: ans = 'Balanced'
    else: ans = 'Right'
    print(ans)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define tam 5010
#define se second
#define fi first
#define pitem item*
#define forr(i,p,n) for(ll i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
typedef vector<vector<ll> > vvi;
typedef  double lld;
int dpiz[tam][tam],dpder[tam][tam];
int main()
{
    int n,val,Y;
    //ios::sync_with_stdio(false);.tie(0);
    scanf("%d %d",&n,&Y);
    vector<int> v;
    int ans=0;
    forr(i,0,n)
    {
        scanf("%d",&val);
        if (val>=Y)
            {
                ans++;
                continue;
            }
        v.pb(val);
    }
    n=v.size();
    ans=0;
    memset(dpiz,0,sizeof dpiz);
    memset(dpder,0,sizeof dpder);

    dpiz[0][0]=dpder[n+1][0]=1;
    int posi,num;
    forr(i,0,v.size())
    {
        num=v[i];
        for(int k=Y-1;k>=0;k--)
        {
             if (dpiz[i][k]==1)
             {
                dpiz[i+1][k]=1;
                if (k+num<Y)
                dpiz[i+1][k+num]=1;
             }
        }
    }

    for(int i=v.size();i>=1;i--)
    {
        num=v[i-1];
        for(int k=Y-1;k>=0;k--)
        {
            if (dpder[i+1][k]==1)
            {
                dpder[i][k]=1;
                if (num+k<Y)
                dpder[i][num+k]=1;
            }
        }
       
    }
    forr(i,1,n+1)
    {
        num=v[i-1];
        set<int> s;     
        forr(k,0,Y)
            if (dpiz[i-1][k]==1)
                s.insert(k);
        bool cond=0;
        forr(k,0,Y)
        {
            if (dpder[i+1][k]==1)
            {

                ll delta=(Y-num)-k;
                //<<k<<" "<<delta<<endl;
                set<int>::iterator ite=s.lower_bound(delta);
                if (ite!=s.end()&& *ite+k<Y&& *ite+num+k>=Y)
                    {
                        cond=1;
                        break;
                    }
            }
        }
        if (cond==0)
            ans++;
        //<<cond<<" respuesta\n";
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 196608
import Data.List

main = getContents >>= \x -> mapM_ putStr (makeIndex x)

makeIndex :: String -> [String]
makeIndex = map tuple2IndexStr.sort.groupWords.map (makePair.words).lines

makePair :: [String] -> (String, Int)
makePair [x,y] = (x, read y)

groupWords :: [(String,Int)] -> [(String,[Int])]
groupWords list = group' [] list
group' list [] = list
group' list (x:xs) = case lookup (fst x) list of
                       Just _ -> group' (addpage list (fst x) (snd x)) xs
                       Nothing -> group' newlist xs
                           where 
                               newlist       = (fst x, [snd x]): list
addpage :: [(String, [Int])] -> String -> Int -> [(String, [Int])]
addpage list key page = takeWhile (\x -> fst x /= key) list ++ new ++ ( tail $ dropWhile (\x -> fst x /= key) list)
    where new = [(key, page:pagelist)]
          (Just pagelist) = lookup key list


tuple2IndexStr :: (String, [Int]) -> String
tuple2IndexStr (word, pages) = unlines [word, unwords (map show (sort pages))]

Measured memory_bytes: 4080
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"


using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 


#define lo long long int



int main() {
	int n,t,c=0;
	char s[300][300];
	cin >> n;
	fori0(n)forj0(n) {
		cin >> s[i][j];
	}
	fori0(n) {
		t = 0;
		forj1(n - 1) {
			for (int k = 0;k <= j - 1;k++) {
				//printf("(%d,%d,%d,%c,%c)\n", i, j, k, s[j][(k + i) % n], s[(k + i) % n][j]);
				if (s[j][(k + i) % n] != s[k][(j+i)%n]) {
					t = 1;
				}
			}
		}
		if (t == 0) { c++; }
	}
	cout << c * n << endl;
	//system("pause");
	return 0;

}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define fr(i,j,k) for(int i=j;i<k;i++)
//#define f(n) fr(i,0,n)
//#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const ll mod = 1e11 + 7;
const int maxn = 2e5+5;
#include<atcoder/all>
using namespace atcoder;
void solve() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << floor_sum(n,m,a,b) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 1;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
    
}


Measured memory_bytes: 3652
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    ll s = 1, sum = 0;
    while (sum + pow(26, s) < n) {
        sum += pow(26, s);
        s++;
    }
    n -= sum;
    string ans;
    while (s--) {
        ans += (char)('a' + (n-1)/((ll)pow(26,s)));
        n = 1 + (n-1)%((ll)pow(26, s));
    }
    cout << ans;
    return 0;
}

    


Measured memory_bytes: 4056
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

data class Restrant(val id: Int, val name: String, val score: Int)
fun main(args: Array<String>) {

    val n = readInt()
    val restrants = (1..n).map { 
        val (s, p) = readListOfString()
        Restrant(it, s, p.toInt())
    }
    val sortedRestrants = restrants.sortedByDescending { it.score }.sortedBy { it.name }
    sortedRestrants.forEach { println(it.id) }
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

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

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 35948
import sys
import math

N = int(input())

cap = [int(input()) for i in range(5)]

now = [N, 0, 0, 0, 0, 0]

ans = math.ceil(float(N)/min(cap)) + 4

#while now[5] != N:
#	for i in reversed(range(5)):
#		if now[i] > 0:
#			if now[i] >= cap[i]:
##				now[i] -= cap[i]
#				now[i+1] += cap[i]
#			elif now[i] < cap[i]:
#				now[i+1] += now[i]
#				now[i] = 0
#
#	ans += 1

print(int(ans))



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

typedef long long ll;

string S;
ll K;

bool all_same() {
  for (ll i = 0; i < S.size(); ++i)
    if (S[i] != S[0]) return false;
  return true;
}
ll calc(string s) {
  ll r = 0;
  for (ll i = 1; i < s.size(); ++i) {
    if (s[i - 1] == s[i]) {
      s[i] = '%';
      ++r;
    }
  }
  return r;
}
ll solve() {
  if (all_same()) {
    return S.size() * K / 2;
  }
  ll a = calc(S), b = calc(S + S);
  return (b - a) * (K - 1) + a;
}
int main() {
  cin >> S >> K;
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 256
char*p,s[172];m;B(b,q,r){char*f[99]={0},i=9,v;for(p=s+b+1;i--;p+=i%3?q:q+r)f[v=p[1]]?*f[v]=*p=42:(f[v]=p);}main(f){for(;~scanf("%*d%18[^a]"+!!*s*3,p=s+1+m);)if(s[m]=10,*p=32,m+=19,m==171){for(m=9;m--;B(m%3*6+m/3*57,2,13))B(m*19,2,0),B(m*2,19,0);f=m=!puts(s+f);}}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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 (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    string S;
    cin >> S;
    ll res = 0;
    REP(i, 4){
        if(S[i]=='+') res++;
        else res--;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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; }
using namespace std;


int main(){
  int N;
  cin>>N;
  int B[N];
  REP(i,N) B[i]=0;
  int A[N];
  REP(i,N){
    cin>>A[i];
    B[A[i]]++;
  }
  
  bool CAN=true;
  
  if(N%2==1){
    for(int i=0; i<=N/2; ++i){
      if((B[0]!=1)||(B[2*i]!=2&&i>0)) CAN=false;
    }
  }
  else{
    for(int i=0; i<N/2; ++i){
      if(B[2*i+1]!=2) CAN=false;
    }
  }
  
  if(CAN){
    ll A=1;
    for(int i=1; i<=N/2; ++i){
      A=A*2%MOD;
    }
    cout<<A<<endl;
  }
  else cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		i,j,k,n,m,x,y;
	int		a[256];
	double	ans = 0;
	
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d",&j);
		ans += (double)1/j;
	}
	
	printf("%.14lf\n", (double)1/ans);

	return 0;
}


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

int main(){
	int r,c,i,j;
	cin>>r>>c;
	int a[r][c];
	int b[r+1][c+1]={};
	for(i=0; i<r; i++){
		for(j=0; j<c; j++){
			cin>>a[i][j];
			b[i][j]=a[i][j];
			b[i][c]+=a[i][j];
			b[r][j]+=a[i][j];
			b[r][c]+=a[i][j];
		}
	}

	for(i=0; i<r+1; i++){
		for(j=0; j<c+1; j++){
			if(j!=0) cout<<" ";
			cout<<b[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3156
N,K = map(int,input().split())
ans = [0]*N
count = 0
for i in range(K):
  d = int(input())
  array = list(map(int,input().split()))
  for j in range(d):
    ans[array[j] - 1] += 1
for k in ans:
  if k == 0:
    count += 1
print(count)
   
  

Measured memory_bytes: 9132
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;

int main()
{
	int N;
	int ANS = 0;
	cin >> N;
	vector <int>hoge(3);
	for (int i = 0; i < 3; i++) {
		hoge[i] = (int)((int)N / pow(10, i)) % 10;
		if (hoge[i] == 9)hoge[i] = 1;
		else hoge[i] = 9;
		ANS += hoge[i] * pow(10, i);
	}
	cout << ANS;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template <typename E>
struct SegmentTree{
  using H = function<E(E,E)>;
  int n,height;
  H h;
  E ei;
  vector<E> laz;
  SegmentTree(H h,E ei):h(h),ei(ei){}  
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    laz.assign(2*n,ei);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    laz[k]=ei;
  }
  inline void thrust(int k){
    for(int i=height;i;i--) eval(k>>i);
  }
  void update(int a,int b,E x){
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
  }
  E get_val(int a){
    thrust(a+=n);
    return laz[a];
  }
  void set_val(int a,E x){
    thrust(a+=n);
    laz[a]=x;
  }
};
//END CUT HERE

struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed AOJ_DSL_2_D(){
  int n,q;
  cin>>n>>q;
  auto h=[](int a,int b){(void)a;return b;};  
  int ei=INT_MAX;
  SegmentTree<int> seg(h,ei);
  seg.init(n);
  for(int i=0;i<q;i++){
    int tp;
    cin>>tp;
    if(tp==0){
      int s,t,x;
      cin>>s>>t>>x;
      seg.update(s,t+1,x);
    }
    if(tp==1){
      int s;
      cin>>s;
      cout<<seg.get_val(s)<<"\n";
    }    
  }
  cout<<flush;
  return 0;  
}
/*
  verified on 2019/06/07
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D&lang=jp
*/

signed AOJ_DSL_2_E(){
  int n,q;
  cin>>n>>q;
  auto h=[](int a,int b){return a+b;};  
  int ei=0;
  SegmentTree<int> seg(h,ei);
  seg.init(n);
  for(int i=0;i<q;i++){
    int tp;
    cin>>tp;
    if(tp==0){
      int s,t,x;
      cin>>s>>t>>x;
      s--;
      seg.update(s,t,x);
    }
    if(tp==1){
      int s;
      cin>>s;
      s--;
      cout<<seg.get_val(s)<<"\n";
    }    
  }
  cout<<flush;
  return 0;  
}
/*
  verified on 2019/06/07
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_E&lang=jp
*/
signed main(){
  //AOJ_DSL_2_D();
  AOJ_DSL_2_E();
  return 0;
}



Measured memory_bytes: 3864
x, y = list(map(int,input().split()))

a= [1,3,5,7,8,10,12]
b= [4,6,9,11]
c= [2]

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9044
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a*b)%2)
		cout<<"Yes"<<endl;
	else if((a*b*2)%2)
		cout<<"Yes"<<endl;
	else if((a*b*3)%2)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
S = (stdin.readline().rstrip())
flag = True
if len(set(S)) == 2:
    flag = True
else:
    flag = False

for i in list(set(S)):
    if S.count(i) != 2:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define M 1000000007
#define SI(x) scanf("%d", &x)
#define PI(x) printf("%d\n", x)
#define SL(x) scanf("%I64d", &x)
#define PL(x) printf("%I64d\n", x)
#define PB push_back
#define MP make_pair

using namespace std;

int main()
{
    ll n, t;
    cin >> n >> t;

    ll a[n];
    for(int i = 0; i<n; i++)
        cin >> a[i];
    ll k = 1;
    ll k2 = 0;
    ll k3 = 0;
    ll cc = a[0];
    for(int i = 0; i<n; i++)
    {

        if(a[i+1]-a[i]>=t)
        {
            //cout << a[i] << " " << cc << endl;
            k3 += a[i] - cc + t;
            cc = a[i+1];
        }
        //cout << k3 << endl;
    }

    cout << k3 << endl;
}


Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <climits>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include<math.h>
#include <set>
#include <time.h>
#include <map>
#include <fstream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <numeric>
#include <unordered_map>
using namespace std;
#define sz(a) int((a).size())
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define vi vector<ll>
#define all(c) (c).begin(),(c).end()
#define allr(c) (c).rbegin(),(c).rend()
#define For(i,n) for(ll i=0;i<n;i++)
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define input(a,n) for(long long i=0;i<n;i++)cin>>a[i]
#define output(a,n) for(long long i=0;i<n;i++)cout<<a[i]<<" "
#define max3(a,b,c) max(max(a,b),c)
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(min(a,b),c)
#define min4(a,b,c,d) min(min3(a,b,c),d)
#define     she_taught_me_to_code cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ep 1e-10
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.second < b.second);
}
ll gcd(ll a,ll b)
{
    if (b == 0)
    return a;
    return gcd(b, a % b);
}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}
ll pow2(ll n)
{
    ll x=1;
    for(ll i=1;i<=n;i++)
    {
        x*=2;
    }
    return x;
}
#define N 1000000
vector<ll> adj[N];
vector<ll> v(N);
vector<bool> visited(N,0);
void DFSUtil(ll u)
{
    visited[u] = true;
    for (ll i=0; i<adj[u].size(); i++)
    {
        if (visited[adj[u][i]] == false)
        {
            DFSUtil(adj[u][i]);
        }
    }
}
void DFS(ll n)
{
    for (ll u=0; u<n; u++)
    {
        if (visited[u] == false)
        {
            DFSUtil(u);
        }
    }
}
void aE(ll u, ll v)
{
    adj[u].push_back(v);
}
int main()
{
    she_taught_me_to_code


    string s;
    cin>>s;
    ll n=s.size();
    for(ll i=0;i<n;i++)
    {
        for(ll j=i;j<n+1;j++)
        {
            string c=s,check="keyence";
            c.erase(c.begin()+i,c.begin()+j);
            if(c==check)
            {
                cout<<"YES";
                return 0;
            }
        }
    }
    cout<<"NO";
}


Measured memory_bytes: 31616
#include<iostream>
using namespace std;
int main() {
	double a;
	while (cin >> a) {
		if (a > 91.00){
			cout << "heavy";
		}
		else if (a > 81.00){
			cout << "light heavy";
		}
		else if (a > 75.00){
			cout << "middle";
		}
		else if (a > 69.00)
		{
			cout << "light middle";
		}
		else if (a > 64.00)
		{
			cout << "welter";
		}
		else if (a > 60.00)
		{
			cout << "light welter";
		}
		else if (a > 57.00)
		{
			cout << "light";
		}
		else if (a > 54.00)
		{
			cout << "feather";
		}
		else if (a > 51.00){
			cout << "bantam";
		}
		else if (a > 48.00)
		{
			cout << "fly";
		}
		else cout << "light fly";
		cout << endl;
	}
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, m;
ll a[100010];
vector<pli> v;
vector<ll> cand;

int main() {
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    sort(a, a+n);
    rep(i, m) {
        int b; ll c;
        cin >> b >> c;
        v.push_back(make_pair(c, b));
    }
    sort(v.begin(), v.end());

    int cnt = 0;
    for (int i = m-1; i >= 0; i--) {
        for (int j = 0; j < v[i].second; j++) {
            cand.push_back(v[i].first);
            cnt++;
            if (cnt >= n) break;
        }
    }
    rep(i, n - cnt) cand.push_back(0);

    ll ans = 0;
    rep(i, n) {
        ans += max(a[i], cand[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5616
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	rep(i, n){
		if(a[i] % 2 == 0){
			if(!((a[i] % 3 == 0) || (a[i] % 5 == 0))){
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main() {
  string s;
  cin >> s;
  if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")
  cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
    int N;
  	cin >>N;
    long long score=0;
    vector<long long>avec(N+1);
    vector<long long>bvec(N);
    for(int i=0;i<N+1;i++){
        cin >>avec[i];
    }
    for(int i=0;i<N;i++){
        cin >>bvec[i];
    }
    for(int i=0;i<N;i++){
        if(bvec[N-i-1] >=avec[N-i]){
            bvec[N-i-1] -=avec[N-i];
            score +=avec[N-i];
            avec[N-i] = 0;
        }
        if(bvec[N-i-1] < avec[N-i]){
            score +=bvec[N-i-1];
            continue;
        }
        if(bvec[N-i-1] >=avec[N-i-1]){
            bvec[N-i-1] -=avec[N-i-1];
            score +=avec[N-i-1];
            avec[N-i-1] = 0;
        }
        if(bvec[N-i-1] < avec[N-i-1]){
            score +=bvec[N-i-1];
            avec[N-i-1] -=bvec[N-i-1];
        }
    }
    cout << score <<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cctype>
#include <climits>
#include <fstream>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second



int main(){
	string s="erasedream";
	int ans = 0;
	int index;
	cin >> s;
	index = s.size();
	while(index >0){
		if(s.substr(index-5,5)=="dream" || s.substr(index-5,5)=="erase"){
			index = index-5;
		}else if(s.substr(index-6,6)=="eraser"){
			index = index-6;
		}else if(s.substr(index-7,7)=="dreamer"){
			index = index-7;
		}else{
			ans = 1;
			break;
		}
	}

		if(ans == 1){
			cout << "NO" << endl;
		}else{
			cout << "YES" << endl;
		}
	


	return 0;
}


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

int		main(void)
{
	int N;

	cin >> N;
	int mx = 0, sum = 0;

	for (int i = 0; i < N; i++)
	{
		int tmp;

		cin >> tmp;
		sum += tmp;
		mx = max(mx, tmp);
	}
	if (mx < sum - mx)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256