akhauriyash/Code-Regression huggingface dataset:
#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>;

char maze[21][21];
int dist[21][21];

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

void reset_dist(){
    rep(i,21) rep(j,21) dist[i][j]=0;
}

int main(){
    int h,w;
    cin >> h >> w;
    int ans=0;

    rep(i,21)rep(j,21){
        maze[i][j]='#';
        dist[i][j]=0;
    }

    rep(i,h){
        string s;
        cin >> s;
        rep(j,s.size()) maze[i+1][j+1]=s[j];
    }
    /*
    rep(i,21){
        rep(j,21){
            cout<<maze[i][j];
        }
        cout<<endl;
    }*/

    //int count=0;
    for(int start=0;start<400;++start){
        for(int goal=start+1;goal<400;++goal){
            int sx,sy,gx,gy;
            sx = start%20 +1;
            sy = (start/20)%20 +1;
            gx = goal%20 +1;
            gy = (goal/20)%20 +1;
            //sy = 1;
            //sx = 2;
            //gy = 2;
            //gx = 3;
            //cout << "now" << sy  << ":"<< sx <<":"<< gy <<":"<< gx << endl;
            if(maze[sy][sx]=='.' && maze[gy][gx]=='.'){
                //scout<<"s: " <<sy<<sx<< "g:"<<gy<<gx<<endl;
                //count++;
                reset_dist();
    queue<P> Q;
    P p(sy,sx);
    Q.push(p);
    while(1){
        //scout <<"go" << endl;
        int x,y;
        P p(0,0);
        p = Q.front();
        Q.pop();
        x = p.second;
        y = p.first;
        //cout << "now ";
        //cout << "y:"<< y << "x:" << x <<endl;
        //cout << dist[y][x] << endl;
        if(y==gy and x==gx){
            if(ans<dist[gy][gx]) {
                //cout << "y: ";
                ans=dist[gy][gx];
                //cout << dist[gy][gx];
                //cout << "ans" << ans << endl;
            }
            break;
        }
        rep(i,4){
            if(y+dy[i]>20 || x+dx[i]>20) continue;
            if(maze[y+dy[i]][x+dx[i]]=='.'){
                if(dist[y+dy[i]][x+dx[i]]==0){
                    P cand(0,0);
                    cand.first = y+dy[i];
                    cand.second = x+dx[i];
                    Q.push(cand);
                    dist[y+dy[i]][x+dx[i]]=dist[y][x]+1;
                    //cout << "append ";
                    //cout << "y:"<< cand.first << "x:" << cand.second <<endl;
                    
                }
            }

        }
    }



            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define N 300005
using namespace std;


bool p[N];
int num[N];

int main(){

  for(int i=0;i<N;i++){
    if(i%7 == 1 || i%7 == 6)p[i] = true;
    else p[i] = false;
  }
  p[1] = false;

  for(int i=6;i*i<N;i++){
    if(p[i]){
      for(int j=2*i;j<N;j+=i)p[j] = false;
    }
  }

  vector<int> v;
  for(int i=0;i<N;i++)
    if(p[i])v.push_back(i);
  
  int n;
  while(cin >> n ,n!=1){
    cout << n << ":";
    for(int i=0;i<(int)v.size();i++){
      if( !(n%v[i]) )cout << " " << v[i];
    }
    cout << endl;
  }
    
}

Measured memory_bytes: 1464
<>;
@w=split/ /,<>;
($s1,$s2)=(0,0);
$s2+=$_ foreach(@w);
foreach(@w){
 ($t1,$t2)=($s1+$_,$s2-$_);
 ($ds,$dt)=($s2-$s1,$t2-$t1);
 if($dt<0){
  if((-$dt)<$ds){
   $a=-$dt;
  }else{
   $a=$ds;
  }
  print$a;
  last;
 }else{
  ($s1,$s2)=($t1,$t2);
 }
}

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

int main(){
	int n;
	cin >> n;
	for(int i=0; i<n; ++i){
		int x, y, b, p;
		scanf(" %d %d %d %d", &x, &y, &b, &p);
		
		int price = ( ((b>=5) ? b : 5)*x+((p>=2) ? p : 2)*y)*0.8;
		if(price > x*b+y*p) price=x*b+y*p;
	
		printf("%d\n", price);
	}

	return 0;
}

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

using namespace std;

int Number[9];
vector<int> UnknownPos;
vector<int> NotUsed;
bool Used[10];


bool judge() {
	int target, currentSum;

	target = Number[6] * 100 + Number[7] * 10 + Number[8];
	currentSum = Number[0] + Number[1] * 10 + Number[2] + Number[3] * 100 + Number[4] * 10 + Number[5];

	//cout << "target" << target << endl;
	//cout << "currentSum" << currentSum << endl;
	if (target == currentSum) {
		return true;
	}
	return false;
}

void solve() {
	int size, cnt;

	for (int i = 1; i < 10; ++i) {
		if (Used[i]) {
			continue;
		}
		NotUsed.push_back(i);
	}
	sort(NotUsed.begin(), NotUsed.end());

	size = UnknownPos.size();
	cnt = 0;
	do {
		for (int i = 0; i < size; ++i) {
			Number[UnknownPos[i]] = NotUsed[i];
		}
		if (judge()) {
			++cnt;
		}
	} while (next_permutation(NotUsed.begin(), NotUsed.end()));

	cout << cnt << endl;
}

int main() {

	UnknownPos.clear();
	NotUsed.clear();
	memset(Used, false, sizeof(Used));
	for (int i = 0; i < 9; ++i) {
		cin >> Number[i];
		if (Number[i] == -1) {
			UnknownPos.push_back(i);
			continue;
		}
		Used[Number[i]] = true;
	}
	solve();
	
	return 0;
}



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

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

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

    for(int i=1; i<n+1; i++){
        printf("node %d: key = %d, ", i, ppp[i]);
        if(i>=2) printf("parent key = %d, ", ppp[i/2]);
        if(i*2<=n) printf("left key = %d, ", ppp[i*2]);
        int aaa = i*2+1;
        if(aaa<=n) printf("right key = %d, ", ppp[i*2+1]);
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   int a[n],n2=0,n4=0;
   for(int i=0;i<n;i++){
       cin >> a[i];
       if(a[i]%4==0) n4++;
       else if(a[i]%2==0) n2++;
   } 
   int n0 = n-n2-n4;
   if(n0<=n4+(n2==0)) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 3984
#include <atcoder/fenwicktree>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int N, Q;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> fw(N);
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        fw.add(i, a);
    }
    for (int z = 0; z < Q; z++) {
        int t;
        cin >> t;
        if (t == 0) {
            int p;
            ll x;
            cin >> p >> x;
            fw.add(p, x);
        }else {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << "\n";
        }
    }
}

Measured memory_bytes: 8216
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

string s;
ll ans;
ll x;

int main()
{
    cin>>s;
    for(ll i = (ll)s.size() - 1; i >= 0; i--)
    {
        ll t = s[i] - '0';
        t += x;
        x = 0;
        if(t >= 6) x = 1, ans += 10 - t;
        else if(t == 5 && i > 0 && s[i - 1] >= '5') x = 1, ans += 10 - t;
        else ans += t;
    }
    if(x) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1412
s = input()
prev = part = ""
ans = [0]*len(s)


def calc_lr(block):
    retval = -(-len(block)//2), len(block)//2
    return [retval[::-1], retval][block.index("L") % 2]


for idx, c in enumerate(s):
    if (prev, c) == ("R", "L"):
        i, j = idx-1, idx

    if (prev, c) == ("L", "R"):
        ans[i], ans[j] = calc_lr(part)
        part = c
    else:
        part += c
    prev = c
else:
    ans[i], ans[j] = calc_lr(part)


print(*ans)

Measured memory_bytes: 6512
//07
#include<iostream>
#include<algorithm>

#define T(h,m) ((h)*60+(m))

using namespace std;

int main(){
  for(int s;cin>>s,s;){
    int sh,sm;
    int t,th,tm;
    cin>>sh>>sm>>t>>th>>tm;
    s--;
    t--;
    int f[7][7]={{0,300,500,600,700,1350,1650},{0,0,350,450,600,1150,1500},{0,0,0,250,400,1000,1350},{0,0,0,0,250,850,1300},{0,0,0,0,0,600,1150},{0,0,0,0,0,0,500},{0,0,0,0,0,0,0}};
    int d[7][7]={{0,0,0,0,0,0,0},{6,0,0,0,0,0,0},{13,7,0,0,0,0,0},{18,12,5,0,0,0,0},{23,17,10,5,0,0,0},{43,37,30,25,20,0,0},{58,52,45,40,35,15}};
    int sum=max(f[s][t],f[t][s]);
    if(!((T(sh,sm)<T(17,30)&&T(19,30)<T(th,tm))||T(sh,sm)>T(19,30)||T(th,tm)<T(17,30))&&max(d[s][t],d[t][s])<=40){
      sum=sum/2+((sum%100==50)?25:0);
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;if(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


pii a[N];
int last[N],f[N],sz[N],fac[N];
int find(int a){return f[a]==a?a:f[a]=find(f[a]);}
void Add(int a,int b){
    a=find(a),b=find(b);
    if(a==b)return;
    if(sz[a]<sz[b])swap(a,b);
    sz[a]+=sz[b];
    f[b]=a;
}
unordered_map<int,int>g[N];
int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    //cout<<setprecision(9)<<fixed;
    //cerr<<setprecision(9)<<fixed;
    int T,i,j,k,ca=0,m,K,n;
    int x,y;
    scanf("%d%d%d",&n,&x,&y);
    rep(i,0,n)scanf("%d%d",&a[i].y,&a[i].x),a[i].y--;
    sort(a,a+n);
    rep(i,0,n)last[i]=-1;
    pii s[2];
    rep(i,0,2)s[i]={inf,inf};
    rep(i,0,n)f[i]=i,sz[i]=1;
    rep(i,0,n){
        k=a[i].y;
        if(last[k]==-1){
            last[k]=i;
            if(s[0].x>a[i].x)s[1]=s[0],s[0]={a[i].x,i};
            else if(s[1].x>a[i].x)s[1]={a[i].x,i};
        }
    }
    rep(i,0,n){
        k=a[i].y;K=x-a[i].x;j=last[k];
        if(j!=-1&&a[j].x<=K){
            Add(i,j);
        }
        K=y-a[i].x;
        if(s[0].x<=K&&a[s[0].y].y!=k)Add(s[0].y,i);
        else if(s[1].x<=K&&a[s[1].y].y!=k)Add(s[1].y,i);
    }
    rep(i,0,n){
        k=a[i].y;
        j=find(i);
        g[j][k]++;
    }
    ll ans=1;
    fac[0]=1;
    rep(i,1,n+1)fac[i]=fac[i-1]*(ll)(i)%mod;
    rep(i,0,n)if(f[i]==i){
        ll q=1;
        for(auto o:g[i]){
            q=q*fac[o.y]%mod;
        }
        //cerr<<i<<" "<<sz[i]<<" "<<q<<"\n";
        ans=ans*fac[sz[i]]%mod*pow((int)q,mod-2)%mod;
        //DBG(ans)
    }
    printf("%lld\n",ans);
    //cerr<<clock()*1./CLOCKS_PER_SEC<<"ms\n";
    return 0;
}

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

int main()
{
    int cat,dog,x;
    cin>>cat>>dog>>x;
if(cat==dog && cat==x)cout<<"Yes";
    if(cat+dog>x && cat<=x)cout<<"YES";
    else cout<<"NO";


    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
char s[200];
bool vis[200],vis1[200];
int t,ans=0;
int main()
{
	scanf("%d%s",&n,s);
	for (int i=0;i<n-1;i++)
	{
		t=0;
		for (int k='a';k<='z';k++) vis[k]=vis1[k]=false;
		for (int k=0;k<=i;k++) vis[s[k]]=true;
		for (int k=i+1;k<n;k++) if (vis[s[k]]&&!vis1[s[k]])
		{
			t++;
			vis1[s[k]]=true;
		}
		if (t>ans) ans=t;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
#include<iomanip>
#include<bitset>
#define mod 1000000007
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

ll n,m;
ll x[200010],rui[200010];
int main(){
    cin>>n>>m;
    rui[0]=0;
    for(int i=0;i<n;i++){
	cin>>x[i];
    }
    sort(x,x+n,greater<ll>());
    for(int i=0;i<n;i++){
	rui[i+1]=rui[i]+x[i];
    }
    ll ans=1e17;
    for(ll k=1;k<=n;k++){
	ll res=m*(n+k);
	for(ll p=0;p*k<n;p++){
	    ll l=p*k,r=(p+1)*k-1;
	    chmin(r,n-1);
	    ll kei=2*p+3;
	    if(p==0)kei=5;
	    res+=kei*(rui[r+1]-rui[l]);
	    chmin(res,(ll)1e17);
	}
	chmin(ans,res);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	static{
		for(int i=0;i<30000;i++){
//			System.out.print("J");
		}
		for(int i=0;i<30000;i++){
//			System.out.print("O");
		}
		for(int i=0;i<30000;i++){
//			System.out.print("I");
		}
	}
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		char[] s=cin.next().toCharArray();
		int N=300000;
		/*
		s=new char[N*3];
		
		for(int i=0;i<N;i++){
			s[i]='J';
		}
		for(int i=0;i<N;i++){
			s[i+N*1]='O';
		}
		for(int i=0;i<N;i++){
			s[i+N*2]='I';
		}
		*/
		String J="J";
		String O="O";
		String I="I";
		int ans=0;
		for(int i=0;i<s.length;i++){
			while(i<s.length&&s[i]=='J'){
				int cntj=0;

				while(i<s.length&&s[i]=='J'){
					cntj++;
					i++;
				}
				int cnto=0;
				while(i<s.length&&s[i]=='O'){
					cnto++;
					i++;
				}
				if(cntj<cnto){
					continue;
				}
				int cnti=0;
				while(i<s.length&&s[i]=='I'){
					cnti++;
					i++;
				}
//				System.out.println(cntj+" "+cnto+" "+cnti);
				if(cnto<=cnti){
					ans=Math.max(ans, cnto);
				}
			}
		}
		System.out.println(ans);
	}

}

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

int main()
{
	int n;
	while (cin>>n) 
	{
		bool prime[500000];
		fill(prime,prime+500000,0);
		vector<int> nums;
		for(int i = 2; i < 500000; ++i)
		{
			if(prime[i]) continue;
			nums.push_back(i);
			for(int j = i*2; j < 500000; j+=i)
			{
				prime[j]=true;
			}
		}

		vector<int>::iterator it=lower_bound(nums.begin(),nums.end(),n);
		if(*(it-1)!=n) cout<<*(it-1);
		else cout<<*(it-2);

		it=upper_bound(nums.begin(),nums.end(),n);
		cout<<" "<<*it<<endl;
	}
  return 0;
}

Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	ll N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	N--;
	bool OK = false;
	rep(i, N + 1) {
		ll X = (2 * i - N) * C - (D - C) * (N - i);
		ll Y = (2 * i - N) * C + (D - C) * i;
		if (X <= B - A && B - A <= Y) OK = true;
	}
	if (OK) co("YES");
	else co("NO");

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner cin = new Scanner(System.in);

		int target = cin.nextInt();

		long list[] = new long[target];

		for(int i=0;i<target;i++){
			list[i] = cin.nextLong();
		}

		long sum_tmp_minus=0L;
		long sum_tmp_plus=0L;
		long count_minus=0;
		long count_plus=0;

		for(int k=0;k<target;k++){
			sum_tmp_minus += list[k];
			if(k%2==0){
				if(sum_tmp_minus>=0){
					count_minus += sum_tmp_minus+1;
					sum_tmp_minus = -1;
				}
			}else{
				if(sum_tmp_minus<=0){
					count_minus += 1-sum_tmp_minus;
					sum_tmp_minus=1;
				}
			}
		}
		for(int l=0;l<target;l++){
			sum_tmp_plus += list[l];
			if(l%2==0){
				if(sum_tmp_plus<=0){
					count_plus += 1-sum_tmp_plus;
					sum_tmp_plus = 1;
				}
			}else{
				if(sum_tmp_plus>=0){
					count_plus += sum_tmp_plus+1;
					sum_tmp_plus=-1;
				}
			}
		}

		System.out.println(Math.min(count_minus, count_plus));

	}
}


Measured memory_bytes: 59464
#include<iostream>

using namespace std;

int A,B,C,X,Y;
int ans=0;

int main(){
	cin>>A>>B>>C>>X>>Y;
	
	int a=C;
	int b=C;

	if(A-a+B-b<=0){
		cout<<A*X+B*Y<<endl;
		return 0;
	}else{


	if(A>C*2){
		ans+=C*2*X;
		Y-=X;
		X=0;
		if(Y<0)Y=0;
	}
	if(B>C*2){
		ans+=C*2*Y;
		X-=Y;
		Y=0;
		if(X<0)X=0;
	}
	if(Y==0){
		cout<<ans+X*A<<endl;
		return 0;
	}
	if(X==0){
		cout<<ans+Y*B<<endl;
		return 0;
	}
	}

	
		int ma=max(X,Y);
		int mi=min(X,Y);
		ans+=mi*C*2;


		
		if(X<Y)ans+=B*(ma-mi);
		else if(X>Y)ans+=A*(ma-mi);


	cout<<ans<<endl;

	
	return 0;
}





Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> PP;
#define REP(i,a,n) for(int i = (a); i < (int)(n); ++i)
#define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i)
#define FLOAT setprecision(16)
#define SPEEDUP {cin.tie(0); ios::sync_with_stdio(false);}
#define INSIDE(i,j,H,W) ((i) >= 0 && (i) < (H) && (j) >= 0 && (j) < (W))
#define YesNo(b) (b ? "Yes" : "No")
#define YESNO(b) (b ? "YES" : "NO")
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

template <class T, class U>
istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U>
ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N>
void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); }
template <class T, class TCompatible, size_t M, size_t N>
void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }

// all_of
// partial_sum, adjacent_difference

#if _DEBUG
#include "IntMod.h"
#include "Union_Find.h"
#include "Graph.h"
#include "Range.h"
#include "Global.h"
#include "Flow_Solver.h"
#include "Tree.h"
#include "Suffix_Array.h"
#endif

#if 1234567891
#include <array>
#include <unordered_set>
#include <unordered_map>
template<typename T>
using PriorityQ = priority_queue<T, vector<T>, greater<T> >;	// コスト小を優先
#endif

string s;
int H[200001];	// 累積和
int MIN[1 << 26];
int main() {
	cin >> s;
	int N = s.size();
	REP(i, 0, N) {
		H[i + 1] = H[i] ^ (1 << (s[i] - 'a'));
	}

	if (H[N] == H[0]) {
		cout << 1 << endl;
		return 0;
	}

	Fill(MIN, INF);
	MIN[0] = 0;
	REP(i, 1, N + 1) {
		int dp = MIN[H[i]];
		REP(c, 0, 26) {
			int ref = (H[i] ^ (1 << c));
			dp = min(dp, MIN[ref]);
		}
		MIN[H[i]] = min(MIN[H[i]], dp + 1);
	}

	cout << MIN[H[N]] << endl;
	return 0;
}


Measured memory_bytes: 263556
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

lint mod=1e9+7;

int main()
{
	int N;
	lint A[100010]={};
	
	cin >> N;
	for(int i=1;i<=N;i++)
		cin >> A[i];
	
	lint xyz[100010][3]={};
	for(int i=1;i<=N;i++)
	{
		xyz[i][0]=xyz[i-1][0];
		xyz[i][1]=xyz[i-1][1];
		xyz[i][2]=xyz[i-1][2];

		for(int j=0;j<3;j++)
		{
			if(xyz[i][j]==A[i])
			{
				xyz[i][j]++;
				break;
			}
		}
	}

	lint cnt[100010]={};
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<3;j++)
			if(xyz[i-1][j]==A[i])
				cnt[i]++;
	}

	lint ans=1;
	for(int i=1;i<=N;i++)
	{
		ans*=cnt[i];
		ans%=mod;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

struct mint {
	ll x;
	mint(ll x = 0) :x(x% mod) {}
	mint& operator+=(const mint a) {
		(x += a.x) %= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		(x += mod - a.x) %= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
};

mint c[4005][4005];
void init() {
	c[0][0] = 1;
	for (int i = 0; i <= 4000; i++) {
		for (int j = 0; j <= i; j++) {
			c[i + 1][j] += c[i][j];
			c[i + 1][j + 1] += c[i][j];
		}
	}
}
mint comb(int n, int k) {
	return c[n][k];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	ll n, k;
	cin >> n >> k;
	for (ll i = 1; i <= k; ++i) {
		mint ans = comb(n - k + 1, i) * comb(k - 1, i - 1);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 125568
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int t;
	cin>>t;
	double sum=0;
	while(t--){
		double n;
		string s;
		cin>>n>>s;
		if(s=="JPY") sum+=n;
		else sum+=n*380000.0;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3820
def main():
    a, b, c = map(int, input().split())
    if a == b and b == c:
        print("No")
    elif a == b:
        print("Yes")
    elif b == c:
        print("Yes")
    elif c == a:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		int a[7] = {};
		rep(i, 0, n) {
			int b; cin >> b;
			if (b >= 60)a[6]++;
			else a[b / 10]++;
		}
		rep(i, 0, 7) {
			cout << a[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3008
#include <iostream>
#include <cstdio>
#include <set>
#include <string>

#define rep(X, Y) for( int (X) = 0; (X) < (Y); ++(X) )
#define rept(X, Y, Z) for( int (X) = (Y); (X) < (Z); ++(X) )

int N, K;
std::string num[11];
std::set<std::string> data;

void f( int used, int cnt, std::string d ){
	if( cnt == 0 ){
		data.insert(d);
		return;
	}

	rep( i, N ){
		if( used & (1 << i) ) continue;

		f( used | 1 << i, cnt - 1, d + num[i] );
	}
}

int main(){
	while( scanf("%d%d", &N, &K), N * K ){
		data.clear();

		rep( i, N ) std::cin >> num[i];

		f( 0, K, "" );
		
		std::cout << data.size() << std::endl;
	}
}

Measured memory_bytes: 1492
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> a(n);

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


    for(int i = 1;i < n+1;i ++){
        ans += b[i] * (b[i] - 1) / 2;
    }

    for(int i = 0;i < n;i ++){
        int t = b[a[i]];
        cout << ans - t * (t-1) / 2 + (t-1) * (t-2) /2 << endl;
    }
}



Measured memory_bytes: 5760
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, x; cin >> n >> x;
	vector<ll> nums(n); fore(e, nums) cin >> e;
	int ans = 1, cur = 0;
	fore(e, nums) {
		cur += e;
		if(cur > x) break;
		ans++;
	}
	println(ans);
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, p, c=1, t=0, tmp;
  cin >> n >> p;
  if (n == 1){
    cout << p << endl;
    return 0;
  }
  tmp = p;
  forll(i, 2, p+1){
	if (pow(i, n) > tmp)
	  break;
	while(tmp % (ll)pow(i, n) == 0){
	  tmp /= (ll)pow(i, n);
	  c *= i;
	}
  }
  cout << c << endl;
}


Measured memory_bytes: 256
N = int(input())
a = []
for _ in range(N):
    a.append(int(input()))
index = 0
ans = 0
while N > 0:
    index = a[index]-1
    if (index == 1):
        print(ans+1)
        quit()
    N-=1
    ans+=1
print(-1)


Measured memory_bytes: 7084
import sys

sys.setrecursionlimit(10 ** 7)
N, Q = map(int, input().split(' '))
input = sys.stdin.readline

tree = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)
memo = [0] * (N)
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    memo[p] += x


def dfs(v, par):
    for i in tree[v]:
        if i == par:
            continue
        memo[i] += memo[v]
        dfs(i, v)


dfs(0, -1)

print(*memo)


Measured memory_bytes: 230960
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N = int(input())

a = 1
ans = len(str(N))

while a*a <= N:
    if N%a == 0:
        b = N//a
        tmp = len(str(b))
        ans = min(ans, tmp)
    a += 1

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()
n=I()
lis=[[]for i in range(n)]
for i in range(n):
    u=I()
    for j in range(u):
        a,b=MI()
        lis[i].append([a,b])
#print(lis)
z=[]
for x in range(2**n):
    u=[]
    for j in range(n):
        u.append(x%2)
        x=x>>1
    #print(u)
    count2=0
    for i in range(n):
        if u[i]==1:
            count=0
            for k in range(len(lis[i])):
                if lis[i][k][1]==u[lis[i][k][0]-1]:
                    count+=1
            if count==len(lis[i]):
                count2+=1
    if count2==sum(u):
        z.append(sum(u))
print(max(z))

Measured memory_bytes: 3776
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  string ans;
  if (a > 0 && b > 0) {
    ans = "Positive";
  } else if ((a <= 0 && b >= 0) || (a >= 0 && b <= 0)) {
    ans = "Zero";
  } else if ((b % 2 - a % 2) % 2) {
    ans = "Positive";
  } else {
    ans = "Negative";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 764
import java.util.*; 

public class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int x,y;
        int t;
        int num;
        x = stdIn.nextInt();
        y = stdIn.nextInt();

        if(x>y){
            t=y;
            y=x;
            x=t;
        }

        num = x%y;
        while(num!=0){
            x = num;
            if(y>x){
                t=x;
                x=y;
                y=t;
            }
            if(x%y==0){
                break;
            }
            num = x%y;
        }
        System.out.println(y);
    }
}


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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    int t=n;
    vector<int> ans;
    while(t>0){
        for (int i = m; i >= 0; --i) {
            if(i==0){
                cout<<-1<<endl;
                return 0;
            }
            if(t-i<0)continue;
            if(s[t-i]=='0'){
                t-=i;
                ans.push_back(i);
                break;
            }
        }
    }
    reverse(ans.rbegin(),ans.rend());
    for (int i = 0; i < ans.size()-1; ++i) {
        cout<<ans[i]<<" ";
    }
    cout<<ans.back()<<endl;
    return 0;
}

Measured memory_bytes: 1144
N = int(input())
A = tuple(map(int,input().split()))

left_amin = [0]*N

stack = [(0,-1)]

for i,a in enumerate(A):
    while stack[-1][0] > a:
        stack.pop()
    left_amin[i] = stack[-1][1]
    stack.append((a,i))

right_amin = [0]*N

stack = [(0,N)]

for i,a in zip(reversed(range(N)),reversed(A)):
    while stack[-1][0] > a:
        stack.pop()
    right_amin[i] = stack[-1][1]
    stack.append((a,i))


res = 0

for i,(l,r,a) in enumerate(zip(left_amin,right_amin,A)):
    res += a*(i-l)*(r-i)
print(res)

Measured memory_bytes: 133728
#include<stdio.h>
#include<math.h>

int main(void) {

	int X;
	int i;
	int flag;

	scanf("%d", &X);

	while (1) {
		flag = 0;
		
		for (i = 2; i < sqrt(X); i++) {
			if (X%i == 0) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			printf("%d", X);
			return;
		}

		X++;
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
using namespace std;
int main(int argc, char* argv[])
{
	int A,B,C;
	cin>>A>>B>>C;
	map<int,int> myMap;
	map<int,int>::iterator mit;
	myMap[A]=1;
	int ans=1;
	mit=myMap.find(B);
	if (mit==myMap.end()){
		myMap[B]=1;
		ans++;
	}
	mit=myMap.find(C);
	if (mit==myMap.end()){
		myMap[C]=1;
		ans++;
	}
	if (ans==2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

L1 = []
L2 = []
ans = "No"
if N%2 == 0:
    for i in range(N//2):
        L1.append(S[i])
    for i in range(N//2, N):
        L2.append(S[i])
    if L1 == L2:
        ans = "Yes"
        
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;}
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0

// 0 false, 1 true 
// string number to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll h, w, m; cin >> h >> w >> m;
    vector<ll> gyo(h);
    vector<ll> retsu(w);
    map<pair<ll, ll>, ll> mp;

    rep(i, m){
        ll x, y; cin >> x >> y;
        x--; y--;
        gyo[x] += 1;
        retsu[y] += 1;
        mp[make_pair(x, y)]++;
    }

    
    vector<ll> R;
    vector<ll> C;
    ll max_x = 0, max_y = 0;
    rep(i, h){
        if(max_x < gyo[i]){
            R.clear();
            max_x = gyo[i];
            R.push_back(i);
        }else if(max_x == gyo[i]){
            R.push_back(i);
        }
    }
    rep(i, w){
        if(max_y < retsu[i]){
            C.clear();
            max_y = retsu[i];
            C.push_back(i);

        }else if(max_y == retsu[i]){
            C.push_back(i);
        }
    }

    ll ans = max_x + max_y;
    bool flag = false;
    rep(i, R.size()){
        rep(j, C.size()){
            if(mp[make_pair(R[i], C[j])] == (ll)0){
                flag = true;
                break;
            }
        }
        if(flag){
            break;
        }
    }
    
    if(flag){
        cout << ans << endl;
    }else{
        cout << ans -1 << endl;
    }
    /*
    if(mp[make_pair(max_x, max_y)] > (ll)0){
        ans -=1;
    }
    
    cout << ans << endl;
    */
    

}

Measured memory_bytes: 35064
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 105;
int num[maxn];
int main(void) {
	for(int i = 1; i <= 9; i ++) {
		for(int j = 1; j <= i; j ++) {
			num[i * j] = 1;
		}
	}
	int n;
	scanf("%d",&n);
	if(num[n]) printf("Yes\n");
	else printf("No\n");
	return 0;
} 

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

using namespace std;

int main(){
int h,w;
while(1){
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if((j%2==0&&i%2==0)||(i%2!=0&&j%2!=0))cout<<"#";
        else cout<<".";
    }
    cout<<endl;
}
cout<<endl;

}
}




Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<pair<long long, int>> S(N);
  for (int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    S[i] = make_pair(A, B);
  }
  sort(S.begin(), S.end());
  long long c = 0;
  int t = 0;
  for (int i = 0; i < N; i++){
    long long a = S[i].first;
    int b = S[i].second;
    if (t + b < M){
      t += b;
      c += a * b;
    } else {
      c += a * (M - t);
      break;
    }
  }
  cout << c;
}

Measured memory_bytes: 1792
A, B = map(int, input().split())
ret, b = "", 1
for i in range(45):
    f = lambda b, x: b*((x+1)//(b*2)) + max((x+1) % (b*2) - b, 0)
    ret = str((f(b, B) - f(b, A-1)) % 2) + ret
    b *= 2
ans, b = 0, 1
for i in range(45):
    ans += b * int(ret[44 - i])
    b *= 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  VEC<LL> a(n), b(n);
  REP(i, 0, n) cin >> a[i];
  REP(i, 0, n) cin >> b[i];

  LL lsum = 0;
  int lnum = 0;
  VEC<LL> sup;
  REP(i, 0, n) {
    int d = a[i] - b[i];
    if (d > 0) {
      sup.push_back(d);
    } else if (d < 0) {
      lsum += d;
      ++lnum;
    }
  }
  sort(ALL(sup));
  LL ans = lnum;
  //DUMP(ans, lsum, sup);
  while (!sup.empty() && lsum < 0) {
    LL s = sup.back();
    sup.pop_back();
    lsum += s;
    ++ans;
    if (lsum >= 0) {
      break;
    }
  }
  //DUMP(ans, lsum, sup);
  if (lsum >= 0) cout << ans << endl;
  else cout<<-1<<endl;

  return 0;
}


Measured memory_bytes: 2428
k, s = gets.split.map(&:to_i)
exit 1 if k < 2 || k > 2500 || s < 0 || s > 3 * k
puts (0..k).map{|x| [[s - x, k].min - [s - x - k, 0].max + 1, 0].max}.inject(&:+)

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

char *demangle(const char *demangle)
{
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}

int main()
{
    string S, M = "ATCG";
    cin >> S;
    int N = S.size();
    int ans = 0, cnt;
    for (int i = 0; i < N; i++)
    {
        if (M.find(S[i]) != -1)
        {
            cnt++;
            ans = max(ans, cnt);
        }
        else
        {
            cnt = 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll ans = 0;
    ll x;
    cin >> x;
    ans += x / 500 * 1000;
    x -= ans / 2;
//    cout << x << endl;
    ans += x/5 * 5;
    cout << ans << endl;

}

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

using namespace std;

class Solver {
    public:
        string line;
        int solve() {
            int count = 0;
            for (int p = 0; p < 3; ++p) {
                for (int q = 0; q < 3; ++q) {
                    for (int r = 0; r < 3; ++r) {
                        if (eval(p, q, r, 0, line.length()) == 2) {
                            ++count;
                        }
                    }
                }
            }
            return count;
        }
        int eval(int p, int q, int r, int begin, int end) {
            int nest = 0;
            int bracket_begin;
            stack<int> values;
            stack<char> operators;
            for (int i = begin; i < end; ++i) {
                int x = -1;
                if (nest == 0) {
                    if ('0' <= line[i] && line[i] <= '2') {
                        x = line[i] - '0';
                    } else if (line[i] == 'P') {
                        x = p;
                    } else if (line[i] == 'Q') {
                        x = q;
                    } else if (line[i] == 'R') {
                        x = r;
                    } else if (line[i] != '(' && line[i] != ')') {
                        operators.push(line[i]);
                    }
                }
                if (line[i] == '(') {
                    if (nest == 0) {
                        bracket_begin = i;
                    }
                    ++nest;
                } else if (line[i] == ')') {
                    --nest;
                    if (nest == 0) {
                        x = eval(p, q, r, bracket_begin + 1, i);
                    }
                }
                if (x < 0) {
                    continue;
                }
                while (!operators.empty()) {
                    char op = operators.top();
                    if (op == '-') {
                        x = 2 - x;
                    } else if (op == '+') {
                        x = max(x, values.top());
                        values.pop();
                    } else if (op == '*') {
                        x = min(x, values.top());
                        values.pop();
                    }
                    operators.pop();
                }
                values.push(x);
            }
            return values.top();
        }
};

int main() {
    Solver s;
    while (true) {
        cin >> s.line;
        if (s.line == ".") {
            return 0;
        }
        cout << s.solve() << endl;
    }
}

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


long long n;
long long bit[2010000];

//aの位置にwを追加
void add(long long a,long long w){
    a++;
    for(int x=a;x<=n+1;x+=(x&(-x)) ){
        bit[x] += w;
    }
}

//v[0] + ... + v[a-1]
long long sum(long long a){
    long long ret=0;
    for(int x=a;x>0;x-=(x&(-x)) ){
        ret+=bit[x];
    }
    return ret;
}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll k;
    cin>>n>>k;
    map<ll,ll> mp;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i] -= k;
        if(i) a[i] += a[i-1];
        mp[a[i]]=0;
    }
    ll cnt = 0;
    mp[-1e18]=0;
    for(auto &i:mp){
        i.second = cnt;
        cnt++;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(a[i]>=0) ans++;
        ans += sum(mp[a[i]]+1);
        add(mp[a[i]],1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 10980
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x, y; cin >> x >> y;
  if(abs(x-y) <= 1) cout << "Brown" << endk;
  else cout << "Alice" << endk;
  return 0;
}


Measured memory_bytes: 3640
#atcoder 
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())

d1=a1-b1
d2=a2-b2

if d1*d2>0:
    print(0)
else:
    if d1>0 and d2<0:
        plus=d1*t1+d2*t2
        if plus>0:
            print(0)
        elif plus==0:
            print("infinity")
        elif plus<0:
            d=-plus
            k=d1*t1
            if k%d==0:
                print(2*k//d)
            else:
                print(2*(k//d)+1)
    else:
        d1=-d1
        d2=-d2
        plus=d1*t1+d2*t2
        if plus>0:
            print(0)
        elif plus==0:
            print("infinity")
        elif plus<0:
            d=-plus
            k=d1*t1
            if k%d==0:
                print(2*k//d)
            else:
                print(2*(k//d)+1)


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n;
V<LL> v;

LL gcd(LL a, LL b) {
    if(a < b) std::swap(a,b);
    if(a == 1) return 1;
    if(a % b == 0) return b;
    return gcd(b, a%b);
}


int main(){
    INIT;
    cin >> n;
    v.resize(n,0);
    REP(i,n) cin >> v[i];
    if(n == 2) {
        cout << std::max(v[0], v[1]) << "\n";
        return 0;
    }
    std::sort(ALL(v), DESC(LL));
    int minidx = 1;
    LL m = gcd(v[0], v[1]);
    for(int i = 2; i < n; i++) {
        LL g = gcd(m,v[i]);
        if(g < m) { m = g; minidx = i; }
    }
    if(minidx == 1) {
        LL ans1 = v[0];
        LL ans2 = v[1];
        for(int i = 2; i < n; i++) {
            ans1 = gcd(ans1,v[i]);
            ans2 = gcd(ans2,v[i]);
        }
        cout << std::max(ans1,ans2) << "\n";
    } else {
        LL ans = gcd(v[0],v[1]);
        FOR(i,2,n) if(minidx != i) ans = gcd(ans,v[i]);
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

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

int main(void)
{
	while(1) {
		int n;
		cin >> n;
		if (n == 0) break;
		vec<string> l(n);
		vec<int> buy(n), p(n), q(n), sell(n), m(n);
		vec<pair<double, string>> seed(n);

		rep(i, n) {
			cin >> l[i];
			cin >> buy[i];
			int a, b, c;
			cin >> a >> b >> c;
			p[i] = a + b + c;
			cin >> a >> b;
			q[i] = a + b;
			cin >> a >> b >> m[i];
			sell[i] = a * b * m[i];
		}

		rep(i, n) {
			seed[i].first = - (double)(sell[i] - buy[i]) / (double)(p[i] + q[i] * m[i]);
			seed[i].second = l[i];
		}

		sort(seed.begin(), seed.end());
		rep(i, n) cout << seed[i].second << endl;
		cout << "#" << endl;
	}
	return 0;
}

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

void EAST(int* dice) {
    int copy = dice[0];
    dice[0] = dice[3];
    dice[3] = dice[5];
    dice[5] = dice[2];
    dice[2] = copy;
}

void NORTH(int* dice) {
    int copy = dice[0];
    dice[0] = dice[1];
    dice[1] = dice[5];
    dice[5] = dice[4];
    dice[4] = copy;
}

void SOUTH(int* dice) {
    int copy = dice[0];
    dice[0] = dice[4];
    dice[4] = dice[5];
    dice[5] = dice[1];
    dice[1] = copy;
}

void WEST(int* dice) {
    int copy = dice[0];
    dice[0] = dice[2];
    dice[2] = dice[5];
    dice[5] = dice[3];
    dice[3] = copy;
}

int main(void) {
    int dice[6];
    string order;
    
    for(int i = 0; i < 6; ++i) {
        cin >> dice[i];
    }
    cin >> order;
    
    for(int i = 0; i < order.length(); ++i) {
        switch(order[i]) {
            case 'E' : EAST(dice);   break;
            case 'N' : NORTH(dice);  break;
            case 'S' : SOUTH(dice);  break;
            case 'W' : WEST(dice);   break;
        }
    }
    cout << dice[0] << endl;
    
    return 0;
}



Measured memory_bytes: 3148
#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>;

int main() {
    ll n, a, b;
    string s;
    cin >> n >> a >> b;
    cin >> s;
    ll passed = 0, passedAb = 0;
    rep(i, n) {
        if (s[i] == 'c') {
            cout << "No" << endl;
        } else {
            if (s[i] == 'a') {
                if (passed < a+b) {
                    cout << "Yes" << endl;
                    passed++;
                } else {
                    cout << "No" << endl;
                }
            } else {
                if (passed < a+b && passedAb+1 <= b) {
                    cout << "Yes" << endl;
                    passed++;
                    passedAb++;
                } else {
                    cout << "No" << endl;
                }
            }
        }
    }
}


Measured memory_bytes: 896