akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 998244353LL
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

#define MAX_N 100000
long long extgcd(long long a, long long b, long long& x, long long& y) {
	long long d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}
long long mod_inverse(long long a, long long m) {
	long long x, y;
	if(extgcd(a, m, x, y) == 1) return (m + x % m) % m;
	else return -1;
}
vector<long long> fact(MAX_N+1, INF);
long long mod_fact(long long n, long long& e) {
	if(fact[0] == INF) {
		fact[0]=1;
		if(MAX_N != 0) fact[1]=1;
		for(ll i = 2; i <= MAX_N; ++i) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
	}
	e = 0;
	if(n == 0) return 1;
	long long res = mod_fact(n / MOD, e);
	e += n / MOD;
	if((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD;
	return (res * fact[n % MOD]) % MOD;
}

ll nck[4040][4040];

// return nCk
long long mod_comb(long long n, long long k) {
	if(n < 0 || k < 0 || n < k) return 0;
	if(nck[n][k]!=-INF*INF) return nck[n][k];
	long long e1, e2, e3;
	long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3);
	if(e1 > e2 + e3) return 0;
	return nck[n][k]=(a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	REP(i,4040) REP(j,4040) nck[i][j]=-INF*INF;
	ll k,n;
	cin>>k>>n;
	for(ll i=2; i<=2*k; i++) {
		ll ans=mod_comb(n+k-1,n);
		ll err=0;
		ll cons=0;
		for(ll j=1; i-j>=j; j++) {
			if(i-j<=k) cons++;
			if(j>=2000) break;
		}
		if(i%2) {
			for(ll j=1; j<=cons; j++) {
				if(n<j*2) continue;
				if(j%2) err+=mod_comb(cons,j)*mod_comb(n-j*2+k-1,n-j*2);
				else err-=mod_comb(cons,j)*mod_comb(n-j*2+k-1,n-j*2);
				err%=MOD;
			}
		} else /* i%2==0 */ {
			for(ll j=1; j<=cons; j++) {
				/* 同じ数による制約を含む */
				if(n<j*2) continue;
				if(j%2) err+=mod_comb(cons-1,j-1)*mod_comb(n-j*2+k-1,n-j*2);
				else err-=mod_comb(cons-1,j-1)*mod_comb(n-j*2+k-1,n-j*2);
				err%=MOD;

				if(j!=cons) /* 同じ数による制約を含まない */ {
					if(n<j*2) continue;
					if(j%2) err+=mod_comb(cons-1,j)*mod_comb(n-j*2+k-1,n-j*2);
					else err-=mod_comb(cons-1,j)*mod_comb(n-j*2+k-1,n-j*2);
					err%=MOD;
				}
			}
		}
		cout<<((ans-err)%MOD+MOD)%MOD<<endl;

	}
	return 0;
}


Measured memory_bytes: 128640
#include<stdio.h>
 
int n,m;
int a[1000000];
 
int check(int p){
  int i;
  int sum=0;
  int idx=0;
  for(i=0;i<m;i++){
    sum=0;
    while(a[idx]+sum<=p){
      sum+=a[idx];
      idx++;
      if(idx==n) return 1;
    }
  }
  return 0;
}
 
int main(){
  int i;
  int left=0,right=100000*10000;
  int mid;
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  while(right-left>1){
    mid=(left+right)/2;
    if(check(mid)==1) right=mid;
    else left=mid;
  }
  printf("%d\n",right);
  return 0;
}

Measured memory_bytes: 988
#include<cstdio>
using namespace std;
int main()
{
	int n,x;
	bool f=1;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if (x%2==0&&!(x%5==0||x%3==0)) f=0;
	}
	if (f) puts("APPROVED");
	else puts("DENIED"); 
	return 0;
} 

Measured memory_bytes: 128
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    
//-----------------------------------------------------------------------------------------------------------//

    READV(H);
    READV(W);
    READV(A);
    READV(B);
    ll ans[H][W];
    FORI(i,0,B)
    {
        FORI(j,0,A)
        {
            ans[i][j]=0;
        }
        FORI(j,A,W)
        {
            ans[i][j]=1;
        }
    }
    FORI(i,B,H)
    {
        FORI(j,0,A)
        {
            ans[i][j]=1;
        }
        FORI(j,A,W)
        {
            ans[i][j]=0;
        }
    }
    FORI(i,0,H)
    {
        FORI(j,0,W)
        {
            cout<<ans[i][j];
        }
        cout<<endl;
    }

//-----------------------------------------------------------------------------------------------------------//


    
    return 0;
}

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



int main(){
  int64_t A, B, K;
  cin >> A >> B >> K;

  if(A > K){
    cout << A-K << " " << B << endl;
  } else if (B > K-A){
    cout << 0 << " " << B-(K-A) << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}


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

char s[20][21];
int d[20][20];
int dx[]{ 0,-1,0,0,1 }, dy[]{ 0,0,1,-1,0 };

int main() {
	int h, w;
	while (scanf("%d%d", &h, &w), h) {
		int ax, ay, bx, by;
		rep(i, h) {
			scanf("%s", s[i]);
			rep(j, w) {
				if (s[i][j] == 'A')ax = i, ay = j;
				if (s[i][j] == 'B')bx = i, by = j;
			}
		}
		string p; cin >> p;
		for (char&c : p) {
			if (c == '5')c = 0;
			if (c == '8')c = 1;
			if (c == '6')c = 2;
			if (c == '4')c = 3;
			if (c == '2')c = 4;
		}
		queue<P>que;
		memset(d, -1, sizeof(d));
		d[ax][ay] = 0; que.push(P(ax, ay));
		while (!que.empty()) {
			P p = que.front(); que.pop();
			for (int i = 1; i <= 4; i++) {
				int nx = p.first + dx[i], ny = p.second + dy[i];
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s[nx][ny] != '#'&&d[nx][ny] == -1) {
					d[nx][ny] = d[p.first][p.second] + 1;
					que.push(P(nx, ny));
				}
			}
		}
		int x = bx, y = by;
		int t = 0;
		rep(i, 1000) {
			for (char c : p) {
				if (d[x][y] != -1 && d[x][y] <= t) {
					printf("%d %d %d\n", t, x, y); goto g;
				}
				int nx = x + dx[c], ny = y + dy[c]; t++;
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w)x = nx, y = ny;
			}
		}
		puts("impossible");
	g:;
	}
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
ll MOD=1e9+7;
ll modpow(ll a, ll n){
  if(n==1) return a%MOD;
  if(n%2==1) return (a*modpow(a,n-1))%MOD;
  else{
    ll t=modpow(a,n/2)%MOD;
    return (t*t)%MOD;
  }
}

int main(){
  ll N,K; cin>>N>>K;
  vector<pair<ll,ll>> A(N,{0,0});
  rep(i,N){
    ll a; cin>>a;
    if(a>=0) A[i]={a,1};
    else A[i]={-a,-1};
  }
  sort(A.begin(), A.end(), [](auto& x, auto& y){return x.first > y.first;});
  ll ans=1;
  rep(i,K){
    ll a1=A[i].first;
    (ans*=a1)%=MOD;
  }
  (ans+=MOD)%=MOD;
  //上からとって負数をみる
  ll tmp=1;
  for(ll i=0; i<K; i++){
    ll a2=A[i].second;
    tmp*=a2;
  }
  if(tmp==1 || N==K){//素直にとれる
    ans*=tmp;
    (ans+=MOD)%=MOD;
    cout<<ans<<endl;
    return 0;
  }
  //負の場合
  //1,負をのぞいて正をとる
  ll c1=1e10, c2=1e10, d1=1e10, d2=1e10;
  for(ll i=K-1; i>=0; i--){
    ll a2=A[i].second;
    if(a2==-1){//小さい負を除く
      c1=A[i].first;
      break;
    }
  }
  for(ll i=K; i<N; i++){
    ll a2=A[i].second;
    if(a2==1){
      c2=A[i].first;
      break;
    }
  }
  //2,正をのぞいて負をとる
  for(ll i=K-1; i>=0; i--){
    ll a2=A[i].second;
    if(a2==1){//小さい正を除く
      d1=A[i].first;
      break;
    }
  }
  for(ll i=K; i<N; i++){
    ll a2=A[i].second;
    if(a2==-1){
      d2=A[i].first;
      break;
    }
  }
//printf("pre:%lld,c1:%lld,c2:%lld,d1:%lld,d2:%lld\n",ans,c1,c2,d1,d2);
  if((c1 !=1e10 && c2 !=1e10 && (d1==1e10 || d2==1e10))
  || ((c1 !=1e10 && c2 !=1e10 && d1!=1e10 && d2!=1e10) && c2*d1>c1*d2)){
    (ans*=modpow(c1,MOD-2))%=MOD;
    (ans*=c2)%=MOD;
//printf("root:1\n");    
  }
  else if (((c1==1e10 || c2==1e10) && d1!=1e10 && d2!=1e10)
  || ((c1 !=1e10 && c2 !=1e10 && d1!=1e10 && d2!=1e10) && c2*d1<=c1*d2)){
    (ans*=modpow(d1,MOD-2))%=MOD;
    (ans*=d2)%=MOD;
//printf("root:2\n");    
  }
  else{//全部マイナスで奇数個とか
    ans=1;
    for(ll i=0; i<K; i++){
      ll a1=A[N-1-i].first;
      ll a2=A[N-1-i].second;
      (ans*=(a1*a2))%=MOD;
    }
//printf("root:3\n");    
  }
  (ans+=MOD)%=MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 6428
#include<bits/stdc++.h>
#define pir pair<int,int>
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;

const int N=510,M=100010;
int n,prime[M],cnt;
ll res[N][N];
bool vis[M];
vector<pir> v;

void pre(int m) {
    for(int i=2;i<=m;i++) {
        if(!vis[i]) prime[++cnt]=i;
        for(int j=1;j<=cnt;j++) {
            int tmp=prime[j]*i;
            if(tmp>m) break;
            vis[tmp]=1;
            if(i%prime[j]==0) break;
        }
    }
}

bool cmp1(pir a,pir b) {
    if(a.fi+a.se!=b.fi+b.se) return a.fi+a.se<b.fi+b.se;
    return a<b;
}

bool cmp2(pir a,pir b) {
    if(a.fi+a.se!=b.fi+b.se) return a.fi-a.se<b.fi-b.se;
    return a<b;
}

ll lcm(ll a,ll b) {
    return a/__gcd(a,b)*b;
}

int main() {
    pre(100000);
    scanf("%d",&n);
    if(n==2) return printf("2 3\n5 4\n"),0;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            if((i+j)%2==0) v.pb({i,j});
            res[i][j]=1;
        }
    }
    sort(v.begin(),v.end(),cmp1);
    pir pre={0,0};
    int* ptr=prime;
    for(auto p:v) {
        if(p.fi+p.se!=pre.fi+pre.se) ptr++;
        res[p.fi][p.se]*=*ptr;pre=p;
    }
    sort(v.begin(),v.end(),cmp2);
    pre={0,0};
    for(auto p:v) {
        if(p.fi-p.se!=pre.fi-pre.se) ptr++;
        res[p.fi][p.se]*=*ptr;pre=p;
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            if((i+j)%2) {
                if(i>1) res[i][j]=lcm(res[i][j],res[i-1][j]);
                if(j>1) res[i][j]=lcm(res[i][j],res[i][j-1]);
                if(i<n) res[i][j]=lcm(res[i][j],res[i+1][j]);
                if(j<n) res[i][j]=lcm(res[i][j],res[i][j+1]);
                printf("%lld ",res[i][j]+1);
            }
            else printf("%lld ",res[i][j]);
        }
        puts("");
    }
    return 0;
}

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

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

int main(){
  int n;
  cin>>n;
  string S[n];
  map<string,int> m;
  rep(i,n){
    cin>>S[i];
    if(m[S[i]]==0)
      m[S[i]]++;
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int i=0;i<n-1;i++){
    if(S[i][S[i].size()-1]!=S[i+1][0]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(N - K + 1):
    left = i
    right = left + K - 1
    if x[left] < 0 and x[right] >= 0:
        q = min(abs(x[left]) * 2 + x[right], x[right] * 2 + abs(x[left]))
        ans.append(q)
        continue
    elif x[right] < 0:
        q = abs(x[left])
        ans.append(q)
        continue
    elif x[left] > 0:
        q = abs(x[right])
        ans.append(q)
        continue
if len(ans) == 0:
    print(0)
    exit()

print(min(ans))


Measured memory_bytes: 20300
#include<stdio.h>

int main(int argc, char const *argv[]) {
	long long n,m;
	scanf("%lld %lld",&n,&m);
	m/=2;
	if(n>m) printf("%lld\n",m);
	else printf("%lld\n",(m+n)/2);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#define YES { puts("Yes"); return; }
#define NO { puts("No"); return; }

int T;
long long K, X0, XM, N;

inline long long gcd(long long a, long long b) {
  if (b == 0) return a;
  else return gcd(b, a % b);
}

inline void solve() {
  if (X0 < K) NO
  if (X0 < XM && K > N) NO
  if (X0 < XM && K == N) YES
  long long g = gcd(K, N);
  long long t = (X0 - XM) / g;
  if (X0 < XM) t = (X0 - XM + 1) / g - 1;
  long long mn = X0 - t * g;
//  printf("mn = %lld\n", mn);
  if (K >= XM) {
    if (mn - K + N < K) NO
    else if (mn >= K) YES
    else NO
  } else {
    if (K <= N) YES
    else if (mn - K + N >= XM) YES
    else NO
  }
}

int main() {
  scanf("%d", &T);
  for (int t = 1; t <= T; ++t) {
    scanf("%lld %lld %lld %lld", &X0, &K, &XM, &N);
    XM++;
    solve();
  }
  return 0;
}

Measured memory_bytes: 128
import sys
import bisect

sys.setrecursionlimit(10**8)

class SegmentTree(object):  #1-indexed
    def __init__(self, size, value):
        self.len = 1 << size.bit_length()
        self.default = value
        # print(self.len)
        self.array = [value] * (2 * self.len)

    def get(self, i):
        i += self.len
        ans = self.default
        while i > 0:
            ans = min(self.array[i], ans)
            i >>= 1
        return ans

    def query(self, l, r, v, i, a, b):
        if self.array[i] != self.default:
            return 0
        if l == a and r == b:
            self.array[i] = v
            return 0
        center = (a + b) // 2
        if center >= r:
            return self.query(l, r, v, i * 2, a, center)
        elif center <= l:
            return self.query(l, r, v, i * 2 + 1, center, b) 
        else:
            return min(
                self.query(l, center, v, i * 2, a, center),
                self.query(center, r, v, i * 2 + 1, center, b))

    def update(self, l, r, v):
        return self.query(l, r, v, 1, 0, self.len)


input = sys.stdin.readline

N, Q = map(int, input().split())

STX_array = [list(map(int, input().split())) for _ in range(N)]

STX_array = sorted(STX_array, key=lambda x: x[2])

Q_array = [int(input()) for _ in range(Q)]

index_array = [i for i in range(Q)]

INF = 10**9 + 7

seg_tree = SegmentTree(Q, INF)

for STX in STX_array:
    s, t, x = STX
    index_left = bisect.bisect_left(Q_array, s - 0.5 - x)
    index_right = bisect.bisect_left(Q_array, t - 0.5 - x)
    if index_left != index_right:
        seg_tree.update(index_left, index_right, x)

for i in range(Q):
    ans = seg_tree.get(i)
    print(ans) if ans != INF else print(-1)

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

char exchange(char c)
{
    if('A' <= c && c <= 'Z')
    {
        return c + ('a' - 'A');
    }
    else if('a' <= c && c <='z')
    {
        return c +('A' - 'a');
    }
    else return c;
}

int main(void)
{
    int i,len;
    char s[4096];  /* 1200バイト以上 */
    fgets(s, sizeof(s), stdin);
    len = strlen(s);   // 文字列の長さをえる
    for(int i = 0; i < len; i++)
    {
        s[i] = exchange(s[i]);
    }
    printf("%s",s);

    return 0;
}


Measured memory_bytes: 2052
import java.util.*

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}

    val es = Array(N) { ArrayList <Pair<Long, Long>>() }

    for (i in 1..M) {
        val (L, R, C) = readLine()!!.split(" ").map{it.toInt()}
        es[L - 1].add(Pair(R - 1L, C.toLong()))
    }

    val d = TreeMap<Long, Long>()
    val INF = 1e18.toLong()

    d[0L] = 0L

    for (i in 0 until N - 1) {
        val e = d.ceilingEntry(i.toLong())

        if (e == null) {
            continue
        }

        for (p in es[i]) {
            val f = d.ceilingEntry(p.first)

            if (f == null || f.value > e.value + p.second) {
                d[p.first] = e.value + p.second

                while (true) {
                    val g = d.lowerEntry(p.first)
                    if (g == null || g.value < e.value + p.second) break
                    d.remove(g.key)
                }
            }
        }
    }

    val e = d.ceilingEntry(N - 1L)
    println(e?.value ?: -1)
}


Measured memory_bytes: 87528
#include<bits/stdc++.h>
#define eps 1e-8
#define pr pair<int,int>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxx = 1e5;

int main()
{
	string str;
	cin >> str;
	if(str == "SUN")
		puts("7");
	else if(str == "MON")
		puts("6");
	else if(str == "TUE")
		puts("5");
	else if(str == "WED")
		puts("4");
	else if(str == "THU")
		puts("3");
	else if(str == "FRI")
		puts("2");
	else
		puts("1");

	return 0;
}



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

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

int main(){
  int N,X;
  cin>>N>>X;
  int L[N];
  rep(i,N)
    cin>>L[i];
  int count=1,arr=0;
  rep(i,N){
   arr+=L[i];
    if(arr<=X)
      count++;
  }
  cout<<count<<endl;
  return 0;
}
  


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

using namespace std;

void solve() {
    int n; cin >> n;
    int flag = 0;
    while (n) {
        flag |= ((n % 10) == 7);
        n /= 10;
    }
    cout << (flag ? "Yes" : "No");
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


Measured memory_bytes: 3636
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

  for(i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}




Measured memory_bytes: 2096
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
LL data[4005],x;
multiset<LL> haha;

int main()
{
  scanf("%d %lld",&n,&x);
  REP(i,n) {
    scanf("%lld",&data[i]);
    data[i+n] = data[i];
  }
  LL risan = INFF;
  REP(i,n)
  {
    LL now = x * i;
    haha.clear();
    FORN(j,0,i) haha.insert(data[j]);
    REP(j,n)
    {
      now += *(haha.begin());
      haha.erase(haha.lower_bound(data[j]));
      haha.insert(data[j+i+1]);
    }
    MIN(risan,now);
  }
  printf("%lld\n",risan);
  return 0;
}










Measured memory_bytes: 384
def solve():
    N = int(input())
    rng = []
    for i in range(N):
        X, L = map(int, input().split())
        first = X - L
        last = X + L
        rng.append((first,last))
    
    rng.sort(key=lambda x:x[1])

    prev_last = -float('inf')
    cnt = 0
    for i in range(N):
        if rng[i][0] >= prev_last:
            cnt += 1
            prev_last = rng[i][1]
    
    print(cnt)
    
if __name__ == '__main__':
    solve()

Measured memory_bytes: 18204
n, x = gets.split.map(&:to_i)
l_list = gets.split.map(&:to_i)

count = 0
d = 0
last_d = 0
(n + 1).times do |i|
  if i == 0
    count += 1
    next
  end
  
  d = last_d + l_list[i-1]
  last_d = d
  
  if d <= x
    count += 1
  else
    break
  end
end

puts count

Measured memory_bytes: 1788
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}
/*		1. Take all the inputs
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	// int main  or  int32_t main ...
	int n,m;
	cin >> n >> m;
	int sum = 0,a;
	while(m--){
		cin >> a;
		sum += a;
	}
	if(sum <= n)cout << n-sum << endl;
	else cout << "-1" << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	while(t--){ solve(); }
	return 0;
}


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

using namespace std;

int main() {
  
  int N, M;
  while(cin >> N >> M && (N|M)) {
    int vote[N][M];
    for(int i=0; i<N; i++)
      for(int j=0; j<M; j++)
	cin >> vote[i][j];
    
    int sum[M]; memset(sum, 0, sizeof sum);
    for(int i=0; i<M; i++)
      for(int j=0; j<N; j++)
	sum[i] += vote[j][i];
    
    vector<pair<int, int> > vec(M);
    for(int i=0; i<M; i++)
      vec[i] = make_pair(sum[i], -(i+1));
    sort(vec.begin(), vec.end(), greater<pair<int,int> >());
    for(int i=0; i<M; i++) {
      if(i) cout << ' ';
      cout << -vec[i].second;
    }
    cout << endl;
  }
  
  
  return 0;
}

Measured memory_bytes: 1596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

#define NIL -1
#define N 100005

//struct Node{
//	int val;
//	Node *p, *l, *r;
//};

struct Node {
	int p, l, r;
	Node():p(NIL), l(NIL), r(NIL){}
};

Node T[N];
int D[N];

void print(int u){
	printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

	if (T[u].p == NIL) printf("root, ");
	else if (T[u].l == NIL) printf("leaf, ");
	else printf("internal node, ");

	printf("[");
	for (int i = 0, c = T[u].l; c != NIL; c = T[c].r) {
		if (i++) printf(", ");
		printf("%d", c);
	}
	printf("]\n");
}

void rec(int u, int d){
	D[u] = d;
	if (T[u].l != NIL) rec(T[u].l, d + 1);
	if (T[u].r != NIL) rec(T[u].r, d);
}


int main(){
	int n; scanf("%d", &n);

	for (int i = 0; i < n; ++i)
	{
		int u, d; scanf("%d %d", &u, &d);

		int l;
		for (int j = 0; j < d; ++j){
			int v; cin >> v;
			if (j == 0){
				T[u].l = v;
			}
			else T[l].r = v;
			l = v;
			T[v].p = u;
		}
	}

	int root;
	for (int i = 0; i < n; ++i) {
		if (T[i].p == NIL) root = i;
	}
	rec(root, 0);
	for (int i = 0; i < n; ++i) print(i);

	return 0;
}

//node 0: parent = -1, depth = 0, root, [1, 4, 10]
//node 1 : parent = 0, depth = 1, internal node, [2, 3]
//node 2 : parent = 1, depth = 2, leaf, []
//node 3 : parent = 1, depth = 2, leaf, []
//node 4 : parent = 0, depth = 1, internal node, [5, 6, 7]
//node 5 : parent = 4, depth = 2, leaf, []
//node 6 : parent = 4, depth = 2, leaf, []
//node 7 : parent = 4, depth = 2, internal node, [8, 9]
//node 8 : parent = 7, depth = 3, leaf, []
//node 9 : parent = 7, depth = 3, leaf, []
//node 10 : parent = 0, depth = 1, internal node, [11, 12]
//node 11 : parent = 10, depth = 2, leaf, []
//node 12 : parent = 10, depth = 2, leaf, []

Measured memory_bytes: 4744
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int H,A;cin >> H >> A;
    int ans = (H+A-1)/A;
    cout << ans << endl;
}


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

int main(){
  map<char,int>mp;
  char c;
  int n;
  long long sum;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>c;
		mp[c]++; 
	}
	sum=1;
	for(char i='a';i<='z';++i){
		sum*=(mp[i]+1);
		sum%=1000000007;
	}
	cout<<sum-1<<endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int cnt = 0;
  for(int i=0; i<N; i++){
    int x;
    cin >> x;
    if(x >= A && x < B){
      continue;
    }
    else{
      cnt++;
    }
  }
  cout << cnt << endl;  
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int i,j,n,m;
  while(1){
    scanf("%d%d",&n,&m);
    if(n==0&&m==0){
      break;
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=m;j++){
	if(i==1||i==n||j==1||j==m) printf("#");
	else printf(".");
      }
      printf("\n");
    }
    printf("\n");


  }


  return 0;
}



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var abcd = ReadLine().Split().Select(int.Parse).ToArray();
        var a =abcd[0];
        var b =abcd[1];
        var c =abcd[2];
        var d =abcd[3];
        WriteLine((Math.Abs(a-c)<=d)||(Math.Abs(a-b)<=d&&Math.Abs(c-b)<=d)?"Yes":"No");
    }
}

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

using namespace std;

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

	int ans = A - B * 2;
	if (ans < 0) {
		cout << 0 << endl;
	} else {
		cout << ans << endl;
	}
	return 0;
}


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


#define ll long long
#define pb push_back

#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, a, b) for(int i = (a); i > (b); --i)

typedef pair <int,int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <ll> vl;

const int mod = 1e9+7;
const ll inf = 2e18+5;


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

    ll n,m,x,y;
    cin>>n>>m;
    vl a(n);
    vector <pair <ll,ll> > b(m);
    loop(i,0,n){
        cin>>a[i];
    }
    loop(i,0,m){
        cin>>x>>y;
        b.push_back(pair<ll,ll>(y,x));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    int cur=0,f=0;    
    loop(i,0,m){
        x=b[i].first;
        y=b[i].second;
        loop(j,cur,cur+y){
            if(a[j]>=x)
                {f=1;break;}
            a[j]=x;
        }
        if(f==1) break;
        cur=cur+y;
    }
    ll s=0;
    loop(i,0,n) s+=a[i];
    cout<<s<<endl;
    return 0;
}   

Measured memory_bytes: 5504
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

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

vector<string> inputs;
int grid[60][60];
void solve(){
	vector<string> final_ans;
	while(true){
		int w, h;
		cin >> w >> h;
		if (w == 0) {
			REP(i, final_ans.size()) {
				cout << final_ans[i] << endl;
			}
			return;
		}
		REP(i, 60) {
			REP(q, 60) {
				grid[i][q] = 0;
			}
		}
		inputs.clear();
		REP(i, h) {
			string s;
			cin >> s;
			inputs.push_back(s);
		}
		reverse(ALL(inputs));
		int now_itr = 1;
		for (int i = 0; i < h; ++i) {
			REP(q, w) {
				if (inputs[i][q] == '.') continue;
				queue<pair<int, int>> next;
				int target = inputs[i][q];
				inputs[i][q] = '.';
				next.push(mp(i, q));
				while (next.empty() == false) {
					pair<int, int> now = next.front();
					next.pop();
					grid[now.first][now.second] = now_itr;
					REP(q, 4) {
						int x = now.first + dx[q];
						int y = now.second + dy[q];
						if (x >= 0 && x < h && y >= 0 && y < w) {
							if (inputs[x][y] == target) {
								inputs[x][y] = '.';
								next.push(mp(x, y));
							}
						}
					}
				}
				now_itr++;
			}
		}
		final_ans.push_back("");
		for (int now_val = 1; now_val < now_itr; ++now_val) {
			int visited[60][60] = {};
			queue<pair<int, int>> next;
			ll now_x_max = 0;
			ll now_x_min = 1e9;
			REP(i, h) {
				REP(q, w) {
					if (grid[i][q] != now_val) continue;
					visited[i][q] = 1;
					next.push(mp(i, q));
					if (i == 0 || (grid[i - 1][q] != 0&&grid[i-1][q] != grid[i][q])) {
						now_x_max = max(now_x_max, q);
						now_x_min = min(now_x_min, q);
					}
				}
			}
			while (next.empty() == false) {
				pair<int, int> now = next.front();
				next.pop();
				REP(q, 4) {
					int x = now.first + dx[q];
					int y = now.second + dy[q];
					if (!(x >= 0 && x < h && y >= 0 && y < w)) continue;
					if (grid[x][y] == 0) continue;
					if (q != 0) {
						if (grid[x][y] != grid[now.first][now.second]) continue;
					}
					if (visited[x][y] == 0) {
						visited[x][y] = 1;
						next.push(mp(x, y));
					}
				}
			}
			int cnt = 0;
			int val = 0;
			REP(i, h) {
				REP(q, w) {
					cnt += visited[i][q] * (2 * q + 1);
					if (visited[i][q] == 1) {
						val++;
					}
				}
			}
			now_x_max++;
			if (!(now_x_min *2 * val < cnt && cnt < now_x_max * val * 2)) {
				final_ans.back() = "UN";
				break;
			}
		}
		final_ans.back() += "STABLE";
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int h,w,ans=0;
    char s;
    cin >> h >> w;
    vector<vector<pair<int,int>>> a(w,vector<pair<int,int>>(h));
    vector<vector<int>> b(w,vector<int>(h));
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            cin >> s;
            if (s=='.') b.at(j).at(i)=0;
            else b.at(j).at(i)=1;
        }
    }
    for (int i=0;i<h;i++){
        int t=0,k=0;
        for (int j=0;j<w;j++){
            if (b.at(j).at(i)==0) t++;
            else {
                for (int l=k;l<k+t;l++){
                    a.at(l).at(i).first=t;
                    
                }
                a.at(j).at(i).first=0;
                k=k+t+1;
                t=0;
            }
        }
        for (int l=k;l<k+t;l++){
            a.at(l).at(i).first=t;
        }
    }
        for (int i=0;i<w;i++){
        int t=0,k=0;
        for (int j=0;j<h;j++){
            if (b.at(i).at(j)==0) t++;
            else {
                for (int l=k;l<k+t;l++){
                    a.at(i).at(l).second=t;
                    
                }
                a.at(i).at(j).second=0;
                k=k+t+1;
                t=0;
            }
        }
        for (int l=k;l<k+t;l++){
            a.at(i).at(l).second=t;
        }
    }
    int p;
    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            p=a.at(j).at(i).first+a.at(j).at(i).second-1;
            ans=max(ans,p);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 47232
from operator import itemgetter
n = int(input())
even = {}
odd = {}
V = list(map(int,input().split()))
for i in range(n):
    if i % 2 == 0:
        if V[i] in even:
            even[V[i]] += 1
        else:
            even[V[i]] = 1
    else:
        if V[i] in odd:
            odd[V[i]] += 1
        else:
            odd[V[i]] = 1
E = sorted(even.items(),key=itemgetter(1))
O = sorted(odd.items(),key=itemgetter(1))
a1=E.pop()
b1=O.pop()
if a1[0] != b1[0]:
    print(n-a1[1]-b1[1])
else:
    ans=a1[1]
    if E:
        a2=E.pop()
        ans=max(ans,a2[1]+b1[1])
    if O:
        b2=O.pop()
        ans = max(ans,a1[1]+b2[1])
    print(n-ans)
    
        

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

def main():
    N, A, B = map(int, input().split())

    if A > B:
        print(0)
    elif N == 1:
        if A == B:
            print(1)
        else:
            print(0)
    elif N == 2:
        print(1)
    else:
        print(B * (N-2) - A * (N-2) + 1)


if __name__ == "__main__":
    main()


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

int main(){
    int n,cnt=1;
    cin >> n;
    string s[n];
    rep(i,n) cin >> s[i];
    sort(s,s+n);
    rep(i,n-1){
        if(s[i]!=s[i+1])cnt++;
    }
    cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 9880
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('\n');
   let H = Number(xs[0].split(' ')[0]);
   let W = Number(xs[0].split(' ')[1]);
   let a = xs.slice(1);
  
   console.log(Array(W+3).join("#"));
   for(let i=0; i<H; i++){
      console.log('#'+a[i]+'#')
   }
   console.log(Array(W+3).join("#"));
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n,a;
	vector<int>v;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	cout<<v[n-1]-v[0]<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<int um> class UF {
	public:
	vector<int> par,rank;
	UF() {rank=vector<int>(um,0); for(int i=0;i<um;i++) par.push_back(i);}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<2000> uf;

int in[2000];
int out[2000];

int N,H;


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>H;
	FOR(i,N) {
		int A,B,C,D,L,R;
		cin>>A>>B>>C>>D;
		if(C>0) L=C;
		else L=-A;
		if(D==0) R=B;
		else R=-D;
		
		out[L+1000]++;
		in[R+1000]++;
		uf(L+1000,R+1000);
	}
	
	for(i=-200;i<=-1;i++) {
		if(in[i+1000]>out[i+1000]) return _P("NO\n");
		if(in[i+1000]<out[i+1000]) uf(1000,i+1000);
	}
	for(i=1;i<=200;i++) {
		if(in[i+1000]<out[i+1000]) return _P("NO\n");
		if(in[i+1000]>out[i+1000]) uf(1000,i+1000);
	}
	
	for(i=1000-200;i<=1000+200;i++) if((in[i]||out[i]) && uf[i]!=uf[1000]) return _P("NO\n");
	_P("YES\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
#[cfg(test)]
#[macro_use]
extern crate contest;

use std::fmt::Debug;
use std::io::{self, Bytes, Read, Stdin, StdinLock};
use std::str::{self, FromStr};

fn main() {
    let stdin = io::stdin();
    let mut sc = StdinScanner::new(&stdin);
    let (a, b, c) = (sc.next::<u32>(), sc.next::<u32>(), sc.next::<u32>());
    let s = format!("{}{}{}", a, b, c);
    let result = s.parse::<u32>().unwrap() % 4 == 0;
    println!("{}", if result { "YES" } else { "NO" })
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        assert_eq_in_time!(1000, "", "");
    }
}


struct StdinScanner<'a> {
    buf: Vec<u8>,
    bytes: Bytes<StdinLock<'a>>,
}


#[allow(dead_code)]
impl<'a> StdinScanner<'a> {
    fn new(stdin: &'a Stdin) -> Self {
        StdinScanner {
            buf: Vec::with_capacity(256),
            bytes: stdin.lock().bytes(),
        }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut c = self.bytes.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = self.bytes.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = self.bytes.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug,
              <C as FromStr>::Err: Debug
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


trait PrintYn {
    fn print_yn(self, yes: &str, no: &str);
}

impl PrintYn for bool {
    fn print_yn(self, yes: &str, no: &str) {
        println!("{}", if self { yes } else { no });
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n, h;
  cin >> n >> h;
  vi a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int start = lower_bound(b.begin(), b.end(), a[n-1]) - b.begin();

  int ans = 0;
  for(int i=n-1;i>=start;i--){
    h -= b[i];
    ans++;
    if (h <= 0){
      cout << ans << endl;
      return 0;
    }
  }
  ans += h / a[n-1];
  if (h%a[n-1]) ans++;

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

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static double dp[][];
	static int X, Y, Z;
	static int V[];
	static int m_kinds[];
	static int m_values[];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			X = sc.nextInt();
			Y = sc.nextInt();
			Z = sc.nextInt();
			if (X == 0)
				break;
			V = new int[X];
			for (int i = 0; i < X; i++) {
				V[i] = sc.nextInt();
			}
			m_kinds = new int[Y+1];
			m_values = new int[Y+1];
			for (int i = 0; i < Z; i++) {
				int n = sc.nextInt();
				m_kinds[n] = sc.nextInt(); 
				m_values[n] = sc.nextInt(); 
			}
			dp = new double[Y+1][5001];
			dp[0][0] = 1;
			System.out.println((int)DP());
		}		
	}

	private static double DP() {
		for (int i = 0; i < Y; i++) {
			for (int j = 0; j < 5001; j++) {
				if (dp[i][j] > 0) {
					for (int k = 0; k < X; k++) {
						int to = i + V[k];
						if (to > Y) to = Y;
						int money = j;
						switch (m_kinds[to]) {
						case 1:
							to += m_values[to];
							if (to > Y) to = Y;
							break;
						case 2:
							money += m_values[to];
							break;
						case 3:
							money -= m_values[to];
							if (money < 0 ) money = 0;
							break;
						}
						dp[to][money] += (dp[i][j] / X);
					}
				}
			}
		}
        double exp = 0.0;
        for (int i = 0; i < 5001; i++) {
            exp += (dp[Y][i] * i);
        }
        return exp;
	}
}

Measured memory_bytes: 61436
/* Copyright 2016 AcrossTheSky */
#include <iostream>
#include <cstdio>
#include <utility>
#include <cassert>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define PER(i, a, b) for (int i = (a); i >= (b); --i)
#define RVC(i, c) fot (int i = 0; i < (c).size(); ++i)
#define RED(k, u) for (int k = head[(u)]; k; k = edge[k].next)
#define SQR(k) (k) * (k)
#define lowbit(x) ((x) & (-(x)))
#define CL(x, v) memset(x, v, sizeof x)
#define MP std::make_pair
#define PB push_back
#define FR first
#define SC second
#define rank rankk
#define next nextt
#define link linkk
#define index indexx
#define abs(x) ((x) > 0 ? (x) : (-(x)))
using namespace std;
typedef long long LL; typedef pair<int, int> PII;

template<class T> inline
bool getmin(T *a, const T &b) {
    if (b < *a) {
        *a = b;
        return true;
    }
    return false;
}

template<class T> inline
bool getmax(T *a, const T &b) {
    if (b > *a) {
        *a = b;
        return true;
    }
    return false;
}

template<class T> inline
void read(T *a) {
    char c;
    while (isspace(c = getchar())) {}
    bool flag = 0;
    if (c == '-') flag = 1, *a = 0;
    else
        *a = c - 48;
    while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
    if (flag) *a = -*a;
}

const int mo = 1000000007;
template<class T>
T pow(T a, T b, int c = mo) {
    T res = 1;
    for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) if (b & i) res = 1LL * res * a % c;
    return res;
}
/*======================= TEMPLATE =======================*/
const int N = 30000;
int a[N], b[N];
int n, p[N];
int main() {
    cin >> n;
    REP(i, 1, n) a[i] = (i - 1) * n + 1;
    REP(i, 1, n) b[i] = a[n - i + 1];
    REP(i, 1, n) {
        int x;
        read(&x);
        a[x] += (i - 1);
    }
    REP(i, 1, n) printf("%d ", a[i]);
    cout << endl;
    REP(i, 1, n) printf("%d ", b[i]);
    cout << endl;
    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int L, N;
  string s;

  cin >> L >> N >> s;

  ll counter = 0;
  for (int i=1; i<L; i++) {
    counter += s[i-1] == 'o' && s[i] == 'o';
  }

  ll ans = s.size();

  for (int i=0; i<N; i++) {
    ans += counter * 3;
    counter *= 2;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3160
NX = input().split()
n = int(NX[0])
x = int(NX[1])

while n!=0 or x!=0:
    out = 0
    for ii in range(n-2):
        i = ii+1 #i:1~n-2
        for jj in range(n-1-i):
            j = jj+1+i #j:i+1~i+1+n-2-i=i+1~n-1
            for kk in range(n-j):
                k = kk+1+j #k:j+1~n-j+j+1 =
                if k !=i and k!=j and i+j+k == x:
                    out = out+1
    print(out)
    NX = input().split()
    n = int(NX[0])
    x = int(NX[1])

Measured memory_bytes: 7676
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <cstdlib>
using namespace std;

// 一行取って、一番初めのTを習得
template <class T> int streamvar(std::istream& in, T& var)
{
    string s;
    if (!in) {
        return 1;
    }
    getline(in, s);
    istringstream is(s);
    is >> var;
    if (is.fail()) 
        return 1;
    return 0;
}
// 一行取って、T vectorに格納する
template <class T> int streamvec(std::istream& in, std::vector<T> &v)
{
    v.clear();
    string s;

    if (!in) 
        return 1;
    getline(in, s);
    if (in.fail()) 
        return 1;
    istringstream is(s);
    while (1) {
        T tmp;
        is >> tmp;
        if (is.fail())
            break;
        v.push_back(tmp);
    }
    return 0;
}

int main(void)
{
    vector<int> v;
    int tmp;
    streamvar(cin, tmp);
    while (!streamvec(cin, v)) {
        sort(v.begin(), v.end());
        if (v[2] * v[2] == v[1] * v[1] + v[0] * v[0])
            cout << "YES" << endl;
        else 
            cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1236