akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

const long long MOD=1e9+7;
const long long BASE1=0x234567, BASE2=0x3456795;

long long modpow(long long b, long long e, long long p=MOD) {
    /* Exponentiation by squaring */
    // returns n == b**e (mod p)
    long long n=1, a=b%p;
    while (e) {
        if (e & 1)
            (n *= a) %= p;

        (a *= a) %= p;
        e >>= 1;
    }
    return n;
}

long long modsub(long long a, long long b, long long p=MOD) {
    // returns n == a-b (mod p)
    return ((a-b)%p+p) % p;
}

int main() {
    size_t H, W;
    scanf("%zu %zu", &H, &W);
    vector<string> F(H);
    for (size_t i=0; i<H; ++i) {
        char buf[1<<10];
        scanf("%s", buf);
        F[i] = buf;
    }

    size_t R, C;
    scanf("%zu %zu", &R, &C);
    vector<string> G(R);
    for (size_t i=0; i<R; ++i) {
        char buf[1<<10];
        scanf("%s", buf);
        G[i] = buf;
    }

    long long target=0;
    for (size_t i=0; i<R; ++i) {
        long long key=0;
        for (size_t j=0; j<C; ++j)
            ((key *= BASE2) += G[i][j]) %= MOD;

        ((target *= BASE1) += key) %= MOD;
    }

    vector<vector<long long>> t1(H, vector<long long>(W));
    vector<vector<long long>> t2(H, vector<long long>(W));
    long long pow=modpow(BASE2, C, MOD);
    for (size_t i=0; i<H; ++i) {
        long long key=0;
        for (size_t j=0; j<W; ++j) {
            ((key *= BASE2) += F[i][j]) %= MOD;
            if (j >= C)
                key = modsub(key, F[i][j-C]*pow, MOD);

            t1[i][j] = t2[i][j] = key;
        }
    }

    pow = modpow(BASE1, R, MOD);
    for (size_t i=0; i<H; ++i)
        for (size_t j=0; j<W; ++j) {
            if (i)
                (t1[i][j] += t1[i-1][j]*BASE1) %= MOD;

            if (i >= R)
                t1[i][j] = modsub(t1[i][j], t2[i-R][j]*pow, MOD);

            if (t1[i][j]==target && i+1>=R && j+1>=C)
                printf("%zu %zu\n", i-R+1, j-C+1);
        }

    return 0;
}

Measured memory_bytes: 20032
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

void dfs(int n, string s, int x) {
  if (s.size() >= n) {
    cout << s << endl;
    return;
  }
  for (int i = 0; i <= x; i++) {
    string ss = s + char('a' + i);
    dfs(n, ss, max(x, i+1));
  }
}


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

  int n; cin >> n;

  string s = "a";
  dfs(n, s, 1);

  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string base_convert(int d, int base) {
    string res = "";
    string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    while (d) {
        int r = d % base;
        if (r < 0) r -= base;
        d = (d - r) / base;
        res += chars[r];
    }
    reverse(res.begin(), res.end());
    if (res == "") res = "0";
    return res;
}

int main() {
    int N; cin >> N;
    cout << base_convert(N, -2) << endl;
    return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, M;
    cin >> N >> M;
    Vl A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    sort(A.begin(), A.end(), greater<ll>());

    ll left = 0, right = 2000000000000;
    while (right - left > 1) {
        ll mid = (left + right) >> 1;
        ll cnt = 0;
        ll idx = N - 1;
        for (int i = 0; i < N; i++) {
            while (idx >= 0 && A[i] + A[idx] < mid) --idx;
            cnt += idx + 1;
        };
        if (cnt < M) {
            right = mid;
        }
        else {
            left = mid;
        }
    }


    Vl csum(N + 1);
    for (int i = 0; i < N; i++) {
        csum[i + 1] = csum[i] + A[i];
    }

    ll cnt = 0;
    ll ans = 0;
    ll idx = N - 1;
    for (int i = 0; i < N; i++) {
        while (idx >= 0 && A[i] + A[idx] <= left) --idx;
        cnt += idx + 1;
        ans += csum[idx + 1] + A[i] * (idx + 1);
    }
    ans += left * (M - cnt);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
N = int(input())
S = [0]*4
for i in range(N):
    C = str(input())
    if C == 'AC':
        S[0] += 1
    elif C == 'WA':
        S[1] += 1
    elif C == 'TLE':
        S[2] += 1
    elif C == 'RE':
        S[3] += 1


print('AC x',S[0])
print('WA x',S[1])
print('TLE x',S[2])
print('RE x',S[3])

Measured memory_bytes: 9208
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <map>
typedef pair<int,string> word;//first:-count second:word
int main()
{
	int n;
	while(cin>>n&&n){
		vector<word> w;w.clear();
		string s,tmp;getline(cin,s);
		s="";
		while(n--){
			getline(cin,tmp);
			if(s=="")s=tmp;
			else s+=" "+tmp;
		}
		tmp="";
		char c;cin>>c;
		for(int i=0;i<s.length();i++){
			if(s[i]==' '){
				if(tmp[0]==c)w.push_back(make_pair(-1,tmp));
				tmp="";
			}else{
				tmp+=s[i];
			}
		}
		if(tmp[0]==c)w.push_back(make_pair(-1,tmp));
		int lim=w.size();
		for(int i=0;i<lim;i++){
			for(int j=i+1;j<lim;j++){
				if(w.at(i).second==w.at(j).second){
					w.at(i).first+=w.at(j).first;
					//printf("erase:%s\n",w.at(j).second.c_str());
					w.erase(w.begin()+j);
					lim--;j--;
				}
			}
		}
		if(w.empty())printf("NA\n");
		else sort(w.begin(),w.end());
		for(int i=0;i<w.size();i++){
			printf(i==w.size()-1?"%s\n":"%s ",w.at(i).second.c_str());
		}
		
	}
    return 0;
}

Measured memory_bytes: 1268
while(1):
    a = input()
    if(a == '.'):
        break
    b = input()
    n = len(a)
    m = len(b)
    l = 0
    flag = 0
    idx_dif = 0
    error_cou = 0
 
    while(1):
        if(flag == 0):
            for i in range(l,n):
                if(a[i] == '\"'):
                    if(i+idx_dif < m and a[l:i+1] == b[l+idx_dif:i+idx_dif+1]):
                        l = i+1
                        flag = 1
                    else:
                        flag = 2
                    break
 
                elif(i == n-1):
                    if(a[l:i] != b[l+idx_dif:m-1]):
                        flag = 2
                    else:
                        l = n-1
 
        elif(flag == 1):
            for i in range(l,n):
                if(a[i] == '\"'):
                    for j in range(l+idx_dif,m):
                        if(b[j] == '\"'):
                            if(a[l:i+1] != b[l+idx_dif:j+1]):
                                error_cou += 1
                            idx_dif = j-i
                            l = i+1
                            flag = 0
                            break
                        if(j == m-1):
                            flag = 2
                            break
                if(flag != 1):
                    break
 
        if(flag == 2 or l >= n-1 or l+idx_dif >= m-1):
            break
 
    if(error_cou >= 2 or flag == 2):
        print("DIFFERENT")
    elif(error_cou == 1):
        print("CLOSE")
    elif(error_cou == 0):
        print("IDENTICAL")


Measured memory_bytes: 5588
# -*- coding: utf-8 -*-
"""

"""
from itertools import combinations

if __name__ == '__main__':
    # ??????????????\???
    num1 = int(input())
    M = [int(x) for x in input().split(' ')]
    num2 = int(input())
    A = [int(x) for x in input().split(' ')]
    #A = [1, 5, 7, 10, 21]
    #pick = 4
    #M = [2, 4, 17, 8]

    # ????????????
    results = ['no' for x in range(len(A))]

    for p in range(1, len(M)+1):
        combi = combinations(M, p)
        for choice in combi:
            total = sum(choice)
            if total in A:
                while total in A:
                    i = A.index(total)
                    results[i] = 'yes'
                    A[i] = 'Done'

    # ???????????????
    for txt in results:
        print(txt)

Measured memory_bytes: 7764
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d, e, k;
	bool flg = false;
	cin >> a >> b >> c >> d >> e >> k;
	if (b - a > k) {
		flg = true;
	}
	if (c - a > k) {
		flg = true;
	}
	if (d - a > k) {
		flg = true;
	}
	if (e - a > k) {
		flg = true;
	}

	if (c - b > k) {
		flg = true;
	}
	if (d - b > k) {
		flg = true;
	}
	if (e - b > k) {
		flg = true;
	}
	if (d - c > k) {
		flg = true;
	}
	if (e - c > k) {
		flg = true;
	}
	if (e - d > k) {
		flg = true;
	}
	if (flg==false) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll a,b;cin>>a>>b;
    ll now=1;
    for(;;){
        if(now*2>b)break;
        now*=2;
    }
    for(;;){
        if(now==0)break;
        if(a<now&&b>=now)break;
        if(a>=now&&b>=now){
            a-=now;
            b-=now;
        }
        now/=2;
    }
    ll ans=now-a;
    if(now==0){
        cout<<1<<endl;
        return 0;
    }
    ll r=now;
    b-=now;
    now=1;
    for(;;){
        if(now>b)break;
        now*=2;
    }
    
    if(now<a){
        ans+=now+r-a;
    }
    else ans+=r;
    //cout<<r<<" "<<now<<endl;
    cout<<ans<<endl;
}






Measured memory_bytes: 256
from math import *

def main():
    N, M = map(int, input().split())
    if N==1:
        print(M)
        return
    special_value = M//N
    divisor_set = set(i for i in range(1, (int(sqrt(M)) + 1)) if (M % i == 0))
    divisor_set = divisor_set.union(set(M//j for j in divisor_set))
    print(int(max([i for i in divisor_set if special_value >= i])))

    return

main()

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

int main() {
    int N, K;
    int ans = 1;
    cin >> N >> K;
    rep(i, N) {
        if (ans * 2 <= ans + K) {
            ans *= 2;
        }
        else {
            ans += K;
        }
    }
    cout << ans << endl;
}


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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		boolean [] prime = new boolean [1000000];
		Arrays.fill(prime, true);
		
		for (int i = 2; i < 1000000; i++) {
			if (prime[i]) {
				for (int j = i * 2; j < 1000000; j += i) {
					prime[j] = false;
				}
			}
		}
		
		Scanner date = new Scanner(System.in);

		int num;
		
		while (date.hasNextInt()) {
			int cnt = 0;
			num = date.nextInt();
			for (int i = 2; i <= num; i++) {
				if (prime[i]) {
					cnt++;
				}
			}
			System.out.println(cnt);
		}
		
	
	}

}

Measured memory_bytes: 22084
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;
const int MOD = 1000000007;

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

    ll l,r; cin >> l >> r;

    ll ans = 1000000;
    
    for(ll i=l; i<=min(r,2019+l); i++){
        for(ll j=i+1;j<=min(r,2019+l); j++){
            ans = min(ans, i%2019*j%2019);
        }
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef MODE_DEBUG
#define  DUMP(x)  cerr << #x << " = " << (x) <<endl
#define DEBUG(x) DUMP(x) << " (L" << __LINE__ << ")" << " " << __FILE__<<endl
#define CHECK(exp,act)  if(exp!=act){DUMP(exp);DEBUG(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#else
#define DUMP(x)
#define DEBUG(x)
#define CHECK(exp,act)
#define STOP(e)
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T>>& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}


int main(){
	while(true){
		int N;ll M;cin >> N >> M;
		if(N==0 && M ==0)break;
		vector<ll> ps(N+1);//0 
		REP(i,N)cin >>ps[i];
		sort(ALL(ps));
		vector<ll> ps2((N+1)*(N+1));
		REP(i,(N+1))REP(j,(N+1))ps2[i*(N+1)+j]=ps[i]+ps[j];
		sort(ALL(ps2));		
		ll Mv=0;
		for(int i=0;i<(N+1)*(N+1);i++){
			int v1=ps2[i];

			int l=0,r=(N+1)*(N+1);
			while(r-l>1){
				int m=(l+r)/2;
				if(v1+ps2[m]<=M){
					Mv=max(Mv,v1+ps2[m]);
					l=m;
				}else{
					r=m;
				}
			}
		}
		cout << Mv<<endl;
	}
	return 0;
}

Measured memory_bytes: 9596
n = int(input())
child = {}
parent = {}

for i in range(n):
    a = list(map(int, input().split()))
    child[a[0]] = a[2:]
    for i in child[a[0]]:
        parent[i] = a[0] 

root = (set(child)-set(parent)).pop()
depth = [None]*n
depth[root] = 0
parent[root] = -1

    
def dfs(s):
    for i in child[s]:
            depth[i]=depth[s]+1
            dfs(i)
    
dfs(root)
    
for i in range(n):
    node_type = "root" if parent[i] == -1 else "leaf" if len(child[i]) == 0 else "internal node"
    print(f'node {i}: parent = {parent[i]}, depth = {depth[i]}, {node_type}, {child[i]}')




Measured memory_bytes: 38324
// abc139_d
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  ll ans = 0;
  for (int i = 1; i < n; ++i) {
    ans+=i;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    long double a,b,c;
    cin>>a>>b>>c;
    if(c-a-b<0){
        cout<<"No"<<endl;
        return 0;
    }
    if((c-a-b)*(c-a-b)>4*a*b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
const int mod = 998244353;
string s;
set<string> vis;

int brute(string s){
    vis.insert(s);
    for(int i = 1 ; i < s.size() ; ++i){
        if(s[i] != s[i - 1]){
            string s1 = s;
            s1[i] = s1[i - 1] = 3 - s1[i] - s1[i - 1];
            if(vis.count(s1))continue;
            brute(s1);
        }
    }
    return vis.size();
}
int dp[maxn][3][3][2];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> s;
    for(auto & c : s)c -= 'a';
    if(*min_element(s.begin(),s.end())==*max_element(s.begin(),s.end()))return cout << 1 , 0;
    if(s.size() <= 3)return cout << brute(s) , 0;
    int res = 1;
    for(int i = 1 ; i < s.size() ; ++i){
        res &= (s[i] != s[i - 1]);
    }
    dp[0][0][0][0] = dp[0][1][1][0] = dp[0][2][2][0] = 1;
    auto add = [&](int &x , int y){
        x += y;
        if(x >= mod)x -= mod;
    };
    for(int i = 0 ; i < s.size() - 1 ; ++i){
        for(int j = 0 ; j < 3 ; ++j){
            for(int t = 0 ; t < 3 ; ++t){
                for(int k = 0 ; k < 2 ; ++k){
                    for(int t1 = 0 ; t1 < 3 ; ++t1){
                        add(dp[i + 1][(j + t1) % 3][t1][k | (t == t1)] , dp[i][j][t][k]);
                    }
                }
            }
        }
    }
    int sum = 0;
    for(auto c : s)sum += c;
    for(int i = 0 ; i < 3 ; ++i)add(res,dp[s.size() - 1][sum % 3][i][1]);
    cout << res;
}



Measured memory_bytes: 14612
#include <stdio.h>

int main(void)
{
	int a, b, ans;
	scanf("%d%d", &a, &b);
	
	ans = 0;
	if(a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}

	if(a > b) {
		ans += a;
		a--;
	}
	else {
		ans += b;
		b--;
	}

	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
N,X,mod = map(int,input().split())
visited = [False for i in range(mod)]
visited[X]=True
mod_loop = [X]
now = X
while visited[now**2%mod] == False:
    mod_loop.append(now**2%mod)
    visited[now**2%mod] = True
    now = now**2%mod
now=now**2%mod

que = []
for i in range(len(mod_loop)):
    if mod_loop[i] == now:
        que.append(i)

leftsum = mod_loop[:que[0]]

looper = mod_loop[que[0]:]

if N<=len(leftsum):
    print(sum(leftsum[:N]))
else:
    ans = sum(leftsum)
    u,v = divmod(N-len(leftsum),len(looper))
    ans += u*sum(looper) + sum(looper[:v])
    print(ans)

Measured memory_bytes: 73724
import fractions
A, B, C, D=list(map(int, input().split()))
counter = 0
lcm = int((C*D)/fractions.gcd(C,D))
cda = (A-1)//C
dda = (A-1)//D
cdb = B//C
ddb = B//D
cdda = int((A-1)//lcm)
cddb = int(B//lcm)
counter = (cdb - cda) + (ddb - dda) - (cddb - cdda)
print(int(B-A+1-counter))

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


namespace _20180502_pra
{
    class Program
    {
        static void Main(string[] args)
        {

            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(x =>int.Parse(x)).ToArray();
            Array.Sort(input);
            Array.Reverse(input);

            long sum = 0;

            for (int i = 0; i < 2*N; i++)
            {
                if (i % 2 == 1) sum += input[i];
            }
            Console.WriteLine(sum);
        }
    }
}

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

using namespace std;

int main() {

	long long a,b,c;

	cin >> a >> b >> c;

	cout << (((a==b && a!=c) || (a==c && a!=b) || (b==c && a!=b)) ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())

    """
    l = [list(input().strip()) for i in range(h)]
    ans = [[-1]*w for i in range(h)]
    for i in range(h):
        for j in range(w):
            if l[i][j] == "#":
                ans[i][j] = -2
    ch -= 1
    cw -= 1
    dh -= 1
    dw -= 1
    """

    base = ["#" * (w + 4)]
    base.append("#" * (w + 4))
    for n in range(h):
        base.append("##" + input() + "##")
    base.append("#" * (w + 4))
    base.append("#" * (w + 4))
    ans = [[-1] * (w + 4) for _ in range(h + 4)]
    for i in range(h + 4):
        for j in range(w + 4):
            if base[i][j] == "#":
                ans[i][j] = -2
    ch += 1
    cw += 1
    dh += 1
    dw += 1

    ans[ch][cw] = 0
    move1 = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    move2 = [
        [-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1],
        [-1, 1], [-1, 2], [0, -2], [0, 2], [1, -2], [1, -1], [1, 1],
        [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]
    ]
    q1 = deque([[ch, cw]])
    q2 = deque([])

    while q1:
        x1, y1 = q1.popleft()
        q2.append([x1, y1])
        for i, j in move1:
            nx, ny = x1 + i, y1 + j
            """
            if nx < 0 or h <= nx or ny < 0 or w <= ny:
                continue
            """
            if ans[nx][ny] == -1:
                ans[nx][ny] = ans[x1][y1]
                q1.append([nx, ny])
        if len(q1) == 0:
            while q2:
                x2, y2 = q2.popleft()
                for i, j in move2:
                    mx, my = x2 + i, y2 + j
                    """
                    if mx < 0 or h <= mx or my < 0 or w <= my:
                        continue
                    """
                    if ans[mx][my] == -1:
                        ans[mx][my] = ans[x2][y2] + 1
                        q1.append([mx, my])
    print(ans[dh][dw])


if __name__ == "__main__":
    main()




Measured memory_bytes: 23404
import bisect as bs
import sys

sys.setrecursionlimit(2*10**5+1)

def dfs(i, nbr, A, prv, done, history, B, ans):#深さ優先探索（再帰）
  
  j = bs.bisect_left(B,A[i]) #Bへの挿入予定位置
  #print(i,A[i],j,B)
  
  #A[i]をhistoryの適当な位置に挿入
  if j < len(B):
    history[i] = (B[j], A[i], j) # 更新前の値、更新後の値、更新位置
    B[j] = A[i]
  else:
    history[i] = (-1, A[i], j) # 「追加する」 、追加する値、追加位置（最後）
    B.append(A[i])
  
  ans[i] = len(B) #答え書き込み
  done[i] = 1 #探索済み
  #print(i,B)
  
  for a in nbr[i]:
    if done[a] == 0: #探索前のみ
      dfs(a, nbr, A, prv, done, history, B, ans)
      prv[a] = i
      
  j = history[i][2]
  if history[i][0] >= 0:
    B[j] = history[i][0] #Bを現状復帰
  else:
    B.pop()
    
N = int(input()) 
A = list(map(int,input().split()))

nbr = [[] for _ in range(N)]

for _ in range(N-1):
  u,v = map(int,input().split())
  u -= 1
  v -= 1
  nbr[u].append(v)
  nbr[v].append(u)

#print(nbr)
  
prv = [-1 for _ in range(N)]
done = [0 for _ in range(N)] 
history = [0 for _ in range(N)]
B = []
ans = [0 for _ in range(N)]

dfs(0, nbr, A, prv, done, history, B, ans)

for i in range(N):
  print(ans[i])


Measured memory_bytes: 560956
#include <iostream>
#include <vector>

using namespace std;

//一次元vector用
void swap(vector<long long> &heap, int i, int j){
    long long tmp = heap[i];
    heap[i]=heap[j];
    heap[j]=tmp;
}

void minHeapify(vector<long long> &heap, int n){
    int l,r,smallest,last;
    l=2*n+1;
    r=2*n+2;
    smallest=n;
    last=heap.size();

    if (l<last && heap[l] < heap[smallest])smallest=l;
    if (r<last && heap[r] < heap[smallest])smallest=r;
    if(smallest!=n){
        swap(heap,n,smallest);
        minHeapify(heap,smallest);
    }
}

long long minHeapPop(vector<long long> &heap){
    long long min_=heap[0];
    heap[0]=heap[heap.size()-1];
    heap.pop_back();
    minHeapify(heap,0);

    return min_;
}

void minHeapPush(vector<long long> &heap, long long num){
    heap.push_back(num);
    int i = heap.size()-1;
    int parent = (i-1)/2;
    while (i>0 && heap[parent] > heap[i]){
        swap(heap,i,parent);
        i=parent;
        parent=(i-1)/2;
    }
}

void buildMinHeap(vector<long long> &heap){
    int size=heap.size();
    for(int i=(size-1)/2; i>=0; i--){
        minHeapify(heap,i);
    }
}

//-----------------maxHeap--------------------------
void maxHeapify(vector<long long> &heap, int n){
    int l,r,largest,last;
    l=2*n+1;
    r=2*n+2;
    largest=n;
    last=heap.size();

    if (l<last && heap[l] > heap[largest])largest=l;
    if (r<last && heap[r] > heap[largest])largest=r;
    if(largest!=n){
        swap(heap,n,largest);
        maxHeapify(heap,largest);
    }
}

long long maxHeapPop(vector<long long> &heap){
    long long max_=heap[0];
    heap[0]=heap[heap.size()-1];
    heap.pop_back();
    maxHeapify(heap,0);

    return max_;
}

void maxHeapPush(vector<long long> &heap, long long num){
    heap.push_back(num);
    int i = heap.size()-1;
    int parent = (i-1)/2;
    while (i>0 && heap[parent] < heap[i]){
        swap(heap,i,parent);
        i=parent;
        parent=(i-1)/2;
    }
}

void buildMaxHeap(vector<long long> &heap){
    int size=heap.size();
    for(int i=(size-1)/2; i>=0; i--){
        maxHeapify(heap,i);
    }
}

int main(){
    int N;
    cin >> N;
    vector<vector<long long>> a(3,vector<long long>(N,0));
    vector<long long> first(N+1,0);
    vector<long long> second(N+1,0);

    for (int i=0; i<3; i++){
        for(int j=0; j<N; j++){
            cin >> a[i][j];
            if (i==0){
                first[0]+=a[0][j];
            }else if(i==2){
                second[0]+=a[2][j];
            }
        }
    }
    buildMinHeap(a[0]);
    buildMaxHeap(a[2]);

    for(int i=1; i<N+1; i++){
        minHeapPush(a[0],a[1][i-1]);
        maxHeapPush(a[2],a[1][N-i]);
        first[i]+=first[i-1]+a[1][i-1]-minHeapPop(a[0]);
        second[i]+=second[i-1]+a[1][N-i]-maxHeapPop(a[2]);
    }
    long long ans=-100000000000000000;
    for(int i=0; i<N+1; i++){
        long long tmp = first[i]-second[N-i];
        if (tmp>ans){
            ans=tmp;
        }
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 4980
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);


  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;

  return 0;
}


Measured memory_bytes: 256
#coding: utf-8                                    
import math                                       
                                                  
N = int(input())                                  
original_list = [int(i) for i in input().split()] 
sorted_list = sorted(original_list)               
min_midian = sorted_list[int(N / 2) - 1]          
max_midian = sorted_list[int(N / 2)]              
                                                  
for i in range(N):                                
  if min_midian >= original_list[i]:              
    print(max_midian)                             
  else:                                           
    print(min_midian)                             

Measured memory_bytes: 25220
import java.util.Scanner;

/**
 * Created by chinalife on 2019/8/21.
 */
public class Main{
    public static int res = Integer.MIN_VALUE;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            res = Integer.MIN_VALUE;
            String hanglie = sc.nextLine();
            String[] hangs = hanglie.split(" ");
            int hang = Integer.valueOf(hangs[0]);
            int lie = Integer.valueOf(hangs[1]);
            if(hang== 0 && lie == 0){
                return;
            }
            int[][] inputArr= new int[hang][lie];
            for(int i = 0;i<hang;i++){
                String input = sc.nextLine();
                String[] strings = input.split(" ");
                for(int j = 0;j < lie;j++){
                    inputArr[i][j] = Integer.valueOf(strings[j]);
                }
            }
            solve(inputArr,hang,lie);
            System.out.println(res);
        }
    }
    public static void solve(int[][] arr,int hang,int lie){
        for(int i = 0;i<(1<<hang);i++){
            for(int j = 0;j<hang;j++){
                if((i&(1<<j)) != 0){
                    flipArr(arr,j);
                }
            }
            int temp = 0;
            for(int j = 0;j<lie;j++){
                int flag = 0;
                for(int k = 0;k<hang;k++){
                    if(arr[k][j] == 1){
                        flag++;
                    }
                }
                temp+=Math.max(flag,hang-flag);
            }
            res = Math.max(temp,res);
            for(int j = 0;j<hang;j++){
                if((i&(1<<j)) != 0){
                    flipArr(arr,j);
                }
            }
        }
    }
    public static void flipArr(int[][] arr,int hang){
        for(int i = 0;i < arr[0].length;i++){
            if(arr[hang][i] == 0){
                arr[hang][i]= 1;
            }else{
                arr[hang][i]= 0;
            }
        }
    }
}



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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p.at(i);
  rep(i, b) cin >> q.at(i);
  rep(i, c) cin >> r.at(i);
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());

  ll ans = 0;
  vector<int> s;
  rep(i, x) {
    s.push_back(p.at(i));
    ans += p.at(i);
  }
  rep(i, y) {
    s.push_back(q.at(i));
    ans += q.at(i);
  }
  sort(s.begin(), s.end());

  int n = min((int)s.size(), c);
  for (int i = 0; i < n; i++) {
    if (s.at(i) < r.at(i)) {
      ans += r.at(i) - s.at(i);
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5476
#include <stdio.h>

int main(void)
{
    int k;
    scanf("%d", &k);
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    printf("%d\n", arr[k-1]);
    return 0;
}

Measured memory_bytes: 128
// AOJ 1246: Concert Hall Scheduling
// 2017.11.8 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX(a,b) ((a)>=(b)?(a):(b))
typedef struct { int i, j, w; } T;
T tbl[1002];
int dp[366][366];

int cmp(T *a, T *b) { return a->i - b->i; }

int main()
{
	int n, i, j, k, ans;

	while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) scanf("%d%d%d", &tbl[i].i, &tbl[i].j, &tbl[i].w);
		qsort(tbl, n, sizeof(T), cmp);
		memset(dp, -1, sizeof(dp));
		dp[0][0] = 0;
		for (i = 0; i < n; i++) for (k = 365; k >= 0; k--) {
	        for (j = tbl[i].i - 1; j >= 0; j--) {
				if (dp[k][j] >= 0) dp[k][tbl[i].j] = MAX(dp[k][tbl[i].j], dp[k][j]+tbl[i].w);
			    if (dp[j][k] >= 0) dp[tbl[i].j][k] = MAX(dp[tbl[i].j][k], dp[j][k]+tbl[i].w);
			}
		}
    
		ans = 0;
		for (i = 0; i <= 365; i++) for(j = 0; j <= 365; j++)
			if (dp[i][j] > ans) ans = dp[i][j];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 2276
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()

int main(){

    int n; cin>>n;
    vector<int> a(n);
    rep(i, n) cin>>a[i];

    sort(all(a));

    vector<bool> ng(1000001, false);
    rep(i, n){
        if(i==0) continue;
        if(a[i]==a[i-1]) ng[a[i]]=true;
    }

    vector<bool> dp(1000001, true);

    for(int i: a){
        if(dp[i]){
            int x=i;
            if(!ng[i]) x+=i;
            while(x<=1000000){
                dp[x]=false;
                x+=i;
            }
        }
    }

    int ans=0;

    for(int i: a){
        if(dp[i]&&(!ng[i])) ans++;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int gcd(int x,int y){
    if(x%y == 0)return y;
    return gcd(y%x,x);
}
int main()
{
    int n;cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int ans = a[n-1];
    rep(i,n-1)ans = gcd(ans,a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
L = rl()

L.sort()

import bisect

ans = 0
for i in range(N):
	for j in range(i+1, N):
		d = L[i]+L[j]
		k = bisect.bisect_left(L, d)
		c = max(k-j-1,0)
		ans += c
print(ans)


Measured memory_bytes: 43100
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int N;
    ll x, a[2123], b[2123];

    cin >> N >> x;
    REP(i, N)
    {
        cin >> a[i];
        b[i] = a[i];
    }

    ll res = __LONG_LONG_MAX__;

    for (int i = 0; i < N; i++)
    {
        ll tmp = x * i;

        REP(j, N)
        {
            b[j] = min(b[j], a[(j - i + N) % N]);
            tmp += b[j];
        }

        res = min(res, tmp);
    }

    cout << res << endl;

    return 0;
}

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

int main(void){
	int n,m,a;
	cin>>n>>m;
	std::list<int> e;
	bool f[200001];
	list<int>::iterator exist[200001];
	for(int i=1;i<=n;i++) f[i]=true;
	while(m--){
		cin>>a;
		if(f[a])e.push_back(a);
		else{
			e.erase(exist[a]);
			e.push_back(a);
		}
		f[a]=false;
		exist[a]=e.end();
		exist[a]--;
	}
	for(list<int>::reverse_iterator it=e.rbegin();it!=e.rend();it++){
		cout<<*it<<endl;
	}
	for(int i=1;i<=n;i++){
		if(f[i])cout<<i<<endl;
	}
}

Measured memory_bytes: 7888
N = int(input())
L = list(map(int,input().split()))
P = list(set(L))
if len(P) == len(L) :
    ans = 0
else :
    D = {}
    ans = 1
    for i in range(N) :
        if L[i] not in D :
            D[L[i]] = 1
        else :
            D[L[i]] += 1
    D = sorted(D.items(),key=lambda x: x[0], reverse=True)
    flag = 0
    for i in range(len(D)) :
        if D[i][1] >= 4 and flag < 1 :
            ans *= D[i][0]**2
            flag += 2
        elif D[i][1] >= 2 and flag < 2 :
            ans *= D[i][0]
            flag += 1
print(ans)
          

Measured memory_bytes: 26636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int N;
	int A[100010],B[100010];
	cin>>N;
	int sum=0,sum2=0;
	REP(i,N){
		cin>>A[i];
		sum+=A[i];
	}
	REP(i,N){
		cin>>B[i];
		sum2+=B[i];
	}
	if(sum2>sum){
		cout<<-1<<endl;
	}
	else{
		int count=0;
		int sa=0;
		vector<int> v;
		REP(i,N){
			if(A[i]<B[i]){
				sa+=abs(B[i]-A[i]);
				count++;
			}
			else{
				v.push_back(A[i]-B[i]);
			}
		}
		if(sa==0){
			cout<<0<<endl;
		}
		else{
			DEB(sa)DEB(count)END
			sort(v.begin(),v.end(),greater<>());
			int l=0;
			while(l<v.size()){
				sa-=v[l];
				count++;
				l++;
				if(sa<=0){
					cout<<count<<endl;
					return 0;
				}
			}
			cout<<-1<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 2936
#include <iostream>
#include <map>

int main(){
    int n,m;
    std::cin >> n >> m;
    long long a[n];
    std::map<int, long long> mp;
    a[0] = 0;
    mp[0] = 1;
    for(int i=0;i<n;i++){
        std::cin >> a[i+1];
        a[i+1] = a[i+1]%m + a[i];
        mp[a[i+1] % m]++;
    }

    long long ans = 0LL;
    for(std::map<int, long long>::iterator itr=mp.begin();itr!=mp.end();++itr){
        ans += (itr->second) * ((itr->second)-1LL) / 2LL;
    }
    std::cout << ans << "\n";
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

ll cnt(ll x){
    ll ret = 0;
    for(;x % 2 == 0;x/=2)ret++;
    return ret;
}

int main(){

    ll N;
    cin >> N;
    ll ans = 1;
    for(ll i = 1; i <= N; i++)if(cnt(ans) < cnt(i))ans = i;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define INF 1e9 + 5
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
void solve() {
    string s;
    cin >> s;
    int n = s.size();
    f(i, n) {
        if (s[i] == '1')
            cout << "9";
        else if (s[i] == '9')
            cout << "1";
        else
            cout << s[i];
    }
    cout << nl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a-b>c)cout << 0 << endl;
  else cout << c-(a-b) << endl;
}  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e6+10;
char t[maxn],s[maxn];
int main()
{
    int n;scanf("%d",&n);
    scanf("%s%s",t+1,s+1);
    for(int i=1;i<=n;++i)
    {
        printf("%c%c",t[i],s[i]);
    }
    printf("\n");
    return 0;
}


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

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> tf(n, vector<int>(n, -1));
  for (int i = 0; i < n; i++){
      int a;
      cin >> a;
      for (int j = 0; j< a;j++) {
          int x,y;
          cin >> x >> y;
          x--;
          tf[i][x] = y;
      }
  }

  int m = 0;
  for (int bit = 0; bit < (1<<n); bit++) {
      vector<int> f(n);
      int tcount = 0;
      for (int i = 0; i < n; i++) {
          if (bit & (1<<i)) {
              f[i] = 1;
              tcount++;
          }
      }
      bool ff = 1;
      for (int i= 0; i< n; i++) {
          if (f[i] == 1) {
              int N = tf[i].size();
              for (int j = 0; j < N; j++){
                  if (tf[i][j]!=f[j] && tf[i][j] != -1) {
                      ff = 0;
                      break;
                  }
              }
          }
          if (!ff) {
              break;
          }
      }
      if (ff) m = max(m, tcount);
  }
  cout << m <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

typedef struct {double x,y;}Point;

void koch(int n,Point a,Point b){
  if(n==0)return;
  Point s,t,u;
  double th = M_PI*60.0 / 180.0;//c ->sincostan

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y=0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}



Measured memory_bytes: 2104
N = int(input())
A = list(map(int, input().split()))
minus = 0
mina = 10 ** 5
for a in A:
    if a < 0:
        minus += 1
    mina = min(mina, abs(a))
print(sum(map(abs, A)) - mina * 2 if minus % 2 else sum(map(abs, A)))


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = n-1; i >= (int)0; i--)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
int main(){
    int k,s;
    std::cin >> k>>s;
    
    int ans=0;
    reprep(i,j,k+1,k+1){
        if(0<= (s-i-j)&&(s-i-j) <=k){
      //      std::cout << s-i-j << std::endl;
            ans++;
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let parent i = int_of_float ((float_of_int (i - 1)) /. 2.)

let left i = 2*i + 1

let right i = 2*i + 2

let to_pow_of_2 n =
  let rec doit i =
    if i >= n then i
    else doit (i * 2) in
  doit 1

let update (s : int array) n i x =
  let j = n + i - 1 in
  s.(j) <- x;
  let rec doit j =
    if j > 0 then begin
      let j = parent j in
      s.(j) <- if s.(left j) < s.(right j) then s.(left j) else s.(right j);
      doit j
    end in
  doit j

let find s n a b =
  let rec doit a b k l r =
    if r <= a || b <= l then 2147483647
    else if a <= l && r <= b then s.(k)
    else begin
      let v = doit a b (left k) l ((l + r) / 2) in
      let w = doit a b (right k) ((l + r) / 2) r in
      if v < w then v else w
    end in
  doit a b 0 0 n

let solve n q =
  let n = to_pow_of_2 n in
  let s = Array.make (2*n-1) 2147483647 in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> update s n x y
      | 1 :: x :: y :: _ -> Printf.printf "%d\n" (find s n x (y + 1))
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

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

int main(){
  int n;
  cin >> n;
  if (n == 2){
    ll x, y;
    cin >> x >> y;
    cout << abs(x-y) << endl;
    return 0;
  }
  ll a[n], ansy=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    ansy+=a[i];
  }
  ansy -= a[0];
  ll ansx=a[0], ans = abs(ansx-ansy); 
  for(int i=1;i<n-1;i++){
    ansx += a[i];
    ansy -= a[i];
    ans = min(ans, abs(ansx-ansy));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect::<Vec<_>>();
    let n = list[0] * list[1];
    if n % 2 == 0 { "Even" } else { "Odd" }.to_string()
}

#[test]
fn test() {
    let tests = vec![("3 4", "Even"), ("1 21", "Odd")];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


Measured memory_bytes: 4352