akhauriyash/Code-Regression huggingface dataset:
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let arr = Array.init n @@ fun i -> Scanf.scanf "%d " @@ fun d -> (i+1, d) in
  Printf.printf "%d\n"
    (Array.fold_left (fun s (i,d) -> if i mod 2 = 1 && d mod 2 = 1 then s + 1 else s) 0 arr)

Measured memory_bytes: 3772
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

char are(char c, int i){
    int tmp = ((int)(c -'0' + i))%10;
    if(tmp>=0) return (char)(tmp + '0');
    return (char)((tmp+10) + '0');
}

int kore(string start, string goal,int sum){
    if(start.empty()) return sum;
    int move = (int)(goal[0] - start[0]);
    if(move==0){
        start.erase(start.begin());goal.erase(goal.begin());
        return kore(start,goal,sum);
    }
    int m=100;
    if(start.length() == 1) return sum+1;
    for(int i=0; i < start.length(); i++){
        string str1, str2;
        int j;
        for( j=1; j < i+1 ; j++){
            str1.push_back(are(start[j],move));
            str2.push_back(goal[j]);
        }
        for(j=i+1; j<start.length();j++){
            str1.push_back(start[j]);
            str2.push_back(goal[j]);
        }
        m = min( kore(str1,str2,sum+1), m);
    }
    return m;
}

int main() {
    for(;;){
        int N;
        cin >> N;
        if(N==0) break;
        string s,g;
        cin >> s >> g;
        cout << kore(s,g,0) << endl;
    }
    return 0;
}



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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ulim = 55555;
    vector<bool> prime(ulim, true);
    prime[0] = prime[1] = false;
    rep(i, 300){
        for(int j = i; j < ulim; j+=i){
            if(!prime[j] && j == i) break;
            if(j > i) prime[j] = false;
        }
    }
    int cnt = 0;
    vector<int> ans;
    rep(i, ulim){
        if(prime[i] && i % 5 == 2) ans.push_back(i);
        if(N == ans.size()) break;
    }
    rep(i, N) cout << ans[i] << " "; cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int a[110];
bool cmp(int x,int y)
{
    return x> y;
}
int main()
{
    int  n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n,cmp);
    int ans = 0;
    for(int i=1;i<=m;i++)
    {
        ans += a[i];
    }
    cout<<ans<<endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ld long double
#define u128 __int128
#define ff first
#define ss second
#define pb push_back

#define MOD 1000000007
#define INTMAX 1000000009
#define N 100050

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	ll mean = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		mean += a[i];
	}
	ll sum = mean;
	
	for (int i = 0; i < n; ++i)
	{
		if((sum - a[i]) * n == mean * (n-1))
		{
			cout << i + 1 << "\n";
			return;
		}
	}
	cout << "Impossible\n";
}

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

	string s;
	cin >> s;
	int y = stoi(s.substr(0, 4));
	int m = stoi(s.substr(5, 2));
	int d = stoi(s.substr(8, 2));

	int f = 1;

	if(y > 2019)
		f = 0;
	else if(y == 2019)
	{
		if(m > 4)
			f = 0;
		else if(m==4)
		{
			if(d > 30)
				f = 0;
		}
	}
	if(f == 0)
		cout << "TBD";
	else
		cout << "Heisei";

	return 0;	
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let mut a = Vec::new();
    for i in 0..n {
        for j in 0..2 {
            let v = it.next().unwrap().parse::<i64>().unwrap();
            a.push((v, i, j));
        }
    }
    a.sort();
    let mut res = 0;
    let mut ok = false;
    let mut cnt_in = 0;
    let mut used = vec![0; n];
    for i in 0..n {
        res += a[i].0;
        used[a[i].1] += 1;
        if used[a[i].1] == 2 { ok = true; }
        if a[i].2 == 0 { cnt_in += 1; }
    }
    if cnt_in != n && cnt_in != 0 && !ok {
        let mut dif = 1_000_000_000_000_000_000;
        for i in 0..n {
            dif = std::cmp::min(dif, a[if a[i].1 != a[n].1 || cnt_in == 1 || cnt_in == n-1 { n } else { n+1 }].0 - a[i].0);
        }
        res += dif;
    }
    println!("{}", res);
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
 
const ll mod=1e9+7;
 
int N,X,Y,Z;
 
int S;
 
ll dp[41][1<<16];
ll dfs(int now, int state)
{
    //cout << "now: " << now << ", state: " << state << endl;
    //cout << "  " << bitset<32>(state) << endl;

    if(dp[now][state]>=0) return dp[now][state];
 
    if(now==N) return 1;
 
    //直前の状態を復元
    vector<int> b;
    int st=0;
    rep(i,S)
    {
        if(state>>i&1)
        {
            b.pb(i-st+1);
            st=i+1;
        }
    }

    //for (size_t i = 0; i < b.size(); ++i) {
    //    cout << b[i] << " ";
    //}
    //cout << endl;
    //cout << bitset<32>(state) << endl;
    //cout << endl;
 
    ll ret=0;
 
    //次に選ぶ数
    for(int i=1; i<=10; ++i)
    {
        bool ok=true;

        //iを次に選んだ時にXYZを含まないかチェック
        //直前から順番に見ていき貪欲に足していく
        int x=0,y=0,z=i;
        int bidx=0;
        while(bidx<b.size() && z<Z) {
            z+=b[bidx++];
        }
        while(bidx<b.size() && y<Y) {
            y+=b[bidx++];
        }
        while(bidx<b.size() && x<X) {
            x+=b[bidx++];
        }
        if(x==X && y==Y && z==Z) {
            ok=false;
        }
 
        if(ok)
        {
            //ret += dfs(now+1, ((state<<i)+(1<<(i-1)))%(1<<S));
            ret += dfs(now+1, ((state<<i)+(1<<(i-1)))%(1<<16));
            ret %= mod;
        }
    }
 
    dp[now][state]=ret;

    return ret;
}
 
int main()
{
    cin >>N >>X >>Y >>Z;
    S=X+Y+Z-1;
 
    ll p10=1;
    rep(i,N) p10=(p10*10)%mod;
 
    memset(dp,-1,sizeof(dp));
    //XYZを含まない数列の個数
    ll r=dfs(0,0);
    //全体から引く
    ll ans=(p10-r+mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


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

    int sum=0;
    rep(i,h){
        rep(j,w){
            char a;
            cin>>a;

            if(a=='#')sum++;
        }
    }
    if(sum==h+w-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>

int a(int n)
{
	int d,s=0;
	while(n){
		d=n%10;
		s=s+d;
		n=n/10;
	}
	return s;
}

int main(void)
{
	int n,s;
	scanf("%d",&n);
	s=a(n);
	if(n%s==0){
		printf("Yes");
	}else{
		printf("No");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

set<int64_t> ans;

void decomPrime(int num) {

	int n = 2;
	while (num > n*n) {
		while (num % n == 0)
		{
			num /= n;
			cout << n << ",";
			ans.insert(n);
		}
		n++;

	}
	cout << num <<endl;
	ans.insert(num);
}


vector <pair<int64_t, int>> decomPrime2(int64_t num) {

	vector <pair<int64_t, int>> ret;

	int n = 2;
	while (sqrt(num) >= n) {
		int a = 0;
		while (num %n == 0) {
			num /= n;
			a++;
			//cout << n << ",";
		}
		if(a != 0)ret.emplace_back(n, a);

		n++;

	}
	//cout << num << endl;

	if (num != 1)ret.emplace_back(num,1);
	//ans.insert(num);

	return ret;
}

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

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

	// 素数である
	return true;
}

vector<int64_t> vec;
bool element(int64_t i) {
	for (auto a : vec)
	{
		if (i == a)return true;
	}
	return false;
}

int64_t func(int64_t N) {

	int64_t z;
	for (int64_t i = 2; i <= N; i++)
	{
		if (isPri(i))
		{
			z = 1;
			while (z <= N)
			{
				z *= i;
				if (N % z == 0)
				{
					if (element(z)) {
						continue;
					}
					return z;
				}
			}
		}
	}
	return 0;
}

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

	//int count = 0;
	/*
	while ((z = func(N)) != 0)
	{
		count++;
		N /= z;
		vec.push_back(z);
	}
	cout << count;

	*/
	int ans = 0;
	for (auto p : decomPrime2(N)) {
		//cout << p.first << "," << p.second << endl;
		int n = p.second;
		int x = 1;
		while (n >= x) {
			ans++;
			n -= x;

			x++;
		}
	}

	cout << ans;

	//cin >> N;


	return 0;

}

Measured memory_bytes: 3720
a = [list(map(int, input().split())) for _ in range(3)]

n = int(input())
b = [int(input()) for _ in range(n)]
x = [[False, False, False] for _ in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                #print("b", x)
                x[j][k] = True
                #print("a", x)
                #print(a, b, a[j][k], b[i], x, j, k)



flag = False

for i in range(3):
    if x[i][0] and x[i][1] and x[i][2]:
        flag = True
    elif x[0][i] and x[1][i] and x[2][i]:
        flag = True

if x[0][0] and x[1][1] and x[2][2]:
    flag = True
elif x[2][0] and x[1][1] and x[0][2]:
    flag = True

#print(a, b, x)

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


int p(string s){
    int i = 0, j = s.size() - 1;
    while (i<j){
        if (s[i]!=s[j]) return 0;
        i++;
        j--;
    }
    return 1;
}


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

    string s;
    cin>>s;
    int n = s.size();
    string l, r;
    for (int i = 1; i <= (n-1)/2; i++){
        l += s[i-1];
    }
    for (int i = (n+3)/2; i <= n; i++){
        r += s[i-1];
    }
    if (p(s) && p(l) && p(r)){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
    
}



Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
ll dp[100005][13];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(void) {
  ll H;
  cin >> H;
  ll ans = 2;
  while(H != 1) {
    H /= 2;
    ans *= 2;
  }

  cout << ans-1 << endl;
}


Measured memory_bytes: 256
n = int(input())
ans = 0


def dfs(x: str):
    if int(x) > n:
        return
    if x.count('3') >= 1 and x.count('5') >= 1 and x.count('7') >= 1:
        global ans
        ans += 1

    dfs(x+'3')
    dfs(x+'5')
    dfs(x+'7')


dfs('0')
print(ans)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }


int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	REP(i, n) {
		cin >> d[i];
	}
	sort(all(d));
	int res = d[n / 2] - d[n / 2 - 1];
	put(res);
	return 0;
}


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

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  endl           "\n"
#define  pb             push_back
#define  sym(s)         s="#"+s+"#";
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());

typedef  long long             ll;
typedef  unsigned long long    ull;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  3e+5+7;

vll adj[N];ll vis[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,x,m;
set<ll>set1,set2;
vll v;
//<<-----Implement Functions Here---->>//


//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>x>>m;ll ans = 0;
		ll f = 0;
		if(n<=1e8)
		{
			ll ans = 0;
			for(ll i=1;i<=n;i++)
			{
				if(x==0)break;
				ans += x%m;
				x = (x%m * x%m)%m;
			}
			cout<<ans<<endl;return;
		}
		ll count1 = 0;ll sum1 = 0;ll count2 = 0;ll sum2 = 0;
		for(ll i=1;i<=1e+5;i++)
		{
			ll h = x%m;
			if(set1.find(h)!=set1.end()){
				f = h;break;
			}
			set1.insert(h);sum1 += h;count1++;v.pb(h);
			x = (x%m * x%m)%m;
		}

		for(auto it:v){
			if(it==f)break;
			set2.insert(it);
			count2++;sum2+=it;
			count1--;sum1-=it;
		}
		ll pos = -1;
		for(ll i=0;i<=1e+5;i++)
		{
			if(v[i]==f){pos = i;break;}
		}
		
		n-=count2;ans += sum2;
		ans += n/count1*sum1;
		ll h = n%count1;
		for(ll i=pos;;i++){
			if(h==0)break;
			ans += v[i];h--;
		}
		cout<<ans<<endl;





		
}

int main(){
    fastio;randomINIT;
    
    while(t--){
        MAIN();
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}

Measured memory_bytes: 12920
def dfs(A,x,y):

	X = [1,0,-1,0]
	Y = [0,1,0,-1]

	A[x][y] = 0

	for i in range(4):
		xx = x + X[i]
		yy = y + Y[i]

		if 0 <= xx < 12 and 0 <= yy < 12:
			if A[xx][yy] == "1":
				dfs(A,xx,yy)

if __name__ == '__main__':

	A = []

	while True:
		try:
			for _ in range(12):
				ll = list(input())
				A.append(ll)

			iland = 0
			for x in range(12):
				for y in range(12):
					if A[x][y] == "1":
						iland += 1
						dfs(A,x,y)
			print(iland)

			s = input()
			A=[]

		except EOFError:
			break



Measured memory_bytes: 5576
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int n, k;
signed main() {
	cin >> n >> k;
	COMinit();
	if (k >= n - 1)cout << comb(2 * n - 1, n) << endl;
	else if (k == 1)cout << n * n - 1 % mod << endl;
	else {
		int ans = 0;
		for (int i = 1; i <= k; i++) {
			ans += (COMB(n, i) * COMB(n - 1, i)) % mod;
			ans %= mod;
		}
		cout << (ans + 1) % mod << endl;
	}
	ggr
}


Measured memory_bytes: 7936
from collections import deque
import sys
input=sys.stdin.readline
H,W = map(int,input().split())
C_pos=list(map(lambda x:int(x)-1,input().split()))
D_pos=list(map(lambda x:int(x)-1,input().split()))
Grid=[[c for c in input()] for _ in range(H)]
Dist=[[float("inf")]*W for _ in range(H)]

DX=[0,0,1,-1]
DY=[1,-1,0,0]

Q=deque()
Q.append((C_pos[0],C_pos[1]))
DX=[-1,1,0,0]
visited=set()
prev_visited=set()

dist=0
while True:
    prev_visited=set(v for v in Q)
    if len(Q)==0:
        print(-1)
        exit()

    #できる限りbfs
    while Q:
        cx,cy=Q.pop()
        if cx==D_pos[0] and cy==D_pos[1]:
            print(dist)
            exit()

        visited.add((cx,cy))
        for dx,dy in zip(DX,reversed(DX)):
            nx = cx+dx
            ny=cy+dy
            if 0<=nx<H and 0<=ny<W and Grid[nx][ny]=="." and (nx,ny) not in visited:
                visited.add((nx,ny))
                prev_visited.add((nx,ny))
                Dist[nx][ny]=dist
                Q.append((nx,ny))
                if nx==D_pos[0] and ny==D_pos[1]:
                    print(dist)
                    exit()

    Q=deque()
    for cx,cy in prev_visited:
        for dx in range(-2,3):
            for dy in range(-2,3):
                if dx==0 and dy==0:
                    continue
                nx = cx+dx
                ny=cy+dy
                if (nx,ny) in visited:
                    continue
                if 0<=nx<H and 0<=ny<W and Grid[nx][ny]==".":
                    Q.append((nx,ny))
    dist+=1



Measured memory_bytes: 183392
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int N;
  string S,T;
  cin>>N>>S>>T;
  for(int i=0;i<N;i++){
    cout<<S[i]<<T[i];
  }cout<<endl;
  return 0;
}

Measured memory_bytes: 3508
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int>a(n, 0), b(n, 0), c(n, 0);
	for(int i = 0; i < n; i++)cin >> a[i];
	for(int i = 0; i < n; i++)cin >> b[i];
	for(int i = 0; i < n-1; i++)cin >> c[i];
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans += b[a[i]-1];
		if(i != 0 && a[i] == a[i-1] + 1)ans += c[a[i-1] - 1];
	}
	cout << ans << endl;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(std::string N){
    int sum = 0;
    rep(i,0,N.size()) {
        sum += N[i] - '0';
    }

    cout << ((sum % 9 == 0) ? "Yes" : "No") << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    std::string N;
    std::cin >> N;
    solve(N);
    return 0;
}


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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, k; std::cin >> n >> k;
  int r, s, p; std::cin >> r >> s >> p;
  string t; std::cin >> t;

  int ans = 0;
  vector<char> unenables(n);
  auto calc = [&](char &t, int &index) {
    char un = ' ';
    if (index >= k) un = unenables[index - k];
    if (t == 'r') {
      unenables[index] = (un != 'p' ? 'p' : '?');
      return (un == 'p' ? 0 : p);
    } else if (t == 's') {
      unenables[index] = (un != 'r' ? 'r' : '?');
      return (un == 'r' ? 0 : r);
    } else if (t == 'p') {
      unenables[index] = (un != 's' ? 's' : '?');
      return (un == 's' ? 0 : s);
    }
    return 0;
  };
  rep(i, n) {
    if (i < k)
      ans += calc(t[i], i);
    else
      ans += calc(t[i], i);
  }
  std::cout << ans << "\n";
}


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

int main() {
	long long x, a, b;
	cin >> x >> a >> b;
	if (b - a <= 0) {
		cout << "delicious" << endl;
	}
	else if (b - a <= x) {
		cout << "safe" << endl;
	}
	else {
		cout << "dangerous" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll x;
ll now=100;
int main(){
	ios::sync_with_stdio(0);
	cin>>x;
	ll ans=0;
	while(now<x){
		ll l=now/100;
		now+=l;
		ans++;
	}
	cout<<ans;
	re 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
using namespace std;


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

	int N, A;
	cin >> N >> A;
	vector<int>x(N);
	rep(i, N)cin >> x[i];
	vector<int>xc(N);
	xc[0] = x[0];
	REP(i, 1, N)xc[i] = xc[i - 1] + x[i];

	vector<vector<vector<int>>>dp(N);
	rep(i, N)dp[i].resize(N+1);
	rep(i, N)rep(j, N+1)dp[i][j].resize(2501, 0);
	//dp[i][j][k]:=i枚目まででj枚選び、合計がちょうどkであるような選び方の数

	rep(i, N)dp[i][0][0] = 1;
	dp[0][1][x[0]] = 1;
	for (int i = 1; i < N; i++) {
		for (int j = 1; j <= i+1; j++) {
			rep(k,x[i])dp[i][j][k] = dp[i - 1][j][k];
			REP(k, x[i], xc[i] + 1) {
				dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
			}
		}
	}
	int answer = 0;
	REP(j, 1, N + 1)answer += dp[N - 1][j][A*j];
	cout << answer << endl;
}

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

void sort(int a[],int n){
	int tmp;
	for(int i=0;i<(n-1);i++){
		for(int j=(n-1);j>i;j--){
			if(a[j-1]>a[j]){
				tmp=a[j-1];
				a[j-1]=a[j];
				a[j]=tmp;
			}
		}
	}
}

void get_divisor(int a,int b[],int *num){
	int n=1;
	b[0]=1;
	for(int i=2;i<=(a/2);i++){
		if((a%i)==0){
			b[n++]=i;
		}
	}
	b[n]=a;
	n++;
	*num=n;
}

int main(){
	
	int n;
	int *a;
	int *b;
	int num=0;

	scanf("%d",&n);
	a=(int*)malloc(sizeof(int)*n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	b=(int*)malloc(sizeof(int)*n);

	sort(a,n);

	get_divisor(a[0],b,&num);

	for(int i=1;i<n;i++){
		for(int j=1;j<num;j++){
			if((a[i]%b[j])!=0){
				b[j]=-1;
			}
		}
	}

	for(int i=0;i<num;i++){
		if(b[i]!=-1){
			printf("%d\n",b[i]);
		}
	}

	return 0;
}


Measured memory_bytes: 2032
package main

import (
	"fmt"
	"math"
)

var X, A, B, C, ans int

func main() {
	fmt.Scan(&A, &B, &C, &X)

	for i := 0; i <= A; i++ {
		for j := 0; j <= B; j++ {
			for k := 0; k <= C; k++ {
				if 500*i+100*j+50*k == X {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)

}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}
type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;

signed main(){
    string s,t; cin>>s>>t;
    bool can=false; int place=0;
    for(int i=0; i+t.size()<=s.size();i++){
        string u=s.substr(i,t.size());
        bool f=true;
        rep(i,u.size()){
            if(u.at(i)=='?') continue;
            if(u.at(i)!=t.at(i)){
                f=false; break;
            }
        }
        if(f){
            can=true; place=max(i,place);
        }
    }
    if(!can){
        cout<<"UNRESTORABLE"<<endl; return 0;
    }
    
    rep(i,s.size()){
        if(i==place) s.replace(i,t.size(),t);
        else if(s.at(i)=='?') s.replace(i,1,"a");
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n,m;
    cin>>n>>m;
    string s[n],t[n];
    rep(i,n)cin>>s[i];
    rep(i,n)cin>>t[i];
    int ans = 0;
    rep(i,n)rep(j,m)ans+=s[i][j]!=t[i][j];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11304
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

struct Elem {
    long point;
    int x, y, z;
      
    bool operator<(const Elem& elem) const
    {
        return (point < elem.point);
    }
};

int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    long* A = new long[X];
    for (int i = 0; i < X; i++) {
        cin >> A[i];
    }
    
    long* B = new long[Y];
    for (int i = 0; i < Y; i++) {
        cin >> B[i];
    }
    
    long* C = new long[Z];
    for (int i = 0; i < Z; i++) {
        cin >> C[i];
    }

    sort(A, A+X, greater<long>());
    sort(B, B+Y, greater<long>());
    sort(C, C+Z, greater<long>());

    priority_queue<Elem, vector<Elem,allocator < Elem > >, less<Elem>> que;
    bool* is_used = new bool[X*Y*Z];
    for (int i = 0; i < X*Y*Z; i++) {
        is_used[i] = false;
    }
    Elem elem;
    elem.point = A[0] + B[0] + C[0];
    elem.x = 0; elem.y = 0; elem.z = 0;
    que.push(elem);
    is_used[0] = true;

    for (int i = 0; i < K; i++) {
        Elem tmp = que.top(); que.pop();
        cout << tmp.point << endl;
        int idx = X*Y*tmp.z + X*tmp.y + (tmp.x+1);
        if (!is_used[idx] && (tmp.x+1) < X) {
            Elem add;
            add.point = A[tmp.x+1] + B[tmp.y] + C[tmp.z];
            add.x = tmp.x+1; add.y = tmp.y; add.z = tmp.z;
            que.push(add);
            is_used[idx] = true;
        }
        idx = X*Y*tmp.z + X*(tmp.y+1) + tmp.x;
        if (!is_used[idx] && (tmp.y+1) < Y) {
            Elem add;
            add.point = A[tmp.x] + B[tmp.y+1] + C[tmp.z];
            add.x = tmp.x; add.y = tmp.y+1; add.z = tmp.z;
            que.push(add);
            is_used[idx] = true;
        }
        idx = X*Y*(tmp.z+1) + X*tmp.y + tmp.x;
        if (!is_used[idx] && (tmp.z+1) < Z) {
            Elem add;
            add.point = A[tmp.x] + B[tmp.y] + C[tmp.z+1];
            add.x = tmp.x; add.y = tmp.y; add.z = tmp.z+1;
            que.push(add);
            is_used[idx] = true;
        }
    }

    return 0;
}


Measured memory_bytes: 977024
import string
numbers = "0123456789"
alphabets = string.ascii_letters  # a-z+A-Zをロード
characters = numbers + alphabets


def base_cvt(value, n=2):
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp % n
        if idx == 0:
            idx = 26
            tmp = int(tmp / n) - 1
        else:
            tmp = int(tmp / n)
        result = characters[idx] + result
    if tmp != 0:
        idx = tmp % n
        result = characters[idx] + result
    return result


N = int(input())

res = base_cvt(N, 26)
if res[-1] == "0":
    res = "q" * (len(res)-1)
for d in str(res):
    if d == "0":
        d = "q"
    if ord(d) >= 96:
        d = str(9 + ord(d) - 96)
    print(chr(96 + int(d)), end="")
print()


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

int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A+2, 0), t(B+2, 0), X(Q, 0);
    s[A] = -1e18;  s[A+1] = 1e18;
    t[B] = -1e18;  t[B+1] = 1e18;
    for(int i=0; i<A; i++)
        cin >> s[i];
    for(int i=0; i<B; i++)
        cin >> t[i];
    for(int i=0; i<Q; i++)
        cin >> X[i];
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    for(ll x : X){
        ll sl = *(lower_bound(s.begin(), s.end(), x) - 1);
        ll sr = *lower_bound(s.begin(), s.end(), x);
        ll tl = *(lower_bound(t.begin(), t.end(), x) - 1);
        ll tr = *lower_bound(t.begin(), t.end(), x);

        // cout << x << " " << sl << " " << sr << " " << tl << " " << tr << endl;

        ll ans = 1e18;
        ans = min(ans, x - min(tl, sl));
        ans = min(ans, max(tr, sr) - x);
        ans = min(ans, (tr - x) + (tr - sl));
        ans = min(ans, (sr - x) + (sr - tl));
        ans = min(ans, (x - tl) + (sr - tl));
        ans = min(ans, (x - sl) + (tr - sl));
        cout << ans << endl;
    }
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
  ll a,b,c; cin>>a>>b>>c;
  ll x,y; cin>>x>>y; ll an=1e18;
  for(int i=0;i<=max(x*2, y*2);i++) {
    ll sm=2*c*i;
    sm += max(0LL, a*(x-i));
    sm += max(0LL, b*(y-i));
    an = min(sm,an);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

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

    string s; cin >> s;
    string t = "CODEFESTIVAL2016";

    int cnt = 0;
    rep(i,s.size()){
        if(s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.container.rbtree;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int n;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		n = readln().strip().to!int;
	}
}

auto main2(Input* input)
{
	with (input)
	{
		int[] keta;
        keta.length = n;
        keta[] = 0;

        LOOP:
        while (true)
        {
            foreach (i; keta)
            {
                char c = cast(char)('a' + i);
                writef("%c", c);
            }
            write("\n");

            for (int i = n - 1; i >= 0; i--)
            {
                if (keta[i] < i)
                {
                    keta[i]++;
                    foreach (j; keta)
                    {
                        if (j == keta[i] - 1)
                            continue LOOP;
                    }
                }
                keta[i] = 0;
            }

            break;
        }
	}
}

alias retType = ReturnType!main2;

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


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

const int maxn=200006;
int l[maxn], r[maxn];
int num[maxn];

int main()
{
    int n;
    while(cin>>n){
        memset(l, 0, sizeof(l));
        memset(r, 0, sizeof(r));
        for(int i=0;i<n;i++){
            cin>>num[i];
            if(i>0){
                l[i] = max(num[i-1], l[i-1]);
            }
        }
        for(int i=n-2;i>=0;i--){
            r[i] = max(r[i+1], num[i+1]);
        }
        for(int i=0;i<n;i++){
            if(i==0){
                cout<<r[i]<<endl;
            }
            else if(i==n-1){
                cout<<l[i]<<endl;
            }
            else{
                cout<<max(l[i], r[i])<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
using namespace std;
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define lli long long int

#define MAX 100000000
//#define DEBUG

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

int N;
vector<pair<int, int>> ans;

void read()
{
    cin >> N;
}
void solve()
{
    REP(i, 1, N + 1)
    REP(j, i + 1, N + 1)
    {
        if ((i + j) != (N + 1 - (N & 1)))
        {
            ans.push_back(make_pair(i, j));
        }
    }
}
void print()
{
    cout << ans.size() << endl;
    for (auto &&i : ans)
    {
        cout << i.first << " " << i.second << endl;
    }
}
int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
#else
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
#endif
    read();
    solve();
    print();
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int n,m,t;
  t=0;
  cin >> n;
  REP(i,n){
    cin >> m;
    t+=m-1;
  }
  cout << t;
  return 0;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;


int main(){
   int n;
   ll k, q;
   cin >> n >> k >> q;
   vector<ll>a(n, k);
   rep(i, 0, q){
       ll p;
       cin >> p;
       p--;
       a[p]++;
   }
   rep(i, 0, n)a[i] -= q;
   rep(i, 0, n){
       if(a[i]>0)cout << "Yes" << endl;
       else cout << "No" << endl;
   }
}

Measured memory_bytes: 4052
(defun first-and-last (num)
  (let ((str (write-to-string num)))
    (values (- (char-code (aref str 0)) (char-code #\0))
            (- (char-code (aref str (1- (length str)))) (char-code #\0)))))

(defun solve (n)
  (let ((count 0))
    (loop for a from 1 to n
          do (multiple-value-bind (first last)
                 (first-and-last a)
               (unless (zerop last)
                 (when (= first last)
                   (when (<= first n)
                     (incf count)))
                 (loop for j from 1
                       for b = (+ (* last (expt 10 j)) first)
                       while (<= b n)
                       do (loop for k from (1- (expt 10 (1- j))) downto 0
                                until (<= (+ b (* k 10)) n)
                                finally (incf count (1+ k))))))
          finally (return count))))

#-swank
(let* ((n (read)))
  (format t "~A~%" (solve n)))


Measured memory_bytes: 68192
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){

int W,H,x,y,way;

scanf("%d%d%d%d",&W,&H,&x,&y);



if(x*2==W && y*2==H){
  way=1;
}

else{
way=0;
}

printf("%lf %d\n",double(W)*double(H)/2,way);

}


Measured memory_bytes: 3780
H, W=map(int, input().split())
A=[]
tate=[False]*W
for i in range(H):
  tmp=list(input())
  if "#" not in tmp:
    continue
  A.append(tmp)
  for j in range(W):
    if tmp[j]=="#":
      tate[j]=True

for i in range(len(A)):
  ans=[]
  for j in range(W):
    if tate[j]:
      ans.append(A[i][j])
  print("".join(ans))
  
  

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

int main(){
	int n;
	cin >> n;
	int a[100][2];
	for ( int i = 0; i < n; i++ ) {
		cin >> a[i][0];
		cin >> a[i][1];
	}
	int c[100][100] = {0};
	for ( int i = 2; i <= n; i++ ) {
		for ( int j = 0; j <= n - i; j++ ) {
			int x = 0;
			for ( int k = 1; k < i; k++ ) {
				int y = 0;
				y = c[j][k] + c[j+k][i-k] + a[j][0] * a[j+k][0] * a[j+i-1][1];
				if ( x == 0 || x > y ) x = y;
			}
			c[j][i] = x;
		}
	}
	cout << c[0][n] << endl;
	return 0;
}

Measured memory_bytes: 1208
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_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BinaryHeap;

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];

    let mut xv: Vec<i32> = read_vec();

    if n >= m {
        println!("0");
    } else {
        xv.sort();
        let mut bh: BinaryHeap<i32> = BinaryHeap::new();
        for i in 0..(m - 1) {
            bh.push(xv[i] - xv[i + 1]);
        }

        let mut ans: u32 = 0;

        for _ in 0..(m - n) {
            ans += -bh.pop().unwrap() as u32;
        }

        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n, m, a;
	while(cin >> n >> m >> a, n || m || a)
	{
		vector< vector<P> > yoko(1001);
		int max_height = 0;
		for(int i = 0; i < m; ++i)
		{
			int h, p, q;
			cin >> h >> p >> q;
			if(max_height < h)
			{
				max_height = h;
			}
			yoko[h].push_back(P(p, q));
		}
		int current = a;
		for(int i = max_height; i >= 1; --i)
		{
			for(int j = 0; j < yoko[i].size(); ++j)
			{
				if(yoko[i][j].first == current)
				{
					current = yoko[i][j].second;
					break;
				}
				else if(yoko[i][j].second == current)
				{
					current = yoko[i][j].first;
					break;
				}
			}
		}
		cout << current << endl;
	}
}

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

Measured memory_bytes: 1240