akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

char worm[12];
int ans;
bool flag;
void bfs(){
  string change;
  map<string,int> used;
  queue<string> que;
  queue<int> zikan;
  que.push(worm);
  zikan.push(0);
  while(!que.empty()){
    string str = que.front();
    ans = zikan.front();
    que.pop();
    zikan.pop();
    for(int i = 0;i < str.length()-1;i++){//変化した状態が題意を満たすかチェック
      if(str[i] !=str[i+1]){
	break;
      }
      if(i ==str.length()-2){
	flag = true;
	return;
      }
    }
    for(int i = 0;i <strlen(worm)-1;i++){
      if(str[i]=='r'&&str[i+1]!='r'){
	if(str[i+1]=='b'){
	  change = str;
	  change[i] ='g';
	  change[i+1]='g';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}else if(str[i+1]=='g'){
	  change = str;
	  change[i] ='b';
	  change[i+1]='b';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}
      }else if(str[i] =='b'&&str[i+1]!='b'){
	if(str[i+1]=='r'){
	  change = str;
	  change[i] ='g';
	  change[i+1]='g';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}else if(str[i+1]=='g'){
	  change = str;
	  change[i] ='r';
	  change[i+1]='r';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}
      }
      else if(str[i]=='g'&&str[i+1]!='g'){
	if(str[i+1]=='b'){
	  change = str;
	  change[i] ='r';
	  change[i+1]='r';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}else if(str[i+1]=='r'){
	  change = str;
	  change[i] ='b';
	  change[i+1]='b';
	  if(used[change]==1){
	    continue;
	  }
	  que.push(change);
	  zikan.push(ans+1);
	  used[change]=1;
	}
      }
    }
  }
}

int main()
{
  while(cin>>worm){
    ans = 0;
    if(worm[0]=='0')
      return 0;
    flag = false;
    bfs();
    if(flag)
      cout <<ans<<endl;
    else
      cout <<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 2908
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int w, h, a[SIZE];
  int sum = 0;
  
  scanf("%d%d", &w, &h);

  priority_queue<int> pq;
  
  for(int i=0;i<w;i++){
    scanf("%d", a+i);
    pq.push(a[i]);
  }

  for(int j=0;j<h;j++){
    int b;
    scanf("%d", &b);

    queue<int> que;

    for(int j=0;j<b;j++){
      int p = pq.top(); pq.pop();
      if(p == 0){
        puts("0");
        return 0;
      }
      que.push(p-1);
    }

    while(que.size()){
      pq.push(que.front());
      que.pop();
    }
  }

  if(pq.top() == 0)
    puts("1");
  else
    puts("0");
  
  return 0;
}




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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[305][305];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    bool b[305]{0};
    int d[305]{0};
    int ans = n;
    for(int c = 0; c < m; c++){
        int s[305]{0};
        for(int i = 0; i < n; i++) s[a[i][d[i]]]++;
        int l = 0;
        for(int i = 0; i < m; i++) l = max(l, s[i]);
        ans = min(ans, l);
        for(int i = 0; i < m; i++){
            if(s[i] == l) b[i] = true;
        }
        for(int i = 0; i < n; i++){
            while(b[a[i][d[i]]] && d[i] < m) d[i]++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3992
using System;

namespace ITP1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            Console.WriteLine("{0} {1}", a * b, (a + b) * 2);
        }
    }
}

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll a[100005],l;
int n,x=-1;
int main(void){
    scanf("%d%lld",&n,&l);
    for(int i=0;i<n;i++){
        scanf("%lld",a+i);
    }
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>=l){
            x=i+1;
            break;
        }
    }
    if(x!=-1){
        printf("Possible\n");
        for(int i=n-2;i>=x;i--)printf("%d\n",i+1);
        for(int i=0;i<x;i++)printf("%d\n",i+1);
    }else printf("Impossible\n");
}

Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderB
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int count = 0;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            for (int i = 0; i < n; i++)
            {
                int num = int.Parse(words[i]);
                if (num != i + 1)
                {
                    count++;
                }
            }
        }

        Console.WriteLine(count == 0 || count == 2 ? "YES" : "NO");
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
int M=1000000007;

ll mpow(ll a,ll n)
{
	ll res=1;
	while (n>0)
	{
		if (n&1) res=res*a%M;
		a=a*a%M;
		n=n/2;
	}
	return res;
}

int main()
{
	string s;
	cin>>s;
	ll ans=0,cnt=0;
	for (int i=0; i<s.length(); i++)
	{
		if (s[i]=='1') 
		{
			ans=(ans+mpow(3,s.length()-i-1)*mpow(2,cnt)%M)%M;
			cnt++;
		}
	}
	ans=(ans+mpow(2,cnt))%M;
	cout << ans;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


typedef long long ll;

using namespace std;

int main() 
{ 
    ll health, n;
	cin >> health >> n;

	ll moves[n];
	for (int i = 0; i < n; i++) cin >> moves[i];


	for (int i = 0; i < n; i++) health -= moves[i];

	if (health > 0){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}


	return 0; 
} 


Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;


int main(){

	int n,length,second_length;
	char snake[201];

	scanf("%d",&n);

	for(int i=0; i < n; i++){
		scanf("%s",snake);

		if(snake[1] == '\0'){
			printf("NA\n");
			continue;
		}

		if(snake[0] == '>' && snake[1] == '\''){
			if(snake[2] != '='){
				printf("NA\n");
			}else{
				for(length = 0;snake[length+2] != '\0' && snake[length+2] == '='; length++);

				if(snake[length+2] != '#'){
					printf("NA\n");
				}else{
					for(second_length = 0; snake[length+3+second_length] != '\0' &&
								snake[length+3+second_length] == '=';second_length++);

					if(length != second_length || snake[length+3+second_length] != '~'){
						printf("NA\n");
					}else{
						if(snake[length+4+second_length] == '\0'){
							printf("A\n");
						}else{
							printf("NA\n");
						}
					}
				}
			}
		}else if(snake[0] == '>' && snake[1] == '^'){
			if(snake[2] != 'Q' || snake[3] != '='){
				printf("NA\n");
			}else{
				bool breakFLG = false;
				for(length=0;snake[length+2] != '\0' && (snake[length+2] == 'Q' || snake[length+2] == '=');length++){
					if(length > 1){
						if(snake[length+2] == 'Q' && snake[length+2-1] != '='){
							breakFLG = true;
							break;
						}
						if(snake[length+2] == '=' && snake[length+2-1] != 'Q'){
							breakFLG = true;
							break;
						}
					}
				}
				if(breakFLG)printf("NA\n");
				else{
					if(snake[length+2-1] == 'Q'|| snake[length+2] != '~'){
						printf("NA\n");
					}else{
						if(snake[length+3] != '~'){
							printf("NA\n");
						}else{
							if(snake[length+4] == '\0'){
								printf("B\n");
							}else{
								printf("NA\n");
							}
						}
					}
				}
			}
		}else{
			printf("NA\n");
		}


	}

    return 0;
}

Measured memory_bytes: 2584
#include <iostream>
#include <vector>
#include <complex>
#include <iomanip>

using namespace std;

typedef complex<double> point;

double cross(point a,point b){
    return imag(conj(a)*b);
}

double triangle_area(point a,point b,point c){
    return cross(b-a,c-a)/2;
}

double vertex_area(vector<point> v){
    double ret = 0;
    for(int i=1;i<v.size()-1;i++){
        ret += triangle_area(v[0],v[i],v[i+1]);
    }
    return ret;
}

int main(){
    cout << fixed << setprecision(10);
    vector<point> v;
    double x,y;
    char c;
    while(cin >> x >> c >> y){
        v.push_back(point(x,y));
    }
    cout << abs(vertex_area(v)) << endl;
    return 0;
}

Measured memory_bytes: 1296
a,b,c,d = map(int, input().split())

if b<=c or d<=a:
    print(0)
elif a<=c and b<=d:
    print(b-c)
elif a<=c and d<=b:
    print(d-c)
elif c<=a and b<=d:
    print(b-a)
elif c<=a and d<=b:
    print(d-a)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

ll func( ll i, ll p){
    ll res = 1; ll x = 10;
    while( i > 0){
        if( i & 1)
            res *= x;
        x = x*x; x %= p;
        i >>= 1;
        res %= p;
    }
    return res;
}

void test_case(){
    int n, p ; cin >> n >> p;
    string s; cin >> s;
    
    if( p == 2 ){
        ll res = 0;
        rng( i, 0, n){
            if( (s[i]- '0') % 2 == 0)
                res += (i+1);
        }
        cout<<res<<endl;
        return;
    }
    
    if( p == 5 ){
        ll res = 0;
        rng( i, 0, n){
            if( (s[i]- '0') % 5 == 0 )
                res += (i+1);
        }
        cout<<res<<endl;
        return;
    }
    
    reverse(s.begin(), s.end());
    ll a[n];
    vector< ll > b(p, 0); ll pre = 0; b[0]++;
    rng(i, 0, n){
        a[i] = (( s[i]-'0')*func(i, p)) % p;
        pre += a[i];
        pre %= p;
        b[pre]++;
    }
    
    ll res = 0;
    rng( i, 0, p){
        if( b[i] > 1){
            res += ( ll(b[i])*ll(b[i]-1) ) / 2ll;
        }
    }
    //res += b[0];
    cout<<res<<endl;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    int t; t = 1;
    while(t--) test_case();
	return 0;
}






Measured memory_bytes: 2196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int w = in.nextInt();
		int h = in.nextInt();
		int n = in.nextInt();

		int maxX = w;
		int minX = 0;
		int maxY = h;
		int minY = 0;

		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			int y = in.nextInt();
			int a = in.nextInt();
			if (a == 1 && minX < x) {
				minX = x;
			} else if (a == 2 && maxX > x) {
				maxX = x;
			} else if (a == 3 && minY < y) {
				minY = y;
			} else if (a == 4 && maxY > y) {
				maxY = y;
			}
		}

		if (maxX < minX || maxY < minY) {
			System.out.println(0);

		} else {
			System.out.println((maxX - minX) * (maxY - minY));
		}
	}
}

Measured memory_bytes: 24020
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces


a, b = na()
n1 = ''
n2 = ''
for i in range(a):
    n1 += str(b)
for i in range(b):
    n2 += str(a)

print(min(n1, n2))

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    char achar='A';
    for(int i=0;i<s.length();i++){
        char c='A'+(s[i]-'A'+n)%26;
        cout<<c;
    }
    cout<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    string A;
    cin >> A;
    char l,p,i,o;
    l = A.at(2);
    p = A.at(3);
    i = A.at(4);
    o = A.at(5);
    if(l==p&&i==o)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int A,B;
    cin >> A >> B;
    bool ok = false;
    if (A % 3 == 0){
        ok = true;
    } else if (B % 3 == 0){
        ok = true;
    } else if ((A + B) % 3 == 0){
        ok = true;
    }

    if (ok){
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> v[200005];

int main(){
  int H, W, N;
  cin >> H >> W >> N;

  rep(i,N){
    int X, Y;
    cin >> X >> Y;
    v[X].push_back(Y);
  }

  int ret = H;
  int range = 1;
  REP(i,2,H+1){
    sort(ALLOF(v[i]));
    if(v[i].size() == 0){
      range++;
    }else{
      if(v[i][0] <= range){
        ret = min(ret, i-1);
      }else if(v[i][0] == range+1){
        ;
      }else{
        range++;
      }
    }
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 11136
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	String S;
	int[] lefts, rights;
	int result = Integer.MAX_VALUE;
	
	Main() throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		N = Integer.parseInt(in.readLine());
		S = in.readLine();
		in.close();
		this.lefts = new int[2];
		this.rights = new int[2];
		init();
		calc();
	}
	
	void init() {
		this.lefts[0] = 0;
		this.lefts[1] = 0;
		this.rights[0] = 0;
		this.rights[1] = 0;
		for(int i = 0; i < S.length(); ++i) {
			if(S.charAt(i) == '#') {
				++rights[1];
			}else {
				++rights[0];
			}
		}
	}

	void calc() {
		this.result = this.rights[0];
		for(int i = 0; i < S.length(); ++i) {
			if(S.charAt(i) == '#') {
				--rights[1];
				++lefts[1];
			}else {
				--rights[0];
				++lefts[0];
			}
			this.result = Math.min(result, rights[0] + lefts[1]);
		}
	}

	public static void main(String[] args) throws IOException {
		Main ins = new Main();
		System.out.println(ins.result);

	}

}

Measured memory_bytes: 25940
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;
    for(int i=0;i<str.length();i++) {
        if(i == k-1)
            cout << char((str[i] - 'A') + 97);
        else
            cout << str[i];
    }
    cout << endl;
    return ;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 256
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
X, Y = map(int, input().split())
if (X in a and Y in a) or (X in b and Y in b) or (X in c and Y in c):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
	int a;
	int sum = 0;
	for (int i = 0; i < 5; i++) {
		cin >> a;
		if (a < 40) {
			sum += 40;
		} else {
			sum += a;
		}
	}
	cout << sum/5 << endl;
	return 0;
}

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

const int maxn = 111;
ll w[maxn], v[maxn], w0;
int N, W;
ll ans;
vector<ll> vv[5];
ll pre[5][maxn];
bool cmp(ll a, ll b) { return a > b; }
int main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }
  w0 = w[0];
  for (int i = 0; i < N; i++) {
    vv[w[i] - w0].push_back(v[i]);
  }
  for (int i = 0; i < 4; i++) {
    sort(vv[i].begin(), vv[i].end(), cmp);
    for (int j = 0; j < vv[i].size(); j++) {
      pre[i][j + 1] = pre[i][j] + vv[i][j];
    }
  }
  for (int i = 0; i <= vv[0].size(); i++) {
    for (int j = 0; j <= vv[1].size(); j++) {
      for (int k = 0; k <= vv[2].size(); k++) {
        for (int l = 0; l <= vv[3].size(); l++) {
          if (w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l <= W) {
            ans = max(ans, pre[0][i] + pre[1][j] + pre[2][k] + pre[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef pair<int, int> pii;
typedef long long ll;
const int MOD = 1000000007;
const int N = 18;
int n,a[N];

ll calc(int l , int x , int r , int y){
  if(r-l==1)return 0;
  ll ret = 1e18;
  for(int idx = l+1 ; idx < r ; ++idx){
    ret = min(ret,calc(l,x,idx,(x+y)) + calc(idx,(x+y),r,y) + (x+y+0ll)*a[idx]);
  }
  return ret;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i)scanf("%d",a+i);
  ll ans = 1ll*a[0]+a[n-1]+calc(0,1,n-1,1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		while (sc.hasNext()) {
			String[] ss = sc.nextLine().split(",");
			int[] hands = new int[5];
			for (int i = 0; i < 5; i++) {
				hands[i] = Integer.parseInt(ss[i]);
			}
			Arrays.sort(hands);
			String res = "null";
			if (isOnePair(hands)) res = "one pair";
			if (isTwoPair(hands)) res = "two pair";
			if (isThreeCard(hands)) res = "three card";
			if (isStraight(hands)) res = "straight";
			if (isFullHouse(hands)) res = "full house";
			if (isFourCard(hands)) res = "four card";
			System.out.println(res);
		}
		
	}
	
	int[] getCount(int[] hands) {
		int[] count = new int[14];
		for (int i = 0; i < hands.length; i++) {
			count[hands[i]]++;
		}
		return count;
	}
	
	private boolean isFourCard(int[] hands) {
		int[] count = getCount(hands);
		for (int i = 1; i <= 13; i++) if (count[i] >= 4) return true;
		return false;
	}
	private boolean isFullHouse(int[] hands) {
		int[] count = getCount(hands);
		int ch = 0;
		for (int i = 1; i <= 13; i++) 
			if (count[i] == 3) ch |= 1;
			else if (count[i] == 2) ch |= 2;
		return ch == 3;
	}
	private boolean isStraight(int[] hands) {
		int k = 0;
		for (int i = 0; i + 1 < hands.length; i++) {
			if (hands[i+1] - hands[i] == 1) {
				k++;
			}
		}
		if (k == 4) return true;
		return hands[0] == 1 && 
				hands[1] == 10 &&
				hands[2] == 11 &&
				hands[3] == 12 &&
				hands[4] == 13;
	}
	private boolean isThreeCard(int[] hands) {
		int[] count = getCount(hands);
		for (int i = 1; i <= 13; i++) if (count[i] >= 3) return true;
		return false;
	}
	private boolean isTwoPair(int[] hands) {
		int[] count = getCount(hands);
		int p = 0;
		for (int i = 1; i <= 13; i++) if (count[i] >= 2) p++;
		return p >= 2;
	}
	private boolean isOnePair(int[] hands) {
		int[] count = getCount(hands);
		for (int i = 1; i <= 13; i++) if (count[i] >= 2) return true;
		return false;
	}
}

Measured memory_bytes: 17192
// https://atcoder.jp/contests/abc138/tasks/abc138_c

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());

    double s = v[0];
    for (long i = 1; i < n; i++)
    {
        s = (s + v[i]) / 2.0;
    }
    cout << s << endl;
}


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

int main() {
  int A,B,C,D,L,R ;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  if (L < R) {
    cout << "Right" << endl;
  }
  if (L == R) {
    cout << "Balanced" << endl;
  }
  if (L > R) {
    cout << "Left" << endl;
  }   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin>> A;
  if((A/1000==A/100%10 && A/100%10==A%100/10) || (A/100%10==A%100/10 && A%100/10==A%10))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

using namespace std;

const int INF = INT_MAX;

int main () {
  int n;
  cin >> n;
  vector <vector <int>> C(n, vector <int> (3));
  for (vector <int>& row: C) {
    for (int& day: row) cin >> day;
  }
  vector <vector <int>> dp(n, vector <int> (3, -INF));
  dp[0] = C[0];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 1; k <= 2; k++) {
        int id = (j + k) % 3;
        dp[i][j] = max(dp[i][j], dp[i - 1][id] + C[i][j]);
      }
    }
  }
  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
  return (0);
}


Measured memory_bytes: 11136
def solve(N, M, ABs):
    from1 = set()
    toN = set()
    for a, b in ABs:
        a, b = min(a, b), max(a, b)
        if a == 1:
            from1.add(b)
        if b == N:
            toN.add(a)
    return "POSSIBLE" if len(from1.intersection(toN)) else "IMPOSSIBLE"

if __name__ == "__main__":
    N, M = map(int, input().split(" "))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(M)]
    print(solve(N, M, ABs))


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

using namespace std;
using ll = long long;

constexpr ll mod = 1e9 + 7;

int main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<string> s(n);
	vector<char> ans(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> s[i];
	}
	for (int i = 0; i < n; ++i)
	{
		auto hand = [&](int &x, int &y) {
			if (x == 0 && y == 0)
			{
				return char(0);
			}
			if (x > y)
			{
				x--;
				y++;
				return s[i][1];
			}
			else if (x < y)
			{
				x++;
				y--;
				return s[i][0];
			}
			else
			{
				if (x == 1 && i < n - 1)
				{
					if (s[i][0] == s[i + 1][0] || s[i][0] == s[i + 1][1])
					{
						x++;
						y--;
						return s[i][0];
					}
					else
					{
						x--;
						y++;
						return s[i][1];
					}
				}
				x--;
				y++;
				return s[i][1];
			}
		};

		if (s[i] == "AB")
		{
			ans[i] = hand(a, b);
			if (ans[i] == 0)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else if (s[i] == "AC")
		{
			ans[i] = hand(a, c);
			if (ans[i] == 0)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			ans[i] = hand(b, c);
			if (ans[i] == 0)
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	for (auto x : ans)
	{
		cout << x << endl;
	}
}

Measured memory_bytes: 6404
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}
void solve()
{
    ll n,a,b,c;cin>>n>>a>>b>>c;
    string arr[n+3];
    for(ll i=0;i<n;i++)cin>>arr[i];
    arr[n]='@';
    string ans;
    for(ll i=0;i<n;i++)
    {
        string cur = arr[i]; string next = arr[i+1];
        if(arr[i]=="AB")
        {
            if(a<b  || (next =="AC" && b))
            {
                ans+='A';a++,b--;
            }
            else
            {
                ans+='B';a--;b++;
            }
        }
        else if(arr[i]=="BC")
        {
            if(b<c || (next=="AB" && c))
            {
                c--,b++;ans+='B';
            }
            else
            {
                b--,c++;ans+='C';
            }
            
        }
        else
        {
            if(a<c || (next == "AB" && c))
            {
                ans+='A';a++,c--;
            }
            else
            {
                ans+='C';a--,c++;
            }
        }
        if(a<0 || (b<0 || c<0))
        {
            cout<<"No"<<endl;return;
        }
    }
    cout<<"Yes"<<endl;
    for(auto it:ans)
    {
        
        cout<<it<<endl;
    }
}
signed main()
{
 
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

 solve();
    return 0;
}


Measured memory_bytes: 6916
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<int,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
int n;
string s;

int main() {
	cin>>n;
	if(n%2==1){
		cout<<"No"<<endl;
		return 0;

	}
	cin>>s;
	if(s.substr(0,s.size()/2)==s.substr(s.size()/2,s.size()/2)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 100005
const ll INF = 1000000001;
const ll MOD = 998244353 ; //1e9+7;

vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
ll vis[N] = {0}, par[N] = {0}, child[N] = {0}, dp[N] = {0};

void dfs(ll v){
    vis[v] = 1;
    for(auto u: g[v]){
        if(!vis[u]){
            dfs(u);
        }
        dp[v] = max(dp[v], 1 + dp[u]);
    }
}

void solve(){
    string s, t; cin >> s >> t;
    ll mx = 0;
    for(ll i=0 ; i + t.size() < s.size() + 1; i++){
        ll cnt = 0;
        for(ll j=0 ; t[j] != 0; j++){
            if(s[i+j] == t[j]) cnt++;
        }
        mx = max(mx, cnt);
        
    }
    cout <<  t.size() - mx << "\n"; 
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
    //}
    return 0;
}


Measured memory_bytes: 5416
#ABC061

n,m =list(map(int,input().split()))
a = [list(map(int,input().split())) for _ in range(m)]
c = [0] * n

for i in range(m):
    c[a[i][0]-1] += 1
    c[a[i][1]-1] += 1
for j in range(n):
    print(c[j])




Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define N 200005
#define M 1000000007
#define pii pair<ll,ll>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int c[N];
vector<int>e[N];
vector<int> d;
int ans[N];
void dfs(int node,int par,int last=0)
{
    int j = upper_bound(d.begin(), d.end(), c[node]) - d.begin();
    bool p=false;
    int x,y;
    if (d[j-1] < c[node] && c[node] < d[j])
    {
        p=true;
        x=j,y=d[j];
        d[j] = c[node];
    }
    if(d[last+1]!=2e9)
    {
        ans[node]=last+1;
    }
    else
        ans[node]=last;

    for(int u:e[node])
    {
        if(u!=par)
        {
            dfs(u,node,ans[node]);
        }
    }
    if(p)
    {
        d[x]=y;
    }
}

main()
{
    int n;
    cin>>n;
    d.resize(n+1);
    for(int i=1; i<=n; i++)
    {
        d[i]=2e9;
    }
    d[0]=-1e9;

    for(int i=1; i<=n; i++)
        cin>>c[i];
    for(int i=1; i<=n-1; i++)
    {
        int a,b;
        cin>>a>>b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<'\n';

}



Measured memory_bytes: 30888
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ITP1
{
    class ITP1_2_A
    {
        static void Main(string[] args)
        {
            int a = 0, b = 0;

            List<int> numberList = Console.ReadLine().Split(' ').Select(int.Parse).ToList<int>();

            a = numberList[0];
            b = numberList[1];

            if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a == b)
            {
                Console.WriteLine("a == b");
            }
        }
    }
}



Measured memory_bytes: 18352
#include <iostream>
#include <math.h>

using namespace std;

int main(){
  int N, D;
  cin >> N >> D;
  double X[N][D];

  for(int i = 0 ; i < N; i++){
    for(int j = 0; j < D; j++){
      cin >> X[i][j];
    }
  }
  double dis = 0;
  int ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1 ; j < N; j++){
      dis = 0;
      for(int k = 0; k < D; k++){
        dis += pow((X[i][k]-X[j][k]), 2);
      }
      dis = sqrt(dis);
      //cout << dis << " " << (int)dis << endl;
      if((int)dis == dis)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
    (A+B)%2==0?cout<<(A+B)/2<<endl:cout<<NO<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
/* Coding space */
int main(){
  set<int> si;
  int n; cin >> n;
  rep(i,n){
    char s; cin >> s;
    si.insert(s);
  }
  cout << (si.size() == 3?"Three":"Four") << endl;
}

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


int N;
vector<ll> A, B;


void input() {
    cin >> N;
    A = B = vector<ll>(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
}


int main() {
    input();
    vector<ll> p2{1};
    rep(i, 30) p2.push_back(p2[i] * 2);
    
    ll ans = 0;
    for (int i = 29; i >= 0; i--) {
        rep(j, N) {
            A[j] %= p2[i + 1];
            B[j] %= p2[i + 1];
        }
        sort(B.begin(), B.end());
        ll s = 0;
        for (ll a : A) {
            auto x = lower_bound(B.begin(), B.end(), p2[i] - a);
            auto y = lower_bound(B.begin(), B.end(), p2[i + 1] - a);
            auto z = lower_bound(B.begin(), B.end(), p2[i] + p2[i + 1] - a);
            // int v = (y - x) + (B.end() - z);
            // if (v > 0) printf("%d %d %d\n", i, a, y - B.begin());
            s += (y - x) + (B.end() - z);
        }
        ans += p2[i] * (s % 2);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3328
R, G, B, N = map(int, input().split())
ans = 0
for i in range(N//R+1):
    x = i * R
    for j in range((N-x)//G+1):
        
        y = j*G
        z = N - x-y
        if z>= 0 and z%B == 0:
            ans += 1
print(int(ans))


Measured memory_bytes: 2940
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  static int A[100000], F[100000];
  for (auto i = 0; i < N; ++i)
    cin >> A[i];
  for (auto i = 1; i < N; ++i) {
    auto f = INT_MAX;
    for (auto j = 1; j <= min(K, i); ++j)
      f = min(f, F[i - j] + abs(A[i] - A[i - j]));
    F[i] = f;
  }
  printf("%d\n", F[N - 1]);
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int gcd(int a,int b){
    int r,tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(void)
{
    int n,i,j,k,b,c,total=0;
    scanf("%d",&n);

    for(i=1;i<n+1;i++){
        for(j=1;j<n+1;j++){
            for(k=1;k<n+1;k++){
                b=gcd(i,j);
                c=gcd(k,b);
                total = total +c;
            }
        }
    }
    printf("%d\n",total);
    return 0;
}


Measured memory_bytes: 1700
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    string s;
    cin >> N >> s;
    ll ans=0;
    FOR(i,1,N){
        set<char> st0,st1,st2;
        rep(j,N){
            if(i>j){
                st0.insert(s[j]);
            }
            else{
                st1.insert(s[j]);
            }
            st2.insert(s[j]);
        }
        chmax(ans,(ll)(st0.size()+st1.size()-st2.size()));
    }
    cout << ans << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

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

int main()
{
    int N, sum = 0;
    cin >> N;
    
    if (N==7 || N==5 ||N==3){
        cout << "YES" << endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{

	public static void main(String args[]){
		FastReader sc = new FastReader();
		int i,n;
		n=sc.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		int c[]=new int[n-1];
		for(i=0;i<n;i++)
			a[i]=sc.nextInt();
		for(i=0;i<n;i++)
			b[i]=sc.nextInt();
		for(i=0;i<n-1;i++)
			c[i]=sc.nextInt();
		int sum=0;
		for(i=0;i<n;i++){
			sum+=b[a[i]-1];
			if(i!=0){
				if(a[i]-a[i-1]==1)
					sum+=c[a[i-1]-1];
			}
		}
		out.println(sum);
		out.flush();
	}

	static PrintWriter out;
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
			out=new PrintWriter(System.out);
		}
		String next(){
			while(st==null || !st.hasMoreElements()){
				try{
					st= new StringTokenizer(br.readLine());
				}
				catch (IOException e){
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String nextLine(){
			String str = "";
			try{
				str=br.readLine();
			}
			catch(IOException e){
				e.printStackTrace();
			}
			return str;
		}
	}

	static class pair{
		int first,second;
		pair(int f,int s){
			first=f;
			second=s;
		}
	}

	public static long fastexpo(long x, long y, long p){
		long res=1;
		while(y > 0){
			if((y & 1)==1)
				res= ((res%p)*(x%p))%p;
			y= y >> 1;			
			x = ((x%p)*(x%p))%p;
		}
		return res;
	}

	public static boolean[] sieve (int n) {
		boolean primes[]=new boolean[n+1];
		Arrays.fill(primes,true);
		primes[0]=primes[1]=false;
		for(int i=2;i*i<=n;i++){
			if(primes[i]){
				for(int j=i*i;j<=n;j+=i)
					primes[j]=false;
			}
		}
		return primes;
	}

	public static long gcd(long a,long b){
        return (BigInteger.valueOf(a).gcd(BigInteger.valueOf(b))).longValue();
    }

    public static void merge(int a[],int l,int m,int r){
        int n1,n2,i,j,k;
        n1=m-l+1;
        n2=r-m;

        int L[]=new int[n1];
        int R[]=new int[n2];

        for(i=0;i<n1;i++)
            L[i]=a[l+i];
        for(j=0;j<n2;j++)
            R[j]=a[m+1+j];

        i=0;j=0;

        k=l;
        while(i<n1&&j<n2){
            if(L[i]<=R[j]){
                a[k]=L[i];
                i++;
            }
            else{
                a[k]=R[j];
                j++;
            }
            k++;
        }

        while(i<n1){
            a[k]=L[i];
            i++;
            k++;
        }
        while(j<n2){
            a[k]=R[j];
            j++;
            k++;
        }
    }
    public static void sort(int a[],int l,int r){
        int m;
        if(l<r){
            m=(l+r)/2;
            sort(a,l,m);
            sort(a,m+1,r);
            merge(a,l,m,r);
        }
    }
}



Measured memory_bytes: 22740
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector> 
using namespace std;

int main(){
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		ans+=b-a+1;
	}
	printf("%d\n",ans);
	return 0;
}
/*
A
int main(){
	int n;
	scanf("%d",&n);
	if(n%10==9||n/10==9) printf("Yes\n");
	else printf("No\n");
	return 0;
} 
*/


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Knight solver = new Knight();
        solver.solve(1, in, out);
        out.close();
    }

    static class Knight {
        public static int MOD = 1000000007;
        static long[] fac;
        static long[] finv;
        static long[] inv;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();

            if ((x + y) % 3 != 0) {
                out.println(0);
                return;
            }

            int n = (2 * y - x) / 3;
            int m = (2 * x - y) / 3;

            if (n < 0 || m < 0) {
                out.println(0);
                return;
            }

            comInit(n + m);
            out.println(com(n + m, n));

        }

        static void comInit(int max) {
            fac = new long[max + 1];
            finv = new long[max + 1];
            inv = new long[max + 1];

            // 階乗
            fac[0] = fac[1] = 1;
            // 逆元の階乗
            finv[0] = finv[1] = 1;
            // 逆元
            inv[1] = 1;

            for (int i = 2; i <= max; i++) {
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
            }
        }

        static long com(int n, int k) {
            if (n < k) {
                return 0;
            }
            return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
        }

    }
}



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


int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin >> n;
	
	int a[n];
	int b[n];
	
	for(int i =0 ;i < n;i++)
	{
		cin >> a[i];
		b[i]=i+1;
	}
	
	int cnt=0;
	int j=0;
	for(int i =0 ;i < n;i++)
	{
		if(b[j]== a[i])
		{
			j++;
		}
	}
	
	if(j==0)
		cout<<-1;
	else
		cout<< n-j;
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}


Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, a, b = map(int, input().split())
    X = list(map(int, input().split()))

    res = 0
    for i in range(1, n):
        res += min((X[i] - X[i - 1]) * a, b)
    print(res)


if __name__ == '__main__':
    resolve()


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

const int MAX_N = 10e5;

typedef struct edge {
    int vertex;
    int length;
} Edge;

void dfs(int vrt, vector<Edge> Graph[MAX_N + 1], int color[MAX_N + 1], int clr = 0, int len = 0) {
    color[vrt] = (clr + len) % 2;
    for (int i = 0; i < Graph[vrt].size(); i++) {
        int new_vrt = Graph[vrt][i].vertex;
        int new_len = Graph[vrt][i].length;
        if (color[new_vrt] != -1) continue;
        dfs(new_vrt, Graph, color, color[vrt], new_len);
    }
    return;
}

int main() {
    int N, u[MAX_N - 1], v[MAX_N - 1], w[MAX_N - 1];
    cin >> N;
    for (int i = 0; i < N-1; i++) {
        cin >> u[i] >> v[i] >> w[i];
    }

    vector<Edge> Graph[MAX_N + 1];
    for (int i = 0; i < N-1; i++) {
        Graph[u[i]].push_back(Edge{v[i], w[i]});
        Graph[v[i]].push_back(Edge{u[i], w[i]});
    }

    int color[MAX_N + 1];
    for (int i = 1; i <= N; i++) color[i] = -1;

    dfs(1, Graph, color);

    for (int i = 1; i <= N; i++) cout << color[i] << endl;
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  while(cin >> n >> m){
    if(n + m == 0){
      break;
    }
    vector<int> v;
    int a;
    rep(i,n){
      cin >> a;
      v.pb(a);
    }
    rep(i,m){
      cin >> a;
      v.pb(a);
    }
    sort(all(v));
    int res = v[0];
    REP(i,1,m+n){
      res = max(res,v[i]-v[i-1]);
    }
    cout << res << endl;
  }
  return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

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

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;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size,-1) { }

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

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

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

	bool connect(int x , int y){
		x = root(x);
		y = root(y);

		if(x==y) return false;

		if(data[x] > data[y]){
			x ^= y;
			y ^= x;
			x ^= y;
		}

		data[x] = data[x] + data[y]; // membersize++
		data[y] = x;
		return true;
	}
};

UnionFind U(100002);
int main() {
	int N,M;
	cin >> N >> M;
	vector<int> A(N+1);
	vector<int> X(M);
	vector<int> Y(M);
	vector<int> Z(M);


	REP(i,M){
		int x,y,z;
		cin >> x >> y >> z;
		z = z % 2;
		X[i] = x; Y[i] = y; Z[i] = z;
		U.connect(x,y);
	}
	ll ans = 0;

	FORq(i,1,N){
		if (U.root(i) == i) ans++;
	}

	cout << ans << "\n";
}


Measured memory_bytes: 2176