akhauriyash/Code-Regression huggingface dataset:
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 25 May 2020
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9+7;
#define endl '\n'

int n;
vector<ll> arr;
ll dp[3001][3001][2];

ll fun(int st, int end, bool player){

	if(st == end){
		if(player==0){
			return arr[st];
		}
		else{
			return -arr[st];
		}
	}

	if(dp[st][end][player] != -1) return dp[st][end][player];

	if(player == 0){
		if(dp[st+1][end][player^1] == -1){	
			dp[st+1][end][player^1] = fun(st+1, end, player^1);
		}
		if(dp[st][end-1][player^1] == -1){
			dp[st][end-1][player^1] = fun(st, end-1, player^1);
		}
		return dp[st][end][player] = max(arr[st] + dp[st+1][end][player^1], arr[end] + dp[st][end-1][player^1]);
	}
	else{
		if(dp[st+1][end][player^1] == -1){
			dp[st+1][end][player^1] = fun(st+1, end, player^1);
		}
		if(dp[st][end-1][player^1] == -1){
			dp[st][end-1][player^1] = fun(st, end-1, player^1);
		}
		return dp[st][end][player] = min(-arr[st] + dp[st+1][end][player^1], -arr[end] + dp[st][end-1][player^1]);
	}

}

signed main(){

    fastio;
    memset(dp, -1, sizeof(dp));

    cin>>n;
    arr = vector<ll>(n);

    for(int i=0;i<n;i++){
    	cin>>arr[i];
    }

    // 0-> Player X, 1-> Player Y
    cout<<fun(0,n-1,0);

    return 0;

}

Measured memory_bytes: 141184
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();

        if(s.equals(u)){
            System.out.println(""+(a-1)+" "+b);
        }else{
            System.out.println(""+a+" "+(b-1));
        }
    }
}

Measured memory_bytes: 21844
def cal():
    import queue
    h, w = map(int, input().split())
    s = [list(input()) for _ in range(h)]
    cost = [[-1]*w for _ in range(h)]
    INF = float('inf')
    count, ans = 0, INF
    for i in range(h):
        for j in range(w):
            if s[i][j] != '#':
                cost[i][j] = INF
            else:
                count += 1        
    q = queue.Queue()
    q.put((0, 0, 1))
    while not q.empty():
        c0, c1, c2 = q.get()
        s[c0][c1] = '#'
        if c0 == h-1 and c1 == w-1:
            return h*w-count-c2
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            x, y = c0+i, c1+j
            if 0 <= x < h and 0 <= y < w:
                if s[x][y] != '#' and cost[x][y] == INF:
                    cost[x][y] = c2+1
                    q.put((x, y, c2+1))

    return ans

ans = cal()
if ans == float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9732
# ABC 141 - Tap Dance

import sys

S = input()

for i in range(len(S)):
    if (i % 2) != 0:
        if  (S[i] != 'L') and (S[i] != 'U') and (S[i] != 'D'):
           print('No')
           sys.exit()
    if  (i % 2) == 0:
        if  (S[i] != 'R') and (S[i] != 'U') and (S[i] != 'D'):
           print('No')
           sys.exit()

print('Yes')

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int O = scan.nextInt();
        int ans = O-H;
        if(ans>=0){
            System.out.println("unsafe");
        }
        else {
            System.out.println("safe");
        }
  }
}

Measured memory_bytes: 35828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define MANX MAXN
#define itn int
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef Mip182
    freopen("a.in","r",stdin);
    #endif
    int n,k;
    cin>>n>>k;
    vi a(n);
    rep(i,n)
    cin>>a[i];
    int l=1,r=1e9;
    int ans=1e9;
    while (l<=r)
    {
        int mid=((l+r)>>1);
        ll cnt=0;
        for (auto to:a)
        {
            cnt+=(to-1)/mid;
        }
      //  cout<<cnt<<" "<<mid<<" "<<k<<'\n';
        if (cnt<=k)
            r=mid-1,ans=mid;
        else
            l=mid+1;
    }
    cout<<ans;


    //n=1 ?
    //recursion - matrix exponential
    //linear algebra - just a joke
    //check ios_base, MAXN, mod1 before submit
    //if debug more than 15 minutes - write stress
    //compression
}

Measured memory_bytes: 3980
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];

    int sumA = 0, sumB = 0;
    rep(i, N) {
        sumA += A[i];
        sumB += B[i];
    }

    if (sumA < sumB) {
        cout << -1 << endl;
        return 0;
    }

    set<pair<int, int>> st;
    rep(i, N) {
        st.insert(mp(A[i] - B[i], i));
    }

    unordered_set<int> used;

    auto it = st.rbegin();
    int tmp = it->first;

    int ret = 0;
    rep(i, N) {
        //cerr << "-- i=" << i << endl;
        //cerr << " A:" << A[i] << " B:" << B[i] << endl;
        if (A[i] >= B[i]) continue;
        ret++;
        int luck = B[i] - A[i];
        //cerr << " luck:" << luck << endl;
        while (true) {
            int val = min(tmp, luck);
            luck -= val;
            tmp -= val;
            used.insert(it->second);
            //cerr << " get " << val << " from idx=" << it->second << endl;
            if (luck == 0) break;
            if (tmp == 0) {
                it++;
                tmp = it->first;
            }
        }
    }

    //cerr << "used.size:" << used.size() << endl;
    ret += used.size();

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <bits/stdc++.h>
#define li long int
using namespace std;

vector <li> graph[100001];
li dp[100001]={0};

li solve(li src){
    if(dp[src] != 0){
        return dp[src];
    }
    
    li leaf = 1, bestchild = 0;
    for(li child : graph[src]){
        leaf = 0;
        bestchild = max(bestchild, solve(child));
    }
    if(leaf != 1){
       dp[src] = 1+bestchild; 
    }
    return dp[src];
}
int main() {
	li n, m, x, y;
	cin>>n>>m;
	for(li i=0;i<m;i++){
	   cin>>x>>y;
	   graph[x].push_back(y);
	}
	li ans =0;
	for(li i=1;i<=n;i++){
	    ans = max(ans, solve(i));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11812
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int N, K;
  cin >> N >> K;
  int ans = 0;
  for(int i = 0; i < N; i++){
    int x;
    cin >> x;
    ans += 2 * min(x, abs(x - K));
  }
  cout << ans << endl;
}


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

const int N = 21; 
const int M = (1 << 21);

vector< vector<int> > dp;//(N, vector<int> (M, -1));
const int mod = 1e9+7; 

int n ;
int arr[N][N]; 

int find(int index, int bitmask)
{
	
   if(index == n ) return 1; 
   if( dp[index][bitmask] != -1) return dp[index][bitmask]; 
    
   int res = 0 ; 
   for(int i = 0 ; i < n ; i ++)
   {
       if( ( (bitmask >> i) &1 ) and (arr[index][i]) ) 
       {
           res = ( 0l + res + find(index+1,bitmask ^ (1 << i)) )%mod;
       }
   }

   return dp[index][bitmask] = res; 

}


void solve()
{
       cin >> n;

       for(int i = 0 ; i < n ; i ++)
          for(int j = 0 ; j < n; j ++)
              cin >> arr[i][j];
       
       dp.clear();
       dp.resize(n,vector<int> (1 << n,-1));
        cout << find(0,(1<<n)-1);

}

int main()
{

	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);

	 solve();
	 return 0;
}

/**


*/




Measured memory_bytes: 183508
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int h,w,k;
string s[305];
int cake[301][301]={0};
int color = 1;
void cut(int up,int dw){
    int row[301];
    int size = 0;
    for(int j=0;j<w;j++){
        for(int i=up;i<=dw;i++){
            if(s[i][j]=='#'){
                row[size++] = j;
                break;
            }
        }
    }
    int start = 0;
    for(int k=0;k<size-1;k++){
        for(int j=start;j<=row[k];j++){
            for(int i=up;i<=dw;i++){
                cake[i][j] = color;
            }
        }start = row[k] + 1;
        color++;
    }
    
    for(int j=start;j<w;j++){
        for(int i=up;i<=dw;i++){
            cake[i][j] = color;
        }
    }
    
}
void print(){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%3d ",cake[i][j]);
        }puts("");
    }
}
int main(void){
    cin >> h >> w >> k;
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    int column[301];
    int size = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#'){
                column[size++] = i;
                break;
            }
        }
    }
    int start = 0;
    for(int i=0;i<size-1;i++){
        cut(start,column[i]);
        color++;
        start = column[i]+1;
    }cut(start,h);
    print();
}



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

using namespace std;

inline int read()
{
    char ch=getchar(); int f=1,x=0;
    while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    return f*x;
}

int n,m,a,b,c,sum,dis[17][17],v[1<<15],f[1<<15][17];

signed main()
{
    n=read(); m=read();
    const int N=1<<n;
    for (int i=1;i<=m;i++)
    {
        a=read(); b=read();
        sum+=dis[a][b]=dis[b][a]=read();
    }
    for (int i=1;i<N;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (!(i>>j&1)) continue;
            for (int k=0;k<j;k++)
            {
                if (!(i>>k&1)) continue;
                v[i]+=dis[j+1][k+1];
            }
        }
    }
    memset(f,-1,sizeof(f));
    f[1][1]=0;
    for (int i=1;i<N;i++)
    {
        for (int j=0;j<n;j++)
        {
            if (!(i>>j&1) || !~f[i][j+1]) continue;
            for (int k=0;k<n;k++)
            {
                if (i>>k&1 || !dis[j+1][k+1]) continue;
                f[i|(1<<k)][k+1]=max(f[i|(1<<k)][k+1],f[i][j+1]+dis[j+1][k+1]);
            }
            int tot=((N-1)^i)|(1<<j);
            for (int k=tot;k;k=(k-1)&tot)
            {
                if (!(k>>j&1)) continue;
                f[i|k][j+1]=max(f[i|k][j+1],f[i][j+1]+v[k]);
            }
        }
    }
    return !printf("%d\n",sum-f[N-1][n]);
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    }
    else if (R < 2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  int n,x;
  cin>>n;
  int cou=0;
  for(int i=1;i<=n;i++){
    cin>>x;
    if(x%2!=0&&i%2!=0)
      cou++;
  }
  cout<<cou<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 int a,b,c;
  cin>>a>>b>>c;
  if(a==b)cout<<c<<endl;
  else cout<<a+b-c<<endl;
}

Measured memory_bytes: 3588
# ARC072C - Sequence (ABC059C)
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    lst = tuple(map(int, input().split()))
    
    # start with positive number
    cur, cnt_1 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new <= 0:
            cnt_1 += abs(new) + 1
            cur = 1
        elif i % 2 == 1 and new >= 0:
            cnt_1 += abs(new) + 1
            cur = -1
        else:
            cur += j

    # start with negative number
    cur, cnt_2 = 0, 0
    for i, j in enumerate(lst):
        new = cur + j
        if i % 2 == 0 and new >= 0:
            cnt_2 += abs(new) + 1
            cur = -1
        elif i % 2 == 1 and new <= 0:
            cnt_2 += abs(new) + 1
            cur = 1
        else:
            cur += j
    
    print(min(cnt_1, cnt_2))


if __name__ == "__main__":
    main()

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    rep (i, h) {
        rep (j, w) {
            string s;
            cin >> s;
            if (s == "snuke") {
                cout << (char)('A' + j) << i + 1 << endl;
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;
typedef long long int lld;
int main(){
	lld n;
	cin >> n;
	int ans = 0;
	while(true){
		if(n % 3 == 0){
			n /= 3;
		}else{
			n = n / 3 + 1;
		}
		ans++;
		if(n == 1) break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 100000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,cost,cap,rev;
	edge(){}
	edge(int tt,int ca,int cc,int rr){
		to=tt;
		cost=cc;
		cap=ca;
		rev=rr;
	}
};

int V;
vector<edge> G[501];
int h[501];
int dist[501];
int prevv[501],preve[501];

void add_edge(int from,int to,int cap,int cost){
	G[from].push_back(edge(to,cap,cost,G[to].size()));
	G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
	int res=0;
	fill(h,h+V,0);
	while(f>0){
		priority_queue<P,vector<P>,greater<P> > que;
		fill(dist,dist+V,INF);
		dist[s]=0;
		que.push(P(0,s));
		while(que.size()){
			P p=que.top();
			que.pop();
			int v=p.second;
			if(dist[v]<p.first)continue;
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
					dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
					prevv[e.to]=v;
					preve[e.to]=i;
					que.push(P(dist[e.to],e.to));
				}
			}
		}
		if(dist[t]==INF)return -1;
		for(int v=0;v<V;v++){
			h[v]+=dist[v];
		}
		int d=f;
		for(int v=t;v!=s;v=prevv[v]){
			d=min(d,G[prevv[v]][preve[v]].cap);
		}
		f-=d;
		res+=d*h[t];
		for(int v=t;v!=s;v=prevv[v]){
			edge &e=G[prevv[v]][preve[v]];
			e.cap-=d;
			G[v][e.rev].cap+=d;
		}
	}
	return res;
}

int n;
int w[101][101],e[101][101];
int fie[101][101];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%d",&w[i][j]);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%d",&e[i][j]);
		}
	}
	int sum=0;
	V=n*2+2;
	int s=n*2,t=s+1;
	for(int i=0;i<n;i++){
		string str;
		cin >> str;
		add_edge(s,i,1,0);
		add_edge(n+i,t,1,0);
		for(int j=0;j<n;j++){
			if(str[j]=='o'){
				sum+=e[i][j];
				add_edge(i,n+j,1,1000-e[i][j]);
				fie[i][j]=1;
			}else{
				add_edge(i,n+j,1,1000+w[i][j]);
			}
		}
	}
	printf("%d\n",sum+min_cost_flow(s,t,n)-1000*n);
	int cnt=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<G[i].size();j++){
			if(G[i][j].to<n || G[i][j].to>=n*2)continue;
			if(G[i][j].cap==0 && fie[i][G[i][j].to-n]==0){
				cnt++;
			}
			if(G[i][j].cap==1 && fie[i][G[i][j].to-n]==1){
				cnt++;
			}
		}
	}
	printf("%d\n",cnt);
	for(int i=0;i<n;i++){
		for(int j=0;j<G[i].size();j++){
			if(G[i][j].to<n || G[i][j].to>=n*2)continue;
			if(G[i][j].cap==0 && fie[i][G[i][j].to-n]==0){
				printf("%d %d write\n",i+1,G[i][j].to-n+1);
			}
			if(G[i][j].cap==1 && fie[i][G[i][j].to-n]==1){
				printf("%d %d erase\n",i+1,G[i][j].to-n+1);
			}
		}
	}
	return 0;
}

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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if(A + B > C + D){
        cout << "Left" << endl;
    }else if(A + B < C + D){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int N, K[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
scanf("%d",&N);
printf("%d\n", K[N-1]);
return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s;cin>>s;
    map<char,int>d;
    rep(i,s.size()){
        d[s[i]]++;
    }
    if(d.size()==1){
        if(s.size()==1){
            cout<<"YES"<<endl;return 0;
        }
    }
    else if(d.size()==2){
        if(s.size()==2){
            cout<<"YES"<<endl;return 0;
        }
    }
    else{
        int m=max({d['a'],d['b'],d['c']});
        int l=min({d['a'],d['b'],d['c']});
        if(m-l<=1){cout<<"YES"<<endl;return 0;}
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc061.contest.atcoder.jp/tasks/arc061_b>
問題文============================================================
 縦 H 行、横 W 列のマス目からなる盤があります。最初、どのマス目も白く塗られています。
 
 すぬけ君が、このうち N マスを黒く塗りつぶしました。
 i 回目 ( 1≤i≤N ) に塗りつぶしたのは、 上から ai 行目で左から bi 列目のマスでした。
 
 すぬけ君がマス目を塗りつぶした後の盤の状態について、以下のものの個数を計算してください。
 
 各整数 j ( 0≤j≤9 ) について、盤の中に完全に含まれるすべての 3 行 3 列の連続するマス目のうち、
 黒いマスがちょうど j 個あるもの。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll H,W,N; cin >> H >> W >> N;
    vector<ll> a(N),b(N);
    for(int i = 0; i < N;i++) cin >> a[i] >> b[i];
    
    map<pll,ll> mp;
    for(int i = 0; i < N;i++){
        for(int j = -2; j <= 0; j++){
            for(int k = -2; k <= 0; k++){
                ll nx = a[i] + j,ny = b[i] + k;
                if(nx <= 0 || nx >= H - 1 || ny <= 0 || ny >= W - 1) continue;
                mp[pll(nx,ny)]++;
            }
        }
    }
    ll ans[10] = {0};
    for(auto it = mp.begin(); it != mp.end(); it++) ans[it->second]++;
    
    ll sum = (H - 2) * (W - 2);
    for(auto v:ans){
        sum -= v;
    }
    ans[0] += sum;
    for(auto v:ans){
        cout << v << endl;
    }
    
	return 0;
}


Measured memory_bytes: 58112
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class Monoid> struct RMQ {
    const Monoid INF;
    int SIZE_R;
    vector<pair<Monoid,int> > dat;
    
    RMQ(int n, const Monoid &inf): INF(inf) { init(n); }
    void init(int n) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        dat.assign(SIZE_R * 2, pair<Monoid,int>(INF, -1));
    }
    
    /* set, a is 0-indexed */
    void set(int a, const Monoid &v) { dat[a + SIZE_R] = make_pair(v, a); }
    void build() {
        for (int k = SIZE_R - 1; k > 0; --k) {
            dat[k] = min(dat[k*2], dat[k*2+1]);
        }
    }
    
    /* update, a is 0-indexed */
    void update(int a, const Monoid &v) {
        int k = a + SIZE_R;
        dat[k] = make_pair(v, a);
        while (k >>= 1) dat[k] = min(dat[k*2], dat[k*2+1]);
    }

    void chmin(int a, const Monoid &v) {
        long long pv = get(a, a+1).first;
        if (pv <= v) return;
        update(a, v);
    }
    
    /* get {min-value, min-index}, a and b are 0-indexed */
    pair<Monoid,int> get(int a, int b) {
        pair<Monoid,int> vleft = make_pair(INF, -1), vright = make_pair(INF, -1);
        for (int left = a + SIZE_R, right = b + SIZE_R; left < right; left >>= 1, right >>= 1) {
            if (left & 1) vleft = min(vleft, dat[left++]);
            if (right & 1) vright = min(dat[--right], vright);
        }
        return min(vleft, vright);
    }
    inline Monoid operator [] (int a) { return dat[a + SIZE_R].first; }
    
    /* debug */
    void print() {
        for (int i = 0; i < SIZE_R; ++i) {
            Monoid val = (*this)[i];
            if (val < INF) cout << val;
            else cout << "INF";
            if (i != SIZE_R-1) cout << ",";
        }
        cout << endl;
    }
};

const long long INF = 1LL<<60;
using pint = pair<int,int>;

int N, Q;
vector<int> b;
vector<vector<int>> rs;

long long f(int i) {
    if (b[i] == 0) return -1;
    else return 1;
}

long long solve() {
    long long offset = 0;
    for (int i = 0; i < N; ++i) if (b[i] == 0) ++offset;

    RMQ<long long> dp(N+2, INF);
    dp.update(0, 0);
    for (auto r : rs[0]) dp.update(r, 0);
    for (int i = 1; i <= N; ++i) {
        for (auto r : rs[i]) {
            long long mi = dp.get(i, r+1).first;
            dp.chmin(r, mi);
            dp.chmin(r, dp.get(i-1, i).first + f(i-1));
        }
        dp.chmin(i, dp.get(i-1, i).first + f(i-1));
    }
    return dp.get(N, N+1).first + offset;
}

int main() {
    while (cin >> N) {
        b.resize(N);
        for (int i = 0; i < N; ++i) cin >> b[i];
        rs.assign(N+1, vector<int>());
        cin >> Q;
        for (int i = 0; i < Q; ++i) {
            int l, r; cin >> l >> r; --l;
            rs[l].push_back(r);
        }
        for (int l = 0; l <= N; ++l)
            sort(rs[l].begin(), rs[l].end(), greater<int>());
        cout << solve() << endl;
    }
}


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

int main(){
	string a,b;
	int ans = 0;
	cin >> a >> b;
	for(int i = 0 ; i < 3 ; i += 1){
		if(a[i] == b[i]){
			ans += 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
'''SDESTINY
N個の展望台の一つ一つずつと繋がっている展望台の番号(0-index)を
setに格納する配列を作る。
全体でN個、その中に繋がっている展望台の数だけ、要素がある。
要素はsetで持っていうる。
そのsetの中から要素を一つ一つ取り出す（（C)の部分）。
取り出した高さH[x]と、いま見ている展望台の高さH[i]を比べて、
H[i]<=H[x]なら、条件に合わない（等号は必要か？）
N 箇所の展望台があり展望台 i の標高が Hi、また展望台を結ぶ道が M 本あり、
道 j は展望台 Aj と Bj を結んでいる。展望台から伸びている道
を1つだけ通って行ける展望台のうち最も高い展望台を良い展望台と呼び、
それがいくつあるか求める。
（A)N 箇所の展望台 i に対応するように配列を作り、
各展望台から道が繋がっている展望台をsetで持つ。0-index
配列を順番に見ていき、見ている展望台とsetが持っている
展望台の高さを比較し、最も高ければ答えを1増やす。
'''
N,M = map(int,input().split())
H = list(map(int,input().split()))
AB = [set() for i in range(N)]#（A)
for i in range(M):
    A,B = map(int,input().split())
    AB[A-1].add(B-1)#0-indexへ
    AB[B-1].add(A-1)
#print(AB)
ans = 0
for i in range(N):#iは見ている展望台をチェック
    res = True
    for x in AB[i]:#（C)二重ループ
    #setのi番目にある複数の要素をxとして一つずつ取り出す
#配列を順番に見ていき、見ている展望台iとsetが持っている
#展望台xの高さを比較し、低ければ条件に合わない
        if H[i]<=H[x]:#これが（B)のif
            #print(H[i],H[x])
            res = False
            break
    if res:#（B)のifでbreakしなければ、最も高いので答を１増やす
        ans += 1
print(ans)

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

int main(void){
 int c[3][3];
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c[i][j];
    }
  }
  if(c[0][1] - c[0][0] == c[1][1] - c[1][0] &&
     c[1][1] - c[1][0] == c[2][1] - c[2][0]){
    if(c[0][2] - c[0][1] == c[1][2] - c[1][1] &&
     c[1][2] - c[1][1] == c[2][2] - c[2][1]){
      if(c[0][2] - c[0][0] == c[1][2] - c[1][0] &&
     c[1][2] - c[1][0] == c[2][2] - c[2][0]){
        
        if(c[1][0] - c[0][0] == c[1][1] - c[0][1] &&
     c[1][1] - c[0][1] == c[1][2] - c[0][2]){
          if(c[2][0] - c[1][0] == c[2][1] - c[1][1] &&
     c[2][1] - c[1][1] == c[2][2] - c[1][2]){
            if(c[2][0] - c[0][0] == c[2][1] - c[0][1] &&
     c[2][1] - c[0][1] == c[2][2] - c[0][2]){
              cout << "Yes";
              return 0;
            }
          }
        }
      }
    }
  }
      
  cout << "No";
                
                 
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    P A[N] = {};
    for (int i = 0; i < N; i++) {
        cin >> A[i].second >> A[i].first;
    }
    sort(A, A + N);
    int t = 0;int flag = 0;
    for (int i = 0;i < N;i++){
        t += A[i].second;
        if (t > A[i].first) {
            flag = 1;
            break;
        }
    }
    if (flag == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1792
a,b,c,x,y = map(int,input().split())

if y > x:
    o = c*min(x,y)*2 + b*abs(x-y)
else:
    o = c*min(x,y)*2 + a*abs(x-y)
p = a*x + b*y
q = c*max(x,y)*2

print(min(o,p,q))

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

int main(){
  int N, M; cin >> N >> M;
  vector<bool> ac(N, false);
  vector<int> wa(N, 0);
  rep(i, M) {
    int p; cin >> p; p--;
    string S; cin >> S;
    if (S == "AC") {
      ac[p] = true;
    } else {
      if (ac[p]) continue;
      wa[p]++;
    }
  }

  int acnum = 0;
  int penum = 0;
  rep(i, N) {
    if (ac[i]) {
      acnum++;
      penum += wa[i];
    }
  }
  cout << acnum << " " << penum << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	int h, w;
	public void run(){
		h = sc.nextInt();
		w = sc.nextInt();
		solve();
	}
	public void solve(){
		boolean ans = true;
		char memo[][] = new char [h][w];
		for(int i = 0; i < h; i++){
			String line = sc.next();
			for(int j = 0; j < w; j++){
				String s = line.substring(j, j+1);
				if(s.equals(".")){
					memo[i][j] = 0;
				}
				else{
					memo[i][j] = 1;
				}
			}
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(memo[i][j] == 1){
					int flag = 0;
					int x[] = {i-1, i, i, i+1};
					int y[] = {j, j-1, j+1, j};
					for(int k = 0; k < 4; k++){
						int ii = x[k];
						int jj = y[k];
						if(ii > -1 && jj > -1 && ii < h && jj < w){
							if(memo[ii][jj] == 1){
								flag = 1;
								break;
							}
						}
					}
					if(flag == 0){
						ans = false;
						break;
					}
				}
			}
			if(!ans) break;
		}
		if(ans) System.out.println("Yes");
		else System.out.println("No");
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
	static class Pair {
        int first,second;
        public Pair(int a,int b) {
            this.first = a;
            this.second = b;
        }
    }	
}


Measured memory_bytes: 22868
#include<algorithm>
#include<stdio.h>
#include<string.h>
using namespace std;
long long  aa[1000010];
long long  k;
struct qq
{
    long long val,zhi,zhi1;
} a1[1001000];
inline bool cmp(const qq &a,const qq &b)
{
    if(a.zhi!=b.zhi)
        return a.zhi<b.zhi;
    return a.val<b.val;
}
inline bool cmp1(const qq &a,const qq &b)
{
    return a.val<b.val;
}
long long  lowbit(long long  x)
{
    return x&(-x);
}
int bb[1001000];
void update(int  x,long long  v)
{
    while(x<=k)
    {
        bb[x]+=v;
        x+=lowbit(x);
    }
}
long long sum(int   x)
{
    long long ret=0;
    while(x>0)
    {
        ret+=bb[x];
        x-=lowbit(x);
    }
    return ret;
}
int main()
{

    memset(aa,0,sizeof(aa));
    memset(bb,0,sizeof(bb));
    for(int i=0; i<1000100; i++)
    {
        a1[i].zhi=0;
        a1[i].zhi1=0;
        a1[i].val=0;
    }
    int n;
    long long  k1;
    scanf("%d%lld",&n,&k1);
    for(int i=1; i<=n; i++)
    {
        scanf("%lld",&aa[i]);
        aa[i]-=k1;
    }
    for(int i=1; i<=n; i++)
    {
        a1[i].zhi=a1[i-1].zhi+aa[i];
        a1[i].val=i;
    }
    k=1;
    sort(a1+1,a1+1+n,cmp);

    a1[1].zhi1=1;
    for(int i=2; i<=n; i++)
    {
        if(a1[i].zhi==a1[i-1].zhi)
            a1[i].zhi1=k;
        else
        {
            k++;
            a1[i].zhi1=k;
        }
    }
    sort(a1+1,a1+1+n,cmp1);
//    printf("%lld\n",k);
//    for(int i=1; i<=n; i++)
//    {
//        printf("%lld %lld \n",a1[i].zhi,a1[i].zhi1);
//    }
//    printf("\n");

    long long ans=0;
    for(long long  i=1; i<=n; i++)
    {
        if(a1[i].zhi>=0)
            ans++;

//        long long ii=i;
        ans+=sum(a1[i].zhi1);
//        printf("%lld\n",ans);
//        printf("%lld\n",)
        update(a1[i].zhi1,1);
    }
    printf("%lld\n",ans);


}


Measured memory_bytes: 35456
#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);
	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	ll ans = 1e17;
	rep(i, n) ans = min(ans, (a[i] - 1) + (b[i] + 1));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
int main(){
    ll a,b,c;cin >> a >> b >> c;
    int ans=-1;
    for(int i=0;i<100;i++){
        int aa=a,bb=b,cc=c;
        if(a%2==0&&b%2==0&&c%2==0){
            a=(bb+cc)/2;
            b=(cc+aa)/2;
            c=(aa+bb)/2;
        }
        else{
            ans=i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**     Md. Mujahedul Azad (Turin)
        Hajee Mohammad Danesh Science & Technology University **/

#include <map>
#include <math.h>
#include <cstdio>
#include <vector>
#include <climits>
#include <cstring>
#include <algorithm>
using namespace std;

template<class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template<class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template<typename T> T power(T val, T p, T mod){val%=mod; T result=1; while(p>0){if(p&0x1)result=(result*val)%mod;val=(val*val)%mod;p>>=1;}return result;}
template<typename T> inline void read(T &res){int sign=1; res=0;char ch = getchar();while(true){if(ch == '-') break;if(ch >= '0' && ch <='9') break;ch = getchar();}if(ch == '-') sign = -1;else res = ch-'0';while(true){ch = getchar();if(ch < '0' || ch > '9') break;res = (res * 10 + (ch - '0'));}res *= sign;}

#define ff                  first
#define se                  second
#define sfr(a)              read(a)
#define G()                 getchar()
#define pb                  push_back
#define pi                  acos(-1.0)
#define sq(x)               ((x) * (x))
#define sfi(x)              scanf("%d", &x)
#define sfrr(a,b)           read(a), read(b)
#define inOut               {input; output;}
#define SZ(x)               ((int) (x).size())
#define all(x)              (x).begin(), (x).end()
#define mem(a,b)            memset((a),(b),sizeof(a))
#define Case                printf("Case %d: ", cases)
#define input               freopen("input.txt","r",stdin)
#define output              freopen("output.txt","w",stdout)

#define PF                  printf
#define CASE                printf("Case %d: ", cs);
#define CASEN               printf("Case %d:\n", cs);

typedef long long ll;
typedef pair<int,int> pii;

const double eps=3e-8;
const int mx = 1e5+5;



int main(){
    int a, b; sfrr(a, b);
    if(a<10 && b<10) PF("%d\n", a*b);
    else PF("-1\n");
    return 0;
}



Measured memory_bytes: 128
s = input().split("T")
x,y = map(int,input().split())
x -= len(s[0])
XY = [[],[]]
for i in range(1,len(s)):
  XY[i%2].append(len(s[i]))
X,Y = XY
X.sort(reverse = True)
Y.sort(reverse = True)
for i in X:
  if x > 0:
    x -= i
  else:
    x += i
for i in Y:
  if y > 0:
    y -= i
  else:
    y += i
if (x,y) == (0,0):
  print("Yes")
else:
  print("No")



Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include<bitset>
using namespace std;
#define M 1000000007
const int N = 5e5 +10;


int main()
{
	int n, m , c;
	cin>>n>>m>>c;
	int b[m];
	for(int i=0;i<m;i++) cin>>b[i];
	int a;
	int ans = 0;
	for(int i=0; i<n; i++)
	{
		int tot = c;
		for(int j =0; j<m;j ++)
		{
			cin>>a;
			tot += a*b[j];
		}
		if(tot > 0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), x = sc.nextInt();
		int m[] = new int[n];
		int sum = 0;
		for(int i = 0; i < n; ++i) {
			m[i] = sc.nextInt();
			sum += m[i];
		}
		sc.close();
		int tmp = x - sum, ans = n;
		Arrays.sort(m);
		ans += tmp / m[0];
		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
n=int(input())
m=0
a=1
for i in range(1,n+1):
    c=0
    j=i
    while 1:
        j/=2
        if j%1==0:
            c+=1
        else:
            break
    if m<c:
        m=c
        a=i
print(a)


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n; cin >> n;
  vector<int> d(n);
  for (int p; cin >> p; d[p - 1]++);
  for (int x: d) cout << x << '\n';

  return 0;
}


Measured memory_bytes: 3972
#include<iostream>

using namespace std;

int main(){
    long long n,a,b;
    cin>>n>>a>>b;
    if(a > b) swap(a,b);
    if(a%2 == b%2){
        cout<<(b-a)/2<<endl;
    } else {
        long long ans = n+1;
        long long tmp = b-a+1;
        ans = min(ans, n-b+(b-a+1)/2);
        ans = min(ans, a-1+(b-a+1)/2);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <utility>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using namespace std;
int maxi = 0;
int tans(int a[2][100], int n, int i, int j,int sum) {
	sum += a[i][j];
	if (i == 1 && j == n - 1) {
		maxi = max(maxi, sum);
		return 0;
	}
	if (i != 1) {
		tans(a, n, i + 1, j, sum);
	}
	if (!(i != 1 && j == n - 1)) {
		tans(a, n, i, j + 1 , sum);
	}

}
int main() {
	int n,a[2][100];
	cin >> n;
	FOR(i, 0, n) {
		cin >> a[0][i];
	}
	FOR(i, 0, n) {
		cin >> a[1][i];
	}
	tans(a, n, 0, 0, 0);
	cout << maxi;
}

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

int main() {
  
  int a , b , c ;
  cin >> a >> b >> c ;
  
  if((a+b+c == 17) && (min(a,min(b,c)) == 5) && (max(a,max(b,c)) == 7))
    cout << "YES" ;
  
  else 
    cout << "NO";
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("Ofast")
using namespace std;
int a[200005],b[200005],n;
int na[200005],nb[200005];
int main (){
	int i,j,res=0;
	scanf ("%d",&n);
	for (i=1;i<=n;i++)
	{scanf ("%d",&a[i]);}
	for (i=1;i<=n;i++)
	{scanf ("%d",&b[i]);}
	for (i=0;i<=29;i++)
	{int mod=(1<<(i+1))-1;
	ll ans=0;
	for (j=1;j<=n;j++) 
	{na[j]=a[j]&mod;nb[j]=b[j]&mod;}
	sort(na+1,na+n+1);
	sort(nb+1,nb+n+1);
	int tar=(1<<i);
	for (j=1;j<=n;j++)
	{int l=1,r=n;
	while (l<=r)
	{int mid=(l+r)>>1;
	if (na[j]+nb[mid]<tar) {l=mid+1;}
	else {r=mid-1;}
	}
	ans+=(n-l+1);
	}
	tar=(1<<i)*2;
	for (j=1;j<=n;j++)
	{int l=1,r=n;
	while (l<=r)
	{int mid=(l+r)>>1;
	if (na[j]+nb[mid]<tar) {l=mid+1;}
	else {r=mid-1;}
	}
	ans-=(n-l+1);
	}
	tar=(1<<i)*3;
	for (j=1;j<=n;j++)
	{int l=1,r=n;
	while (l<=r)
	{int mid=(l+r)>>1;
	if (na[j]+nb[mid]<tar) {l=mid+1;}
	else {r=mid-1;}
	}
	ans+=(n-l+1);
	}
	if (ans&1ll) res|=(1<<i);
	}
	printf ("%d\n",res);
	return 0;
}

Measured memory_bytes: 3456
n,l = map(int,input().split())
a = [int(i) for i in input().split()]
for i in range(n-1):
  if a[i]+a[i+1] >= l:
    print('Possible')
    for j in range(n-1,i+1,-1):
      print(j)
    for k in range(1,i+2):
      print(k)
    exit()
print('Impossible')

Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ara[10];//ara2[10];
    for(int i=1;i<=3;i++)
    {
        cin>>ara[i];
    }
    int c=0;
    char item;
    for(int i=1;i<=3;i++)
    {
        cin>>item;
        if(item==ara[i])
        {
            c++;
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
//Bismillah hirrahmanir Rahim
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
   long long int a,b,x,y;
   cin>>a>>b;
   x=a%b;
   y=abs(x-b);
   cout<<min(x,y);
    return 0;
    }


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

struct query{
  ll type;//0=empty, 1=add-sum ,2=set-max
  ll value;
  query(ll a=0,ll b=0):type(a),value(b) {}
};

ll INF=(1LL<<60);

struct segtree{
  ll SIZE;
  vector<query> s;
  vector<ll> t;// sum-add
  vector<ll> u;// max-set

  segtree(ll n=1){
    SIZE=1;
    while(SIZE<n)SIZE*=2;
    s.clear();
    t.clear();
    u.clear();
    s.resize(SIZE*2, query());
    t.resize(SIZE*2, 0);
    u.resize(SIZE*2, 0);
  }
  
  void func(ll k,ll l,ll r,query q){
    if(q.type==1){
      if(s[k].type==0)s[k]=q;
      else s[k].value+=q.value;
      t[k]+=q.value*(r-l);
      u[k]+=q.value;
    }
    if(q.type==2){
      s[k]=q;
      t[k]=q.value*(r-l);
      u[k]=q.value;
    }
  }

  void compute(ll k,ll l,ll r){
    query q=s[k];
    s[k]=query();
    if(q.type==0||r-l==1)return;
    ll m=(l+r)/2;
    func(k*2+1,l,m,q);
    func(k*2+2,m,r,q);
  }

  void Update(ll a,ll b,query x,ll k,ll l,ll r){
    if(b<=l || r<=a)return;
    compute(k,l,r);
    if(a<=l && r<=b){
      func(k,l,r,x);
    }else{
      ll m=(l+r)/2;
      Update(a,b,x,k*2+1,l,m);
      Update(a,b,x,k*2+2,m,r);
      t[k]=t[k*2+1]+t[k*2+2];
      u[k]=max(u[k*2+1],u[k*2+2]);
    }
  }

  ll Dfs(ll type,ll a,ll b,ll k,ll l,ll r){
    if(b<=l || r<=a){
      if(type==1)return 0; //add
      if(type==2)return -INF; // max
    }
    compute(k,l,r);
    if(a<=l && r<=b){
      if(type==1)return t[k];
      if(type==2)return u[k];
    }else{
      ll m=(l+r)/2;
      ll lv=Dfs(type,a,b,k*2+1,l,m);
      ll rv=Dfs(type,a,b,k*2+2,m,r);
      if(type==1)return lv+rv; // add
      if(type==2)return max(lv,rv); // max
    }
  }

  void Add(ll a,ll b,ll x){
    Update(a,b,query(1,x), 0,0,SIZE);
  }
  void Set(ll a,ll b,ll x){
    Update(a,b,query(2,x), 0,0,SIZE);
  }
  ll Getsum(ll a,ll b){
    return Dfs(1,a,b, 0,0,SIZE);
  }

  ll Getmax(ll a,ll b){
    return Dfs(2,a,b, 0,0,SIZE);
  }
  
};

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n+1);
  segtree T(n+1);
  T.Set(0,n+1,0);
  for(ll i=1;i<=n;i++) {
    cin >> a[i];
    a[i]-=k;
  }
  for(ll i=0;i<n;i++) {
    a[i+1]+=a[i];
  }
  vector<pll> b(n+1);
  for(ll i=0;i<=n;i++) {
    b[i]={a[i],i};
  }
  sort(b.begin(),b.end());
  b[0].first=0;
  for(ll i=0;i<n;i++) {
    if(a[b[i].second]==a[b[i+1].second]) {
      b[i+1].first=b[i].first;
    }
    else {
      b[i+1].first=b[i].first+1;
    }
  }
  for(ll i=0;i<=n;i++) {
    a[b[i].second]=b[i].first;
  }
  ll ans=0;
  for(ll i=0;i<=n;i++) {
    ans+=T.Getsum(0,a[i]+1);
    T.Add(a[i],a[i]+1,1);
  }
  cout << ans << endl;
}

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

int main(){
	ll n,m;
	cin>>n>>m;
	ll ans=m;
	for (int i=1;i<=sqrt(m);i++){
		if (m%i==0){
			ll a=i;
			if (a>=n) ans=min(ans,a);
			a=m/i;
			if (a>=n) ans=min(ans,a);
		}
	}
	
	cout<<m/ans<<endl;
}
 

Measured memory_bytes: 256
H, W = map(int, input().split())
ban = [list(input()) for _ in range(H)]
cnt = 0
for i in range(H):
    for j in range(W):
        if ban[i][j] == "#":
            cnt += 1
if cnt == H + W - 1:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 9184
import sys
s=input()
sgn=1
if len(s)%2==0:
    for i in range(len(s)):
        if i%2==0:
            if s[i]!="h": sgn=0
        else:
            if s[i]!="i": sgn=0

else:
    sgn=0
print("Yes" if sgn==1 else "No")


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        var inp2 = Console.ReadLine().Split(' ');

        int monsterNum = int.Parse(inp[0]);
        int specialNum = int.Parse(inp[1]);

        var monsterList = new List<int>();
        for(int i = 0;i < inp2.Length;i++) {
            monsterList.Add(int.Parse(inp2[i]));
        }
        monsterList.Sort();
        monsterList.Reverse();

        long count = 0;

        for(int i = specialNum;i < monsterList.Count;i++) {
            count += monsterList[i];
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 32860
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
string S;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cin >> S;
    map<char, int> cnts;
    for (const auto &val : S)
    {
        cnts[val]++;
    }
    ll result = 1;
    for (const auto &val : cnts)
    {
        result *= (val.second + 1);
        result %= MOD;
    }
    result = ((result - 1) + MOD) % MOD;
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[1000];
	const char *apple = "apple";
	const char *peach = "peach";
	int i;

	gets(str);
	for (i = 0; str[i] != 0; i++){
		if (strncmp(&str[i], apple, 5) == 0){
			strncpy(str + i, peach, 5);
		}
		else if (strncmp(&str[i], peach, 5) == 0){
			strncpy(str + i, apple, 5);
		}
	}
	puts(str);

	return 0;
}

Measured memory_bytes: 520
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if(L > R) {
    cout << "Left" << endl;
  }
  else if(L < R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
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;}
 
const ll INF=1e15;
 
int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k << endl;
        return 0;
    }
    if(k<=a+b){
        cout << a << endl;
        return 0;
    }
    cout << a-(k-a-b) << endl;
    return 0;
} 

Measured memory_bytes: 3596
//agc15 q1
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <tuple>
#define pb push_back
#define mkt make_tuple
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
const int INF =  2147483647;
const ll INFLL = 9223372036854775807;



int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll ans;
  ll n, a, b;

  cin >> n >> a >> b;
  if ((a != b && n == 1) || a > b) {
    ans = 0;
  } else if (a == b) {
    ans = 1;
  } else {
    ans = ((n-1)*b+a) - ((n-1)*a+b) + 1;
  }

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


Measured memory_bytes: 256