akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int main()
{
	string a,b;cin >> a >> b;
	
	
	if(a==b)
	{
		cout << "EQUAL" << endl;
		return 0;
	}
	if(a.size() > b.size())
	{
		cout << "GREATER" << endl;
		return 0;
	}
	if(a.size() < b.size())
	{
		cout << "LESS" << endl;
		return 0;
	}
	
	REP(i,a.size())
	{
		if(a[i] > b[i])
		{
			cout << "GREATER" << endl;
			return 0;
		}
		if(a[i] < b[i])
		{
			cout << "LESS" << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!long;
    const S = readln.chomp;
    auto leftList = new long[N+1];
    foreach (i; 0..N) leftList[i+1] = S[i] == 'E' ? 1 : 0;
    foreach (i; 0..N) leftList[i+1] += leftList[i];
    auto rightList = new long[N+1];
    foreach (i; 0..N) rightList[i+1] = S[i] == 'W' ? 1 : 0;
    foreach (i; 0..N) rightList[i+1] += rightList[i];

    iota(N+1).map!(i => rightList[i] + leftList[$-1] - leftList[i]).reduce!min.writeln;
}



Measured memory_bytes: 8020
def main() -> None:
    H, N = rmi()
    AB = []
    for _ in range(N):
        AB.append(rmi())
    dp = [10 ** 9] * (H + 1)
    dp[0] = 0
    for damage, mp in AB:
        for i in range(len(dp)):
            prev = max(i - damage, 0)
            dp[i] = min(dp[i], dp[prev] + mp)
    w(dp[H])


def r() -> str:
    return input().strip()


def ri() -> int:
    return int(r())


def rmi(delim: str = ' ') -> tuple:
    return tuple(map(int, input().split(delim)))


def w(data) -> None:
    print(data)


def wm(*data, delim: str = ' ') -> None:
    print(delim.join(map(str, data)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 41200
#!/usr/bin/python
# -*- coding: UTF-8 -*-

all_nums = input()
a = all_nums.split(' ')[0]
b = all_nums.split(' ')[1]
c = all_nums.split(' ')[2]
'''
swaptmp = a
a = b
b = swaptmp
swaptmp = a
a = c
c = swaptmp'''
print(c+' '+a+' '+b)

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
    char o[55],e[55] ;
    scanf ("%s%s",o,e) ;
    for (int i=0; i<strlen(e); i++){
        printf("%c%c",o[i],e[i]);
    }
    if (strlen(o)==strlen(e)){
        printf ("\n");
    } else {
        printf ("%c\n",o[strlen(o)-1]) ;
    }
    return 0 ;
}

Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool check(ll N, ll M, ll c) {
  ll res = max(0LL, c - N);
  return c * 2 <= M - res * 2;
}

int main() {
  ll N, M;
  cin >> N >> M;

  ll ok = 0, ng = 1e12 + 1;
  while(ng - ok > 1) {
    ll c = (ok + ng) / 2;
    if (check(N, M, c)) {
      ok = c;
    } else {
      ng = c;
    }
  }
  cout << ok << endl;
  return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int m;
vector<vector<int>> edges;
vector<vector<P>> cnt;
vector<ll> dp;

ll dfs1(int i,int p = -1) {
    ll res = 1;
    for (int j : edges[i]) if (j != p) {
        ll a = dfs1(j,i);
        cnt[i].push_back(P(a,j));
        res *= a+1;
        res %= m;
    }
    return res;
}

void dfs2(int i,ll res,int p = -1) {
    if (p != -1) cnt[i].push_back(P(res,p));
    int s = cnt[i].size();
    vector<ll> prod_l(s+1,1),prod_r(s+1,1);
    for (int x = 0;x < s;++x) {
        prod_l[x+1] = prod_l[x]*(cnt[i][x].first+1)%m;
        prod_r[s-1-x] = prod_r[s-x]*(cnt[i][s-1-x].first+1)%m;
    }
    dp[i] = prod_r[0];
    for (int j = 0;j < s;++j) {
        int k = cnt[i][j].second;
        if (k != p) dfs2(k,prod_l[j]*prod_r[j+1]%m,i);
    }
}

int main() {
    int n;
    cin >> n >> m;
    edges.resize(n);
    dp.resize(n,1);
    cnt.resize(n);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs1(0);
    dfs2(0,1);
    for (int i = 0;i < n;++i) cout << dp[i] << "\n";
    return 0;
}

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

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};


int main() {
	int N, K;
	cin >> N >> K;
	vector<int>P(N);
	vector<int>C(N);
	for (int i = 0; i < N; ++i) {
		cin >> P[i];
		P[i]--;
	}
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
	}
	UnionFind uf(N);
	for (int n = 0; n < N; ++n) {
		uf.merge(n, P[n]);
	}
	map<int, long long>cost;
	for (int n = 0; n < N; ++n) {
		cost[uf.root(n)] += C[n];
	}

	long long ans = -1e18;
	for (int i = 0;i<N;++i) {
		long long isize = uf.size(i);
		long long icost = cost[uf.root(i)];
		long long anstmp =0;
		long long tmpK = K;
		if (tmpK>= 2 * isize) {
			long long n = tmpK / isize - 1;
			if (icost > 0) {
				anstmp += n * icost;
			}
			tmpK -= n * isize;
		}
		int now = i;
		long long  maxsub = C[now];
		long long  anssub = 0;
		for (int j = 0; j < tmpK; ++j) {
			//cout << now << "_" << C[now] << endl;
			anssub += C[now];
			now = P[now];
			maxsub = max(maxsub,anssub);
		}
		//cout << maxsub<<"_"<<anstmp<<endl;
		ans = max(maxsub+anstmp,ans);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    char a, b; cin >> a >> b;
    if(a == b) cout << 'H' << endl;
    else cout << 'D' << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<iomanip>

int main(){
    int n;
    double ans[4]={};
    
    std::cin>>n;
    
    std::vector<double> x(n);
    for(int i=0; i<n; i++){
        std::cin>>x[i];
    }
    std::vector<double> y(n);
    for(int i=0; i<n; i++){
        std::cin>>y[i];
    }
    std::vector<double> ab(n);
    for(int i=0; i<n; i++){
        ab[i]=std::abs(x[i]-y[i]);
    }
    
    for(int i=0; i<n; i++){
        ans[0]+=ab[i];
    }
    for(int i=0; i<n; i++){
        ans[1]+=std::pow(ab[i], 2.0);
    }
    ans[1]=std::sqrt(ans[1]);
    for(int i=0; i<n; i++){
        ans[2]+=std::pow(ab[i], 3.0);
    }
    ans[2]=std::pow(ans[2], (double)1/(double)3);
    for(int i=0;i<n;i++){
        ans[3]= std::max(ans[3],ab[i]);
    }
    std::cout<<std::fixed<<std::setprecision(6);
    for(int i=0; i<4; i++){
    std::cout<<ans[i]<<std::endl;
    }

    return 0;
}


Measured memory_bytes: 3448
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    int count=0;
    int outlet=1;
    while (1) {
        if (outlet<b) {
            outlet--;
            outlet+=a;
            count++;
        } else {
            cout<<count<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
using System;

namespace study11
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int ans = 0;
            for (int K = 1; K <= N; K++)
            {
                var NA = (int)(Math.Log10(K) + 1);
                if (NA % 2 == 1)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

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

int main() {
  string s; cin >> s;
  string w_s[s.size()], b_s[s.size()];
  
  int w_cnt = 0, b_cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (i % 2 == 0) {
      if (s[i] == '1') ++b_cnt;
      else if (s[i] == '0') ++w_cnt;
    }
    else {
      if (s[i] == '1') ++w_cnt;
      else if (s[i] == '0') ++b_cnt;
    }
  }
  cout << min(w_cnt, b_cnt) << endl;
  
  return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
int main()
{
  char x;
  while(1)
    {
      scanf("%c",&x);
      if((x>='A')&&(x<='Z')) x+='a'-'A';
      else if((x>='a')&&(x<='z')) x-='a'-'A';
      printf("%c",x);
      if(x=='\n') break;
    }

  return 0;
}

Measured memory_bytes: 524
readlines.each do |l|
  x1,y1,x2,y2,x3,y3,xp,yp = l.split.map(&:to_f)
  v1x, v1y = x2-x1, y2-y1
  v2x, v2y = x3-x1, y3-y1
  vpx, vpy = xp-x1, yp-y1
  # (vpx, vpy) = t(v1x, v1y) + u(v2x, v2y)
  t = (vpx*v2y - vpy*v2x)/(v1x*v2y - v1y*v2x)
  u = (vpx*v1y - vpy*v1x)/(v1y*v2x - v2y*v1x)
  if 0<t && 0<u && t+u<1
    puts "YES"
  else
    puts "NO"
  end
end

Measured memory_bytes: 6140
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,k;
    cin >> n >> k;
    int64_t res = 1;
    int64_t m = k;
    for(int i=0; i<n; i++){
        if(n/m==0){
            break;
        }
        m *= k;
        res++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
using namespace std;
const int INF=LLONG_MAX-1e10;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;
map<int,int>have;
main()
{
    IOS
    cin>>n;
    fun(i)
    {
        cin>>a[i];
        have[a[i]-i]++;
    }
    fun(i)
    {
//        val=;
        ans+=have[-(a[i]+i)];
    }
    out(ans)

    return 0;
}


Measured memory_bytes: 27908
#include<iostream>
#include <string>
#include <stdexcept>

using namespace std;

int main(){
  string S;
  int N;
  cin >> N;
  cin >> S;
  int i;
  int count = 1;
  for(i=1;i<=N-1;i++)
    if(S.at(i) != S.at(i-1)) count++;
  cout << count << endl;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1e9+1e7;

int K, T;
int a[105];

int main(int argc, char const *argv[]) {
	cin >> K >> T;
	for (int i = 0; i < T; i++) cin >> a[i];
	int cnt = T;
	sort(a, a + cnt);
	reverse(a, a + cnt);
	while(cnt > 1) {
		a[0]--;
		a[1]--;
		sort(a, a + cnt);
		reverse(a, a + cnt);
		if (a[cnt-2] == 0) cnt -= 2;
		else if (a[cnt-1] == 0) cnt--;
	}
	if (a[0] == 0) printf("0\n");
	else cout << a[0] - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math


def solve(N: int, K: int, A: "List[int]"):
    if N <= K:
        print(1)
    else:
        cnt = 1
        n = N - K
        cnt += math.ceil(n/(K-1))
        print(cnt)
        
    


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
import itertools
from pprint import pprint
N,M = map(int,input().split())
K =[]
S = []
for i in range(M):
	ki, *s = map(int,input().split())
	K.append(ki)
	S.append(s)
C = list(map(int,input().split()))
status = [(0, 1) for _ in range(N)]
state = list(itertools.product(*status))  # 直積を求める
ans = 0
for i in state:
	flg = True
	for kidx,ki in enumerate(K):
		ci = 0
		for si in range(ki):
#			print("kidx:",kidx,", si:",si,", ki:",ki,", S[kidx][si]:",S[kidx][si],", state[S[kidx][si]]:",state[S[kidx][si]])
			ci += i[S[kidx][si]-1]
		if ci%2 != C[kidx]:
			flg = False
	if flg:
		ans += 1
print(ans)


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

long long dp[101][100005];

const int mod = 1e9 + 7;
long long a[101];
int main(){
	long long n, k;
	cin >> n >> k;
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	
	for(int i = k; i >= k - a[0]; i--){
		dp[0][i] = 1LL;
	}
	for(int i = 1; i <= k; i++){
		dp[0][i] = (dp[0][i] + dp[0][i - 1]) % mod;
	}
	
	for(int i = 1; i < n; i++){
		dp[i][0] = dp[i - 1][a[i]];
	
		for(int j = 1; j <= k; j++){
			dp[i][j] = ((dp[i][j] + dp[i][j - 1] + dp[i - 1][min(k, j + a[i])] - dp[i - 1][j - 1]) % mod + mod) % mod;
		}
	}
	
	cout << dp[n - 1][0] % mod;
}





Measured memory_bytes: 78336
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, c[2020][2020] = {1};
    cin >> n >> k;
    for (int i = 1; i <= n + 3; i++) {
        c[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
            if (c[i][j] >= mod) c[i][j] -= mod;
        }
    }
    for (int i = 1; i <= k; i++) {
        cout << 1ll * c[k - 1][i - 1] * c[n - k + 1][i] % mod << '\n';
    }
}


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

int n, m[20];
vector<int>X1;
vector<int>X2;
int Mid = 0;

int main() {
	while (true) {
		X1.clear();
		X2.clear();
		int sum = 0;
		cin >> n;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> m[i];
			sum += m[i];
		}
		Mid = n / 2;
		int s = 0;
		for (int i = 0; i < (1 << Mid); i++) {
			s = 0;
			for (int j = 0; j < Mid; j++) {
				if ((i / (1 << j)) % 2 == 0) {
					s += m[j];
				}
			}
			X1.push_back(s);
		}
		for (int i = 0; i < (1 << (n - Mid)); i++) {
			s = 0;
			for (int j = 0; j < (n - Mid); j++) {
				if ((i / (1 << j)) % 2 == 0) {
					s += m[Mid + j];
				}
			}
			X2.push_back(s);
		}
		int minx = 1000000000;
		sort(X2.begin(), X2.end());
		for (int i = 0; i < X1.size(); i++) {
			if (X1[i] <= sum / 2) {
				int target = sum / 2 - X1[i];
				int p = upper_bound(X2.begin(), X2.end(), target) - X2.begin();
				p--;
				for (int j = 0; j < 3; j++) {
					if (p >= 0 && p < X2.size()) {
						int a = X2[p] + X1[i];
						int b = sum - a;
						minx = min(minx, abs(a - b));
					}
					p++;
				}
			}
		}
		cout << minx << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int d[n],i;
    for(i=0;i<n;i++){
      scanf("%d",&d[i]);
    }
    int sum=0;
    for ( i = 0; i < n; i++){
       for(int j=i+1;j<n;j++){
         sum+=d[i]*d[j];
       }     
    }
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
constexpr int NIL = -1;
int N;

struct Node {
	int parent;
	int left; // 左の子
	int right;  // 右の子
};

vector<Node> BT;
vector<int> Depth;
vector<int> Height;

void setDepth(int p, int d) {
	Depth[p] = d;

	if (BT[p].left != NIL) {
		setDepth(BT[p].left, d + 1);
	}
	if (BT[p].right != NIL) {
		setDepth(BT[p].right, d + 1);
	}
}

int setHeight(int p) {

	int h;
	if (p == NIL) return -1;
	if (BT[p].left == NIL && BT[p].right == NIL) {
		Height[p] = 0;
		h = Depth[p];
	}
	else {
		h = max(setHeight(BT[p].left), setHeight(BT[p].right));
		Height[p] = h - Depth[p];
	}

	return h;
}

int getSibling(int id) {
	int p = BT[id].parent;

	if (p == NIL) return -1;

	if (BT[p].right == id) return BT[p].left;
	else return BT[p].right;
}

string getType(int id) {
	if (BT[id].parent == NIL) return "root";
	else if (BT[id].left == NIL && BT[id].right == NIL) return "leaf";
	else return "internal node";
}

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

		int deg = 0;
		if (BT[i].left != NIL) deg++;
		if (BT[i].right != NIL) deg++;

		cout << "node " << i
			<< ": parent = " << BT[i].parent << ", sibling = " << getSibling(i) << ", degree = " << deg
			<< ", depth = " << Depth[i] << ", height = " << Height[i] << ", " << getType(i) << endl;
	}
}


int main() {
	cin >> N;
	BT.resize(N, { NIL, NIL, NIL });
	Depth.resize(N, 0);
	Height.resize(N, 0);

	int p, l, r;
	for (int i = 0; i < N; i++) {
		cin >> p >> l >> r;
		
		// 左
		BT[p].left = l;
		if (l != NIL) BT[l].parent = p;

		// 右
		BT[p].right = r;
		if (r != NIL) BT[r].parent = p;
	}

	// 親捜索
	int root;
	for (int i = 0; i < N; i++) {
		if (BT[i].parent == NIL) { 
			root = i;
			break;
		}
	}

	// 深度計算
	setDepth(root, 0);

	// 高さ計算
	setHeight(root);

	print();

	return 0;
}


Measured memory_bytes: 3152
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

# inputa = [int(n) for n in inputa]
# inputa.sort()

# inputa = list(inputa[0])

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

if a <= 8 and b <= 8:
    print("Yay!")
else:
    print(":(")



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

UL N, Q;
UL A[100001] = {};
ULL ans = 0;

int main() {
	scanf("%u", &N);
	rep(i, N) {
		UL a; scanf("%u", &a);
		A[a]++;
		ans += a;
	}
	scanf("%u", &Q);
	rep(q, Q) {
		UL b, c; scanf("%u%u", &b, &c);
		ans -= A[b] * (ULL)b;
		ans += A[b] * (ULL)c;
		A[c] += A[b];
		A[b] = 0;
		printf("%llu\n", ans);
	}

	return 0;
}


Measured memory_bytes: 4108
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main() {
  int ta, tb;

  REP(i, 7) {
    cin >> ta >> tb;
    cout << ta-tb << endl;
  }
}

Measured memory_bytes: 1164
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i=0; i<K; i++){
        if (i%2 == 0){
            //Takahasi's turn;
            if (A%2){
                A--;
            }
            B += A/2;
            A -= A/2;
        }
        else {
            // Aoki's turn;
            if (B%2)B--;
            A += B/2;
            B -= B/2;
        }
    }
    cout << A << " " << B << endl;
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int n, m, Q;
static const int MAX = 501;
int train[MAX][MAX];

int main() {

    cin >> n >> m >> Q;

    for(int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r ;
        train[l][r]++;
    }

    for (int i = 1; i <= n ; i++) {
        for (int j = 1; j <= n; j++) {
            train[i][j] += train[i][j-1];
        }
    }

    for(int i = 0; i < Q; i++){
        int p, q;
        cin >> p >> q;
        int ans = 0;
        for (int j = p; j <= q; j++) ans += train[j][q] - train[j][p-1];
        cout << ans << '\n';
    }
}



Measured memory_bytes: 1920
#include<cstdio>
#include<algorithm>
#define LL long long
#define F(x,y,z) for(int x=y;x<=z;++x)
#define D(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
LL Min(LL x,LL y){return x<y?x:y;}
LL Max(LL x,LL y){return x>y?x:y;}
LL R(){
    LL ans=0,f=1;char c=' ';
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) ans=ans*10+c-'0';
    return ans*f;
}

int main(){
	LL n=R(),m=R();
	LL s1=n/m;
	LL an=s1;
	an+=3*s1*(s1-1);
	an+=s1*(s1-1)*(s1-2);
	if (m%2==0){
		LL ss=(n+m/2)/m;
		an+=ss;
		an+=3*ss*(ss-1);
		an+=ss*(ss-1)*(ss-2);
	}
	printf("%lld\n",an);
    return 0;
}

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

using namespace std;

#define MODULE 1000000007
#define MP make_pair

template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9
const int MAXN = 100001;

/*struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];*/


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

//-----Template---------
int t[1001];
int N,A,B;
int main(){
    ios::sync_with_stdio(false);
    cin>>N>>A>>B;
    for(int i=0;i<N;i++){
        cin>>t[i];
    }
    int count=0;
    for (int i = 0; i < N; ++i) {
        if(!(A<=t[i] && t[i]<B)){
            count++;
        }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 384
def ascan; gets.split.map(&:to_i); end

gets;
aa = ascan

x1 = -1e9; s1 = 0
x2 = -1e9; s2 = 0

aa.each do |a|
    # change
    s1_ = [s1,s2].min+1
    #unchange
    s2_ = s1
    if x2 != a
        s2_ = [s2_, s2].min
        x2 = a
    end
    
    s1,s2 = s1_,s2_
end

p [s1,s2].min

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n%2) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll nCr(ll n,ll r){
  ll ans=1;
  rep(i,r) ans=ans*(n-i)%mod*inv(i+1)%mod;
  return ans;
}
int main(){
  long long n,m,k,ans,a=0,b,x;
  cin>>n>>m>>k;
  rep(i,n)rep(j,m) a=(a+i+j)%mod;
  b=a;
  rep(i,n-1) b=(b+m*(i+1)-m*(n-i-1)+mod)%mod,a=(a+b)%mod;
  b=a;
  rep(i,m-1) b=(b+n*n*(i+1)-n*n*(m-i-1)+mod)%mod,a=(a+b)%mod;
  ans=(nCr(k,2)*nCr(n*m,k))%mod;
  ans=(a*ans)%mod;
  x=n*m*(n*m-1)%mod;
  cout<<ans*inv(x)%mod;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int A, B;
    cin >> A >> B;
    if ((A % 3 == 0)||(B % 3 == 0)||((A + B) % 3 == 0)){
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}

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

const double PI  = 3.141592653589793238463;

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> bigger(n);
    vector<string> smaller(m);
    for(int i = 0; i < n; i++){
        cin >> bigger[i];
    }
    for(int i = 0; i < m; i++){
        cin >> smaller[i];
    }
    
    for(int i = 0; i <= n-m; i++){
        for(int j = 0; j <= n-m; j++){
            bool t = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(bigger[i+k][j+l] != smaller[k][l]){
                        t = false;
                    }
                }
            }
            if(t){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No";
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;

int digit(int n){
  int res = 0;
  while(n){
    n /= 10;
    res++;
  }
  return res;
}
int topnum(int m){
  while(m>=10){
    m /= 10;
  }
  return m;
}
int sum(int l){
  if(l<0) return 0;

  int r = 1;
  int res = 0;
  for(int i=0;i<l+1;i++){
    res += r;
    r *= 10;
  }
  return res;
}
int power(int n){
  if(n<0) return 0;

  if(n==0) return 1;
  else return 10*power(n-1);
}

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

    //cout << digit(N) << " " << topnum(N) <<endl;
    //cout << sum(N) <<endl;

    int dig = digit(N);

    int cnt[10][10];

    for(int i=1;i<10;i++){
      for(int j=1;j<10;j++) cnt[i][j] = 0;
    }

    for(int i=1;i<10;i++){
      for(int j=1;j<10;j++){
        if(i==j && i<=N) cnt[i][j]++; // 1-dig

        if(10*i+j<=N) cnt[i][j]++; //2-dig

        if(dig >=3){
          int l = dig;
          while(l >= 3){
            if(i*power(l-1)+j <=N){
              int a = (N - i*power(l-1)-j)/10;
              cnt[i][j] += min(a+1 , power(l-2));
            }
            l--;
          }      
        }
      }
    }


    int ans = 0;
    for(int i=1;i<10;i++){
      for(int j=1;j<10;j++){
        ans += cnt[i][j]*cnt[j][i];
      }
    }
    cout << ans << endl;


    //cout << cnt[1][1] <<endl;


    
  	return 0;
}













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

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> data(h);
  int i = 0;
  do {
    cin >> data.at(i);
    i++;
  } while (i < h);

  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  cout << endl;

  for (int i = 0; i < h; i++) {
    cout << "#";
    cout << data.at(i);
    cout << "#" << endl;
  }

  for (int i = 0; i < w + 2; i++) {
    cout << "#";
  }
  return 0;
}


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

typedef long long ll;

int main(){
    string s;
    cin >> s;

    int n = s.length();

    ll ans = 0;
    for(int i = 0; i < 1<<(n-1); i++){
        ll accum = 0, tmp = s[0]-'0';
        for(int j = 1; j < n; j++){
            if(i & 1<<(j-1)){
                accum += tmp;
                tmp = s[j]-'0';
            }else{
                tmp *= 10ll;
                tmp += s[j]-'0';
            }
        }
        accum += tmp;
        ans += accum;
    }

    cout << ans << endl;

    return 0;
}

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

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

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

Measured memory_bytes: 3584
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int k, x, a;
	if(scanf("%d", &k)== 1);
	if(scanf("%d", &x)== 1);
	
	a = 500*k;
	
	if(a >= x){
		printf("Yes");
	}else{
		printf("No");
	}
	
    return 0;
}

Measured memory_bytes: 128
S=input()

T=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA"]
T+=["AKIHABR","AKIHBAR","KIHABAR","AKIHBRA","KIHABRA","KIHBARA"]
T+=["KIHABR","KIHBAR","KIHBRA","AKIHBR","KIHBR"]
#print(T)

print("YES" if S in T else "NO")

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define pii pair<int, int>
#define gsort(x, n) sort((x), (x) + (n), greater<int>())
#define all(x) (x).begin(), (x).end()
#define int int64_t
#define ll long long
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

signed main()
{

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m, p, q, cnt;
    cin >> n >> m;
    p = m;
    q = m + n - 1;

    if (q <= 0)
        cnt = q;
    else if (p >= 0)
        cnt = p;
    else
        cnt = 0;

    cout << ((p + q) * (q - p + 1) / 2) - cnt << '\n';
}

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        for(int i = 1; i <= 5; i++){
            int pre = sc.nextInt();
            if(pre == 0){
                ans = i;
                break;
            }
        }
        System.out.println(ans);
    }
}


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

string n;
long long m = 0, w = 0, t = 0;

int main()
{
	cin >> n;
	
	long long j = n.size();

	for (long long i = j - 1; i >= 0; i--) {

		long long k = (long long)(n[i] - '0') + w;

		if (k < 6) {
			m += k - t;

			if (k == 5 & t == 0) {
				w = 1;
				t = 1;
			}
			else {
				w = 0;
				t = 0;
			}
		}
		else {
			m += 10 - k;
			w = 1;
			t = 0;
		}
	}

	if ((n[j - 1] == '5') && (t == 1))
		w = 0;

	cout << m + w << endl;

	return 0;
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

int A[25][25];
ll DP[25][1<<22];
ll mod = 1e9+7;
int n;

ll solve(int man, ll mask)
{
    if(mask == (1<<n)-1)return 1;
    if(man >= n)return 0;
    if(DP[man][mask]!=-1)return DP[man][mask];

    bitset<32>M(mask);
    DP[man][mask]=0;

    for(int i=0; i<n; i++)
        if(!M[i] && A[man][i])
            {
                DP[man][mask]+=solve(man+1,mask|(1<<i));
                DP[man][mask]%=mod;
            }

    return DP[man][mask];
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    memset(DP, -1, sizeof DP);
    cin>>n;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
        cin>>A[i][j];

    cout<<solve(0,0);
}


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

ll GCD(ll x, ll y) {
    return x ? GCD(y % x, x) : y;
}

int main(void){
	ll a, b;
	cin >> a >> b;
	ll gcd = GCD(a, b);
	ll gcd_ = gcd;
	ll cnt = 1;
	for(ll i = 2; i*i <= gcd_; ++i){
		if(gcd % i == 0){
			cnt++;
			// cout << i << endl;
			while(true){
				if(gcd % i != 0) break;
				gcd /= i;
			}
		}
	}
	if(gcd != 1) cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define N 2000000
bool prime[N+1];
int main(){
  for(int i=2;i<=N;++i) prime[i]=true;
  for(int i=2;i<=N;++i) if(prime[i]) for(int j=2;i*j<=N;++j) prime[i*j]=false;

  int k;
  while(cin>>k,k){
    int m=k,M=k;
    while(!prime[m]) --m;
    while(!prime[M]) ++M;
    cout << M-m << endl;
  }
  return 0;
}

Measured memory_bytes: 3112
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

func main() {
  var h,w,n int = Next3Ints()
  m := map[Point]int{}
  for i:=0;i<n;i++ {
    var a,b int = Next2Ints()
    for x:=-1;x<2;x++ {
      if a+x <= 1 { continue }
      if a+x >= h { break }
      for y:=-1;y<2;y++ {
        if b+y <= 1 { continue }
        if b+y >= w { break }
        p := Point{a+x,b+y}
        m[p]++
      }
    }
  }
  var c []int = make([]int,10)
  for _,v := range m {
    c[v]++
  }
  fmt.Println(int64(h-2)*int64(w-2)-int64(len(m)))
  for i:=1;i<10;i++ {
    fmt.Println(c[i])
  }
}

var reader = bufio.NewReaderSize(os.Stdin,1000000)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func Next2Ints() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func Next3Ints() (int,int,int) {
  var x,y,z int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  z,_ = strconv.Atoi(s[2])
  return x,y,z
}

type Point struct {
  x int
  y int
}

Measured memory_bytes: 112768
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int p[13];

bool check(int i, bool a){
  if(i == 10) return true;
  if(p[i] == 0) return check(i+1,a);
  if(p[i] >= 1){
    if(p[i+1] != 0 && p[i+2] != 0){
      p[i]--; p[i+1]--; p[i+2]--;
      if(check(i,a)){
	p[i]++; p[i+1]++; p[i+2]++;
	return true;
      }
      p[i]++; p[i+1]++; p[i+2]++;
    }
  }
  if(p[i] >= 2){
    if(!a){
      p[i]-=2;
      if(check(i,true)){
	p[i]+=2;
	return true;
      }
      p[i]+=2;
    }
  }
  if(p[i] >= 3){
    p[i] -= 3;
    if(check(i,a)){
      p[i] += 3;
      return true;
    }
    p[i] += 3;
  }
  return false;
}

int main(){
  string str;
  while(cin>>str){
    bool f = true;
    memset(p, 0, sizeof(p));
    REP(i,13) p[str[i] - '0']++;
    REP(i,9){
      if(p[i+1] < 4){
	p[i+1]++;
	if(check(1,false)){
	  if(f){
	    f = false;
	  }else{
	    putchar(' ');
	  }
	  printf("%d",i+1);
	}
	p[i+1]--;
      }
    }	     
    if(f) printf("0");
    puts("");
  }
  return 0;
}

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

int main(){

  int l,a,b,c,d,max1=0;
  cin>>l>>a>>b>>c>>d;
  if(a%c!=0)
    max1=a/c+1;
  else max1=a/c;
  if(b%d!=0) max1=max(max1,b/d+1);
  else max1=max(max1,b/d);
  cout<<l-max1<<endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
long long b[100005][52];
long long dp[55][2];

    vector<int>v;
    int n;
long long go(long long int idx,long long int flag)
{
  //  cout<<idx<<" "<<flag<<endl;
    if(idx==-1)
    {
        return 0;
    }
    if(dp[idx][flag]!=-1)
    {
        return dp[idx][flag];
    }
    long long int c=0,d=0;
    for(long long int j=1;j<=n;j++)
    {
        if(b[j][idx]==1)
        {
            c++;
        }
        else
            d++;
    }
   // cout<<c<<" "<<d<<endl;
    long long ans=0;
    if(flag==1)
    {
        ans=max(ans,go(idx-1,1)+(1LL*d*(1LL<<idx)));
        ans=max(ans,go(idx-1,1)+(1LL*c*(1LL<<idx)));
    }
    else if(flag==0&&v[idx]==1)
    {
        ans=max(ans,go(idx-1,0)+(1LL*d*(1LL<<idx)));
        ans=max(ans,go(idx-1,1)+(1LL*c*(1LL<<idx)));
    }
    else if(flag==0&&v[idx]==0)
    {
        ans=max(ans,go(idx-1,0)+(1LL*c*(1LL<<idx)));
    }
    return dp[idx][flag]=ans;
}
int main()
{

    srand(time(NULL));
  //  long long int n;
    cin>>n;
 //   n=rand()%1000+1;
    long long k;
    cin>>k;
   long long k1;
    //k=rand()%100000+1;
    k1=k;
    long long a[n+1];
    long long int i,j;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    //    a[i]=rand()%10000000000+1;

    }
    for(i=1;i<=n;i++)
    {
        for(j=50;j>=0;j--)
        {
            if(a[i]&(1LL<<j))
            {
                b[i][j]=1;
            }
            else
            {
                b[i][j]=0;
            }
        }
    }
    
    //cout<<endl;
    while(k>0)
    {
        v.push_back(k%2);
        k/=2;
    }
    while(v.size()<=51)
    {
        v.push_back(0);
    }
    memset(dp,-1,sizeof(dp));
    vector<int>v2;
    long long ans=0,ans5=0;
    int flag=0;
    cout<<go(50,0)<<endl;
   /* long long ans3=0,ans4=0;
   // cout<<n<<" "<<k1<<endl;
    /*for(i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    long long pos=0;
    for(j=0;j<=k1;j++)
    {
        ans3=0;
        for(i=1;i<=n;i++)
        {
            ans3+=a[i]^j;
        }
        if(ans3>ans4)
        {
            ans4=ans3;
            pos=j;
        }
    //    ans4=max(ans3,ans4);
    }
    cout<<pos<<endl;
    cout<<ans4<<endl;*/
      //  cout<<ans4<<endl;
}
/*
2 0
10 4
*/


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

int n;
vector<int> x(10);
vector<int> y(10);
double all;

void dfs(int p, int q, double r){
    if (p == (int)pow(2, n) - 1){
        all += r;
        return;
    }
    for (int i = 0; i < n; i++){
        if (((p >> i) & 1) == 0){
            double nr;
            if (q == - 1) nr = 0;
            else nr = sqrt((x[q] - x[i]) * (x[q] - x[i]) + (y[q] - y[i]) * (y[q] - y[i]));
            dfs(p | (int)pow(2, i), i, r + nr);
        }
    }
}

int main(){
    cin >> n;
    all = 0;
    
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    dfs(0, - 1, 0);
    int div = 1;
    for (int i = 1; i <= n; i++) div *= i;
    cout << setprecision(15) << all / div << endl;
}

Measured memory_bytes: 256
#include <cstdio>

char s[1000];

int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int wc[2] = {};
  for (int i = 0; s[i]; ++ i)
    if (s[i] == 'R')
      ++ wc[0];
    else ++ wc[1];
  printf(wc[0] > wc[1] ? "Yes" : "No");
}


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

int main() {
  ll x, k, d; cin >> x >> k >> d;
  x = abs(x);
  ll n = x / d;
  ll ans = 0;
  if (n <= k) {
    ans =  x % d;
    ll q = k - n;
    if (q%2 == 1) {
      ans = abs(ans - d);
    }
  } else ans = x - (k*d);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
#define int long long
using ll = long long;
const int MX = 1e6;
const ll inf = 1e13;
const int mod = 1e9+7;

signed main() {
    int n;
    cin >> n;
    FOR(i,1,361) {
        if((n*i)%360==0) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3632
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();
		double hourX = Math.sin((h + m / 60.0) / 6.0 * Math.PI) * a;
		double hourY = Math.cos((h + m / 60.0) / 6.0 * Math.PI) * a;
		double minX = Math.sin(m / 30.0 * Math.PI) * b;
		double minY = Math.cos(m / 30.0 * Math.PI) * b;
		double ans = Math.sqrt((hourX - minX) * (hourX - minX) + (hourY - minY) * (hourY - minY));
		System.out.println(ans);
	}
}
 

Measured memory_bytes: 35976
#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 FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << "," << el.second << "] "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
string S;

void input(){
    #ifdef __LOCAL
        fs::path path_to_file = __FILE__;
        fs::path input,output;
        input = output = path_to_file.parent_path();
        input += string("/input/") + string(path_to_file.stem()) + string(".txt");
        output += string("/output/") + string(path_to_file.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> S;
}

int solve(){
    input();
    vector<int> W_count(N,0);
    vector<int> E_count(N,0);
    vector<int> W_sum(N,0);
    vector<int> E_sum(N,0);
    for(int i=0;i<N;i++){
        if(S[i]=='W') W_count[i]++;
        else E_count[i]++;
    }
    for(int i=0;i<N-1;i++){
        W_sum[i+1] = W_sum[i] + W_count[i];
    }
    for(int i=N-1;i>0;i--){
        E_sum[i-1] = E_sum[i] + E_count[i];
    }
    int ans=INF;
    for(int i=0;i<N;i++){
        ans = min(ans,W_sum[i]+E_sum[i]);
    }
    cout << ans << endl;
    return 0;    
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 5380
<?php
$f = fopen( 'php://stdin', 'r' );
$line_count = 0;
$total_rows = 0;
$total_columns = 0;
$black_rows = 0;
$black_columns = 0;
while($line = fgets($f)) {
    $line_count++;
    $line_array = array_map('intval', explode(' ', $line));
    if ($line_count === 1) {
        $total_rows = $line_array[0];
        $total_columns = $line_array[1];
    } else {
        $black_rows = $line_array[0];
        $black_columns = $line_array[1];
    }
}
$total_cells = $total_rows * $total_columns;
$blacked_cells = $black_rows * $total_columns + $black_columns * $total_rows - $black_rows * $black_columns;
$result = $total_cells - $blacked_cells;
echo $result;
fclose($f);


Measured memory_bytes: 4604