akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

namespace flow {
  // MAKSYMALNY PRZEPLYW (algorytm Edmondsa-Karpa)
  // Adam Polak

  const int N = 1000;
  int n, cap[N][N];   // INPUT
  int flow[N][N];     // OUTPUT

  int edmonds(int s, int t) {
      int b,e,q[n],p[n],d,FLOW=0;
      REP(i,n) REP(j,n) flow[i][j]=0;
      for(;;) {
          REP(i,n) p[i]=-1;
          for(q[b=e=0]=s;b<=e;b++)
              REP(v,n)
                  if (flow[q[b]][v] < cap[q[b]][v] && p[v]<0)
                      p[q[++e]=v] = q[b];
          if (p[t]<0) break;
          d = cap[p[t]][t] - flow[p[t]][t];
          for(int i=t;i!=s;i=p[i]) d=min(d,cap[p[i]][i]-flow[p[i]][i]);
          for(int i=t;i!=s;i=p[i]) {
              flow[p[i]][i] += d;
              flow[i][p[i]] -= d;
          }
          FLOW += d;
      }
      return FLOW;
  }
}

typedef pair<int, int> PII;
typedef long long LL;

char M[200][200];

int main() {
  int H, W;
  scanf("%d%d", &H, &W);
  REP(i,H) scanf("%s", M[i]);

  int S = H + W, T = H+W+1;
  REP(h,H)REP(w,W) {
    if (M[h][w] == 'o') {
      flow::cap[h][H+w] = flow::cap[H+w][h] = 1;
    } else if (M[h][w] == 'S') {
      flow::cap[S][h] = flow::cap[S][H+w] = 1000;
    } else if (M[h][w] == 'T') {
      flow::cap[h][T] = flow::cap[H+w][T] = 1000;
    }
  }

  flow::n = H + W + 2;

  int f = flow::edmonds(S, T);
  printf("%d\n", f > 500 ? -1 : f);
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define REYNA(i,a,b) for(int i=(a);i<(b);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, pair <int, ll> > PP;
typedef pair <PII, int> PPI;
typedef pair <int, PII> PIP;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
const int maxn = 100010;
int tab[maxn], n;

PLL wyn[maxn];
ll f(ll x, ll y) {
	ll k = (y / x);
	while (k * x < y) ++k;
	return k * x;
}

void licz(int i)
{
	wyn[i].e1 = f(tab[i], wyn[i + 1].e1);
	ll xd = wyn[i + 1].e2 / (ll) tab[i];
	wyn[i + 1].e2 = (ll)tab[i] * xd;
	wyn[i].e2 = f(tab[i], wyn[i + 1].e2) + tab[i] - 1;
}

int main()
{
	boost;
	cin >> n;
	FOR(i, 1, n) cin >> tab[i];
	if (tab[n] != 2) OUT(-1);
	wyn[n + 1] = mp(2, 2);
	for (int i = n; i > 0; --i) licz(i);
	if (wyn[1].e1 <= wyn[1].e2) cout << wyn[1].e1 << ' ' << wyn[1].e2;
	else cout << -1;
}


Measured memory_bytes: 2176
import java.util.*;

class Main{
    int[] cnt;

    boolean check(){
        for ( int i = 0; i <= 100; i++ ) if ( cnt[i] % 4 > 0 ) return false;
        return true;
    }

    void solve(){
        Scanner sc = new Scanner(System.in);
        cnt = new int[101];
        for ( int i = 0; i <= 100; i++ ) cnt[i] = 0;
        for ( int i = 0; i < 12; i++ ){
            int x = sc.nextInt(); cnt[x]++;
        }
        if ( check() ) System.out.println("yes");
        else System.out.println("no");
    }

    public static void main(String[] a){ new Main().solve(); }
}



Measured memory_bytes: 26344
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;

const int N = 100010;
char s[N];
int n, cnta, cntb, cntc;

int main()
{
	scanf("%s", s+1); int n = strlen(s+1);
	for (int i = 1; i <= n; i ++){
		if (s[i] == 'a') cnta ++;
		if (s[i] == 'b') cntb ++;
		if (s[i] == 'c') cntc ++;
	}
	//printf("%d %d %d\n", cnta, cntb, cntc);
	if ((abs(cnta-cntb) <= 1) && (abs(cnta-cntc) <= 1) && (abs(cntb-cntc) <= 1)) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 888
class Dice:
    # 0: top, 1: front, 2: right, 3: left, 4: back, 5: bottom
    def __init__(self, n0, n1, n2, n3, n4, n5):
        self.faces = [n0, n1, n2, n3, n4, n5]

    def move(self, op):
        tmp = self.faces[0]
        if op == 'E':
            self.faces[0] = self.faces[3]
            self.faces[3] = self.faces[5]
            self.faces[5] = self.faces[2]
            self.faces[2] = tmp
        elif op == 'N':
            self.faces[0] = self.faces[1]
            self.faces[1] = self.faces[5]
            self.faces[5] = self.faces[4]
            self.faces[4] = tmp
        elif op == 'S':
            self.faces[0] = self.faces[4]
            self.faces[4] = self.faces[5]
            self.faces[5] = self.faces[1]
            self.faces[1] = tmp
        elif op == 'W':
            self.faces[0] = self.faces[2]
            self.faces[2] = self.faces[5]
            self.faces[5] = self.faces[3]
            self.faces[3] = tmp

    def spin_horizontally(self):
        tmp = self.faces[1]
        self.faces[1] = self.faces[2]
        self.faces[2] = self.faces[4]
        self.faces[4] = self.faces[3]
        self.faces[3] = tmp

    def top(self):
        return self.faces[0]

    def front(self):
        return self.faces[1]

    def right(self):
        return self.faces[2]

n = list(map(int, input().split()))
dice = Dice(n[0], n[1], n[2], n[3], n[4], n[5])
q = int(input())
for _ in range(q):
    t, f = map(int, input().split())

    for i in range(5):
        if dice.top() == t:
            break
        if i % 2 == 0:
            dice.move('S')
        else:
            dice.move('E')

    for i in range(3):
        if dice.front() == f:
            break
        dice.spin_horizontally()

    print(dice.right())



Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 100000007;
#define fr first
#define sc second
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll ad(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

ll ml(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

ll pw(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    return res;
}

int mu(ll n) {
	int c = 1, pn = p.size();
	for(int i = 0; i < pn && p[i] * p[i] <= n; i++) {
		if(n%p[i] == 0) c = -c, n /= p[i];
		if(n%p[i] == 0) return 0;
	}
	if(n > 1) return -c;
	return c;
}

void sieveMU(ll n, vl &mu) {
    vl factor(n+1, 0);
    for(int i = 2; i * i <= n; i++) {
        if(!factor[i]) {
            for(int j = i * i; j <= n; j += i) factor[j] = i;
        }
    }
    mu[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!factor[i]) {
            mu[i] = -1;
            continue;
        }
        if((i/factor[i])%factor[i] == 0) {
            mu[i] = 0;
        } else {
            mu[i] = (-1)*mu[i/factor[i]];
        }
    }
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(ll n, ll r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ml(ifac[r], ifac[n-r]));
}

ll P(int n, int r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ifac[n-r]);
}

void sieve(ll n) {
    vector<bool> prime(n+1, true);
    for(int i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(int j = i*i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    p.push_back(2);
    for(int i = 3; i <= n; i += 2) {
        if(prime[i]) p.push_back(i);
    }
}

ll PIE(ll n, ll k, ll f, ll mod = md) {
	if(f < 0 || k < 0 || n < 0) return 0;
	ll ans = 0, l = min(n, k/(f+1));
	for(int i = 0; i <= l; i++) {
		ans = ad(ans, (i&1 ? -1 : 1) * ml(C(n, i), C(n - 1 + k - (f+1) * i, k - (f+1) * i)));
	}
	return ans;
}

void mat_mul(vvl &M, vvl &S, int N) {
	vvl res(N, vl (N, 0));
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			for(int k = 0; k < N; k++) {
				res[i][j] += M[i][k]*S[k][j];
			}
		}
	}
	M = res;
}

void mat_exp(vvl &F, int N, ll n) {
	vvl res(N, vl (N,0));
	for(int i = 0; i < N; i++) res[i][i] = 1;
	while(n) {
		if(n & 1) mat_mul(res, F, N);
		mat_mul(F, F, N);
		n >>= 1;
	}
	F = res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll n = s.size(), sm = 0;
    for(int i = 0; i < n; i++) {
    	sm += s[i] - '0';
    }
    cout << (sm%9 == 0 ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
string s[11111];
int vab,va,vb;
ll ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>s[i];
	for(int i=1;i<=n;i++){
		for(int j=1;j<s[i].size();j++){
			if(s[i][j-1]=='A'&&s[i][j]=='B')ans++;
		}
		if(s[i][0]=='B'&&s[i].back()=='A')vab++;
		else if(s[i][0]=='B')vb++;
		else if(s[i].back()=='A')va++;
	}
	if(!vab){
		cout<<ans+min(va,vb)<<endl;
		return 0;
	}
	ans+=vab-1;
	if(va)va--,ans++;
	if(vb)vb--,ans++;
	ans+=min(va,vb);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<queue>
using namespace std;
int n,c[17],d[100];
main()
{
	for(int i=0;i<17;i++)c[i]=-1;
	priority_queue<pair<int,int> >P;
	int now=0;
	for(int i=0;i<100;i++)
	{
		while(!P.empty()&&-P.top().first<=i*5)
		{
			int u=P.top().second;
			P.pop();
			for(int j=0;j<17;j++)if(c[j]==u)c[j]=-1;
		}
		int L=-1;
		while(L<0)
		{
			for(int j=0;j+(i%5==1?5:2)<=17;j++)
			{
				bool ok=1;
				for(int k=0;k<(i%5==1?5:2);k++)ok&=c[j+k]==-1;
				if(ok)
				{
					L=j;break;
				}
			}
			if(L>=0)break;
			pair<int,int>p=P.top();P.pop();
			now=-p.first;
			for(int j=0;j<17;j++)if(c[j]==p.second)c[j]=-1;
		}
		if(now<i*5)now=i*5;
		P.push(make_pair(-now-(17*(i%2)+3*(i%3)+19),i));
		d[i]=now-i*5;
		for(int k=0;k<(i%5==1?5:2);k++)c[L+k]=i;
	}
	while(cin>>n)cout<<d[n]<<endl;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int odd = (N+1)/2;
	cout << (double)odd/N << endl;
}

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

int main(void){
   long long  N,K;
    cin>>N>>K;
    if(N==1)
        cout<<K<<endl;
    else{
        string ans=to_string((int)pow(K-1,N-1)*K);
        cout<<ans<<endl;
    }
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

const int N = 1e5+34;

int a[N];

void solve() {
    int n; scanf("%d", &n);
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a+i);
        sum += abs(a[i]-a[i-1]);
    }
    sum += abs(a[n]);
    debug(sum);
    for (int i = 1; i <= n; ++i) {
        int cur = sum-abs(a[i]-a[i-1]);
        if (i == n) {
            cur -= abs(a[i]);
            cur += abs(a[i-1]);
        } else {
            cur -= abs(a[i+1]-a[i]);
            cur += abs(a[i+1]-a[i-1]);
        }
        printf("%d\n", cur);
    }
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    string str;
    cin >> n >> str;
    
    auto makeseq = [](const string& str, vector<int> res) -> vector<int> {
        int n = str.size();
        assert(res.size() == 2);
        const int SHEEP = 1;
        const int WOLF  = -1;
        repeat_from_to(i, 1, n-2) {
            if ((str[i] == 'o' && res[i] == SHEEP) || (str[i] == 'x' && res[i] == WOLF))
                res.push_back( res[i-1] );
            else
                res.push_back( -res[i-1] );
        }
        return res;
    };
    
    auto isvalid = [](int mid, char say, int prev, int next) -> bool {
        const int SHEEP = 1;
        const int WOLF  = -1;
        bool res;
        if ((mid == SHEEP && say == 'o') || (mid == WOLF && say == 'x')) {
            res = (prev == next);
        }
        else {
            res = (prev != next);
        }
        return res;
    };
    
    auto show = [](vector<int> res) -> void {
        int n = res.size();
        repeat(i, n) {
            if (res[i] == 1) cout << 'S';
            else cout << 'W';
        }
    };
    
    vector<vector<int>> ss {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
    repeat(i, 4) {
        vector<int> res = makeseq(str, ss[i]);
        if (isvalid(res[0], str[0], res[1], res[n-1]) && isvalid(res[n-1], str[n-1], res[n-2], res[0])) {
            show(res);
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1444
// ConsoleApplication7.cpp : ??????????????? ??¢????????±????????§????????¨????????? ?????????????????????????????????
//

#include <stdio.h>
#include <limits.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char* argv[])
{
	int n, cn;
	int min = INT_MAX, max = INT_MIN;
	long long sum = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> cn;
		min = std::min(min, cn);
		max = std::max(max, cn);
		sum += cn;
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int H,W,K; cin >> H >> W >> K;
    char S[H][W]; REP(i,H)REP(j,W) cin >> S[i][j];
    int A[H+1][W+1]; CLR(A);
    REP(i,H)REP(j,W) A[i+1][j+1] = S[i][j]-'0';
    REP(i,H)REP(j,W){
        A[i+1][j+1] += A[i+1][j] + A[i][j+1] - A[i][j];
    }

    int ans = INT_INF;
    REP(i,1<<(H-1)){
        int tmp = 0;
        VI cut; cut.push_back(0);
        REP(j,H-1) if(i & 1<<j) cut.push_back(j+1);
        cut.push_back(H);
        tmp = cut.size()-2;
        // 各jについてカットするべきか
        VI cutj; cutj.push_back(0);
        REP(j,W){
            int last = cutj.back();
            // cutiでの各ブロックの個数を取得
            int num;
            bool flag = false;
            REP(k,cut.size()-1){
                num = A[cut[k+1]][j+1] - A[cut[k]][j+1] - A[cut[k+1]][last] + A[cut[k]][last];
                if(num > K){
                    flag = true;
                    break;
                }
            }
            if(flag && last == j){
                tmp = INT_INF;
                break;
            }
            if(flag){
                cutj.push_back(j);
                tmp++;
            }
        }
        chmin(ans, tmp);
    }
    cout << ans << en;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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

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

ll gcd(ll a, ll b) {
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) {
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) {
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int H,W; cin>>H>>W;
	int N; cin>>N;
	int A[H*W];
	int k=0;
	for(int i=0; i<N; i++) {
		int a; cin>>a;
		for(int j=0; j<a; j++,k++) A[k]=i+1;
	}

	int field[H][W];
	k=0;
	for(int i=0; i<H/2; i++) {
		for(int j=0; j<W; j++) {
			field[2*i][j]=A[k];
			k++;
		}
		for(int j=W-1; j>=0; j--) {
			field[2*i+1][j]=A[k];
			k++;
		}
	}
	if(H%2) {
		for(int j=0; j<W; j++) {
			field[H-1][j]=A[k];
			k++;
		}
	}

	for(int i=0; i<H; i++) {
		for(int j=0; j<W; j++)
			cout<<field[i][j]<<" ";
		cout<<endl;
	}
		
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 105; i <= N; i++) {
        if(i%2==0) continue;
        int yakusuu = 1;
        int n = i;
        int j = 2;
        while (n > 1) {
            int k = 1;
            while (n % j == 0) {
                n /= j;
                k++;
            }
            yakusuu *= k;
            j++;
        }
        if(yakusuu==8) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		boolean[][] map;
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			map = new boolean[21][21];
			for(int i = 0;i < n;i++){
				map[scan.nextInt()][scan.nextInt()] = true;
			}
			int m = scan.nextInt();
			int x = 10;
			int y = 10;
			int t = 0;
			int count = n;
			for(int i = 0;i < m;i++){
				String op = scan.next();
				t = scan.nextInt();
				if(t == 0){
					continue;
				}
				if(op.equals("N")){
					for(int j = 0;j < t;j++){
						if(checkTresure(map,x,++y)){
							count--;
						}
					}
				}else if(op.equals("S")){
					for(int j = 0;j < t;j++){
						if(checkTresure(map,x,--y)){
							count--;
						}
					}
				}else if(op.equals("E")){
					for(int j = 0;j < t;j++){
						if(checkTresure(map,++x,y)){
							count--;
						}
					}
				}else if(op.equals("W")){
					for(int j = 0;j < t;j++){
						if(checkTresure(map,--x,y)){
							count--;
						}
					}
				}
			}
			System.out.println((count==0)?"Yes":"No");
		}
	}
	public static boolean checkTresure(boolean[][] map,int x,int y){
		boolean a = (map[x][y])?true:false;
		if(a){
			map[x][y] = false;
		}
		return a;
	}
}

Measured memory_bytes: 33000
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N;
        cin >> N;
        vll a(N+1);
        rep(i, 1, N+1) cin >> a[i];
        
        ll ans = 0;
        rep(i, 1, N+1) {
                if (a[a[i]] == i) ++ans;
        }

        cout << ans / 2 << endl;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    char s[4];
    int count = 0;
    REP(i, 4){
        cin >> s[i];
    }
    REP(i, 4){
        if(s[i] == s[i+1]){
            count++;
            
        }
    }
 
    if(count){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
X, N = map(int, input().split())
p = list(map(int, input().split()))

p_set = set(p)

i = 0
while True:
    if not X-i in p_set:
        print(X-i)
        break
    elif not X+i in p_set:
        print(X+i)
        break
    else:
        i += 1
    


Measured memory_bytes: 9176
#include <iostream>
using namespace std;
int main(void){
  long long a, b, x;
  cin >> a >> b >> x;
  long long bb, aa;
  bb=b/x;
  aa=a/x;
  if(a%x==0)cout << bb-aa+1 << endl;
  else cout << bb-aa << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn       cout<<"Yes\n"; else cout<<"No\n";
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;
const ll LINF = 1e18;


int main()
{
    int k,a;
    string s;
    cin>>s>>k;
    vs q,v;
    a=s.size();
    red(i,a) q.pb(s.substr(i));
    sort(all(q));

    rep(i,min(5,a)) rep(j,q[i].size()) v.pb(q[i].substr(0,j+1));//,cout<<q[i].substr(0,j+1)<<endl;
    sort(all(v));
    v.erase(unique(v.begin(), v.end()), v.end());
    cout<<v[k-1]<<endl;
    

    return 0;
}


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

using namespace std;

using ll = long long;

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

    int n, m;
    cin >> n >> m;

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

    for (int v = 0; v < n; ++v)
        cout << deg[v] << '\n';

    return 0;
}


Measured memory_bytes: 256
//
// Created by tac on 2016/10/12.
//

#include <algorithm>
#include <cstdlib>
#include <vector>
#include <iostream>

std::vector<int>& sort_vector(std::vector<int>& vec) {
    std::sort(vec.begin(), vec.end());
    return vec;
}

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
    std::vector<int> vec {a, b, c};
    sort_vector(vec);
    std::cout << vec[0] << " " << vec[1] << " " << vec[2] << std::endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3132
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {
        Stdin stdin = new Stdin();
        int h = stdin.nextInt();
        int w = stdin.nextInt();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                String s = stdin.nextToken();
                if (s.equals("snuke")) {
                    System.out.printf("%c%d%n", 'A' + j, i + 1);
                    System.exit(0);
                }
            }
        }
    }

    private static final class Stdin {
        private BufferedReader stdin;
        private ArrayDeque<String> tokens;

        public Stdin() {
            this.stdin = new BufferedReader(new InputStreamReader(System.in));
            this.tokens = new ArrayDeque<>();
        }

        public String nextToken() throws IOException {
            if (tokens.isEmpty()) {
                for (String token : stdin.readLine().split(" ")) {
                    tokens.add(token);
                }
            }
            return tokens.poll();
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(nextToken());
        }

        public int nextLong() throws NumberFormatException, IOException {
            return Integer.parseInt(nextToken());
        }
    }
}


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

const int mod = 1e9 + 7;
inline int add(int u, int v) {
  return u + v >= mod ? u + v - mod : u + v;
}
inline int sub(int u, int v) {
  return add(u, mod - v);
}
inline int mul(int u, int v) {
  return u * 1ll * v % mod;
}
int pwr(int a, int n) {
  int r = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) r = mul(r, a);
    a = mul(a, a);
  }
  return r;
}
inline int inv(int a) {
  return pwr(a, mod - 2);
}

struct DSU {
  VI par, sz;
  DSU(int n) {
    par.resize(n);
    iota(par.begin(), par.end(), 0);
    sz.resize(n, 1);
  }
  int find(int u) {
    if (par[u] == u) return u;
    return par[u] = find(par[u]);
  }
  bool merge(int u, int v) {
    u = find(u), v = find(v);
    if (u == v) return false;
    par[u] = v;
    sz[v] += sz[u];
    return true;
  }
  int get_size(int u) {
    return sz[find(u)];
  }
};

const int N = 5005;
int p[N];
int ways[N][N], wt[N];

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;
  DSU dsu(n + 1);
  int req = n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] != -1) {
      if (!dsu.merge(i, p[i])) {
        req--;
      }
    }
  }

  int k = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] == -1) {
      wt[++k] = dsu.get_size(i);
    }
  }

  ways[0][0] = 1;
  for (int i = 1; i <= k; i++) {
    ways[i][0] = ways[i - 1][0];
    for (int j = 1; j <= i; j++) {
      ways[i][j] = add(ways[i - 1][j], mul(ways[i - 1][j - 1], wt[i]));
    }
  }

  int ans = mul(req, pwr(n - 1, k));
  int fact = 1;
  for (int j = 2; j <= k; j++) {
    fact = mul(fact, j - 1);
    ans = sub(ans, mul(mul(ways[k][j], fact), pwr(n - 1, k - j)));
  }
  for (int i = 1; i <= k; i++) {
    ans = sub(ans, mul(wt[i] - 1, pwr(n - 1, k - 1)));
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 70448
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,K;
    cin>>N>>K;
    map<ll,ll> h;
    
    REP(i,N){
        ll a,b;
        cin>>a>>b;
        if(h.count(a)==0)h[a]=b;
        else h[a]+=b;
    }
    
    ll cnt=0;
    for(const auto v:h){
        ll t=v.second;
        //sl(t,v.first)
        cnt+=t;
        if(cnt>=K){
            cout<<v.first<<endl;
            break;
        }
    }
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll n;
string s;
set<string> se;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n);
	for(int i = 1;i <= n;i++){
		cin >> s;
		se.insert(s);
	}
	cout << se.size() << endl;
	return 0;
}


Measured memory_bytes: 19172
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int arr[101][2];
long long  findMaxKnapsack(int n,int W){
    long long  dp[n+1][W+1];
     for(int i=0;i<=n;++i){
         dp[i][0]=0;
     }
     for(int j=0;j<=W;++j)
     dp[0][j]=0;

     for(int i=1;i<=n;++i){
         for(int j=1;j<=W;++j){
             dp[i][j]=dp[i-1][j];
             if(arr[i-1][0]>j){
                 continue;
             }
             long long  leliya=arr[i-1][1]+dp[i-1][j-arr[i-1][0]];
             dp[i][j]=max(dp[i][j],leliya);
         }
     }

      
     return dp[n][W];

}
int main(){
  int n,W;
  cin>>n>>W;
  for(int i=0;i<n;++i){
      for(int j=0;j<2;++j){
          cin>>arr[i][j];
      }
  }
  cout<<findMaxKnapsack(n,W);

 

}

Measured memory_bytes: 82536
#include<iostream>
using namespace std;
int main()
{
	int sx,sy,tx,ty,i;
	cin>>sx>>sy>>tx>>ty;
	for(i=1;i<=ty-sy;i++)cout<<"U";
	for(i=1;i<=tx-sx;i++)cout<<"R";
	for(i=1;i<=ty-sy;i++)cout<<"D";
	for(i=1;i<=tx-sx;i++)cout<<"L";
	cout<<"L";
	for(i=1;i<=ty-sy+1;i++)cout<<"U";
	for(i=1;i<=tx-sx+1;i++)cout<<"R";
	cout<<"D"<<"R";
	for(i=1;i<=ty-sy+1;i++)cout<<"D";
	for(i=1;i<=tx-sx+1;i++)cout<<"L";
	cout<<"U";
	return 0;
 } 

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if (i <= 9 || (i >= 100 && i < 1000) || (i >= 10000 && i <= 99999)) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            bool ans = s.StartsWith("A") && s.Substring(2, s.Length - 3).Count(c => c == 'C') == 1 && s.All(c => c == 'A' || c == 'C' || char.IsLower(c));
            Console.WriteLine(ans ? "AC" : "WA");
        }
    }
}

Measured memory_bytes: 13408
s = input()
a = [0,0]
res = 0
for i in range(len(s)):
  if s[i] == '0':
    a[0] += 1
  elif s[i] == '1':
    a[1] += 1
  if a[0] >= 1 and a[1] >= 1:
    res += 2
    a[0] -= 1
    a[1] -= 1
print(res)

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

int main() {
 
  string N;
  cin >> N;
  if (N[0] == N[1] && N[1] == N[2]) {
    cout << "Yes" << endl;
  }
  else if (N[1] == N[2] && N[2] == N[3]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pow2(int x) {
  int y;
  if (x==0) return 1;
  else {
    y=pow2(x/2)*pow2(x/2);
    if (x%2==1) y*=2;
    return y;
  }
}
int main() {
  int h,w,k,i,j,c,divn,d,dn,p,m,f,ans;
  cin>>h>>w>>k;
  vector<string> s(h);
  for(i=0;i<h;i++) cin>>s.at(i);
  divn=pow2(h-1);
  vector<int> div(h-1);
  ans=h+w;
  for(d=0;d<divn;d++) {
    m=d;
    dn=0;
    for(i=0;i<h-1;i++) {
      div.at(i)=m%2;
      m/=2;
      dn+=div.at(i);
    }
    vector<int> sum(dn+1);
    c=dn;
    for(j=0;j<w;j++) {
      vector<int> sum1(dn+1);
      p=0;
      for(i=0;i<h;i++) {
        if (s.at(i).at(j)=='1') sum1.at(p)++;
        if (i<h-1 && div.at(i)==1) p++;
      }
      f=0;
      for(i=0;i<=dn;i++) if (sum1.at(i)>k) f=-1;
      if (f==-1) break;
      for(i=0;i<=dn;i++) {
        sum.at(i)+=sum1.at(i);
        if (sum.at(i)>k) f=1;
      }
      if (f==1) {
        c++;
        for(i=0;i<=dn;i++) sum.at(i)=sum1.at(i);
      }
    }
    if (f==-1) continue;
    ans=min(ans,c);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
from fractions import gcd
def prime_factorize(n):
    a = set()
    while n % 2 == 0:
        a.add(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.add(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.add(n)
    return a

def main(a, b):
    #a, b = [int(i) for i in sys.stdin.readline().split()]
    _gcd = gcd(a,b)
    #memo_ls = [0 for i in range(_gcd)]
    #memo_set = set()
    cnt = 0
    if _gcd == 1:
        print(1)
    else:
        res = prime_factorize(_gcd)
        print(len(res) + 1)
if __name__ == "__main__":
    a, b = [int(i) for i in sys.stdin.readline().split()]
    main(a, b)

Measured memory_bytes: 64108
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;


long N;
vector<long> A(200000);


int main()
{
    cin >> N;
    for( int i = 0; i < N; ++i ) cin >> A[i];

    // 予め和の配列を求めていく
    vector<long> S(200000);  // S[i] = A[0]~A[i]の和
    for( int i = 0; i < N; ++i ){
        if( i == 0 ) S[i] = A[i];
        else S[i] = S[i-1] + A[i];
    }
    
    // 分割点は全て +1 との間で定義 (つまりinclusive) 
    int posl = 0, posr = 2;
    vector<long> P(4); 
    long ans = LONG_MAX;
    // 2番目の分割点についてしゃくとり法で全探索
    for( int middle = 1; middle < N-2; ++middle ){
        long diffl = LONG_MAX, diffr = LONG_MAX;
        
        for( int left = posl; left < middle; ++left ){
            if( diffl > abs(S[middle] - 2*S[left]) ){
                diffl = abs( (S[middle] - S[left]) - S[left] );
                posl = left;
            }else break;
        }
        
        for( int right = max(middle+1, posr); right < N-1; ++right ){
            if( diffr > abs(S[N-1] - 2*S[right] + S[middle]) ){
                diffr = abs( (S[N-1] - S[right]) - (S[right] - S[middle]) );
                posr = right;
            }else break;
        }

        P[0] = S[posl];
        P[1] = S[middle] - S[posl];
        P[2] = S[posr] - S[middle];
        P[3] = S[N-1] - S[posr];
        sort( P.begin(), P.end() );
        
        ans = min( ans, P[3] - P[0] );
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
//struct cmp {bool operator()(const pair<int, char> &a, const pair<int, char> &b) {if (a.first == b.first) {return a.second > b.second;} else {return a.first > b.first;}}};
#include<bits/stdc++.h>
#define endl "\n"
#define _  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
//#define int long long
#define MOD 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 100 + 5;
const ll inf = LLONG_MAX;
using namespace std;

template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T>
void print_container(T &container) {for (auto &t : container) {cout << t << " ";} cout << endl;}
//Pain is temporary Glory is forever!!
//Think quick,Code Fast!!

int x, n;
int a[N];
set<int> ms;

void solve() {
	cin >> x >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ms.insert(a[i]);
	}

	int a, b;
	for (int i = x;; i++) {
		if (ms.find(i) == ms.end()) {
			a = i;
			break;
		}
	}
	for (int i = x;; i--) {
		if (ms.find(i) == ms.end()) {
			b = i;
			break;
		}
	}

	if (abs(x - a) < abs(x - b)) {
		cout << a << endl;
	} else {
		cout << b << endl;
	}
}

int32_t main() {
	_


	solve();
}





Measured memory_bytes: 3536
use std::vec::Vec;
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

const MOD: usize = 1_000_000_000 + 7;

fn main() {
  let n: usize = read();
  let mut map = HashMap::new();
  let mut ans = 1;

  for i in 1..n+1 {
    let hash = trial_division(i);
    //println!("i = {} hash = {:?}",i,  hash);
    for (key, count) in hash.into_iter() {
      match map.get(&key) {
          Some(&val) => {
            map.insert(key, val + count);
          },
          _  => { map.insert(key, count); },
      }
    }
  }
  map.remove(&1);
  //println!("{:?}", map);
  for (key, count) in map.into_iter() {
    ans *= (count + 1);
    ans %= MOD;
  }
  println!("{}", ans);
}





// 試し割り
// O(√N)
fn trial_division(n :usize) -> HashMap<usize, usize>{
    let mut primes = HashMap::new();
    let mut i = 2;
    let mut n = n;

    //  n を root n 以下の整数で割り切れるまで割っていく
    while i * i <= n {
        while n % i == 0 {
            n /= i;
            // match primes.get_mut(&i) {
            //   None => { primes.insert(i, 1); },
            //   Some(x) => {
            //       *x += 1;
            //   },
            // }

            match primes.get(&i) {
              Some(&val) => {
                primes.insert(i, val + 1);
              },
              _  => { primes.insert(i, 1); },
            }
        }
        i+=1;
    }

    // 最後にnが素数になっている場合はそれ自身も素因数に含めて終了
    // match primes.get_mut(&n) {
    //   None => { primes.insert(n, 1); },
    //   Some(x) => {
    //     *x += 1;
    //   },
    // }

     match primes.get(&n) {
          Some(&val) => {
            primes.insert(n, val + 1);
          },
          _  => { primes.insert(n, 1); },
      }

    primes
}


Measured memory_bytes: 4352
#include <vector>
#include <bitset>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
using namespace std;

class Data
{
public:
    int g;
    int e;
    Data(){
        g = e = -1;
    }
    Data(int g0, int e0){
        g = g0;
        e = e0;
    }
    bool operator<(const Data& d) const{
        return g < d.g || (g == d.g && e < d.e);
    }
};

bool check[32][32][32][32];
Data memo[32][32][32][32];

Data solve(int y1, int x1, int y2, int x2, int s)
{
    if(check[y1][x1][y2][x2])
        return memo[y1][x1][y2][x2];

    int tmp = 0;
    for(int i=y1; i<=y2; ++i){
        for(int j=x1; j<=x2; ++j){
            tmp += memo[i][j][i][j].e;
        }
    }
    if(tmp < s)
        return Data();

    Data ret(1, tmp);
    for(int i=y1; i<y2; ++i){
        Data d1 = solve(y1, x1, i, x2, s);
        Data d2 = solve(i+1, x1, y2, x2, s);
        if(d1.g == -1 || d2.g == -1)
            continue;
        Data d3(d1.g + d2.g, min(d1.e, d2.e));
        ret = max(ret, d3);
    }
    for(int i=x1; i<x2; ++i){
        Data d1 = solve(y1, x1, y2, i, s);
        Data d2 = solve(y1, i+1, y2, x2, s);
        if(d1.g == -1 || d2.g == -1)
            continue;
        Data d3(d1.g + d2.g, min(d1.e, d2.e));
        ret = max(ret, d3);
    }

    check[y1][x1][y2][x2] = true;
    memo[y1][x1][y2][x2] = ret;
    return ret;
}

int main()
{
    for(;;){
        int h, w, s;
        cin >> h >> w >> s;
        if(h == 0)
            return 0;

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                for(int k=0; k<h; ++k){
                    for(int l=0; l<w; ++l){
                        check[i][j][k][l] = false;
                        memo[i][j][k][l] = Data();
                    }
                }
            }
        }

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                memo[i][j][i][j].g = 1;
                cin >> memo[i][j][i][j].e;
                s -= memo[i][j][i][j].e;
            }
        }
        s *= -1;

        Data d = solve(0, 0, h-1, w-1, s);
        cout << d.g << ' ' << (d.e-s) << endl;
    }
}

Measured memory_bytes: 9992
(let* ((a (read))
    (b (read))
    (h (read))
    (m (read))
    (rad (* PI 2 (- (+ (/ h 12) (/ (/ m 60) 12)) (/ m 60))))
    (rsq (- (+ (* a a) (* b b)) (* (* 2 a b) (cos rad)))))
    (format t "~F" (sqrt rsq))
)

Measured memory_bytes: 23708
#include <bits/stdc++.h>
using namespace std;
const int mn=2*(1e5)+10;
int n,m;
bool t1[mn],tn[mn];
int main() {
	scanf("%d %d",&n,&m);
	for (int i=1;i<=m;i++) {
		int a,b;
		scanf("%d %d",&a,&b);
		if (a==1)
			t1[b]=1;
		if (b==1)
			t1[a]=1;
		if (a==n)
			tn[b]=1;
		if (b==n)
			tn[a]=1;
	}
	bool ans=false;
	for (int i=2;i<n;i++)
		if (t1[i]&&tn[i]) {
			ans=true;
			break;
		}
	if (!ans)
		printf("IM");
	printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        String message = "";
        switch (a) {
            case 25: message = "Christmas";
                break;
            case 24: message = "Christmas Eve";
                break;
            case 23: message = "Christmas Eve Eve";
                break;
            case 22: message = "Christmas Eve Eve Eve";
                break;
        }
        System.out.println(message);
    }
}


Measured memory_bytes: 21844
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto nab = readln.split.to!(long[]);
    auto N = nab[0];
    auto A = nab[1];
    auto B = nab[2];
    writeln(max(0, B*(N-1)+A - (A*(N-1)+B) + 1));
}

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

template <typename T>
vector<T> SlideMin(const vector<T> &v, int k) {
    deque<int> deq;
    vector<T> res;
    for (int i = 0; i < v.size(); i++) {
        while (!deq.empty() && v[deq.back()] >= v[i]) deq.pop_back();
        deq.push_back(i);
        if (i - k + 1 >= 0) {
            res.emplace_back(v[deq.front()]);
            if (deq.front() == i - k + 1) deq.pop_front();
        }
    }
    return res;
}

int main() {
    int N, L; cin >> N >> L;
    vector<int> a(N);
    for (int &ai: a) cin >> ai;
    vector<int> ans = SlideMin(a, L);
    for (int i = 0; i < N - L + 1; i++) cout << ans[i] << " \n"[i == N - L];
    return 0;
}


Measured memory_bytes: 10988
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	int n;
	cin >> n;

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int old = a.at(0);
	int cnt = 1;
	for (int i = 1; i < n; i++)
	{
		if (a.at(i) != old)
		{
			cnt++;
		}
		old = a.at(i);
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
w = list(map(int,input().split()))

INF = 10**9
x = [INF]*2
for i in range(n):
    x[a[i]] = min(x[a[i]], w[i])

ans = sum(x)
if ans >= INF:
    ans = 0
print(ans)



Measured memory_bytes: 5600