akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	string s;
	cin >> s;
	int a = 0;
	rep(i,0,3){
		if(s[i] == '1'){
			a++;
		}
	}

	cout << a << endl;
	ret 0;
}

Measured memory_bytes: 256
import sys
a,b,c = map(int,input().split(" "))
li = [[a,b,c]]
count=0

for i in range(10**9):
  if (a % 2)==1 or (b % 2)==1 or (c % 2)==1:
    break
  else:
    a2 = a/2
    b2 = b/2
    c2 = c/2
    a = b2+c2
    b = c2+a2
    c = a2+b2  
    count += 1
  if [a,b,c] in li:
    print(-1)
    sys.exit()
  else:
    li.append([a,b,c])
    
print(count)

Measured memory_bytes: 9232
N = int(input())
As = list(map(int, input().split()))

cnt = 0
flg = True
while flg:
    flg = False
    for i in range(N-1,0,-1):
        if As[i-1] > As[i]:
            tmp = As[i]
            As[i] = As[i-1]
            As[i-1] = tmp        
            flg = True
            cnt += 1
print(" ".join([str(a) for a in As]))
print(cnt)


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

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

  vector<int> table(N);
  int count = 0;
  int position = 1;

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

  for (int i=0; i<N+1; i++) {
    position = table[position-1];
    count += 1;

    if (position == 2) {
      cout << count << endl;
      break;
    }

    else if (i == N) {
      cout << -1 << endl;
    }

  }
}

Measured memory_bytes: 640
#include<cstdio>

#define	SEA	0
#define	GND	1

using namespace std;

struct P{int x,y;};

P color[13][13];

P UF_root(P p)
{
	if(color[p.y][p.x].x==-1)	return p;
	return p=UF_root(color[p.y][p.x]);
}

bool UF_find(P p,P q)
{
	p=UF_root(p);
	q=UF_root(q);
	return p.x==q.x && p.y==q.y;
}

void UF_union(P p,P q)
{
	p=UF_root(p);
	q=UF_root(q);
	if(p.x!=q.x || p.y!=q.y)	color[q.y][q.x]=p;
}

int main()
{
	int world[13][13];
	for(int i=0;i<13;i++)	world[i][0]=world[0][i]=SEA;

	while(1){
		for(int i=1;i<13;i++){
			char s[16];
			if(scanf("%s",s)==EOF)	return 0;
			for(int j=1;j<13;j++)	world[i][j]=s[j-1]-'0';
		}

		for(int i=0;i<13;i++)
			for(int j=0;j<13;j++)
				color[i][j].x=-1;

		int dx[]={-1,0},dy[]={0,-1};
		for(int y=1;y<13;y++){
			for(int x=1;x<13;x++){
				for(int k=0;k<2;k++){
					P p={x,y},q={x+dx[k],y+dy[k]};
					if(world[p.y][p.x]==world[q.y][q.x] && !UF_find(p,q))
						UF_union(p,q);
				}
			}
		}

		int cnt=0;
		for(int y=1;y<13;y++)
			for(int x=1;x<13;x++)
				if(world[y][x]==GND && color[y][x].x==-1)	cnt++;
		printf("%d\n",cnt);
	}
}

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

int main() {
    int N, flag = 0; cin >> N;
    long long A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 0) flag = 1;
    }

    if (flag) { cout << 0 << endl; return 0; }
    long long ans = 1;
    for (int i = 0; i < N; i++) {
        if (A[i] <= 1000000000000000000 / ans) {
            ans *= A[i];
        } else {
            ans = -1;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4404
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}

int main(void){
	int n=in(),a[2][100],i,j,m=0;
	rep(i,2){
		rep(j,n)
			a[i][j]=in();
	}
	int t;
	rep(i,n){
		t=0;
		rep(j,i+1)t+=a[0][j];
		for(j--;j<n;j++)t+=a[1][j];
		m=max(m,t);
	}
	print(m);
	return 0;
}

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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    vector<ll> cusum(n);
    cusum[0] = a[0];
    
    for(int i = 1; i < n; i++){
        cusum[i] = cusum[i-1] + a[i];
    }
    
    ll minv = 1e18;
    
    for(int i = 0; i < n - 1; i++){
        minv = min(minv, abs(cusum[i]-(cusum[n-1]-cusum[i])));
    }
    
    cout << minv << endl;
    
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    string str;
    string str2;
    cin >> str;
    cin >> str2;
    reverse(str.begin(), str.end());
    if(str == str2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,a=7,i,f=0;
  scanf("%d",&n);
  while(n)
  {
    i=n%10;
    if(i==a)
    {
      f=1;
    break;
    }
    n/=10;
  }
 if(f==1)
 {
	printf("Yes");
 }
  else
    printf("No");
  return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=3e5+51;
const li inf=0x3f3f3f3f3f3f3f3f;
struct Tuple{
	li x,y;
	inline bool operator <(const Tuple &rhs)const
	{
		return this->x<rhs.x;
	}
};
Tuple p[MAXN];
ll cnt;
li res,res2,maxb,minb=inf,maxr,minr=inf;
li maxn[MAXN],minn[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
}
int main()
{
	cnt=read();
	for(register int i=0;i<cnt;i++)
	{
		p[i].x=read(),p[i].y=read();
		if(p[i].x>p[i].y)
		{
			swap(p[i].x,p[i].y);
		}
		maxr=max(maxr,p[i].x),minr=min(minr,p[i].x);
		maxb=max(maxb,p[i].y),minb=min(minb,p[i].y);
	}
	res=(li)(maxr-minr)*(maxb-minb),minb=minr;
	sort(p,p+cnt),res2=inf;
	maxn[0]=minn[0]=p[0].y;
	for(register int i=1;i<cnt;i++)
	{
		maxn[i]=max(maxn[i-1],p[i].y),minn[i]=min(minn[i-1],p[i].y);
		if(i!=cnt-1)
		{
			res2=min(res2,max(maxn[i],p[cnt-1].x)-min(minn[i],p[i+1].x));
		}
	}
	res2*=(li)(maxb-minb);
	printf("%lld\n",min(res,res2));
}


Measured memory_bytes: 7936
#include<stdio.h>
 
 
 int main(void) {
 int n, r,a;
   scanf("%d",&n);
   scanf("%d",&r);
 if(n>=10) a = r;
 else a = r + 100 * (10 - n);
  printf("%d\n", a);
  return 0;
 }

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
struct UnionFind {
  vector<ll> data;
  ll num;
  UnionFind(ll size) : data(size, -1) ,num(size){ }
  bool unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
	  num--;
    }
    return x != y;
  }
  bool find(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  vector<ll>a(m),b(m);
  rep(i,0,m)cin>>a[i]>>b[i];
  UnionFind uf(n);
  ll now=n*(n-1)/2;
  vector<ll>ret(m);
  rrep(i,0,m){
    ret[i]=now;
    a[i]--;b[i]--;
    if(!uf.find(a[i],b[i])){
      now-=uf.size(a[i])*uf.size(b[i]);
      uf.unite(a[i],b[i]);
    }
  }
  rep(i,0,m)cout<<ret[i]<<endl;
  return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, l; cin >> n >> l;
    long long ans = 0; long long mini = 1e9;
    for (int u = 0; u < n; u++) {
        ans += l + u;
        if (abs(mini) > abs(l+u)) {
            mini = l+u;
        }
    }
    cout << ans - mini << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] != 'A'){
    cout << "WA" << endl;
    return 0;
  }
  bool f = false;
  int n = s.size();
  FOR(i, 2, n - 1){
    if(isupper(s[i])){
      if(f || s[i] != 'C'){
        cout << "WA" << endl;
        return 0;
      }
      f = true;
    }
  }
  if(f && islower(s[1]) && islower(s[n - 1])){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i, n;
    scanf("%d", &n);
    int R[n];
    for( i = 0; i < n; ++i )
        scanf("%d", &R[i]);
    int min = R[0], max = R[1] - R[0];
    for( i = 1; i < n; ++i ){
        max = max < R[i] - min ? R[i] - min : max;
        min = min > R[i] ? R[i] : min;
    }

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

    return 0;
}


Measured memory_bytes: 2552
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //string[] str = Console.ReadLine().Split(' ');
            int r = int.Parse(Console.ReadLine());
            //int M = int.Parse(str[1]);

            int ans = r * r;
            Console.WriteLine(ans);
        }
        static void func() //A[0]が最大値のヒープ最大値変更
        {
           
        }
        
    }
}


Measured memory_bytes: 11092
/*ex9-1
  Sweet_Sweet_Soul*/

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    stack stk;
    char tmp; /*popを代入するための変数*/
    char string[11]; /*NULL文字含めた11文字を確保*/
    char *ptr; /*文字列操作用のポインタ*/
    scanf("%s",string);
    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk);
    ptr=string;
    while(*ptr!='\0'){ /*stringをヌル文字まで操作*/
        if(*ptr=='B'){ /*ptrの指す文字がBの時*/
            if(stk.count!=0){ /*pop可能ならpop*/
                tmp=pop(&stk);
            }
        }
        else{ /*0か1ならその文字をpush*/
            push(&stk,*ptr);
        }
        ptr++;
    }
    for(int i=0;i<stk.count;i++){ /*後ろからcount個出力*/
        printf("%c",stk.data[SIZE-1-i]);
    }
    printf("\n");
    return 0;
}


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

int main(){
  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  ll ans1 = A*X + B*Y;
  ll ans2 = 2*C*max(X, Y);
  ll ans3;
  if(X <= Y) ans3 = C*2*X + (Y-X)*B;
  else if(X > Y)  ans3 = C*2*Y + (X-Y)*A;
  cout << min(ans1, min(ans2, ans3)) << endl;
  return 0;
}

Measured memory_bytes: 3560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		
		if(s.charAt(0) == s.charAt(2)) out.println("Yes"); else out.println("No");
	}
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

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

int main() {
  int a, b, c, x, y, z;
  cin >> a >> b;
  c = 0;
  for (int i = a; i < b + 1; i++) {
    x = i % 100, y = i / 1000;
    z = x / 10 + (x % 10) * 10;
    
    if (z == y) {
      c += 1;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// comnputing order k
mint comb(int n, int k){
	mint res = 1;
	for(int i=n; i>n-k; i--) res = res * i;
	for(int i=k; i>0; i--) res = res / i;
	return res;
}
int main(void) {
	int x,y; cin >> x >> y;
	if((x+y)%3){
		cout << 0 << endl;
		return 0;
	}
	int n,m;
	n = (2*y-x)/3;	
	m = (2*x-y)/3;	
	if(n<0||m<0){
		cout << 0 << endl;
		return 0;		
	}
	cout << comb(n+m,n) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

bool next_choice(int ixh[], int h, int N) {
  for(int i = h-1, n = N; i >= 0; --i, --n) {
    if(ixh[i]+1 < n) {
      int v = ixh[i]+1;
      for(int j = i; j < h; ++j) ixh[j] = v++;
      return true;
    }
  }
  return false;
}

int calc(int ix[], int N) {
  int res = 0;
  for(int i = 0; i < N-1; ++i) {
    if(ix[i] == i) continue;
    for(int j = i+1; j < N; ++j) if(ix[j]==i) {
      res += j-i;
      for(int k = j; k > i; --k) ix[k]=ix[k-1];
      break;
    }
  }
  return res;
}

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int main() {
  int N = getZ(), H = (N+1)/2;
  int ab[2][18];
  for(int i = 0; i < N; ++i) std::cin >> ab[i%2][i];
  for(int i = 0; i < N; ++i) std::cin >> ab[(i+1)%2][i];
  int ix[18], ixh[9], ixe[9], ixo[9];
  bool used[18];
  std::iota(ixh, ixh+H, 0);
  
  int ans = 10000;
  // check all possibility; MAX: comb(18,9) < 50000
  for(;;) {
    // prepare even
    std::copy_n(ixh, H, ixe);
    std::sort(ixe, ixe+H, [&](int l, int r){ return ab[0][l] < ab[0][r]; });
    
    // prepare odd
    std::fill_n(used, N, false);
    for(int i = 0; i < H; ++i) used[ixh[i]] = true;
    int ix_o = 0;
    for(int i = 0; i < N; ++i) if(!used[i]) ixo[ix_o++] = i;
    std::sort(ixo, ixo + N-H, [&](int l, int r){ return ab[1][l] < ab[1][r]; });
    
    // check if sorted
    bool sorted = true;
    for(int i = 0; i < N-H; ++i) {
      if(ab[0][ixe[i]] > ab[1][ixo[i]]) { sorted = false; break; }
      if(i+1 < H &&  ab[1][ixo[i]] > ab[0][ixe[i+1]]) { sorted = false; break; }
    }
    if(sorted) {
      // merge
      for(int i = 0; i < H; ++i) ix[i*2] = ixe[i];
      for(int i = 0; i < N-H; ++i) ix[i*2+1] = ixo[i];
      ans = std::min(ans, calc(ix, N));
    }
    
    if(!next_choice(ixh, H, N)) break;
  }
  if(ans > 9999) ans = -1;
  fin(ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b==c || a+c==b || b+c==a){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A + B >= 10) {
			System.out.println("error");
		} else {
			System.out.println(A + B);
		}
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define int	long long
#define sz(x)	((int)(x).size())
#define w(x)	int x; cin>>x; while(x--)
#define db(x)	{ cerr << #x << " = " << x << endl; }
using namespace std;

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

int32_t main(){
	c_p_c();
	int a,b,c,k; cin>>a>>b>>c>>k;
	if(k<=a) cout<<k;
	else if(k>a && k<=a+b) cout<<a;
	else cout<<a-(k-a-b);
	return 0;
}

// g++ -std=c++17 -Wshadow -Wall -o "sol" "sol.cpp" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG


Measured memory_bytes: 3652
#include <iostream>
#include <cstring>

using namespace std;

int d[] = {-1,1,0,0};

int count(int x,int y, char map[22][22]){
        int c = 0; 
        map[x][y] = '#';
        c++;
        for(int i = 0; i < 4; i++){
                int nx = x+d[i];
                int ny = y+d[3-i];
                if(map[nx][ny] == '.'){
                        c += count(nx,ny,map);
                }  
        }  
        return c; 
}

int main(){
        int w,h;
        cin >> w >> h; 
        while(w){
                char map[22][22];
                memset(map,'#',sizeof(map));
                int x,y;
                for(int i = 1; i <= h; i++){
                        for(int j = 1; j <= w; j++){
                                cin >> map[i][j];
                                if(map[i][j] == '@'){
                                        x = i; y = j; 
                                        map[i][j] = '.';
                                }  
                        }  
                }  
                cout << count(x,y,map) << endl;
                cin >> w >> h; 
        }  
}

Measured memory_bytes: 0
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b){
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b){
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b){
	int res=1;
	while(b){
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=100002;
 
void solve(){
	int n;
	cin>>n;
	vector<vector<pair<int,int>>>z;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		vector<pair<int,int>>a(x);
		cin>>a;
		z.pb(a);
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		vector<int>used(n);
		int flag=0;
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				if(used[j]==1){
					flag++;
					break;
				}
				for(auto k:z[j]){
					if(used[k.F-1]==0){
						used[k.F-1]=k.S+1;
					}
					else if(k.S+1!=used[k.F-1]){
						flag++;
						break;
					}
				}
			}
			else{
				if(used[j]==2){
					flag++;
					break;
				}
			}
		}
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				if(used[j]==1){
					flag++;
				}
			}
			else{
				if(used[j]==2){
					flag++;
				}
			}
		}
		if(!flag){
			ans=max(ans,__builtin_popcount(i));
		}
	}
	cout<<ans;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
ans = 0
for i in range(1, N+1):
    cnt = 0
    while i*(2**cnt)<K:
        cnt += 1
    ans += 1/(2**cnt)
print(ans/N)

Measured memory_bytes: 65836
def main():
    a, b, c, x, y = map(int, input().split())
    xyK = min(x, y)
    k = min(a + b, c * 2) * xyK
    x -= xyK
    y -= xyK
    print(k + x * min(a, c * 2) + y * min(b, c * 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 8988
// AOJ ALDS1_2_D Shell Sort
// 2018.4.27 bal4u

#include <stdio.h>

int cnt;

void insertion_sort(int n, int *a, int g)
{
	int i, j, key;

	for (i = g; i < n; i++) {
		key = a[i];
		j = i-g;
		while (a[j] > key) {
			a[j+g] = a[j];
			cnt++;
			j -= g;
			if (j < 0) break;
		}
		a[j+g] = key;
	}
}

int m;
int g[102];

void shell_sort(int n, int *a)
{
	int i, lim;

	lim = n / 9;		// 要素数/9
	if (lim < 40) lim = 40;
	
	g[0] = 1;
	m = 0; do m++, g[m] = 3*g[m-1]+1;
	while (g[m] < n && g[m] <= lim);

	cnt = 0;
	i = m; while (i--) insertion_sort(n, a, g[i]);
}

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char buf[20];
void mypr(int n)
{
	int i;
	if (n == 0) { pc('0'); return; }
	i = 0; while (n) buf[i++] = n%10 +'0', n /= 10;
	while (i) pc(buf[--i]);
}

int a[1000002];

int main()
{
	int N, i;

	N = in(); for (i = 0; i < N; i++) a[i] = in();

	shell_sort(N, a);
	
	mypr(m), pc('\n');
	mypr(g[m-1]); for (i = m-2; i >= 0; i--) pc(' '), mypr(g[i]); pc('\n');
	mypr(cnt), pc('\n');
	for (i = 0; i < N; i++) mypr(a[i]), pc('\n');

	return 0;
}


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

#define int long long

void fastio()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	fastio();
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	cout << 15 - (a + b + c + d + e);
	return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];

    if (N < M) {
        cout << "No" << endl;
        return 0;
    }

    rep(i, N) {
        rep(j, N) {
            bool ok = true;
            rep(k, M) {
                rep(l, M) {
                    if (N <= i+k || N <= j + l || A[i + k][j + l] != B[k][l]) ok = false;
                }
            }
            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 256
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

fn read_vec<T: FromStr>(s: String) -> Result<Vec<T>, T::Err> {
    s.split(' ').map(|x| x.parse()).collect()
}

fn main() {
    const M: i64 = 1000_000_000 + 7;
    let mut lines = BufReader::new(io::stdin()).lines().map(|l| l.unwrap());
    let nk: Vec<usize> = read_vec(lines.next().unwrap()).unwrap();
    let mut v: Vec<i64> = read_vec(lines.next().unwrap()).unwrap();
    if nk[0] == nk[1] {
        let mut ans = v.iter().fold(1, |acc, x| acc * (x % M) % M);
        ans = (ans + M) % M;
        println!("{}", ans);
        return;
    }

    v.sort_by_key(|x| {
        let y = x >> 31;
        y - (x ^ y) // 絶対値のマイナス
    });
    let (head, tail) = v.split_at(nk[1]);
    if head.iter().any(|&x| x == 0) {
        println!("0");
        return;
    }
    // そのまま積を求めれば良い単純な場合
    // headの中に奇数が偶数個存在する
    let simple = head.iter().filter(|&&c| c < 0).count() & 1 == 0;
    // 奇数が奇数個存在するとき
    if !simple {
        // a,bを交換すると、絶対値は(b/(-a))倍になる
        let a = *head.iter().filter(|&&c| c < 0).last().unwrap();
        let b = tail.iter().filter(|&&c| c >= 0).next().cloned();
        // c,dを交換すると、絶対値は((-d)/c)倍になる
        let c = head.iter().filter(|&&c| c >= 0).last().cloned();
        let d = tail.iter().filter(|&&c| c < 0).next().cloned();
        // b/(-a)と(-d)/cで大きい方をとる
        // (-d)/c > b/(-a)  <-> da>bc
        let (x, y) = match (a, b) {
            (a, Some(b)) => match (c, d) {
                (Some(c), Some(d)) if a * d > b * c => (c, d),
                _ => (a, b),
            },
            (_, None) => match (c, d) {
                (Some(c), Some(d)) => (c, d),
                _ => {
                    // 全部負の数だった
                    let ans = v
                        .iter()
                        .rev()
                        .take(nk[1])
                        .fold(1, |acc, x| acc * (x % M) % M);
                    println!("{}", (ans + M) % M);
                    return;
                }
            },
        };
        let i = v.iter().position(|&xx| xx == x).unwrap();
        v[i] = y;
    }
    let ans = v.iter().take(nk[1]).fold(1, |acc, x| acc * (x % M) % M);
    println!("{}", (ans + M) % M);
}

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

int main() {
	int n, y, m, d,days=0,i,j;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> y >> m >> d;
		//y?????????
		for (j = y; j < 999; j++) {
			if (j % 3 == 2) {
				days = days + 200;
			}
			else {
				days = days + 195;
			}
		}
		//m?????????
		for(j=m;j<10;j++){
			if (j % 2 == 0||y%3==0) {
				days = days + 20;
			}
			else {
				days = days + 19;
			}
		}
		//d?????????
		
	   if (y % 3 == 0 || m % 2 == 1) {
				days = days + 20 - d;
			}
			else { days = days + 19 - d; }
		
		cout << days + 1<<endl;
		days = 0;
	}
	return 0; }

Measured memory_bytes: 3032
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[255];
int n;

int solve(bool x){
  int i, j, r, res = 0;
  if(x){
    rep(i, n)for(j = 0;j < n;){
      if(s[i][j] == '0'){ ++j; continue; }
      for(r = j + 1;r < n;++r)if(s[i][r] == '0')break;
      res = max(res, r - j);
      j = r;
    }
  }else{
    rep(i, n){
      for(j = 0;j < n - i;){
        if(s[j][j + i] == '0'){ ++j; continue; }
        for(r = j + 1;r + i < n;++r)if(s[r][r + i] == '0')break;
        res = max(res, r - j);
        j = r;
      }
      for(j = 0;j < n - i;){
        if(s[j + i][j] == '0'){ ++j; continue; }
        for(r = j + 1;r + i < n;++r)if(s[r + i][r] == '0')break;
        res = max(res, r - j);
        j = r;
      }
    }
  }
  return res;
}
void pr(void){
  int i;
  kabe;
  rep(i, n)cout << s[i] << endl;
  return;
}
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    scanf("%d", &n);
    if(!n)break;

    rep(i, n)cin >> s[i];

    int res = 0;
    res = solve(1);
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(1));
    rep(i, n)rep(j, i)swap(s[i][j], s[j][i]);
    res = max(res, solve(0));
    rep(i, n)rep(j, n / 2)swap(s[i][j], s[i][n - j - 1]);
    res = max(res, solve(0));
    pri(res);

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3304
import Data.List
import Data.Array
main=do
 [x,y,z,k]<-map read.words<$>getLine
 a<-array (1,x).zip [1..x].sortBy (\a b->compare b a).map read.words<$>getLine
 b<-array (1,y).zip [1..y].sortBy (\a b->compare b a).map read.words<$>getLine
 c<-array (1,z).zip [1..z].sortBy (\a b->compare b a).map read.words<$>getLine
 mapM_ print (take k (sortBy (\a b->compare b a) [a!h+b!i+c!j|h<-[1..x],i<-[1..(quot k h)],j<-[1..(quot k (h*i))],i<=y,j<=z]))

Measured memory_bytes: 13692
# include"stdio.h"
int main(){
    int h,w;
    scanf("%d %d",&h,&w);
    char a[h][w+1];
    for(int i=0;i<h;i++)
            scanf("%s",a[i]);
    char c[h+2][w+2+1];
    for(int i=0;i<h+2;i++){
        c[i][0]='#';
        c[i][w+1]='#';
    }
    for(int i=0;i<w+2;i++){
        c[0][i]='#';
        c[h+1][i]='#';
    }
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            c[i][j]=a[i-1][j-1];
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            printf("%c",c[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 1632
n = input()

firsttwo = int(n[0:2])
lasttwo = int(n[2:4])

if(firsttwo > 00 and firsttwo < 13):
  if(lasttwo > 00 and lasttwo < 13):
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if(lasttwo > 00 and lasttwo < 13):
    print('YYMM')
  else:
    print('NA')          
        
    

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

ll check1(ll a, ll b, ll d, ll e){
	ll ret = 2 * b;
	if(a <= min(d, e)){
		ret += 6 * a;
		d -= a;
		e -= a;
		a = 0;
	}else if(a > min(d, e)){
		ll minus = min(d, e);
		ret += 6 * minus;
		a -= minus;
		d -= minus;
		e -= minus;
	}
	ret += 4 * (a / 2);
	ret += 4 * (d / 2);
	ret += 4 * (e / 2);

	return ret / 2;
}

ll check2(ll a, ll b, ll d, ll e){
	ll ret = 2 * b;
	if(a > 0 && d > 0 && e > 0){
		ret += 6;
		a--;
		d--;
		e--;
	}
	ret += 4 * (a / 2);
	ret += 4 * (d / 2);
	ret += 4 * (e / 2);

	return ret / 2;
}


int main() {
	ll a, b, c, d, e, f, g;
	cin >> a >> b >> c >> d >> e >> f >> g;
	ll ans = 0,ans2 = max(check1(a, b, d, e),check2(a, b, d, e));
	ans += 2 * b;

	ans += 4 * (d / 2);
	d %= 2;

	ans += 4 * (e / 2);
	e %= 2;

	ans += 4 * (a / 2);
	a %= 2;

	if(a == 1 && d == 1 && e == 1){
		ans += 6;
	}

	ans /= 2;
	cout << max(ans, ans2) << endl;
	return 0;
}

Measured memory_bytes: 384
class Tree:
  def __init__(self):
    self.parent = -1
    self.brother = -1
    self.lchild = -1
    self.rchild = -1

n = int(input())

A = [Tree() for _ in range(n)]

for i in range(n):
  id, *children = [int(x) for x in input().split()]
  A[id].lchild, A[id].rchild = children
  if A[id].lchild != -1 and A[id].rchild != -1:
    A[A[id].lchild].brother = A[id].rchild
  for child in children:
    if child != -1:
      A[child].parent = id

root = [i for i, x in enumerate(A) if x.parent == -1][0]

def preorder(A,C,a):
  C.append(a)
  F = []
  if A[a].lchild != -1:
    preorder(A,C,A[a].lchild)
    if A[a].rchild != -1:
      F.append(A[a].rchild)
  elif A[a].rchild != -1:
    preorder(A,C,A[a].rchild)
  elif A[a].brother != -1:
    preorder(A,C,A[a].brother)
  while F != []:
    f = F.pop()
    if not f in C:
      preorder(A,C,f)
  return C

def start(A,a):
  global b
  b = A[a].lchild
  if b != -1:
    start(A,b)
  else:
    b = a
  return b

def inorder(A,D,a):
  if A[a].lchild == -1:
    D.append(a)
    if A[a].rchild != -1:
      inorder(A,D,start(A,A[a].rchild))
  if A[a].parent != -1:
    c = A[a].parent
    if a == A[c].lchild and A[c].rchild != -1:
      D.append(c)
      inorder(A,D,start(A,A[c].rchild))
    elif a == A[c].lchild and A[c].rchild == -1:
      D.append(c)
      inorder(A,D,c)
    elif a == A[c].rchild and A[c].lchild != -1:
      inorder(A,D,c)

def postorder(A,E,a,e):
  if A[a].lchild == -1 and A[a].rchild != -1:
    postorder(A,E,start(A,A[a].rchild),A[a].rchild)
  E.append(a)
  if a != e:
    if A[a].brother != -1:
      postorder(A,E,start(A,A[a].brother),e)
    else:
      postorder(A,E,A[a].parent,e)

C = []
D = []
E = []

print("Preorder")
print(" ",end="")
print(" ".join(map(str, preorder(A,C,root))))
print("Inorder")
print(" ",end="")
s = start(A,root)
inorder(A,D,s)
print(" ".join(map(str, D)))
print("Postorder")
print(" ",end="")
postorder(A,E,s,root)
print(" ".join(map(str, E)))


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <random>
#include <queue>
#include <deque>
#include <iterator>
#include <map>
#include <functional>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define pb(a) push_back(a)
#define llong long long
#define INF 1145141919
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = { 1, 0, -1, 0 };
int dx[] = { 0, 1, 0, -1 };
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }


int main() {
	int x, y;
	cin >> x >> y;
	cout << x + (y / 2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    vector<int> h(N);
    REP(i, N) cin >> h[i];

    int ans = 0;
    while(true) {
        
        if (*max_element(ALL(h)) == 0) break;

        int i = 0;
        while(i < N) {
            if (h[i] == 0) i++;
            else {
                ans++;
                while(i < N && h[i] > 0) {
                    h[i]--;
                    i++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    int ans = 0, n = s.length();
    rep(i, n)
    {
        if (s[i] == 'o')
            ans++;
    }
    ans += 15 - n;
    if (ans >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
/*  Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int a[N];
int32_t main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    map<int,int>mp,mp1;
    for(int i=1;i<=n;i+=2)
    {
        mp[a[i]]++;
    }
    for(int i=2;i<=n;i+=2)
    {
        mp1[a[i]]++;
    }
    int mx=0,ans,mx1=0,ans1;
    for(auto it:mp)
    {
        if(mx<it.ss)
        {
            mx=it.ss;
            ans=it.ff;
        }
    }
    for(auto it:mp1)
    {
        if(mx1<it.ss)
        {
            mx1=it.ss;
            ans1=it.ff;
        }
    }
    int flag=0;
    if(ans1==ans)
    {
        mx1=0;
        ans1=0;
        for(auto it:mp1)
        {
            if(mx1<it.ss&&it.ff!=ans)
            {
                mx1=it.ss;
                ans1=it.ff;
            }
        }
        flag=1;
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i&1)
        {
            sum+=(a[i]!=ans);
        }
        else
        {
            sum+=(a[i]!=ans1);
        }
    }
    ans1=ans;
    if(flag==1)
    {
        mx=0;
        ans=0;
        for(auto it:mp)
        {
            if(mx<it.ss&&it.ff!=ans1)
            {
                mx=it.ss;
                ans=it.ff;
            }
        }
    }
    int sum1=0;
    for(int i=1;i<=n;i++)
    {
        if(i&1)
        {
            sum1+=(a[i]!=ans);
        }
        else
        {
            sum1+=(a[i]!=ans1);
        }
    }
    cout<<min(sum,sum1)<<endl;



}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int N;cin>>N;
  REP(i,N) {
    char s;cin>>s;
    if (s=='Y') {
      OUT("Four");
      return 0;
    }
  }
  OUT("Three");

  return 0;
}

Measured memory_bytes: 256
n = int(input())
v = list(map(int, input().split()))
a = [[0, i] for i in range(10 ** 5 + 1)]
b = [[0, i] for i in range(10 ** 5 + 1)]
for i in range(n):
    if i % 2 == 0:
        a[v[i]][0] += 1
    else:
        b[v[i]][0] += 1
a.sort(reverse = True)
b.sort(reverse = True)
if a[0][1] == b[0][1]:
    ans = n - max(a[0][0] + b[1][0], a[1][0] + b[0][0])
else:
    ans = n - (a[0][0] + b[0][0])
print(ans)

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

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

  int ans = 1;

  rep(i, n){
    if (ans*2 < ans+k){
      ans *= 2;
    }
    else ans += k;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;

inline LL read() {
	LL x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int N = 2e5+11;
int n;
int a[N];
LL ans;
LL L[N],R[N];

int main() {
	n=read();
	For(i, 1, n) a[i]=read();
	For(i, 1, n) L[i]=L[i-1]+a[i];
	Dow(i, n, 1) R[i]=R[i+1]+a[i];
	ans = 1e18;
	For(i, 1, n-1) 
		ans = min(ans,abs(L[i]-R[i+1]));
	printf("%lld\n",ans);
}









Measured memory_bytes: 4224