akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
using namespace std;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n,n){
        int Na = n+1;
        int a[12*12] = {};
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin >> a[i*Na+j];
                a[n*Na+j] += a[i*Na+j];
                a[i*Na+n] += a[i*Na+j];
            }
            a[n*Na+n] += a[i*Na+n];
        }
        for(int i=0;i<Na;i++){
            for(int j=0;j<Na;j++){
                printf("%5d",a[i*Na+j]);
            }
            printf("\n");
        }
    }
    return 0;
}


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



int main()
{
    ll n , m;
    cin>>n>>m;
    pair<ll , ll> *student = new pair<ll, ll> [n];
    pair<ll , ll> *cpoint = new pair<ll, ll> [m];
    for(ll i=0;i<n;i++)
    {
         cin>>student[i].first >>student[i].second;
    }
    for(ll i=0;i<m;i++)
    {
        cin>>cpoint[i].first >>cpoint[i].second;
    }
    for(int i=0;i<n;i++)
    {
        ll ans =0;
        ll minD = LLONG_MAX;
        for(int j=0;j<m;j++)
        {
            ll temp = abs( student[i].first - cpoint[j].first) +  abs( student[i].second - cpoint[j].second);

            if( temp < minD)
            {
                minD = temp;
                ans = j;

            }
        }
        cout<<ans+1<<endl;
    }

}

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

using namespace std;

int main(){
    string s, t;
    int a, b;
    string u;
    cin>>s>>t>>a>>b>>u;
    if(s==u){
        a--;
    }
    else if(u==t){
        b--;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

s1 = set()
s2 = set()
s3 = set()

for i in S:
  for j in s2:
    s3.add(j+i)
  for k in s1:
    s2.add(k+i)
  s1.add(i)

print(len(s3))

Measured memory_bytes: 9220
N = int(input())
A = [0]
visited = [False]
for i in range(N):
    A.append(int(input()))
    visited.append(False)

idx = 1
ans = 0
while idx != 2 and visited[idx] == False:
    visited[idx] = True
    idx = A[idx]
    ans += 1
if idx == 2:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 7876
#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 all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

int main() {
  int n; cin >> n;
  set<int> s;

  vector<ll> a(n);
  REP(i, n){
    cin >> a[i];
    if(s.find(a[i]) != s.end()) s.erase(a[i]);
    else s.insert(a[i]);
  }

  cout << (int)s.size() << endl;

  return 0;
}


Measured memory_bytes: 5760
// A - Rating Goal

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int R, G;
	cin >> R >> G;

	int ans = 2 * G - R;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use proconio::*;
const MOD: usize = 1000000007;

fn main() {
    input!{
        n: usize,
    }

    let mut ans = vec![0usize; 4];
    ans[0] = 1usize;

    for _ in 0..n {
        let tmp = ans.clone();
        ans[0] = tmp[0] * 8 % MOD;
        ans[1] = (tmp[1] * 9 + tmp[0]) % MOD;
        ans[2] = (tmp[2] * 9 + tmp[0]) % MOD;
        ans[3] = (tmp[1] + tmp[2] + tmp[3] * 10) % MOD;
    }

    println!("{}", ans[3]);
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int c[3][3];
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      cin >> c[i][j];
  string ans = "Yes";
  for(int i = 0; i < 3; i++){
    int d = min({c[i][0], c[i][1], c[i][2]});
    if(d > 0){
      c[i][0] -= d;
      c[i][1] -= d;
      c[i][2] -= d;
    }
    int e = min({c[0][i], c[1][i], c[2][i]});
    if(e > 0){
      c[0][i] -= e;
      c[1][i] -= e;
      c[2][i] -= e;
    }
  }
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      if(c[i][j] > 0){
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# http://drken1215.hatenablog.com/entry/2020/01/12/011700

def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    *a, = map(int, input().split())

    # -+-+-+-prepare combination-+-+-+-
    # -+-+-+-START-+-+-+-
    fact = [0] * (N + 1)
    fact[0] = 1
    fact[1] = 1
    for x in range(2, N + 1):
        fact[x] = x * fact[x - 1] % MOD

    invs = [1] * (N + 1)
    invs[N] = pow(fact[N], MOD - 2, MOD)
    for x in range(N - 1, 0, -1):
        invs[x] = invs[x + 1] * (x + 1) % MOD

    def cmb(n, r):
        if n - r < r: return cmb(n, n - r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return (((fact[n] * invs[r]) % MOD) * invs[n - r]) % MOD

    # -+-+-+-END-+-+-+-

    dp = [0] * (N + 1)
    dp[0] = 1

    for i, ai in enumerate(a):
        ndp = [0] * (N + 1)
        for counted in range(N + 1):
            for to_count in range(min(N - counted, ai) + 1):
                ndp[counted + to_count] = (
                                                  ndp[counted + to_count]
                                                  + dp[counted]
                                                  * cmb(N - counted, to_count)
                                                  * cmb(N - to_count, ai - to_count)
                                          ) % MOD
        dp = ndp

    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 78044
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DCandidatesOfNoShortestPaths {
        private static final int INFINITY = Integer.MAX_VALUE / 3;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();

            int[][] adj = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    adj[i][j] = INFINITY;
                }
            }

            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1, b = in.nextInt() - 1, c = in.nextInt();
                adj[a][b] = adj[b][a] = c;
            }

            int[][] shortest = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    shortest[i][j] = adj[i][j];
                }
            }

            for (int k = 0; k < n; k++) {
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        shortest[i][j] = Math.min(shortest[i][j], shortest[i][k] + shortest[k][j]);
                    }
                }
            }

            int answer = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if (shortest[i][j] < adj[i][j] && adj[i][j] < INFINITY) {
                        answer++;
                    }
                }
            }

            out.println(answer / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 23624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
    int K,N;
    cin>>K>>N;
    vector<int>A(N);
    int ans=K;
     int m=0;
    rep(i,N){
        cin>>A[i];
        if(i!=0){
            if(m<abs(A[i]-A[i-1])){
                m=abs(A[i]-A[i-1]);
            }
        }
    }
    if(m<K-abs(A[0]-A[N-1])){
        m=K-abs(A[0]-A[N-1]);
    }
    cout<<ans-m<<endl;
}

Measured memory_bytes: 4016
#include "bits/stdc++.h"
using namespace std;

const long long MOD = 1000000007;

long long LDP(long long N) {
	long long COUNT = 0, BIT[64] = {};
	for (int i = 0; i < 64; i++) {
		BIT[i] = N % 2;
		N /= 2;
	}
	long long Cur = 1, END = 0;
	for (int i = 0; i < 64; i++) {
		if (BIT[i] == 1) {
			END = Cur;
			Cur *= 1;
			Cur %= MOD;
		}
		else {
			Cur *= 2;
			Cur %= MOD;
		}
	}
	COUNT = END;
	bool flag = true;
	for (int i = 63; i >= 0; i--) {
		if (BIT[i] == 0) continue;
		Cur = 1, END = 0;
		if (flag) {
			for (int j = 0; j < i; j++) {
				COUNT += Cur;
				COUNT %= MOD;
				Cur *= 3;
				Cur %= MOD;
			}
			flag = false;
			continue;
		}
		for (int j = 0; j < 64; j++) {
			if (j < i) {
				Cur *= 3;
				Cur %= MOD;
			}
			else {
				if (BIT[j] == 1 && i != j) {
					END = Cur;
					Cur *= 1;
					Cur %= MOD;
				}
				else {
					Cur *= 2;
					Cur %= MOD;
				}
			}
		}
		COUNT += END;
		COUNT %= MOD;
	}
	return COUNT;
}

long long RDP(long long N) {
	long long COUNT = 0, BIT[64] = {};
	for (int i = 0; i < 64; i++) {
		BIT[i] = N % 2;
		N /= 2;
	}
	long long Cur = 1, END = 0;
	for (int i = 0; i < 64; i++) {
		if (BIT[i] == 1) {
			END = Cur;
			Cur *= 2;
			Cur %= MOD;
		}
		else {
			Cur *= 1;
			Cur %= MOD;
		}
	}
	COUNT = END;
	bool flag = true;
	for (int i = 63; i >= 0; i--) {
		if (BIT[i] == 0) continue;
		Cur = 1, END = 0;
		if (flag) {
			for (int j = 0; j < i; j++) {
				COUNT += Cur;
				COUNT %= MOD;
				Cur *= 3;
				Cur %= MOD;
			}
			flag = false;
			continue;
		}
		for (int j = 0; j < 64; j++) {
			if (j < i) {
				Cur *= 3;
				Cur %= MOD;
			}
			else {
				if (BIT[j] == 1 && i != j) {
					END = Cur;
					Cur *= 2;
					Cur %= MOD;
				}
				else {
					Cur *= 1;
					Cur %= MOD;
				}
			}
		}
		COUNT += END;
		COUNT %= MOD;
	}
	return COUNT;
}

int main() {
	long long L, R;
	cin >> L >> R;
	if (L == R) {
		cout << 1 << endl;
		return 0;
	}
	while (1) {
		long long LMBS = 1, RMBS = 1;
		while (L > LMBS * 2) LMBS *= 2;
		while (R > RMBS * 2) RMBS *= 2;
		if (LMBS != RMBS) break;
		if (L == LMBS || R == RMBS) break;
		L -= LMBS;
		R -= RMBS;
	}
	cout << (RDP(R) - LDP(L - 1) + MOD) % MOD << endl;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n = int(input())
    maxv = -10 ** 9
    minv = int(input())

    for _ in range(1, n):
        temp = int(input())
        maxv = temp - minv if temp - minv > maxv else maxv
        minv = temp if temp < minv else minv

    print(maxv)



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

int main()
{
	int N ,L; 
	int last=0;
	cin >> N >> L;

	int a[N+3];
	cin >> a[1];

	for(int i=1; i<N ; i++)
	{
		cin >> a[i+1];
		if(a[i+1]+a[i] >= L )
		{
			last = i;
			break;
		}
	}

	if(last != 0)
	{
		cout << "Possible" << endl;
		for(int i=1;i<last;i++)
		{
			cout << i << endl;
		}
		for(int i=N-1;i>last-1;i=i-1)
		{
			cout << i << endl;
		}
	}else{
		cout << "Impossible" << endl;
	}

	return 0;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

bool isPrime(ll n) {
    if (n < 2)return false;
    for (ll i = 2; i * i <= n; i++)if (!(n % i))return false;
    return true;
}

int main() {
    init();

    int n; cin >> n;
    eFOR(i, n, INF)if (isPrime(i)) {
        cout << i << "\n";
        break;
    }
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000
 
typedef struct node_tbl
{
    int key;
    int parent;
    int left;
    int right;
} node;
 
const int nil = -1;
node t[MAX_N + 1];
int root;
int ix;
 
void
insert(int k)
{
    int y = nil;
    int x = root;
    int z = ix++;
 
    t[z].key = k;
    t[z].left = nil;
    t[z].right = nil;
 
    while (x != nil)
    {
        y = x;
        if (t[z].key < t[x].key)
            x = t[x].left;
        else
            x = t[x].right;
    }
 
    t[z].parent = y;
    if (y == nil)
        root = z;
    else
    {
        if (t[z].key < t[y].key)
            t[y].left = z;
        else
            t[y].right = z;
    }
}
 
void
inorder(int u)
{
    if (u == nil)
        return;
 
    inorder(t[u].left);
    printf(" %d", t[u].key);
    inorder(t[u].right);
}
 
void
preorder(int u)
{
    if (u == nil)
        return;
 
    printf(" %d", t[u].key);
    preorder(t[u].left);
    preorder(t[u].right);
}
 
int
main(int argc, char** argv)
{
    char command[8];
    int n;
    int x;
    int i;
 
    root = nil;
    ix = 0;
    scanf("%d", &n);
    for (i = 0; i < n; ++i)
    {
        scanf("%s", command);
        if(command[0] == 'i')
        {
            scanf("%d",&x);
            insert(x);
        }else if(command[0] == 'p')
        {
            inorder(root);
            printf("\n");
            
            preorder(root);
            printf("\n");
        }
    }
 
    return 0;
}


Measured memory_bytes: 9556
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*
ll dx[8]={-1,-1,-1,0,0,1,1,1};
ll dy[8]={-1,0,1,-1,1,-1,0,1};
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}
*/
int main()
{
     ll n,m,a,b;
     cin>>n>>m;
     vector<pair<ll,ll> > v1,v2;
     for(int i=0;i<n;i++)
     {
         cin>>a>>b;
         v1.pb({a,b});
     }
     for(int i=0;i<m;i++)
     {
         cin>>a>>b;
         v2.pb({a,b});
     }
     ll pos;
     vector<ll> vec;
     for(int i=0;i<v1.size();i++)
     {
         ll mx=INT_MAX;
         for(int j=0;j<v2.size();j++)
         {
             ll dis=abs(v1[i].f-v2[j].f)+abs(v1[i].s-v2[j].s);
             //cout<<mx<<endl;
             if(dis<mx)
             {
                 pos=j+1;
                 mx=dis;
             }
         }
         vec.pb(pos);
     }
     for(int i=0;i<vec.size();i++)
        cout<<vec[i]<<endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n ; 
	cin >> n; 
	int ct = 0 ;
	rep(i,1,n+1){
		if(i&1) ct++;
	}
	cerr<< ct << endl;
	cout << fixed << setprecision(9) << ((ld)ct/n) << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3744
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  string s;
  cin >> s;
  map<char,ll> m;

  rep(i,sz(s)) m[s[i]]++;

  ll mm = min(m['a'], min(m['b'], m['c']));

  m['a'] -= mm;
  m['b'] -= mm;
  m['c'] -= mm;

  ll sum = m['a'] + m['b'] + m['c'];

  bool flg = false;
  if(sum < 3)
  {
    flg = true;
  }

  if(sum == 2)
  {
    ll cnt = 0;
    for(auto it:m)
    {
      if(it.second > 0)
      {
        cnt++;
      }
    }
    if(cnt == 1)
    {
      flg = false;
    }
  }

  if(flg) cout << "YES" << endl;
  else cout << "NO" << endl;

}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 200005
#define pb push_back
#define S second
#define pb push_back
#define mp make_pair
#define INF 1e16
#define fr(i,j,k) for(ll i=j;i<=k;i++)
#define frd(i,j,k) for(ll i=j;i>=k;i--)
#define F first
#define sd(n) scanf("%lld",&n)
#define pd(n) printf("%lld\n",n)
#define db double
#define mod 1000000007
#define pii pair<ll,ll>
int main()
{
    ll n;
    cin>>n;
    ll o=0,e=0;
    ll x;
    if(n==1)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    while(n--)
    {
        sd(x);
        if(x&1)
            o++;
        else e++;
    }

    if(o&1)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;

    

}

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

int main() {
  int N, K, sum, x;
  cin >> N;
  cin >> K;
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    sum += min(abs(x - K), abs(x)) * 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int N;
    cin >> N;
    int count_diff_place = 0;;
    REP(i, N) {
    	int p;
    	cin >> p;
    	if (p != i + 1) count_diff_place++;
    }

    string ans;
    if (count_diff_place == 0 || count_diff_place == 2) {
    	ans = "YES";
    }
    else {
    	ans = "NO";
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import math

N, A, B = map(int, input().split())

h = []
min_h = 10 ** 10
max_h = 0
for _ in range(N):
    hi = int(input())
    if hi < min_h:
        min_h = hi
    if hi > max_h:
        max_h = hi
    h.append(hi)
    
min_K = math.ceil(min_h / A)
max_K = math.ceil(max_h / B)
K = min_K
while(min_K != max_K):
    x = [math.ceil((n - K * B) / (A - B)) for n in h]
    sum_x = sum([xi for xi in x if xi > 0])
    if sum_x <= K:
        max_K = K
        K = int((min_K + K) / 2)
    else:
        min_K = K + 1
        K = int((K + max_K) / 2) + 1

print(min_K)

Measured memory_bytes: 15172
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i = 0;i < 3;i++){
    if(s[i] == '1'){
      s[i] = '9';
    }else{
      s[i] = '1';
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

struct SegTree(alias _fun, alias def, T)
if (is(typeof(def) : T))
{
    import std.functional : binaryFun;
    alias fun = binaryFun!_fun;

    ///
    this(size_t n, T[] ts) {
        this.n = 1;
        while (this.n < n) this.n *= 2;
        this.tree.length = this.n * 2 - 1;
        foreach (ref e; this.tree) e = def;
        foreach (i, e; ts) this.put(i, e);
    }

    ///
    void put(size_t i, T e) {
        i += this.n - 1;
        this.tree[i] = e;
        while (i > 0) {
            i = (i-1) / 2;
            this.tree[i] = fun(this.tree[i*2+1], this.tree[i*2+2]);
        }
    }

    ///
    T query(size_t a, size_t b) {
        T impl(size_t i, size_t l, size_t r) {
            if (r <= a || b <= l) return def;
            if (a <= l && r <= b) return this.tree[i];
            return fun(
                impl(i*2+1, l, (l+r)/2),
                impl(i*2+2, (l+r)/2, r)
            );
        }
        return impl(0, 0, this.n);
    }

private:
    size_t n;
    T[] tree;
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(size_t n, T[] arr = [])
{
    return SegTree!(f, def, T)(n, arr);
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(T[] arr)
{
    return SegTree!(f, def, T)(arr.length, arr);
}

enum P = 998244353L;

alias R = Tuple!(long, "x", long, "d");

void main()
{
    auto N = readln.chomp.to!long;
    R[] rs;
    foreach (_; 0..N) {
        auto xd = readln.split.to!(long[]);
        rs ~= R(xd[0], xd[1]);
    }
    sort!"a.x < b.x"(rs);

    auto RS = new long[](N);
    foreach_reverse (i; 0..N) {
        if (i == N-1) {
            RS[i] = i;
            continue;
        }
        if (rs[N-1].x < rs[i].x + rs[i].d) {
            RS[i] = N-1;
            continue;
        }
        auto l = i, r = N-1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (rs[m].x >= rs[i].x + rs[i].d) {
                r = m;
            } else {
                l = m;
            }
        }
        RS[i] = l;
    }

    auto DS = new long[](N);
    foreach (i; 0..N) {
        DS[i] = RS[i];
    }
    auto segt = seg_tree!("a > b ? a : b", 0, long)(DS);
    foreach_reverse (i; 0..N) {
        RS[i] = segt.query(i, RS[i]+1);
        segt.put(i, RS[i]);
    }

    auto DP = new long[](N);
    DP[] = -1;
    long solve(long i) {
        if (i == N) return 1;
        if (DP[i] == -1) {
            DP[i] = (solve(i+1) + solve(RS[i]+1)) % P;
        }
        return DP[i];
    }
    writeln(solve(0));
}

Measured memory_bytes: 29692
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    readln;
    auto s = readln.chomp;
    string k;
    string kk;
    string l;
    int p;

    foreach (c; s) {
        switch (c) {
            case '(':
                if (!p++) {
                    kk ~= k;
                    k = "";
                }
                k ~= '(';
                break;
            case ')':
                if (p) {
                    --p;
                    k = k ~ ')';
                } else {
                    kk = '(' ~ kk;
                    k ~= ')';
                }
                break;
            default:
        }
    }
    while (p--) k ~= ')';

    writeln(kk ~ k);
}

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

int main(){
  int a;
  cin>>a;
  rep(i,9){
    if(a%(i+1)==0&&a/(i+1)<=9){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

//結合可能
int N,M;
int c[100001] = {};
int main(){
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int a,b;
		cin >> a >> b;
		c[a]++;
		c[b]++;
	}
	bool flg = true;
	for(int i=0; i<=N; i++){
		if(c[i]%2 == 1) flg = false;
	}
	if(flg) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	string S;
	cin >> S;
	int i;
	for (i = 0; i < S.size(); ++i)
	{
		if (S[i] == 'L' && i % 2 == 0)
		{
			cout << "No" << endl;
			return 0;
		}
		if (S[i] == 'R' && i % 2 != 0)
		{
			cout << "No" << endl;
			return 0;
		}
		
	}
	cout << "Yes" << endl;
	return 0;
}



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

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


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main(void){
    int A, B;
    cin >> A >> B;

    int ret;
    if(A>12)
        ret = B;
    else if(A<6)
        ret = 0;
    else
        ret = B/2;

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


Measured memory_bytes: 256
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n,m = map(int, input().split())
    ma = [0]*n
    hl = list(map(int, input().split()))
    for i in range(m):
        a,b = map(int, input().split())
        ma[a-1] = max(ma[a-1], hl[b-1])
        ma[b-1] = max(ma[b-1], hl[a-1])
    for i in range(n):
        if hl[i] > ma[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21116
#include<iostream>

using namespace std;

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

const int MAX = 1000000;

bool prime[MAX];
int c[MAX];

int main() {
  rep (i, MAX) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 0; i * i <= MAX; ++i) {
    if (prime[i]) {
      for (int j = i * i; j < MAX; j += i) prime[j] = false;
    }
  }
  rep (i, MAX - 1) c[i + 1] = c[i] + (prime[i + 1] ? 1 : 0);
  int n;
  while (cin >> n) {
    cout << c[n] << endl;
  }
}

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

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

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<string> count;
  string w, p_w;
  cin >> p_w;
  count.push_back(p_w);
  REPI(i, 1, N) {
    cin >> w;
    if (p_w.back() != w.front()) {
      cout << "No" << endl;
      return 0;
    }

    if (find(count.begin(), count.end(), w) != count.end()) {
      cout << "No" << endl;
      return 0;
    }

    count.push_back(w);
    p_w = w;
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()

ans = 0
drink = 0
for i in range(N):
  if drink + AB[i][1] <= M:
    ans += AB[i][0] * AB[i][1]
    drink += AB[i][1]
  else:
    if drink == M:
      break
    else:
      n = M - drink
      ans += n * AB[i][0]
      drink = M

print(ans)

Measured memory_bytes: 27876
n = int(input())
a = list(map(int, input().split()))
prod_sum = 0
sum_arr = [0]*n
sum_arr[n-1] = a[n-1]
for i in range(n-2, -1, -1):
    sum_arr[i] = sum_arr[i+1] + a[i]
for i in range(n-1):
        prod_sum += a[i]*sum_arr[i+1]
print(prod_sum%(10**9+7))


Measured memory_bytes: 105304
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
main(){
  string huda;
  int m,hito=0,kaiba=0;
  while(1){
    kaiba=0;
    hito=0;
    cin>>m;
    if(m==0){
      break;
    }
    int n[m+1];
    cin>>huda;
    for(int i=0;i<m;i++){
      n[i]=0;
    }
    for(int i=0;i<100;i++){
      if(huda[i]=='M'){
	n[hito]++;
      }else if(huda[i]=='S'){
	kaiba+=n[hito]+1;
	n[hito]=0;
    }else{
	n[hito]+=kaiba+1;
	kaiba=0;
      }
      hito++;
      if(hito==m){
	hito=0;
      }
    }
    for(int j=0;j<m;j++){
      for(int i=0;i<m-1;i++){
	if(n[i]>n[i+1]){
	  int temp=n[i];
	  n[i]=n[i+1];
	  n[i+1]=temp;
	}
      }
    }
    for(int i=0;i<m;i++){
      cout<<n[i];
      cout<<' ';
    }
    cout<<kaiba<<endl;
  }
  return(0);
}



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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long


signed main()
{
  int w, h, n;  cin >> w >> h >> n;
  int xmin,    xmax,    ymin,    ymax;
      xmin = 0;xmax = w;ymin = 0;ymax = h;
  
  int x, y, a;
  for(int i = 0;i < n;i++){
    cin >> x >> y >> a;
    
    if((a == 1) && (xmin <= x)){
      xmin = x;
    }
    
    else if((a == 2) && (xmax >= x)){
      xmax = x;
      if(xmax < xmin){
        xmax = xmin;
      }
    }
    
    else if((a == 3) && (ymin <= y)){
      ymin = y;
    }
    
    else if((a == 4) && (ymax >= y)){
      ymax = y;
      if(ymax < ymin){
        ymax = ymin;
      }
    }
  }
  
  cout << (xmax - xmin) * (ymax -  ymin) << endl;
  return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint {
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
  operator ll() const { return v; }
  mint pow(ll t) const;
  mint inv() const;
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return (mint)0 - a; }
mint& operator/=(mint& a, mint b) { return a *= b.inv(); }
mint operator/(mint a, mint b) { return a /= b; }
mint mint::pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t >> 1);
  a *= a;
  if (t & 1) a *= *this;
  return a;
}
mint mint::inv() const { return pow(MOD - 2); }
bool operator==(mint a, mint b) { return a.v == b.v; }
bool operator!=(mint a, mint b) { return a.v != b.v; }
istream& operator>>(istream& os, mint& a) { return (os >> a.v); }
ostream& operator<<(ostream& os, const mint& a) { return (os << a.v); }

mint mfact(int n) { // n! (mod MOD)
  static vector<mint> fact(1, 1);
  int pn = fact.size();
  if (pn < n + 1) {
    fact.resize(n + 1);
    for (int i = pn; i <= n; i++) fact[i] = fact[i - 1] * (mint)i;
  }
  return fact[n];
}
mint nPk(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  if (k == 0) return 1;
  return mfact(n) * mfact(n - k).inv();
}
mint nCk(int n, int k) {
  if (n < 0 || k < 0 || n < k) return 0;
  if (k == 0) return 1;
  return mfact(n) * mfact(k).inv() * mfact(n - k).inv();
}

mint f(int r, int c) {
  mint res = 0;
  // for (int i = 1; i <= r; i++) {
  //   res += nCk(i + c + 1, c) - (mint)1;
  // }
  res = nCk(r + 1 + c + 1, r + 1) - nCk(c + 1, 1) - (mint)1;
  return res;
}

void solve() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  if (abs(r2 - r1) > abs(c2 - c1)) {
    swap(r1, c1);
    swap(r2, c2);
  }
  dump(r1, r2, c1, c2);
  mint ans = 0;
  ans = f(r2, c2) - f(r1 - 1, c2) - f(r2, c1 - 1) + f(r1 - 1, c1 - 1);
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 32632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N)
{
    cout << (N - 1) / 2 << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


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

int n, h[100005];
int main(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> h[i];
    reverse(h, h+n);
    for(int i = 1; i < n; i++){
        if(h[i] > h[i-1] && h[i]-h[i-1] > 1){ cout << "No"; return 0; }
        if(h[i] > h[i-1]) h[i]--;
    }
    cout << "Yes";
}


Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0; i<n; i++)
    cin>>v[i];
  sort(v.begin(), v.end());
  std::cout <<  v[n/2]-v[n/2-1] << std::endl;
  return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
while(true){
int a = scan.nextInt();
char op = scan.next().charAt(0);
int b = scan.nextInt();

if(op == '?'){break;}

if(op == '+'){System.out.println(a + b);}

if(op == '-'){System.out.println(a - b);}

if(op == '*'){System.out.println(a * b);}

if(op == '/'){System.out.println(a / b);}
}}}

Measured memory_bytes: 26296
mod = pow(10, 9) + 7

N = pow(10, 6)

fact = [0]*N
inv = [0]*N

fact[0] = inv[0] = 1
inv[1] = fact[1] = 1
for i in range(2, N):
	fact[i] = (i*fact[i-1])%mod
	inv[i] = pow(fact[i], mod-2, mod)

def ncr(n, r):
	return (fact[n]*inv[r]*inv[n-r])%mod

X, Y = map(int, input().split())

if (X + Y)%3 != 0:
	print(0)
else:
	m = (2*Y - X)//3
	n = (X - m)//2
	if n < 0 or m < 0:
		print(0)
	else:
		ans = ncr(n+m, n)
		print(ans)

Measured memory_bytes: 56304
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

typedef pair<int, int> P;



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

    int ans = 0;
    for(int i=1; i < n-1; i++) {
        vector<int> tmp(3);
        tmp[0] = p[i-1];
        tmp[1] = p[i];
        tmp[2] = p[i+1];
        sort(tmp.begin(),tmp.end());
        if(tmp[1] == p[i]) ans++;
    }

    cout << ans << endl;
    return 0;


}


Measured memory_bytes: 256
while true
    n = gets.to_i
    break if n == 0
    sum = 0
    n.times{
        x, y, h, w = gets.chomp.split.map(&:to_i)
        s = x + y + h
        fee = 0
        if s <= 60 && w <= 2
            fee = 600
        elsif s <= 80 && w <= 5
            fee = 800
        elsif s <= 100 && w <= 10
            fee = 1000
        elsif s <= 120 && w <= 15
            fee = 1200
        elsif s <= 140 && w <= 20
            fee = 1400
        elsif s <= 160 && w <= 25
            fee = 1600
        end
        sum += fee
    }
    puts sum
end



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

int main()
{
	int n,ans=0,dis=0;
	cin>>n;
	int ar[n];
	int i=0;
	for(i=0;i<n;i++){
		cin>>ar[i];
	}
	sort(ar,ar+n);
	for(i=0;i<n-1;i++){
		dis=ar[i+1]-ar[i];
		ans=ans+dis;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 256
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
B = list(map(int,stdin[1].split()))
A = [0]*N
A[0] = B[0]
A[N-1] = B[N-2]
for i in range(1,N-1):
    A[i] = min(B[i],B[i-1])
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,Y,A=-1,B=-1,C=-1;
  cin>>N>>Y;Y/=1000;
  for(int i=0;i<=N;i++)
    for(int j=0;j<=N-i;j++)
      if(9*i+4*j+N==Y)
          A=i,B=j,C=N-i-j;
  cout<<A<<" "<<B<<" "<<C<<endl;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{

  int a,b,c;
  int ans = 0;
  
  scanf("%d%d%d", &a, &b, &c);


  if( a < b ){
    if( b < c ) ans++;
    }
  
  if( ans ) {printf("Yes\n");}
  else      {printf("No\n"); }
       
  return 0;

}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    string s;
    while(cin>>s)
    {
        printf("2018");
        for(int i=4;i<s.size();i++)
        {
            printf("%c",s[i]);
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
module Graph
	require 'set'
	def add_node(label = nil)
		Node.new(label)
	end

	def add_edge(u, v, label = nil)
		e = Edge.new(u, v, label)
		u.outgoings << e
		v.incomings << e
		e
	end

	def del_edge(e)
		u, v = e.from, e.to
		u.outgoings.delete(e)
		v.incomings.delete(e)
		e
	end
	
	class Node
		def initialize(label)
			@label = label
			@outgoings = Set.new
			@incomings = Set.new
		end

		def to_nodes
			@outgoings.map(&:to)
		end

		def from_nodes
			@incomings.map(&:from)
		end


		def to_s
			@label
		end
		
		attr_accessor :outgoings, :incomings
		attr_reader :label
	end

	class Edge
		def initialize(u, v, label = nil)
			@from = u	
			@to = v
			@label = label
		end
		attr_reader :from, :to, :label
	end

	def each_layer_from(start)
		reached = Set[start]
		current_layer = [start]
		loop {
			yield current_layer
			next_layer = []
			current_layer.each{|u|
				u.to_nodes.each{|v|
					next if reached.include?(v)
					reached << v
					next_layer << v
				}
			}	
			break if next_layer.empty?
			current_layer = next_layer
		}
	end
end

extend Graph

n, k = gets.split.map &:to_i
orig_nodes = (0..n-1).map{|i|
	add_node([i] + gets.split.map(&:to_i)) 
}

k.times {
	i, j = gets.split.map &:to_i
	u = orig_nodes[i-1]
	v = orig_nodes[j-1]
	add_edge(u, v)
	add_edge(v, u)
}


f_dist = (1..n).map{ Float::INFINITY }
f_dist[0] = 0
f_unreached = (0..n-1).to_a
b_dist = (1..n).map{ Float::INFINITY }
b_dist[n-1] = 0
b_unreached = (0..n-1).to_a

f_min = b_min = 0
best = Float::INFINITY

loop.with_index {|_, itr|
	i = f_unreached.min_by{|i| f_dist[i]}
	break if i == n-1
	f_unreached.delete(i)
	u = orig_nodes[i]
	_, c, r = u.label
	f_min = f_dist[i]

	depth = 0	
	each_layer_from(u){|layer|
		layer.each{|v|
			j, _, _ = v.label
			d = f_dist[i] + c
			f_dist[j] = d if d < f_dist[j]
			best = d + b_dist[j] if d + b_dist[j] < best
		}
		break if depth == r
		depth += 1
	}

	i = b_unreached.min_by{|i| b_dist[i]}
	b_unreached.delete(i)
	b_min = b_dist[i]
	u = orig_nodes[i]
	depth = 0
	each_layer_from(u){|layer|
		layer.each{|v|
			j, c, r = v.label
			if depth <= r
				d = b_dist[i] + c
				b_dist[j] = d if d < b_dist[j]
				best = d + f_dist[j] if d + f_dist[j] < best
			end
		}
		depth += 1
	}
	break if f_min + b_min >= best

}
p best

Measured memory_bytes: 25400