akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    string S;
    cin>>S;
    if(S[0]=='A' && S[1]=='A' && S[2]=='A') cout<<"No"<<endl;
    else if(S[0]=='B' && S[1]=='B' && S[2]=='B') cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

long long sum(long long N, long long d) {
	long long an = (N/d)*d;
	long long n = N/d+1;
	return (an*n)/2;
}

int main() {
	int T;
	cin >> T;
	cout << sum(T,1) - sum(T,3) - sum(T,5) + sum(T,15) << endl;
	return 0;
}

Measured memory_bytes: 3636
n = int(input())
edges = [[] for _ in range(n)]
 
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)
dp = [0]*n
dp[0] =1
fp = [0]*n
fp[n-1] =1
def bfs(u):
    q = []
    q.append(u)
    while q:
        p = q.pop()
        for i in edges[p]:
            if dp[i] ==0 :
                q.append(i)
                dp[i]+=dp[p]+1
def ffs(u):
    q = []
    q.append(u)
    while q:
        p = q.pop()
        for i in edges[p]:
            if fp[i] ==0 :
                q.append(i)
                fp[i]+=fp[p]+1
bfs(0)
ffs(n-1)
c = 0
for i in range(n):
    if dp[i] <= fp[i]:
        c += 1
if 2*c > n:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 59040
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

vector<string> s;

int main() {
	cout << fixed << setprecision(12);	
	s.push_back("Sunny");
	s.push_back("Cloudy");
	s.push_back("Rainy");
	string t;
	cin >> t;
	for (int i = 0; i < 3; i++) {
		if (s[i] == t) {
			cout << s[(i + 1) % 3] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3600
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W = [int(x) for x in input().split()]
    CH, CW = [int(x) - 1 for x in input().split()]
    DH, DW = [int(x) - 1 for x in input().split()]
    S = [input().strip() for _ in range(H)]

    warp = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2],
            [-1, -2], [-1, -1], [-1, 1], [-1, 2],
            [0, 2], [0, -2],
            [1, -2], [1, -1], [1, 1], [1, 2],
            [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]

    visited = [[float("inf")] * W for _ in range(H)]

    q = collections.deque()
    visited[CH][CW] = 0
    q.append((CH, CW))
    while q:
        cx, cy = q.popleft()
        cc = visited[cx][cy]

        # 隣接
        kabe_cnt = 0
        for nx, ny in ([0, 1], [0, -1], [1, 0], [-1, 0]):
            nnx = cx + nx
            nny = cy + ny
            if 0 <= nnx <= H - 1 and 0 <= nny <= W - 1:
                if S[nnx][nny] == ".":
                    if visited[nnx][nny] > cc:
                        q.appendleft((nnx, nny))
                        visited[nnx][nny] = cc
                else:
                    kabe_cnt += 1

        # ワープ
        if kabe_cnt > 0:
            for nx, ny in warp:
                nnx = cx + nx
                nny = cy + ny
                if 0 <= nnx <= H - 1 and 0 <= nny <= W - 1:
                    if S[nnx][nny] == "." and visited[nnx][nny] > cc + 1:
                        q.append((nnx, nny))
                        visited[nnx][nny] = cc + 1

    if visited[DH][DW] == float("inf"):
        print(-1)
    else:
        print(visited[DH][DW])


if __name__ == '__main__':
    main()


Measured memory_bytes: 101400
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;
unsigned gcd(unsigned a, unsigned b) {
    if (a == 0) return b;
    if (b == 0) return a;
    if (a < b) gcd(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    LL n;
    cin >> n;
    vector<LL> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vector<LL> l_gcd(n, 0), r_gcd(n, 0);

    l_gcd[0] = a[0];
    for (LL i = 1; i < n; i++) {
        l_gcd[i] = gcd(l_gcd[i - 1], a[i]);
    }

    r_gcd[n - 1] = a[n - 1];
    for (LL i = n - 2; i >= 0; i--) {
        r_gcd[i] = gcd(r_gcd[i + 1], a[i]);
    }

    LL ans = r_gcd[1];
    for (LL i = 1; i < n - 1; i++) {
        ans = max(ans, (LL)gcd(l_gcd[i - 1], r_gcd[i + 1]));
    }
    ans = max(ans, l_gcd[n - 2]);
    cout << ans << endl;
}


Measured memory_bytes: 2688
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

static const double EPS = 1e-8;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int gSum = 0;
int w,h,c;

class Data{
public:
	int stage[8][8];
	int count;
	Data() : count(0), stage(){}
	Data(int _stage[8][8],int _count){
		memcpy(this->stage,_stage,sizeof(int)*8*8);
		this->count = _count;
	}
	bool operator>(const Data& d) const{
		return this->count > d.count;
	}

	bool operator<(const Data& d) const{
		return this->count < d.count;
	}
};

void dfs(int stage[8][8],int x,int y,int from,int to,bool visited[8][8]){
	stage[y][x] = to;
	visited[y][x] = true;

	for(int i=0;i<4;i++){
		int dx = x + tx[i];
		int dy = y + ty[i];
		if(dx < 0 || dx >= w || dy < 0 || dy >= h) continue;
		if(stage[dy][dx] != from ) continue;
		if(visited[dy][dx]) continue;

		dfs(stage,dx,dy,from,to,visited);
	}
}

void dfs2 (int stage[8][8],int x,int y,bool visited[8][8]){
	visited[y][x] = true;
	gSum++;
	for(int i=0;i<4;i++){
		int dx = x + tx[i];
		int dy = y + ty[i];
		if(dx < 0 || dx >= w || dy < 0 || dy >= h) continue;
		if(stage[dy][dx] != c) continue;
		if(visited[dy][dx]) continue;

		dfs2(stage,dx,dy,visited);
	}
}

string stg2str(int stage[8][8]){
	string res = "";
	for(int y=0;y<h;y++){
		for(int x=0;x<w;x++){
			res += stage[y][x] + '0';
		}
	}

	return res;
}

int main()
{
	while(~scanf("%d %d %d",&h,&w,&c)){
		if(h==w && w==c && c==0) break;

		int stage[8][8];
		for(int y=0;y<h;y++){
			for(int x=0;x<w;x++){
				scanf("%d",&stage[y][x]);
			}
		}

		priority_queue<Data,vector<Data>,greater<Data> > que;
		que.push(Data(stage,0));

		int maxv = 0;
		map<string,int> cost;

		while(!que.empty()){
			Data d = que.top();
			que.pop();

			if(d.count >= 5) continue;
			for(int i=1;i<=6;i++){
				int next[8][8];
				memcpy(next,d.stage,sizeof(int)*8*8);

				
				bool visited[8][8];
				memset(visited,0,sizeof(visited));
				dfs(next,0,0,d.stage[0][0],i,visited);


				string str = stg2str(next);
				if(cost.find(str) != cost.end() && cost[str] <= d.count + 1) continue;

				cost[str] = d.count + 1;

				gSum = 0;
				memset(visited,0,sizeof(visited));
				dfs2(next,0,0,visited);
				maxv = max(maxv,gSum);

				que.push(Data(next,d.count+1));
			}
		}

		printf("%d\n",maxv);
	}
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
    unordered_map<int, int> masu;
    int a[9];
    rep(i, 9) {
        cin >> a[i];
    }
    rep(i, 9) {
        masu[a[i]] = 0;
    }
    int n;
    cin >> n;
    rep(i, n) {
        int enter;
        cin >> enter;
        masu[enter] = 1;
    }
    if((masu[a[0]] == 1 && masu[a[1]] == 1 && masu[a[2]] == 1) ||
       (masu[a[3]] == 1 && masu[a[4]] == 1 && masu[a[5]] == 1) ||
       (masu[a[6]] == 1 && masu[a[7]] == 1 && masu[a[8]] == 1) ||
       (masu[a[0]] == 1 && masu[a[3]] == 1 && masu[a[6]] == 1) ||
       (masu[a[1]] == 1 && masu[a[4]] == 1 && masu[a[7]] == 1) ||
       (masu[a[2]] == 1 && masu[a[5]] == 1 && masu[a[8]] == 1) ||
       (masu[a[0]] == 1 && masu[a[4]] == 1 && masu[a[8]] == 1) ||
       (masu[a[2]] == 1 && masu[a[4]] == 1 && masu[a[6]] == 1))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

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

int main(){

    int n;
    cin>> n;

    vector<int> a(n,0);

    rep(i,n){
        int t;
        cin >> t;
        a[t]++;
    }

    if(n%2==1){
        if(a[0]!=1){
            cout << 0 << endl;
            return 0;
        }
        for(int i=1;i<n;i++){
            if(i%2==0){
                if(a[i]!=2){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(a[i]!=0){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }else{
        for(int i=0;i<n;i++){
            if(i%2==1){
                if(a[i]!=2){
                    cout << 0 << endl;
                    return 0;
                }
            }else{
                if(a[i]!=0){
                    cout << 0 << endl;
                    return 0;
                }
            }
        }
    }

    ll ans=1;
    ll m=(1e+9)+7;
    for(int i=0;i<n/2;i++){
        ans*=2;
        ans%=m;
    }
    cout << ans << endl;

    return 0;
}

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

int main(void) {
	int N, K, x;

	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> x;
		if (2 * x > K)
			ans += 2 * (K - x);
		else
			ans += 2 * x;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    if a[0] == 1:
        print(1)
        exit(0)
    if a[0] == a[a[0]-1]:
        print(a[0])
        exit(0)
    pos = a[0]
    num = 1
    nums = set([1])
    while pos not in nums:
        nums.add(pos)
        num += 1
        pos = a[pos-1]
    lastnum = pos
    prefix = 0
    pos = 1
    while pos != lastnum:
        prefix += 1
        pos = a[pos-1]
    num -= prefix
    if k > prefix:
        k = (k-prefix)%num+prefix
    pos = 1
    for _ in range(k):
       pos = a[pos-1]
    print(pos)

if __name__ == "__main__":
    main()

Measured memory_bytes: 111788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll a,b,c;
  cin>>a>>b>>c;
  ll sum=a+b+c;
  vector<tuple<ll,ll,ll>> vec={make_tuple(a,b,c)};
  ll cnt=0;
  while(true){
    if(a%2==1||b%2==1||c%2==1){
      cout<<cnt;
      return 0;
    }
    a=(sum-a)/2;
    b=(sum-b)/2;
    c=(sum-c)/2;
    tuple<ll,ll,ll> tmp=make_tuple(a,b,c);
    auto result = find(vec.begin(),vec.end(),tmp);
    if(result!=vec.end()){
      cout<<-1;
      return 0;
    }
    cnt++;
    vec.push_back(tmp);
  }
}

Measured memory_bytes: 256
import math

A,B,H,M = map(int,input().split())

deg_m = 360*M/60
deg_h = 360*H/12 + 30*M/60

if deg_h > deg_m: 
    deg = deg_h - deg_m
else:
    deg = deg_m - deg_h

if deg > 180:
    deg = 360 - deg

C = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(deg)))

print(C)

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

using namespace std;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
typedef long long ll;

const int maxn = 110;
const string ACGT("ACGT");

int N;

vector<unordered_map<string, ll>> memo(maxn);

bool check(string last4) {
    if (last4.find("AGC") != string::npos) {
        return false;
    }
    for (int i = 0; i < 4 - 1; ++i) {
        swap(last4[i], last4[i + 1]);
        if (last4.find("AGC") != string::npos) {
            return false;
        }
        swap(last4[i], last4[i + 1]);
    }
    return true;
}

ll dfs(int cur, const string& last3) {
    if (memo[cur].count(last3)) {
        return memo[cur][last3];
    }
    if (cur == N) {
        return 1;
    }
    ll ret = 0;
    for (char c : ACGT) {
        if (check(last3 + c)) {
            ret = (ret + dfs(cur + 1, last3.substr(1) + c)) % MOD;
        }
    }
    return memo[cur][last3] = ret;
}

int main() {
    cin >> N;
    cout << dfs(0, "XXX") << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

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

Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;

int main()
{
	int x,y;
	cin>>x>>y;
	if(2*x<=y&&4*x>=y&&y%2==0)
	cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define list_input(x, n) x[n]; rep(i,n){ cin >> x[i];}
#define ll long long

string S;
ll ans = 0;

void dfs(int i, ll add, ll sum) {
  add += (ll)(S[i] - '0');
  if (i == S.size() -1) {
    ans += sum + add;
    return;
  }
  dfs(i+1, 0, add+sum);
  dfs(i+1, add*10, sum);
}

int main(){
  cin >> S;
  dfs(0,0,0);
  cout << ans << endl;
}


Measured memory_bytes: 256
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N, M = I()
count = 0
 
min_a = 1
max_b = N
 
for i in range(M):
    a,b = [int(i) for i in input().split()]
    if min_a < a:
        min_a = a
    if max_b > b:
        max_b = b
 
print(max(0, max_b-min_a+1))

Measured memory_bytes: 10512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,a[200005],ans;
vector<int> bn(ll l,ll r){
    if(l==r){
        vector<int>b;
        b.PB(a[l]);
        return b;
    }
    ll m=(l+r)/2;
    vector<int>x=bn(l,m);
    vector<int>y=bn(m+1,r);
    vector<int>b;
    ll s=0,xs=0,ys=0;
    while(xs<x.size()&&ys<y.size()){
        if(x[xs]<=y[ys]){
            b.PB(y[ys]);
            ys++;
            ans+=s;
        }else{
            b.PB(x[xs]);
            xs++;
            s++;
        }
    }
    while(xs<x.size())b.PB(x[xs++]);
    while(ys<y.size()){
        ans+=s;
        b.PB(y[ys++]);
    }
    return b;
}
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++)scanf("%lld",a+i);
    bn(0,n-1);
    printf("%lld\n",ans);
}



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

using namespace std;

#define FOR(i, a, n) for(int i = a; i < n; ++i)
#define ll long long

int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

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

    int a = (n - 1);
    int b = (m - 1);

    int sum1 = (a * (a + 1)) / 2;
    int sum2 = (b * (b + 1)) / 2;
    int ans = sum1 + sum2;

    printf("%d", ans);

	return 0;
}


// g++ -std=c++11 -o solve solve.cpp
// ./solve < input.txt


Measured memory_bytes: 256
import itertools
import math

n = int(input())
p = [i for i in input().split()]
q = [i for i in input().split()]

perm = sorted(list(itertools.permutations([str(int(i+1)) for i in range(n)])))
for i in range(math.factorial(n)):
    if list(perm[i]) == p:
        a = i + 1
    if list(perm[i]) == q:
        b = i + 1
print(abs(a-b))

Measured memory_bytes: 8228
#include <iostream>

int main()
{
    int a = 0, b = 0;
    std::cin >> a >> b;
    if (a > b)
        std::cout << "a > b" << std::endl;
    else if (a == b)
        std::cout << "a == b" << std::endl;
    else
        std::cout << "a < b" << std::endl;
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <math.h>
int main(void){
    // Your code here!
  double x1,x2,y1,y2,d;
  scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
  
  d=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  d=sqrt(d);
  
  printf("%lf\n", d);
   
   return 0;
    
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N + 1);
  REP(i, N + 1) cin >> A[i];
  vector<int> B(N);
  REP(i, N) cin >> B[i];
  int ans = 0;
  REP(i, N) {
    if(A[i] >= B[i]) {
      ans += B[i];
    } else {
      ans += A[i];
      B[i] -= A[i];
      if(A[i + 1] >= B[i]) {
        ans += B[i];
        A[i + 1] -= B[i];
      } else {
        ans += A[i + 1];
        A[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    lli n,x,t;
    cin>>n>>x>>t;

    cout<<(lli)ceil((n*1.0)/x)*t<<endl;
}

Measured memory_bytes: 3756
#include<iostream>
using namespace std;
int a[7],b[7];
int N;
int dfs(int U,int id)
{
	if(id==N)return U==0;
	int ret=0;
	for(int k=0;k<=b[id];k++)
	{
		if(U<k*a[id])break;
		ret+=dfs(U-k*a[id],id+1);
	}
	return ret;
}
main()
{
	while(cin>>N,N)
	{
		for(int i=0;i<N;i++)cin>>a[i]>>b[i];
		int Q;cin>>Q;
		for(;Q--;)
		{
			int g;cin>>g;cout<<dfs(g,0)<<endl;
		}
	}
}



Measured memory_bytes: 3008
#include<iostream>
#include<array>
#include<algorithm>

using namespace std;
 
int main() 
{
    int N;
    cin >> N;

    array<int,81> kuku;
    for(int i=0;i<9;++i)
    {
        for(int j=0;j<9;++j)
        {
            kuku[i*9+j]=(i+1)*(j+1);
        }
    }

    auto it = find(kuku.begin(),kuku.end(),N);
    if(N <= 81 && it != kuku.end())
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    } 

    
    return 0;
}

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

int main(void) {
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for (int i=0;i<n;i++) {
        cout<<s.at(i)<<t.at(i);
    }
    cout<<endl;
}

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


const int MAX = 510000;
const int MOD = 1000000007;

long long 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 COM(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;
}

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;
}


ll po(ll a, ll n){
    ll ret = 1;
    for(; n > 0; n >>= 1, a = a * a % MOD){
        if(n % 2 == 1){
            ret = ret * a % MOD;
        }
    }
    return ret;
}

int main() {
    ll n, a, b; cin >> n >> a >> b;
    ll ans = po(2, n) - 1; 
    ll aa = 1, bb = 1;
    for(int i = 1; i <= a; i++){
        aa %= MOD;
        aa = aa * (n - i + 1) % MOD;
        aa = (aa * modinv(i, MOD)) % MOD;
    } 
    for(int i = 1; i <= b; i++){
        bb %= MOD;
        bb = bb * (n - i + 1) % MOD;
        bb = (bb * modinv(i, MOD)) % MOD;
    } 
    
    ans += MOD * 2;
    cout << (ans - aa - bb) % MOD << endl;
}



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

vector<int> N, one;

int main () {
	int n, m; cin>>n>>m;
	for(int i=1; i<=m; i++) {
		int x, y; cin>>x>>y;
		if(x==1 && y!=n) one.push_back(y);
		if(x==n && y!=1) N.push_back(y);
		if(y==1 && x!=n) one.push_back(x);
		if(y==n && x!=1) N.push_back(x);
	}
	sort(one.begin(), one.end());
	sort(N.begin(), N.end());
	//for(auto b : one) cout<<b<<' '<<endl; cout<<endl;
	///////for(auto b : N) cout<<b<<' '<<endl; cout<<endl;
	for(int i=0; i<one.size(); i++) {
		if(binary_search(N.begin(), N.end(), one[i])) {
			cout<<"POSSIBLE"<<endl;
			//system("pause");
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1276
N, A = gets.split.map(&:to_i)
 
X = gets.split.map{ |i| i.to_i.-A }.sort.reverse
 
max = 0
X.each do |x|
  max += x if x > 0
end
 
dp = Array.new(N+1){ Array.new( max + 1, 0 ) }
 
dp[0][0] = 1
 
X.each_with_index do |x,i|
  
  dp[i].each_with_index do |d,j|
    
    dp[i+1][j] = dp[i][j]
    dp[i+1][j] += dp[i][j-x] if ( 0<=j-x and j-x<=max)
    
    
  end
end
 
puts dp[N][0] - 1

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;

  string ans = "";

  rep(i, s.length()){
    if(s[i] == '0'){
      ans += "0";
    }else if(s[i] == '1'){
      ans += "1";
    }else{
      if(ans.length() > 0){
        ans.erase(ans.length()-1);
      }
    }
  } 
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll X, N;
    cin>>X>>N;
    vector<ll> P(N);
    rep(i, N){
        cin>>P[i];
    }
    ll Min=INF;
    ll Ans=0;
    for(ll i=-100; i<=200; i++){
      	bool OK=true;
        rep(j, N){
            if(i==P[j])OK=false;
        }
      	if(!OK)continue;
        if(Min>abs(X-i)){
            Min=abs(X-i);
            Ans=i;
        }
    }
    cout<<Ans<<endl;
}
     

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

int main(){
	auto read_string 	=	[](){ string s; cin >> s; return s; };
	auto read_int       =   [](){ int tmp; cin >> tmp; return tmp; };
	auto read_char      =   [](){ char c; cin >> c; return c; };
	auto str_repeat	 	=	[](string a,int count){	string res = ""; for(size_t i = 0 ; i < count ; i++) res += a; return res;	};
	auto to_lower_case 	= 	[](string s){ string res=""; for(size_t i = 0 ; i < s.size() ; i++) res += tolower(s[i]); return res; };
	auto to_upper_case 	= 	[](string s){ string res=""; for(size_t i = 0 ; i < s.size() ; i++) res += toupper(s[i]); return res; };
	auto read_vec_int   =   [](int count){ vector<int> tmp(count); for(size_t i = 0 ; i < count ; i++) cin >> tmp[i]; return tmp; };
	auto title_case     =   [](string s) { string ret = ""; ret+=toupper(s[0]); ret += s.substr(1); return ret; };
	auto is_upper 		=   [](char c){ return (int)c >= (int)'A' && (int)c <= (int)'Z'; };
	auto is_lower		=   [](char c){ return (int)c >= (int)'a' && (int)c <= (int)'z'; };

	int r = read_int();
	if(r < 1200){
		cout <<  "ABC" << endl;
	}else if (r < 2800){
		cout << "ARC" << endl;
	}else{
		cout <<  "AGC" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int N=26;
int D;
vector<int> c(N);
vector<vector<int>> s;

lint calc_score(vector<int> &t){
  lint ans=0;
  int last[N];
  REP(n,N)last[n]=-1;
  REP(d,D){
    ans+=s[d][t[d]];
    last[t[d]]=d;
    REP(n,N)ans-=c[n]*(d-last[n]);
  }
  return ans;
}

int main(){
  cin>>D;
  REP(i,N)cin>>c[i];
  REP(d,D){
    vector<int> v(N);
    REP(n,N)cin>>v[n];
    s.push_back(v);
  }
  vector<int> t(D);
  REP(d,D){
    cin>>t[d];
    t[d]--;
  }
  int M;
  cin>>M;
  vector<lint> ans;
  REP(i,M){
    int d,q;
    cin>>d>>q;
    d--;q--;
    t[d]=q;
    ans.push_back(calc_score(t));
  }
  for(auto e:ans)cout<<e<<endl;
  return 0;
}


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

int main(){
    int N,K;
    cin>>N>>K;
    if(N%2==0){
        if(N/2>=K){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }else{
        if((N/2)+1>=K){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		//数ごとに出てきた回数を数える
		HashMap<Integer, Long> map = new HashMap<>();
		for(int i = 0; i < n; i++) {
			int key = list.get(i);
			//該当数がなければ１、あればl+1を追加
			Long l = map.get(key);
			map.put(key, l == null? 1 : l + 1);
		}
		//組み合わせ総数を算出
		long total = 0;
		for(long i : map.values()) {
			if (i > 1)
			total += combination(i, 2);
		}
		
		for (int i = 0; i < n; i++) {
			long ans = total;
			long tmp = map.get(list.get(i));
			ans = ans - combination(tmp , 2) + combination(tmp-1, 2);
			out.println(ans);
		}
		

		out.close();
	}
	
	public static long factorial(long n) {
		if (n <= 1)
			return 1;
		else {
			return n * factorial(n - 1);
		}
	}

	public static long combination(long n, long r) {
		long top = n;
		for (int i = 0; i < r - 1; i++) {
			top = top * (--n);
		}
		long bottom = factorial(r);
		return top / bottom;
	}
}


Measured memory_bytes: 94000
package main

import "fmt"

func main() {
	for {
		var s string
		fmt.Scan(&s)
		if s == "-" {
			break
		}
		var m int
		fmt.Scan(&m)
		h := 0
		for i := 0; i < m; i++ {
			var x int
			fmt.Scan(&x)
			h += x
		}
		h %= len(s)
		fmt.Print(s[h:])
		fmt.Println(s[0:h])
	}
}



Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main()
{
    float a,b;
    cin>>a>>b;
    float c=(a+b)/2;
    int q=c*10,w=q%10;
    q-=w;
    if(w>4)
        w=10;
    else
        w=0;
    q+=w;
    q/=10;
    cout<<q;

}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

int a,b,c,j=0;

    scanf("%d %d %d\n", &a,&b,&c);
    
  for ( int i = a; i <= b; i++) 
  {
      if (c%i==0) {
        j++;
      }
  }



    printf("%d\n",j);
  

  return 0;
}


Measured memory_bytes: 2120
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }


int
main(void){  
  int N;
  cin >> N;
  ll a[N];  
  REP(i, N) cin >> a[i];
  SORT(a, N);
  ll ans = 0;

  if(N % 2 == 0) {
    for(int i = 1; i < N/2; i++) {
      ans += (ll)(i*2)*abs(a[i] - a[i-1]);
      ans += (ll)(i*2)*abs(a[N-1-i] - a[N-i]);
    }
    ans += (ll)(N-1)*abs(a[N/2]-a[N/2-1]);
  } else {
    for(int i = 1; i <= N/2; i++) {
      ans += (ll)(i*2)*abs(a[i] - a[i-1]);
      ans += (ll)(i*2)*abs(a[N-1-i] - a[N-i]);
    }
    ll work = min(abs(a[N/2]-a[N/2-1]),	a[N/2+1]-a[N/2]);
    ans -= work;
 
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n,ansc[100]={},o=0,hr=0,h=0,o2=0;
  string event;
  cin>>n;
  int i=0;
  int j=0;
  while(1){
    cin>>event;
    if(event=="OUT"){
      o++;
      o2++;
    }
    if(event=="HIT")h++;
    if(event=="HOMERUN")hr++;

    if(o2==3*n)break;

    if(h==4){
      ansc[j]++;
      h--;
    }
    else if(o==3){
      o=0;
      h=0;
      j++;
    }
    else if(hr==1){
      ansc[j]+=h+1;
      h=0;
      hr=0;
    }
    i++;
  }
  for(int j=0;j<n;j++)
  cout<<ansc[j]<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector <int> vi;
typedef long double LD;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=2005;
int n;
int fa[N];
int a[N],depth[N];
vector <int> e[N],ans;
void dfs(int x,int d){
	depth[x]=d;
	for (auto y : e[x])
		dfs(y,d+1);
}
#define end End
int del[N],c[N],end[N],cnt;
bool check(){
	For(i,1,n)
		if (!del[i])
			return 1;
	return 0;
}
void get(int x){
	end[x]=x;
	for (auto y : e[x]){
		if (del[y])
			continue;
		get(y);
		if (!end[y])
			end[x]=0;
		else if (end[x]==x)
			end[x]=end[y];
		else
			end[x]=0;
	}
	if (end[x])
		c[x]=1,cnt++;
}
void Opt(int x){
	ans.pb(x);
	int y=x,v=a[x],flag=0;
	while (y!=1){
		int tmp=a[fa[y]];
		a[fa[y]]=v;
		v=tmp;
		y=fa[y];
	}
	a[x]=v;
}
int main(){
	n=read();
	For(i,2,n){
		fa[i]=read()+1;
		e[fa[i]].pb(i);
	}
	For(i,1,n)
		a[i]=read()+1;
	dfs(1,0);
	while (check()){
		clr(c),cnt=0;
		get(1);
		while (cnt){
			int x=a[1];
			if (c[x]==1){
				int p=end[x];
				while (c[a[p]]==3&&depth[a[p]]>depth[x])
					p=fa[p];
				Opt(p);
				cnt--;
				c[x]=3;
			}
			else {
				assert(c[x]!=3);
				int p=0;
				For(i,1,n)
					if (!del[i]&&c[a[i]]<=1)
						if (!p||depth[i]>depth[p])
							p=i;
				Opt(p);
				c[x]=2;
			}
		}
		For(i,1,n)
			if (!del[i]&&end[i]) assert(a[i]==i),
				del[i]=1;
	}
	cout<<ans.size()<<endl;
	for (auto v : ans)
		printf("%d\n",v-1);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int sx, sy;
int tx, ty;
int main() {
	cin>>sx>>sy>>tx>>ty;
	string ans="";
	for (int i = 1; i <= tx- sx; ++i) {
		ans += "R";
	}
	for (int i = 1; i <= ty-sy; ++i) {
		ans += "U";
	}
	ans += "R";
	for (int i = 1; i <= ty - sy; ++i) {
		ans += "D";
	}
	ans += "D";
	ans += "L";
	for (int i = 1; i <= tx - sx; ++i) {
		ans +="L";
	}
	ans += "U";
	for (int i = 1; i <= ty - sy; ++i) {
		ans +="U";
	}
	for (int i =1;i<=tx-sx; ++i) {
		ans +="R";
	}
	ans += "U";
	for (int i = 1; i <= tx-sx;++i) {
		ans += "L";
	}
	ans += "LD";
	for (int i = 1; i <= ty-sy; ++i) {
		ans += "D";
	}
	ans += "R";
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
x = []
for line in sys.stdin:
    h,w = line.split()
    h,w = int(h), int(w)
    if h == 0 and w== 0: break
    s1 = '.#' * ((w+1)/2)
    s2 = '#.' * ((w+1)/2)
    for j in range(h):
        if (j & 1)==0: print s2[:w]
        else: print s1[:w]
    print
    

Measured memory_bytes: 4228
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<stdlib.h>
#define f first
#define s second
using namespace std;

int main()
{
  int m,n,a,b;
  string s,ans="correct";
  map<string,pair<int,int> > M;
  stack<vector<int> > S;

  cin>>m;
  for(int i=0;i<m;i++){
    cin>>s>>a>>b;
    M[s].f=a;
    M[s].s=b;
  }
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=="+" || s=="-" || s=="*" || s=="/"){
      vector<int> V1=S.top();S.pop();
      vector<int> V2=S.top();S.pop();
      vector<int> V3;
      bool flag[256];
      for(int i=0;i<256;i++)flag[i]=false;
      if(s=="+"){
	for(int i=0;i<V1.size();i++){
	  for(int j=0;j<V2.size();j++){
	    int c=(V2[j]+V1[i])%256;
	    if(flag[c])continue;
	    V3.push_back(c);
	    flag[c]=true;
	  }
	}
      }
      else if(s=="-"){
	for(int i=0;i<V1.size();i++){
	  for(int j=0;j<V2.size();j++){
	    int c=(V2[j]-V1[i]+256)%256;
       	    if(flag[c])continue;
	    V3.push_back(c);
	    flag[c]=true;
	  }
	}
      }
      else if(s=="*"){
	for(int i=0;i<V1.size();i++){
	  for(int j=0;j<V2.size();j++){
	    int c=(V2[j]*V1[i])%256;
	    if(flag[c])continue;
	    V3.push_back(c);
	    flag[c]=true;
	  }
	}
      }
      else {
	for(int i=0;i<V1.size();i++){
	  for(int j=0;j<V2.size();j++){
	    if(V1[i]==0){
	      ans="error";
	      break;
	    }
	    int c=(V2[j]/V1[i])%256;
	    if(flag[c])continue;
	    V3.push_back(c);
	    flag[c]=true;
	  }
	}
      }
      S.push(V3);
    }
    else {
      pair<int,int> p=M[s];
      vector<int> V;
      if(p.f!=0 || p.s!=0){
	for(int i=p.f;i<=p.s;i++)V.push_back(i);
      }
      else {
	V.push_back(atoi(s.c_str()));
      }
      S.push(V);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1264
def check(b, i, j, x, y):
 if i < 0 or j < 0 or i == x or j == y:
  return 0
 if b[i][j] == "#":
  return 1
 return 0

bounds = raw_input().split(" ")
x = int(bounds[0])
y = int(bounds[1])
board = [None] * x
for i in range(0, x):
 k = raw_input()
 board[i] = [None] * y
 for j in range(0, y):
  board[i][j] = k[j]

for i in range(0, x):
 for j in range(0, y):
  if board[i][j] == ".":
   p = 0
   p += check(board, i-1, j-1, x, y)
   p += check(board, i-1, j  , x, y)
   p += check(board, i-1, j+1, x, y)
   p += check(board, i  , j-1, x, y)
   p += check(board, i  , j+1, x, y)
   p += check(board, i+1, j-1, x, y)
   p += check(board, i+1, j  , x, y)
   p += check(board, i+1, j+1, x, y)
   board[i][j] = p
 z = ""
 for j in range(0, y):
  z += str(board[i][j])
 print(z)


Measured memory_bytes: 2696
//
//  main.cpp

#include <iostream>
#include <vector>
using namespace std;


int main(){
	
	while(1){
		int m;
		cin >> m;
		if(m == 0){
			break;
		}
		vector<pair<int,int> > basecons;
		int x,y;
		for(int i=0;i<m;i++){
			cin >> x >> y;
			basecons.push_back(make_pair(x,y));
		}

		vector<pair<int,int> > allcons;
		
		int n;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> x >> y;
			allcons.push_back(make_pair(x,y));
		}
		
		int count = 0;
		for(int i=0;i<n;i++){//??¨?????????????????????
			count = 0;
			int distancex = allcons[i].first - basecons[0].first;
			int distancey = allcons[i].second - basecons[0].second;
//			bool isExistCons = false;
			for(int j=0;j<m;j++){//??¨????????¢??????????????¨
//				bool isExistStar = false;
				for(int k=0;k<n;k++){//??¢????????????????????????????????¨?????????
					if(allcons[k].first == basecons[j].first + distancex && allcons[k].second == basecons[j].second + distancey){
//						isExistStar = true;
						count++;
						break;
					}/*else{
//						isExistStar = false;
					}*/
				}
				/*
				if(isExistStar){
					isExistCons = true;
				}else{
					isExistCons = false;
					break;
				}*/
			}
//			if(isExistCons){
			if(count == m){
				cout << distancex << " " << distancey << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3108
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
ans = set()

for bit in range(1 << n):
    s = 0
    for i in range(n):
        s += A[i] * (bit & (1 << i) > 0)
    ans.add(s)

for query in m:
    print('yes' if query in ans else 'no')



Measured memory_bytes: 5644
module Main where

import Control.Monad
import Data.List
import Debug.Trace
  
main :: IO ()
main = do
  [n, x] <- map read . words <$> getLine :: IO [Integer] -- (< 50, exp)
  print $ pat n x
  where
    pat 0 x = 1
    pat n x
      | x < 2 = 0
      | x < len (n-1) + 2 = pat (n-1) (x-1)
      | x < len (n-1) + 3 = 1 + pat (n-1) (x-1)
      | x < len n = 1 + pat (n-1) (x-1) + pat (n-1) (x-len(n-1)-2)
      | otherwise = 1 + pat (n-1) (x-1) * 2
    len 0 = 1
    len n = len (n - 1) * 2 + 3

Measured memory_bytes: 892
#include <iostream>
#include <math.h>
using namespace std;


int main(){

int money=100000;
int i,n;

cin >> n;

for(i=0;i<n;i++){
money*=1.05;

if(money%1000!=0){
money+=1000-(money%1000);
}
}


cout << money << endl;

}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s;
  int n=s.size();
  t.push_back(s[0]);
  string u="";
  int cnt=1;
  for(int i=1;i<n;i++){
    u.push_back(s[i]);
    if(t!=u){
      cnt++;
      t=u;
      u="";
    }
  }
  cout << cnt << endl;
}

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

public class Main{

	public static void main(String[] args) throws IOException {
		int a = readInt(), b = readInt(), c = readInt(); println(Math.max(a, Math.max(b, c)) - Math.min(a, Math.min(b, c)));
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


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

using namespace std;

typedef long long ll;

// modint
const ll mod = 1e9+7;
template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
      return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
    
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  
  static int get_mod() { return mod; }
};
 
using mint = ModInt<mod>;

int main(){
  long long N; cin >> N; 
  mint ans = 0;
  mint tmp10 = 10;
  mint tmp9 = 9;
  mint tmp8 = 8;

  ans += tmp10.pow(N);
  
  ans += tmp8.pow(N);
  ans -= tmp9.pow(N) * 2;
  
  cout << ans << endl;
}

Measured memory_bytes: 3596
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
ll n,m;
cin>>n>>m;
V<ll> a(n),b(n);
for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
    b[i]/=2;
}
for(int i=0;i<n;i++){
  if(b[i]>m){
    cout<<0<<endl;
    return 0;
  }
}
bool check=true;
sort(all(a));
while(1){
for(int i=0;i<n;i++){
    if(a[i]%2==0){
        a[i]/=2;
    if(!check){
        cout<<0<<endl;
        return 0;
    }
    }
    else {
      check=false;
    }
}
if(!check)break;
}
ll d=b[0];
for(int i=1;i<n;i++){
    d=lcm(d,b[i]);
}
cout<<(m/d+1)/2<<endl;

}




Measured memory_bytes: 1792
p=int(input())
a=[int(i) for i in input().split()]
b=[0 for i in range(p)]
#f(i)=ai
#(i,ai) 0<=i<p
#P(x)=sum range(p+1) ai fi(x)/fi(i)
#fi(i)=i!*(N-i-1)!
c=[0 for i in range(p+1)]
c[1]=-1
c[-1]=1
def inv(x):
    return pow(x,p-2,p)
def divide(k):
    #cを(x-k)で割る
    tmp=[c[i] for i in range(p+1)]
    res=[0 for i in range(p)]
    for i in range(p-1,-1,-1):
        res[i]=tmp[i+1]
        tmp[i]+=k*tmp[i+1]
        tmp[i]%=p
        #print(k,tmp,res)
    return res
#devide(i):fi(x)
Fact=[0 for i in range(p)]
Finv=[0 for i in range(p)]
Fact[0]=1
for i in range(p-1):
    Fact[i+1]=((i+1)*Fact[i])%p
Finv[p-1]=inv(Fact[p-1])
for i in range(p-1)[::-1]:
    Finv[i]=((i+1)*Finv[i+1])%p
ans=[0 for i in range(p)]
for i in range(p):
    fix=divide(i)
    fixiinv=(Finv[i]*Finv[p-i-1])%p
    fixiinv*=(-1)**(p-i-1)
    fixiinv%=p
    #print(fix,a[i],fixiinv)
    for j in range(p):
        ans[j]+=(((a[i]*fix[j])%p)*fixiinv)%p
        ans[j]%=p
print(*ans)


Measured memory_bytes: 55328