akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 13;
int n, val[maxN], deg[maxN];
vector<int> adj[maxN];
map<pair<int, int>, bool> mark;
void dfs (int x) {
    while (adj[x].size()) {
	int u = adj[x].back();
	adj[x].pop_back();
	if (!mark[make_pair(u, x)]) {
	    mark[make_pair(u, x)] = 1;
	    mark[make_pair(x, u)] = 1;
	    if (x < n && u >= n && u != 2 * n)
		val[x] = 1;
	    if (x >= n && u < n && x != 2 * n) 
		val[u] = -1;
	    dfs(u);
	}
    }
}	
	    
int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
	int p;
	cin >> p;
	if (p == -1) {
	    adj[2 * n].push_back(i);
	    adj[i].push_back(2 * n);
	}
	else {
	    p--;
	    adj[p].push_back(i);
	    adj[i].push_back(p);
	    deg[p]++;
	}
    }
    for (int i = 0; i < n; i++) {
	int p;
	cin >> p;
	if (p == -1) {
	    adj[2 * n].push_back(i + n);
	    adj[i + n].push_back(2 * n);
	}
	else {
	    p += n - 1;
	    adj[p].push_back(i + n);
	    adj[i + n].push_back(p);
	    deg[p]++;
	}
    }
    
    for (int i = 0; i < n; i++) {
	if (deg[i] % 2 != deg[i + n] % 2)
	    return cout << "IMPOSSIBLE" << endl, 0;
	if (deg[i] % 2 == 0) {
	    adj[i].push_back(i + n);
	    adj[i + n].push_back(i);
	}
	else
	    val[i] = val[i + n] = 0;
    }
    cout << "POSSIBLE\n";
    dfs(2 * n);
    for (int i = 0; i < n; i++)
	cout << val[i] << " ";
    cout << '\n';
}


Measured memory_bytes: 91128
class UnionSet:
    def __init__(self, num_node: int) -> None:
        self.size = [1] * num_node
        self.id = [i for i in range(num_node + 1)]

    def get_root(self, i: int) -> int:
        while i != self.id[i]:
            self.id[i] = self.id[self.id[i]]
            i = self.id[i]
        return i

    def is_connected(self, node1: int, node2: int) -> bool:
        return self.get_root(node1) == self.get_root(node2)

    def unite(self, node1: int, node2: int) -> None:
        i, j = self.get_root(node1), self.get_root(node2)
        if i == j:
            return
        if self.size[i] < self.size[j]:
            self.id[i] = j
            self.size[j] += self.size[i]
        else:
            self.id[j] = i
            self.size[i] += self.size[j]


if __name__ == "__main__":
    num_users, num_relations = map(lambda x: int(x), input().split())
    union_set = UnionSet(num_users)

    for _ in range(num_relations):
        user1, user2 = map(lambda x: int(x), input().split())
        union_set.unite(user1, user2)

    num_questions = int(input())
    for _ in range(num_questions):
        user1, user2 = map(lambda x: int(x), input().split())
        if union_set.is_connected(user1, user2):
            print("yes")
        else:
            print("no")



Measured memory_bytes: 10464
#include <iostream>
#include<stdlib.h>
#include<math.h>
int main()
{
	int x,a,b;
	std::cin>>x>>a>>b;
	int A= abs(a-x);
	int B= abs(b-x);
	if(A<B){
		std::cout<<"A";
	}
	if(A>B){
		std::cout<<"B";
	}
	if(A==B){
		std::cout<<"A";
	}
	return 0;
}


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

int a,b,c,d,gede;
int main () {
cin>>a>>b>>c>>d;
if(a*b > d*c){
	gede= a*b;
}else{
	gede= c*d;
}
cout<<gede<<endl;
}

Measured memory_bytes: 256
N, Q = map(int, input().split(" "))
S = input()
t = [0] * (N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
for i in range(Q):
    l, r = map(int, input().split(" "))
    print(t[r-1]-t[l-1])

Measured memory_bytes: 7748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int K = 19;
const int KM = 1 << (K - 1);
int laz[1 << K];
int zero = 2e9;
void update(int L, int R, int X, int A, int l, int r) {
	if (r <= L || R <= l) return;
	if (L <= l && r <= R) {
		laz[A] = X;
		return;
	}
	update(L, R, X, A * 2, l, (l + r) / 2);
	update(L, R, X, A * 2 + 1, (l + r) / 2, r);
}

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


	int N, Q;
	cin >> N >> Q;
	pair<int, pair<int, int>> XST[200000];
	rep(i, N) {
		int S, T, X;
		cin >> S >> T >> X;
		XST[i] = mp(X, mp(S, T));
	}
	sort(XST, XST + N);
	reverse(XST, XST + N);
	int D[200002];
	D[0] = 0;
	D[Q + 1] = zero;
	rep1(i, Q) cin >> D[i];
	rep(i, 1 << K) laz[i] = zero;

	rep(i, N) {
		int L = 0, R = Q + 1;
		while (L + 1 < R) {
			int H = (L + R) / 2;
			if (D[H] + XST[i].first >= XST[i].second.first) R = H;
			else L = H;
		}
		int L2 = 0, R2 = Q + 1;
		while (L2 + 1 < R2) {
			int H = (L2 + R2) / 2;
			if (D[H] + XST[i].first >= XST[i].second.second) R2 = H;
			else L2 = H;
		}

		if (R <= L2) update(R, L2 + 1, XST[i].first, 1, 0, KM);
	}
	rep1(i, KM - 1) {
		laz[i * 2] = min(laz[i * 2], laz[i]);
		laz[i * 2 + 1] = min(laz[i * 2 + 1], laz[i]);
	}
	rep1(i, Q) {
		if (laz[KM + i] == zero) co(-1);
		else co(laz[KM + i]);
	}

	Would you please return 0;
}

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

int n;
long long arr[55];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	bool found=true;
	long long sol=0;
	int cnt=0;
	while(found){
		cnt++;
		found=false;
		for(int i=0;i<n;i++){
			if(arr[i]>=n)found=true;
			else continue;
			long long times= arr[i]/n;
			
			arr[i] %= n;
			sol += times;
			
			for(int j=0;j<n;j++){
				if(j==i)continue;
				arr[j] += times;
			}
		}
	}
	//cout<<cnt<<endl;
	cout<<sol<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

ans=[]
#print(2**0.5*10**(3.5))
#print(4472*4473/2)

for i in range(4473):
    if i*(i+1)/2>=N:
        for j in range(i)[::-1]:
            if N-j-1>=0:
                N-=j+1
                ans.append(j+1)
        for item in ans[::-1]:
            print(item)
        exit()
    


Measured memory_bytes: 3572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
int a[10][10000];
int b[10][10000];
int main() {
	int R,C;
	while(scanf("%d %d",&R,&C),R|C) {
		for(int i=0;i<R;i++) {
			for(int j=0;j<C;j++) {
				scanf("%d",&a[i][j]);
			}
		}
		int ans=0;
		for(int bit=0;bit<(1<<R);bit++) {
			memcpy(b,a,sizeof(a));
			for(int i=0;i<R;i++) {
				if(bit&(1<<i)) {
					for(int j=0;j<C;j++) b[i][j]^=1;
				}
			}
			int sum=0;
			for(int i=0;i<C;i++) {
				int x=0;
				for(int j=0;j<R;j++) {
					x+=b[j][i];
				}
				sum+=max(x,R-x);
			}
			ans=max(ans,sum);
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1984
#![allow(unused_mut, unused_variables, unused_assignments, non_snake_case)]

macro_rules! input {
    ($($s:tt : $r:tt),*) => {
        let stdin = std::io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        $(let $s:$r = iter.next().unwrap().parse().unwrap();)*
    };
}

fn main() {
    input!(W:f64, H:f64, X:f64, Y:f64);
    let f = if X == W / 2.0 && Y == H / 2.0 {1} else {0};
    let area = W * H / 2.0;
    println!("{} {}", area, f);
}


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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define MOD 1000000007

int main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	string s, t;
	cin >> s >> t;
	ll ans = 0;
	for(ll i=0; i<s.size(); i++){
		if(s[i] != t[i])
			ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3792
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N;
list<int>P;
list<long long int>ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	P.push_back(2);
	for (int i = 3; i < pow(2,16); i += 2) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
			if (j*j > i)break;
		}
		if (flag)P.push_back(i);
	}
	while (N) {
		vector<long long int>l(N);
		vector<long long int>r(N);
		vector<int>lx(N);
		vector<int>rx(N);
		vector<long long int>lw(N);
		vector<long long int>rw(N);
		vector<bool>flag(N, true);
		stack<int>node;
		for (int i = 0; i < N; i++) {
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			c--;
			d--;
			for (auto i : P) {
				while (a%i == 0 && b%i == 0) {
					a /= i;
					b /= i;
				}
				if (min(a, b) < i)break;
			}
			l[i] = a;
			r[i] = b;
			lx[i] = c;
			rx[i] = d;
			if (c == -1 && d == -1) {

				lw[i] = r[i];
				rw[i] = l[i];
			}
			else if (c == -1)lw[i] = 1;
			else if (d == -1)rw[i] = 1;
			if (c >= 0)flag[c] = false;
			if (d >= 0)flag[d] = false;
		}
	//	cout << "hijiki";
		for (int i = 0; i < N; i++) {
			if (flag[i]) {
				node.push(i);
			}
		}
		while (!node.empty()) {
			int current = node.top();
			bool con = false;
			if (lx[current] >= 0) {
				if (lw[lx[current]] && rw[lx[current]])lw[current] = lw[lx[current]] + rw[lx[current]];
				else {
					node.push(lx[current]);
					con = true;
				}
			}
			if (rx[current] >= 0) {
				if (lw[rx[current]] && rw[rx[current]])rw[current] = lw[rx[current]] + rw[rx[current]];
				else {
					node.push(rx[current]);
					continue;
				}
			}
			if (con)continue;
			if (l[current] * lw[current] != r[current] * rw[current]) {
				long long int a = r[current] * rw[current];
				long long int b = l[current] * lw[current];
				for (auto i : P) {
					while(a%i==0&&b%i==0){
						a /= i;
						b /= i;
					}
					if (min(a, b) < i)break;
				}
				lw[current] *= a;
				rw[current] *= b;
			}
		//	cout << current << " " << lw[current] << " " << rw[current] << endl;
			node.pop();
		}
		for (int i = 0; i < N; i++) {
			if (flag[i]) {
				ans.push_back(lw[i] + rw[i]);
				//cout << lw[i] + rw[i] << endl;
				break;
			}
		}
		cin >> N;
	}
	for (auto i : ans)cout << i << endl;
	return 0;
}

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


int main(){
    int n;
    cin>>n;
    if(n<105)cout<<0<<endl;
    else if(n<135) cout<<1<<endl;
    else if(n<165)cout<<2<<endl;
    else if(n<189)cout<<3<<endl;
  else if(n<195)cout<<4<<endl;
    else cout<<5<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100000
int a[N+1],dp[N+1];
int main(){
	int n,i;scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",a+i);
	dp[1]=0;dp[2]=abs(a[2]-a[1]);
	for(i=3;i<=n;i++)dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

const int N = 1000;

char s[N];

int main()
{
	scanf("%s",s + 1);
	int n = strlen(s + 1);
	for (int i = 1 ; i <= n ; i++) 
	{
		if (s[i] == '1') s[i] = '9';
		else if (s[i] == '9') s[i] = '1';
	}
	printf("%s\n",s + 1);
	return 0;
}


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

using namespace std;


struct P
{
    int x,y,z;

    bool operator<(const P &a)const{
        if(x!=a.x) return x<a.x;
        return y<a.y;
    }
};


long long x,y,z,mod=998244353;
vector<P> v[111111];
int i,n,m,k,a,d,b,c;
int e;
int o[111111];
int l[111111];
int j[1];
stack<int> s;
queue<int> q;
P u[1];

//char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();


bool as(P a,P b)
{
    return a.x<b.x;
}

void f(int n)
{
    //l[n]=1;
    int k=o[n];
    for(int h=0;h<v[n].size();h++)
        k+=v[n][h].z;
    k-=k%2;
    for(int h=0;h<v[n].size();h++)
    if(k>o[n]&&v[n][h].z)
    {
        k--;
        v[v[n][h].x][v[n][h].y].z=0;
        printf("%d %d\n",n,v[n][h].x);
        //q.push(v[n][h].x);
        //f(v[n][h].x);
    }
    else if(v[n][h].z)
    {
        o[v[n][h].x]++;
        v[v[n][h].x][v[n][h].y].z=0;
        printf("%d %d\n",v[n][h].x,n);
        //q.push(v[n][h].x);
        //f(v[n][h].x);
    }
}

void g(int n)
{
    s.push(n);
    l[n]=1;
    for(int h=0;h<v[n].size();h++)
    if(l[v[n][h].x]==0)
    {
        g(v[n][h].x);
    }
}

int main()
{
    scanf("%d %d",&a,&b);
    for(int t=1;t<=b;t++)
    {
        scanf("%d %d",&n,&m);
        v[n].push_back({m,v[m].size(),1});
        v[m].push_back({n,v[n].size()-1,1});
    }
    if(b%2)
    {
        puts("-1");
        return 0;
    }
    g(1);
    for(;s.size();s.pop())
    f(s.top());
}



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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q.r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
    ll n; cin >> n;
    ll a[n]; rep(i, n) cin >> a[i];
    ll M = MIN, m = a[0];
    for(ll i = 1;i < n;i++)
    {
        M = max(M, a[i] - m);
        m = min(m, a[i]);
    }
    fin(M)
    return;
}

//前処理
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20); //高精度少数表示
    Main();
    return 0;
}



Measured memory_bytes: 4688
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string a;
	string str = "CODEFESTIVAL2016";
	cin >> a;
	int k = 0;
	for(int i = 0;i < 16;i++)
	    {
	    	if(a[i] != str[i])k++;
		}
	cout << k << endl;
	return 0;
}

Measured memory_bytes: 256
def chk(i):
    print(i)
    return {'Vacant': 0, 'Male': 1, 'Female': -1}[input()]
N = int(input())
l = 0
r = N
sl = chk(l)
if sl:
    while True:
        m = (l+r)//2
        sm = chk(m)
        if sm == 0:
            break
        
        if (sl == sm and (l-m) % 2 == 0) or (sl != sm and (l-m) % 2 == 1):
            l = m
            sl = sm
        else:
            r = m


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define _GLIBCXX_DEBUG

int main(){
  
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  if(n <= k){
    cout << n * x << endl;
  }
  else{
    cout << k * x + (n -k) * y << endl;
  }

}

Measured memory_bytes: 256
#include <iostream> // c++の標準入出力
#include <stdio.h> // c言語の標準入出力
#include <string>
#include <algorithm>
#include <functional>
#include<math.h>

using namespace std;

int main()
{
	int a, b,c;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	std::cout << min(a*b,c);
		
}

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

const int N = 100005;
ll n, m, t, a[N], k, l[N], r[N], ans, tong;
ll b[N];
vector<pll> kq;
string s;
priority_queue< pii, vector<pii>, greater<pii> > pr;
void sol()
{
    cin >> n >> s;
    s = " " + s;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        l[i] = i - 1;
        r[i] = i + 1;
    }
    for(int i = 2; i <= n; i ++)
    {
        if(s[i-1] != s[i])
        {
            k = abs(a[i] - a[i-1]);
            pii u;
            u.fi = k;
            u.se.fi = i-1;
            u.se.se = i;
            pr.push(u);
        }

    }
    while(!pr.empty())
    {
        pii u = pr.top();
        pr.pop();
        ll x = u.se.fi, y = u.se.se;
        if(b[x] == 1 || b[y] == 1)continue;
        b[x] = 1;
        b[y] = 1;

        l[r[y]] = l[x];
        r[l[x]] = r[y];
        kq.pb({x, y});
        if(l[x] > 0 && r[y] <= n && s[l[x]] != s[r[y]])
        {
            pii v;
            v.fi = abs(a[l[x]] - a[r[y]]);
            v.se.fi = l[x];
            v.se.se = r[y];
            pr.push(v);
        }
    }
    cout << kq.size() <<'\n';
    for(pll u : kq)cout << u.fi <<" "<<u.se<<'\n';
}
ll random(ll minn, ll maxn)
{
    return minn + rand() % (maxn + 1 - minn);
}
priority_queue<ll> st;
ll uoc(ll a, ll b)
{
    while(b != 0)
    {
        ll r = a % b;
        a = b;
        b = r;
    }
    return a;
}
void test()
{
   char ch;
   cin >> ch;
   if(ch >= 'a')cout << 'a';
   else cout << 'A';
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    test();
}


Measured memory_bytes: 3624
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

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

    rep(i, K) {
        if(i % 2 == 0) {
            if(A % 2 == 1) {
                A--;
            }
            A /= 2;
            B += A;
        } else {
            if(B % 2 == 1) {
                B--;
            }
            B /= 2;
            A += B;
        }
    }
    cout << A << " " << B << endl;
}

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

#define leading __builtin_clzll

typedef long long ll;

const int MAXN = 2e2 + 5;

int N;
ll a[MAXN];
char s[MAXN];

void load() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%lld", a + i);
  scanf("%s", s);
}

bool add(ll val, vector <ll> &basis) {
  vector <ll> nxt;
  bool added = false;
  for (auto it : basis) {
    if (val && !added) {
      if (leading(val) < leading(it)) {
        nxt.push_back(val);
        added = true;
      }
      else if (leading(val) == leading(it))
        val ^= it;
    }
    nxt.push_back(it);
  }
  if (val && !added) {
    nxt.push_back(val);
    added = true;
  }
  basis = nxt;
  return added;
}

int solve() {
  vector <ll> b;
  for (int i = N - 1; i >= 0; i--)
    if (add(a[i], b) && s[i] == '1') 
      return 1;
  return 0;
}

int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) {
    load();
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 3708
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())

int main(){
  int n;
  cin>>n;
  vll a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<a[n-1]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

int main() {
	int k, t; cin >> k >>  t;
	vi a(t); Loop(i, t) cin >> a[i];
	sort(a.begin(), a.end());
	int m = a.back();
	int sum = accumulate(a.begin(), a.end() - 1, 0);
	if (m <= sum + 1) cout << 0 << endl;
	else cout << m - sum - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    char houses[4][3][10] = {{{0}}};
    int n, b, f, r, v;
 
    scanf("%d", &n);
    while (n--) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        houses[b-1][f-1][r-1] += v;
    }
    for (b = 0; b < 4; b++) {
        for (f = 0; f < 3; f++) {
            for (r = 0; r < 10; r++) {
                printf(" %d", houses[b][f][r]);
            }
            putchar('\n');
        }
        if (b < 3) {
            puts("#####" "#####" "#####" "#####");
        }
    }
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>

using namespace std;

#define INF 100000000000000
#define LL long long 

int a[200005];

int main()
{
	LL n;
	cin>>n;
	LL sum=0;
	for(LL i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	
	LL t=0;
	LL d=INF;
	for(LL i=0;i<n-1;i++)
	{
		t+=a[i];
		d=min(abs(t-(sum-t)),d);
	}
	
	cout<<d<<endl;
	return 0;
} 

Measured memory_bytes: 1024
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    a = I()
    if a == 0:
        print(1)
    elif a == 1:
        print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 67940
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k,q] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  xs <- U.replicateM q $ do
    [a] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (a-1)
  let vec = U.create $ do
        vec <- UM.replicate n (k-q)
        U.forM_ xs $ \i -> do
          UM.modify vec (+ 1) i
        return vec
  U.forM_ vec $ \s -> do
    if s <= 0 then
      putStrLn "No"
    else
      putStrLn "Yes"


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
int n;
vector<int> v[100005];
bool vis[100005];
bool Vis[100005];
int END;
//int cntB,cntW;
int dist[100005];
int pre[100005];
void dfs(int x,int d){
	dist[x]=d;
	if (v[x].size()==1){
		dist[x]=d;
	}
	for (int i=0;i<v[x].size();i++){
		if (vis[v[x][i]]){
			continue;
		}
		vis[v[x][i]]=true;
		pre[v[x][i]]=x;
		dfs(v[x][i],d+1);
	}
}
int cntB,cntW;
int re;
void Dfs(int x,int d){
	//cout<<x<<" "<<d<<endl;
	if (v[x].size()==1){
		//re+=d;
		return;
	}
	for (int i=0;i<v[x].size();i++){
		if (Vis[v[x][i]]){
			continue;
		}
	//	cout<<v[x][i]<<endl;
		Vis[v[x][i]]=true;
		re++;
		Dfs(v[x][i],d+1);
	}
}
void solve(int st,int ed){
	int t=ed;
	Vis[t]=true;
	while (t!=st){
		t=pre[t];
		Vis[t]=true;
	}
	Vis[st]=true;
	int len=dist[ed]-dist[st];
	//if (len%2==0){
		int cnt=0;
		t=ed;
		while (t!=st && cnt<(len+1)/2){
	//		cout<<t<<endl;
			re=0;
			Dfs(t,0);
	//		cout<<"re="<<re<<endl;
			cntW+=re;
	//		cout<<"cntW="<<cntW<<endl;
		    t=pre[t];
		    cnt++;
		//    system("pause");
		}
//		cout<<"??";
//		cout<<endl;
		while (t!=st){
//			cout<<t<<endl;
			re=0;
			Dfs(t,0);
//			cout<<"re="<<re<<endl;
			cntB+=re;
//			cout<<"cntB="<<cntB<<endl;
			t=pre[t];
//			system("pause");
		}
		re=0;
		Dfs(st,0);
//		cout<<re;
		cntB+=re;
	//}
//	cout<<cntB<<" "<<cntW<<endl;
	cntB+=(len+2)/2;
	cntW+=(len+1)-(len+2)/2;
//	cout<<cntB<<" "<<cntW<<endl;
	if (cntB<=cntW){
		cout<<"Snuke";
	}
	else{
		cout<<"Fennec";
	}
}
int main(){
	cin>>n;
	END=n;
	for (int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	vis[1]=true;
	dfs(1,0);
	//cout<<cntB<<" "<<cntW<<endl;
	memset(vis,0,sizeof(vis));
	solve(1,n);
}

Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin>>a.at(i);
  }

  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long long int alice=0,bob=0;
  bool al=true;
  for(int i=0; i<n; i++){
    if(al){
      al=false;
      alice+=a.at(i);
    }else{
      al=true;
      bob+=a.at(i);
    }
  }
  cout<<alice-bob<<endl;
}

Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

ifstream in("bleach.in");
ofstream out("bleach.out");

int const NMAX = 1e6;
int v[1 + NMAX];

int main() {

  int badn, bada = 3;
  char badc;
  cin >> badn;
  for(int i =1;i <= badn;i++){
    cin >> badc;
    if(badc == 'Y'){
      cout << "Four";
      return 0;
    }
  }
  if(bada == 3){
    cout << "Three";//freeze
  }
  return 0;
}


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

using namespace std;

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

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

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

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

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

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

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

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

int main() {
  string str;

  getline(cin, str);


  REP(i, str.size()) {
    if(str[i] >= 'a' && str[i] <= 'z') cout << (char)(str[i]+('A'-'a'));
    else cout << str[i];
  }
  cout << endl;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;

int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;

  if(k<=a){
    out(k);
  } else if (k <= a+b) {
    out(a);
  } else {
    out(a-(k-a-b));
  }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    int N;
    cin >> N;
    vector<int> D(N);
    vector<bool> used(N,false);
    int itrT = 0;
    int itrD = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> D[i];
    }
    int M;
    cin >> M;
    vector<int> T(M);
    for (int i = 0; i < M;i++)
    {
        cin >> T[i];
    }
    sort(all(D));
    sort(all(T));
    bool ok = false;
    while(1){
        if(D[itrD] == T[itrT]){
            itrD++;
            itrT++;
        }
        else if(D[itrD] < T[itrT]){
            itrD++;
        }
        else{
            break;
        }
        if(itrT == M){
            ok = true;
            break;
        }
        if(itrD == N){
            break;
        }
    }
    if(ok){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 4836
#include<stdio.h>

int main(){

    int R, G, x;

    scanf("%d", &R);
    scanf("%d", &G);

    x = 2 * G - R;

    if(R >= 0 && R <= 4500 && G >= 0 && G <= 4500){
        printf("%d", x);
    }

    return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	int x = n;
	int sum = 0;
	while(x){
		sum += x%10;
		x/=10;
	}
	if(n%sum == 0) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9+1;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  set<int> odd;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 != 0) odd.insert(a[i]); 
  }
  sort(a.begin(), a.end());
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 && odd.count(a[i])) res++; 
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 2944
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        StringBuilder output = new StringBuilder();
        String word;
        int m;
        int h;
        int original_length;
        while (true) {
            word = scan.next();
            if ("-".equals(word))
                break;
            m = scan.nextInt();
            for (int i = 0; i < m; i++) {
                h = scan.nextInt();
                original_length = word.length();
                word = word + word.substring(0,h);
                word = word.substring(word.length() - original_length);
            }
            output.append(word + '\n');
        }
        System.out.print(output);
    }
}

Measured memory_bytes: 26460
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N = 2e5 + 1;
int n , ans , mx1 , mx2;
pair<int,int> p[N];
int main(){	
	scanf("%d",&n);
	for (int i = 0,x,y; i < n; ++i){
		scanf("%d%d",&x,&y);
		p[i] = {x , y};
	}
	sort(p , p + n);
	mx1 = -p[0].first + p[0].second;
	mx2 = -p[0].first + -p[0].second;
	for (int i = 1; i < n; ++i){
		int x = p[i].first , y = p[i].second;
		ans = max({ans , x - y + mx1 , x + y + mx2});
		mx1 = max(mx1 , -x + y);
		mx2 = max(mx2 , -x + -y);
	}
	cout << ans << endl;

	
	
		
}	

Measured memory_bytes: 5324
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let (A, B, C, D) = get!(usize, usize, usize, usize);

    let ans = if A + B > C + D {
        "Left"
    } else if A + B == C + D{
        "Balanced"
    } else {
        "Right"
    };

    // 出力
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int f[100005],h[100005];
int main(){
	int n,k;
	cin>>n>>k;;
	for(int i=1;i<=n;i++){
	    cin>>h[i];
	}
	f[1]=0;
	for(int i=2;i<=n;i++){
	    f[i]=2e9;
	    for(int j=i-1;j>=max(i-k,1);j--)f[i]=min(f[j]+abs(h[i]-h[j]),f[i]);
	}
	cout<<f[n];
}


Measured memory_bytes: 4356
import java.util.*;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int counter = 0;
      
      for(int i = 0; i < n; i ++) {
         int key = Integer.parseInt(sc.nextLine());
         if(isPrime(key)) {
            counter ++;
         }
      }
      
      System.out.println(counter);
   }
   
   public static boolean isPrime(int a) {
      if(a == 2) {
         return true;
      } else if(a == 1 || a % 2 == 0) {
         return false;
      } else {
         for(int i = 3; i <= (int)Math.sqrt(a); i += 2) {
            if(a % i == 0) {
               return false;
            }
         }
         return true;
      }
   }
   
}


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

int main(){
	
	string col = "RGBY";
	
	int H, W, d;
	cin >> H >> W >> d;
	
	if(d % 2 != 0){
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				cout << col[(i + j) % 4];
			}
			cout << endl;
		}
		cout << endl;
		return 0;
	}
	
	string hoge[2];
	hoge[0] = "RG";
	hoge[1] = "BY";
	
	for(int i = 10000; i < 10000 + H; i++){
		for(int j = 0; j < W; j++){
			int dum = j;
			if((i + j) % 2 != 0){
				dum++;
			}
			cout << hoge[((i - dum) / d) % 2][((i + dum) / d) % 2];
		}
		cout << endl;
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

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

    int A[N];
    int B[N];
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];

    int D[N];
    REP(i, N) D[i] = A[i] - B[i];

    sort(D, D+N);
    ll sum = 0;
    REP(i, N) sum += D[i];
    if (sum < 0) { cout << -1 << endl; return 0; }

    int f = 0;
    int b = N-1;
    bool ff = false;
    bool bf = false;

    while (D[f] < 0)
    {
        int m = min(-D[f], D[b]);
        D[f] += m;
        D[b] -= m;

        ff = true;
        bf = true;

        if (D[f] == 0) { ++f; ff = false; }
        if (D[b] == 0) { --b; bf = false; }
    }

    int a = f + N-b;
    if ( ff) ++a;
    if (!bf) --a;

    cout << a << endl;

    return 0;
}


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

void printArray(int a[], int n) {
    string sep = "";
    for (int i = 0; i < n; i++) {
        cout << sep << a[i];
        sep = " ";
    }
    cout << endl;
}

int selectionSort(int a[], int n) {
    int numOfSwap = 0;
    for (int i = 0; i < n; i++) {
        int minj = i;
        bool swapped = false;
        for (int j = i; j < n; j++) {
            if (a[j] < a[minj]) {
                minj = j;
                swapped = true;
            }
        }
        if (swapped) {
            swap(a[i], a[minj]);
            numOfSwap++;
        }
    }
    return numOfSwap;
}

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

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

    int numOfSwap = selectionSort(a, n);

    printArray(a, n);
    cout << numOfSwap << endl;
}

Measured memory_bytes: 3144
def main():
    n, m = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    cnt = 0
    global parent
    parent = list(range(n+1))
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if root(i) == root(p[i]):
            cnt += 1
    print(cnt)

def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def unite(x, y):
    root_x = root(x)
    if root_x != root(y):
        parent[root_x] = y

if __name__ == "__main__":
    main()

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

bool isok(vector<int> & v1, vector<int> & v2) {
  int d = v1.size();
  int sum = 0;
  for (int i = 0; i < d; ++i)
    sum += (v1[i] - v2[i]) * (v1[i] - v2[i]);
  int m = sqrt(sum);
  return (m * m == sum);
}

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (auto & xn : x) {
    for (int & xnd : xn)
      cin >> xnd;
  }
  int count = 0;
  for (int i = 0; i < n - 1; ++i) {
  	for (int j = i + 1; j < n; ++j) {
      if (isok(x[i], x[j]))
        count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    string w;
    cin >> w;
    string WW = w;
    WW[0] -= 32;

    ll cnt = 0;
    while(1){
        string t;
        cin >> t;
        if (t == "END_OF_TEXT") break;

        rep(i, t.size()) if ('A' <= t[i] and t[i] <= 'Z') t[i] += 32;

        if (t==w) cnt++;
    }

    cout << cnt << endl;
}


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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int x, n; cin >> x >> n;
    vi a(n);
    for(int& u : a)
        cin >> u;
    if(n == 0){
        cout << x << '\n';
        return;
    }
    sort(all(a));
    vi ans;
    for(int candidate = x; candidate <= 105; candidate++){
        if(!binary_search(all(a), candidate)){
            ans.pb(candidate);
            break;
        }
    }
    for(int candidate = x - 1; candidate >= -5; candidate--){
        if(!binary_search(all(a), candidate)){
            ans.pb(candidate);
            break;
        }
    }
    if(ans.size() == 1){
        cout << ans[0] << '\n';
    }
    else{
        if((int)abs(ans[0] - x) < (int)abs(ans[1] - x))
            cout << ans[0] << '\n';
        else
            cout << ans[1] << '\n';
    }
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3624
n, a, b = map(int, raw_input().split())
X = map(int, raw_input().split())
energy = 0
for i in range(n-1):
    if (X[i+1] - X[i]) * a < b:
        energy += (X[i+1]-X[i]) * a
    else:
        energy += b
print energy

Measured memory_bytes: 11320
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  n=n%10;
  if(n==3)
  {
  printf("bon");
  }
  else if(n==0||n==1||n==6||n==8)
  {
    printf("pon");
  }
  else
  {
    printf("hon");
  }
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S; long long K;
	cin>>S>>K;
	for (int i=0; i<min((long long)S.size(), K); i++) {
		if (S[i]>='2'){cout<<S[i]<<endl; return 0;}
	}
	cout<<1;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
const int inf=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
  int n,k;cin>>n>>k;
  ll a[n];
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll ans=0;
  rep(i,k)ans+=a[i];
  cout<<ans<<endl;
  return 0;
  }

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
        long [] l = new long[n+1];
	int i;
	l[0] = 2;
	l[1] = 1;

	for(i=2;i<=n;i++){
	    l[i] = l[i-2] + l[i-1];
	}
	System.out.println(l[n]);
    }
}


Measured memory_bytes: 21840
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n = inn()
a = inl()
b = [0] * (n+1)
cnt = 0
for i in range(n,0,-1):
    sum = 0
    for j in range(i*2,n+1,i):
        sum += b[j]
    if sum%2 != a[i-1]:
        b[i] = 1
        cnt += 1
print(cnt)
for i in range(1,n+1):
    if b[i]==1:
        printn(str(i)+' ')
print("")


Measured memory_bytes: 7624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n,k;
  cin >> n >> k;
  vector<ll> a, part;
  rep(i,n) {
    ll t; cin >> t; a.pb(t);
  }
  for (int i = 0; i < n; ++i) {
    ll tmp = 0;
    for (int j = i; j < n; ++j) {
      tmp += a[j];
      part.pb(tmp);
    }
  }

  vector<ll> tw;
  ll po = 1;
  for (int i = 0; i <= 39; ++i) {
    tw.pb(po);
    po *= 2;
  }

  vector<ll> ans = part;
  ll res = 0;
  for (int i = 39; i >= 0; --i) {
    vector<ll> tm;
    ll cnt = 0;
    for (auto itr : ans) {
      ll ttt = itr & tw[i];
      if (ttt == tw[i]) {
        tm.pb(itr);
        cnt++;
      }
    }
    if (cnt >= k) {
      ans = tm;
      res += tw[i];
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 9976
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll n;
  cin >> n;
  ll dq = q*8, dh = h*4, ds = s*2;
  ll mn = min({dq, dh, ds, d});
  ll ans = (n/2)*mn;
  n %= 2;
  dq = q*4, dh = h*2;
  mn = min({dq, dh, s});
  ans += n*mn;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256