akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void fnInput(int& rnBgn, vector<int>& rvnCoord)
{
  int nCoordSiz;
  cin >> nCoordSiz >> rnBgn;
  rvnCoord.resize(nCoordSiz);

  for (int& rnCoord : rvnCoord)
    cin >> rnCoord;
}

int fnGcd(int nOne, int nOtr)
{
  if ( !nOtr )
    return nOne;
  else
    return fnGcd(nOtr, nOne % nOtr);
}

int fnMaxMovemnt(int nBgn, const vector<int>& cnrvnCoord)
{
  vector<int> vnDiff(cnrvnCoord.size());

  for (int i = 0; i < cnrvnCoord.size(); ++i)
    vnDiff[i] = abs(nBgn - cnrvnCoord[i]);

  int nGcd = vnDiff[0];

  for (int i = 1; i < vnDiff.size(); ++i)
    nGcd = fnGcd(nGcd, vnDiff[i]);

  return nGcd;
}
  
int main()
{
  int nBgn;
  vector<int> vnCoord;
  
  fnInput(nBgn, vnCoord);
  cout << fnMaxMovemnt(nBgn, vnCoord) << endl;

  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::string s;
	std::cin >> s;
	uint32 f = 0;
	rep(i, 0, s.length()) {
		if (f) {
			if (s[i] == 'F') {
				std::cout << "Yes\n";
				return 0;
			}
		}
		else {
			if (s[i] == 'C') {
				f = 1;
			}
		}
	}
	std::cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=505;
int a[N],n,k,sum,b[N];
vector<int> vec;
bool check(int x){
    for(int i=0;i<n;i++) b[i]=a[i]%x;
    sort(b,b+n,greater<int>());
    int l=0,r=n-1,t=0;
    while(l<=r) {
        while(b[l]+b[r]<x) b[l]+=b[r],t+=b[r--];
        t+=x-b[l];
        b[r]=b[l]+b[r]-x;
        if(b[r]==0) r--;
        l++;
    }
    return t<=k;
}
int main() {
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    for(int i=1;i*i<=sum;i++) {
        if(sum%i==0) {
            vec.push_back(i);
            if(i*i!=sum) vec.push_back(sum/i);
        }
    }
    sort(vec.begin(),vec.end(),greater<int>());
    for(int i=0;i<vec.size();i++)
        if(check(vec[i])) {
            printf("%d\n",vec[i]);
            break;
        }
    return 0;
}

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

int main() {
  int n; cin >> n;
  string ans;
  if(n % 10 == 3) ans = "bon";
  else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) ans = "pon";
  else ans = "hon";
  
  cout << ans << endl;
}

Measured memory_bytes: 3596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int numPeople = in.nextInt(), numSports = in.nextInt();
            int[][] A = new int[numPeople][numSports];
            for (int person = 0; person < numPeople; ++person) {
                for (int i = 0; i < numSports; ++i)
                    A[person][i] = in.nextInt() - 1;
            }
            boolean[] removed = new boolean[numSports];
            int[] cnt = new int[numSports];
            int[] rank = new int[numPeople];

            int answer = numPeople;

            for (int i = 0; i < numSports; ++i) {
                Arrays.fill(cnt, 0);
                for (int person = 0; person < numPeople; ++person) {
                    ++cnt[A[person][rank[person]]];
                }
                int max = 0, idMax = -1;
                for (int sport = 0; sport < numSports; ++sport) {
                    if (cnt[sport] > max) {
                        max = cnt[sport];
                        idMax = sport;
                    }
                }
                answer = Math.min(answer, max);
                removed[idMax] = true;
                for (int person = 0; person < numPeople; ++person) {
                    while (rank[person] < numSports && removed[A[person][rank[person]]])
                        ++rank[person];
                }
            }

            out.println(answer);
        }

    }

    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: 31336
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll e;
	while(1){
		cin >> e;
		if(e==0)break;
		ll ans=MOD;
		FOR(i,0,e+1){
			FOR(j,0,e+1){
				ll k = e - i*i - j*j*j;
				ll m = k + i + j;
				if(k<0)break;
				if(ans>m){
					ans = m;
				}
			}
			if(i*i>e)break;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3240
#include <iostream>
using namespace std;
int main () {
	int a, b, c;
	cin >> a >> b >> c;
	if (min (a, min (b, c)) == a) {
		cout << a + min (b, c);
	}
	else if (min (a, min (b, c)) == b) {
		cout << b + min (a, c);
	}
	else {
		cout << c + min (a, b);
	}
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
	var a = parseInt(input.charAt(0)+input.charAt(1));
	var b = parseInt(input.charAt(2)+input.charAt(3));
	var r = 0;	// 1=YYMM、2=MMYY、3=両方、4=どちらでもない
	if(a >= 13 || a == 0){
		r = 1;
	}
	if(b >= 13 || b == 0){
		r = 2;
	}
	if(a >= 1 && a <= 12 && b >= 1 && b <= 12){
		r = 3;
	}
	if(a >= 13 && b >= 13 || a >= 13 && b == 0 || a == 0 && b >= 13 || a == 0 && b == 0){
		r = 4;
	}
	if(r == 1){ console.log("YYMM"); }
	if(r == 2){ console.log("MMYY"); }
	if(r == 3){ console.log("AMBIGUOUS"); }
	if(r == 4){ console.log("NA"); }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main() {

    while (true) {

        int N, M;
        cin >> N >> M;

        if (N == 0 && M == 0) break;

        int r;
        cin >> r;

        map<pair<int, int>, int> MAP;
        vector<vector<int>> students(M, vector<int>(1270, 0));

        for (int i = 0; i < r; i++) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            m--;

            if (s == 1) {
                MAP[make_pair(n, m)] = t;
            }
            if (s == 0) {
                int start = MAP[make_pair(n, m)];
                int end = t;
                for (int j = start; j < end; j++) students[m][j] = 1;
            }
        }

        int Q;
        cin >> Q;

        for (int i = 0; i < Q; i++) {
            int ts, te, m;
            cin >> ts >> te >> m;
            m--;

            int ans = 0;
            for (int j = ts; j < te; j++) if (students[m][j])ans++;
            cout << ans << endl;
        }

//        for (int i = 0; i < M; i++) {
//            for (int j = 0; j < students[i].size(); j++) cout << students[i][j] << " ";
//            cout << endl;
//        }

    }

    return 0;
}


Measured memory_bytes: 51328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    lint T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    lint D = (A1 * T1 + A2 * T2) - (B1 * T1 + B2 * T2);
    if (D == 0) {
        cout << "infinity\n";
        return 0;
    }
    if (D < 0) {
        swap(A1, B1);
        swap(A2, B2);
        D = -D;
    }
    if (A1 * T1 > B1 * T1 && D > 0) {
        cout << 0 << "\n";
        return 0;
    }
    lint ans = 1;
    lint S = B1 * T1 - A1 * T1;
    if (S % D == 0) {
        ans += (S / D - 1) * 2;
        ans += 1;
    } else {
        ans += S / D * 2;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
 
int main() {

  int n;
  cin >> n;
  int ans=0;

  for(int i=1;i<=n;i++){
    if(i<10){
      ans++;
    }
    else if(i>=100&i<1000){
      ans++;
    }
    else if(i>=10000&i<100000){
      ans++;
    }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cassert>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <limits.h>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iomanip>
using namespace std;
//////////////////
// Aditya Kumar //
//  BITS H      //
//////////////////
#define mod 1000000007
#define ll long long
#define ss second
#define ff first
// #define endl '\n'
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int  long long
#define pb push_back
#define mod 1000000007
 
#define FOR(i, a, b) for(long long i=a;i<b;i++)


const int N = 1e6 + 10;
map<int,int> mp2;
map<int,int> mp;
ll ST[N << 2];
int freq[N];

void init(int nd, int l, int r){
        if(l == r){
                ST[nd] = freq[l];
                return;
        }
        int mid = (l+r) >> 1;
        init(nd<<1, l, mid);
        init(nd<<1|1, mid+1, r);
        ST[nd] = ST[nd<<1] + ST[nd<<1|1];
}

ll query(int nd, int l, int r, int L, int R) {
        if( R < l || L > r) return 0;
        if(L<=l && R>=r) {
                // cout << ST[nd] << endl;
                return ST[nd];
        } 
        int mid = (l+r) >> 1;
        return query(nd<<1, l, mid, L, R) + query(nd<<1|1, mid+1, r, L, R);
}

void upd(int nd, int l, int r, int pos, int val) {
        if(l == r) {
                ST[nd] += val;
                return;
        }
        int mid = (l+r) >> 1;
        if(pos <= mid) {
                upd(nd<<1, l, mid, pos, val);
        } else upd(nd<<1|1, mid+1, r, pos, val);
        ST[nd] = ST[nd<<1] + ST[nd<<1|1];
}

int32_t main()
{
       
        int n;
        int k; 
        cin >> n;
        cin >> k;
        // If k%2 == 0  .. Have all k%2 items :3
        // 
        if(k%2 == 0) {
                //  K multiples trips
                int num = n/k;
                int num2 = 0;
                for(int i=0;i<=n;i++) {
                        // cout << n << " " << k;
                        if(i%k == (k/2)) num2++;
                }
                // cout << num << endl;
                // cout << num2 << endl;
                int ans = num * num * num + num2*num2*num2;
                // Take n%k == k/2 items
                cout << ans;


        } else {
                // Only K multiples trips
                int num = n/k;
                cout << num * num * num << endl;
        }
        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long x,money=100,ans=0;
  scanf("%ld",&x);
  
  while(1){
	money = money * 1.01;
    ans++;
  
    if(money >= x){
  printf("%ld\n",ans);
 return 0;
    }
  }
}

Measured memory_bytes: 1732
Scanf.scanf "%d %d %d %d %d" (fun a b c x y ->
    let lim = 2 * max x y in
    let rec loop i acc =
        if i > lim then acc / 2 else
            let cost = a * max 0 (2 * x - i) + b * max 0 (2 * y - i) + 2 * c * i in
            loop (i + 1) (min cost acc)
    in
    loop 0 max_int |> Printf.printf "%d\n"
)

Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		int n = sc.nextInt();
		int k = sc.nextInt();
		int count = 1;
		int sub = n - k;
		if (sub % (k - 1) == 0) {
			count += sub / (k - 1);
		} else {
			count += sub / (k - 1) + 1;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath> 
using namespace std;
char s[10005];
int m,k;
inline int get()
{
	char c;
	int x=0,p=1;
	c=getchar();
	while (c<'0'||c>'9') {if (c=='-') p=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*p;
}
int main()
{
	scanf("%s",s);
	for (int i=0;i<strlen(s);i++)
	    if (s[i]=='9') {printf("Yes");return 0;}
	printf("No");
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

vector< pair<ll,ll> > prime_factorize(ll n){
    vector<pair<ll, ll> > res;
    for (ll p = 2; p*p<=n; ++p){
        if(n%p != 0) continue;
        int num = 0;
        while(n%p == 0){
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n,1));
    return res;
}

signed main(){start();
    int n,ans=0;
    cin>>n;
    map<int,int> fact;
    REP(i,1,n+1){
        vector<Pii> a=prime_factorize(i);
        REP(j,0,a.size()) fact[a[j].first]+=a[j].second;
    }
    vector<Pii> f;
    for(auto x : fact) f.pb(mp(x.first,x.second));
    REP(i,0,f.size()) if(f[i].second>=74) ans++;
    REP(i,0,f.size()){
        if(f[i].second>=2){
            REP(j,i+1,f.size()) if(f[j].second>=24) ans++;
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=24){
            REP(j,i+1,f.size()) if(f[j].second>=2) ans++;
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=4){
            REP(j,i+1,f.size()) if(f[j].second>=14) ans++;
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=14){
            REP(j,i+1,f.size()) if(f[j].second>=4) ans++;
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=4){
            REP(j,i+1,f.size()){
                if(f[j].second>=4){
                    REP(k,j+1,f.size()) if(f[k].second>=2) ans++;
                }
            }
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=4){
            REP(j,i+1,f.size()){
                if(f[j].second>=2){
                    REP(k,j+1,f.size()) if(f[k].second>=4) ans++;
                }
            }
        }
    }
    REP(i,0,f.size()){
        if(f[i].second>=2){
            REP(j,i+1,f.size()){
                if(f[j].second>=4){
                    REP(k,j+1,f.size()) if(f[k].second>=4) ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();

        sc.close();

        int area = H*W;
        int result = area - h*W - (H-h)*w;

        System.out.println(result);
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
const int mod=1e9+7;
using namespace std;
bool used[200005];
vector<int> b[200005];
long long dp[200005][2];
void dfs(long long u){
	if(used[u]) return;
	used[u]=true;
	for(auto v : b[u]){
		if(!used[v]){
			dfs(v);
			dp[u][0]*=(dp[v][0]+dp[v][1])%mod;
			dp[u][0]%=mod;
			dp[u][1]*=dp[v][0]%mod;
			dp[u][1]%=mod;
		}
	}
}
int main(){
	long long n,u,v;
	scanf("%lld",&n);
	for(long long i=1;i<=n-1;i++){
		scanf("%lld %lld",&u,&v);
		b[u].push_back(v);
		b[v].push_back(u);
	}
	for(long long i=1;i<=n;i++){
		dp[i][0]=1;
		dp[i][1]=1;
	}
	dfs(1);
	printf("%lld",(dp[1][0]+dp[1][1])%mod);
}

Measured memory_bytes: 14976
line = list(input().split(" "))
n = int(line[0])
k = int(line[1])
line = list(input().split(" "))
r = int(line[0])
s = int(line[1])
p = int(line[2])
line = list(input())
result = 0
dp = [[0,0,0]for i in range(n)]
for j in range(k):
    i = 1
    if line[j] == "r":
        dp[j] = [0,0,p]
    elif line[j] == "s":
        dp[j] = [r,0,0]
    else:
        dp[j] = [0,s,0]
    while True:
        m = k*i + j
        if m >= n:
            m -= k
            break
        if line[m] == "r":
            a = [0,0,p]
        elif line[m] == "s":
            a = [r,0,0]
        else:
            a = [0,s,0]
        dp[m][0] = max(dp[m-k][1]+a[0],dp[m-k][2]+a[0])
        dp[m][1] = max(dp[m-k][0]+a[1],dp[m-k][2]+a[1])
        dp[m][2] = max(dp[m-k][0]+a[2],dp[m-k][1]+a[2])
        i += 1
    result += max(dp[m][0],dp[m][1],dp[m][2])
print(result)

Measured memory_bytes: 75020
#include<stdio.h>
#include <stdlib.h>

int main(void){
  int n;
  char s;
  scanf("%d",&n);
  scanf("%c",&s);
  while(1){
    scanf("%c",&s);
    if(s == '\n'){
      break;
    }
    s += n;
    if(s>90){
      s-=26;
    }
    printf("%c",s);
  }
  printf("\n");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (i % 2 == 0) {
            cout << s[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;





int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){cin>>a[i]; sum+=a[i];}
    ll ans=E;
    ll A=0;
    for(int i=0;i+1<n;i++){
        A+=a[i];
        ans=min(ans,abs(sum-2*A));
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 1792
//ABC-139-E
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

const int MAX_V = 1000 *  (1000 - 1) / 2;

int ans = 0;

/*
    To.size() == V であればトポロジカルソートができた、そうでなければできなかったと判定できる
*/
vector<int> Tsort(vector<vector<int>> & G){
    vector<int> To;
    int V = G.size();
    stack<int> st;
    int indeg[V] = {};
    for(int i = 0; i < V; i++){
        for(int j = 0; j < G[i].size(); j++){
            indeg[G[i][j]]++;
        }
    }
    for(int i = 0; i < V; i++){
        if(indeg[i] == 0){
            st.push(i);
        }
    }
    vector<int> dp(V);
    while(!st.empty()){
        int u = st.top();
        st.pop();
        To.push_back(u);
        for(int i = 0; i < G[u].size(); i++){
            indeg[G[u][i]]--;
            dp[G[u][i]] = max(dp[G[u][i]], dp[u] + 1);
            ans = max(ans, dp[G[u][i]]);
            if(indeg[G[u][i]] == 0){
                st.push(G[u][i]);
            }
        }
    }
    return To;
}

signed main(){
    int n;
    cin >> n;
    int id[n][n];
    int V = 0;
    REP(i,n){
        for(int j = i + 1; j < n; j++){
            id[i][j] = V;
            V++;
        }
    }
    int num[n][n - 1];
    int a,b;
    REP(i,n){
        REP(j,n - 1){
            cin >> a;
            a--;
            b = i;
            if(a > b){
                swap(a, b);
            }
            num[i][j] = id[a][b];
        }
    }
    vector<vector<int>> G(V);
    REP(i,n){
        REP(j,n - 2){
            G[num[i][j]].push_back(num[i][j + 1]);
        }
    }
    vector<int> To = Tsort(G);
    if(To.size() != V){
        cout << -1 << endl;
        return 0;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 41464
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    ll n, sum = 0;
    cin >> n;
    v_ll a(n);
    
    irep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    
    ll a_sum = a[0];
    ll b_sum = sum - a[0];
    ll ans = abs(a_sum - b_sum);

    irep2(i, 1, n-1) {
        a_sum += a[i];
        b_sum = sum - a_sum;
        ans = min(ans, abs(a_sum - b_sum));
    }

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


Measured memory_bytes: 1920
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N, A, B;
  cin >> N >> A >> B;
  unordered_map<long, long> mp;
  rep(i, N) {
    long p;
    cin >> p;
    if (p <= A) mp[1]++;
    else if (p<= B) mp[2]++;
    else mp[3]++;
  }
  cout << min(mp[1], min(mp[2], mp[3])) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);


int main()
{
	FASTIO;

	ll n;
	 cin>>n;

    //dp[i] denote the probability of getting i heads.
    double dp[n+1];
    dp[0]=1.0;

    for(int i=1;i<=n;i++)
    {
        double p_head;
         cin>>p_head;
         dp[i]=dp[i-1]*p_head;


        for(int j=i-1;j>0;j--)
        {
           dp[j]= p_head*dp[j-1] +(1.0-p_head)*dp[j];

        }
        dp[0]*=(1.0-p_head);
    }
    double ans=0.0;

    int index= (n+1)/2;
    for(int i=index;i<=n;i++)
        ans+=dp[i];

    cout<<setprecision(10)<<ans<<"\n";

	return 0;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int main(){
//  freopen("test.in","r",stdin);
//  freopen("test.out","w",stdout);
	int n,sum=0;
	cin>>n;
	int a[n+1];
	memset(a,0,sizeof(a));
	for(int i =0;i<n;i++) cin>>a[i];
	for(int i =0 ;i<n;i++){
		for(int j=i+1;j<n;j++){
			sum+=a[i]*a[j];
		}
	}
	cout<<sum;
    return 0;
}

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

int main(){
	int t;
	int n[11], m[11];
	double E[11];
	
	cin >> t;
	for(int i=0 ; i < t ; i++ ){
		cin >> n[i] >> m[i];
		
		int v[101];
		double r[101];
		for(int j=0 ; j < m[i] ; j++ ){
			cin >> v[j] >> r[j];
		}
		
		double white = 1.0;
		for(int j=0 ; j < m[i] ; j++ ){
			white -= r[j];
		}
		double e = 0.0;
		for(int j=0 ; ; j++ ){
			double sum = 0.0;
			for(int k=0 ; k < m[i] ; k++ ){
				sum += v[k] * r[k] * pow( white , (double)j );
			}
			e += sum;
			if( sum < 1e-7 ){
				break;
			}
		}
		E[i] = e;
	}
	int p, q, v[101];
	double r[101];
	cin >> p >> q;
	for(int i=0 ; i < q ; i++ ){
		cin >> v[i] >> r[i];
	}
	
	double white = 1.0;
	for(int j=0 ; j < q ; j++ ){
		white -= r[j];
	}
	double e = 0.0;
	for(int j=0 ; ; j++ ){
		double sum = 0.0;
		for(int k=0 ; k < q ; k++ ){
			sum += v[k] * r[k] * pow( white , (double)j );
		}
		e += sum;
		if( sum < 1e-7 ){
			break;
		}
	}
	bool flag = false;
	//cout << "e:" << e << endl;
	for(int i=0 ; i < t ; i++ ){
		//cout << "E[" << i << "]:" << E[i] << endl;
		if( e < E[i] ){
			flag = true;
		}
	}
	if( flag )
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

ll x;

ll solve() {
    ll res = 0;
    res += x / 11 * 2;
    x %= 11;
    return res + (x == 0 ? 0 : (x <= 6 ? 1 : 2));
}

void input() {
    cin >> x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define endl '\n'
#define N 200005
int a[N],dp[N];
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    for(int i=1;i<=n;i++)
    dp[i] = mod;
    dp[1] = 0;
    dp[2] = abs(a[1] - a[2]);
    for(int i=3;i<=n;i++)
    {	
    	for(int j=max(i-k,1);j<i;j++)
    	dp[i] = min(dp[i],abs(a[i] - a[j])+dp[j]);
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4368
K = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(A[K-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000001
#define MAXN        200005
#define mod         1000000007
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll i,flag=0,n=s.size();
    for(i=0;i<n;i+=2){
        if(s[i]!='h'){
            flag=1;
        }
    }
    for(i=1;i<n;i+=2){
        if(s[i]!='i'){
            flag=1;
        }
    }
    if(flag==1 || n%2==1){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    t=STR()
    ct=0
    for i in range(3):
        if s[i]==t[i]:
            ct+=1
    print(ct)
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){

	int h[10];
	
	int i,j,t;
	for(i=0;i<10;i++){
		scanf("%d",&h[i]);
	}
	for(i=0;i<9;i++)
	{
		for(j=i;j<10;j++)
		{
			if(h[i]<h[j])
			{
			   t=h[i];
			   h[i]=h[j];
			   h[j]=t;
			}
		}
	}
	for(i=0;i<3;i++)
	{
		printf("%d\n",h[i]);
	}


	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))


int main(){
	ll n;
	cin >> n;
	if(n&1){
		cout << 0 << endl;
		return 0;
	}
	ll ans2 = n/2;
	ll ans5 = 0;
	ll t = 2;
	ll f = 5;

	n /= 2;
	while(t<=n && t>0){
		ans2 += n/t;
		t *= 2;
	}
	while(f<=n && f>0){
		ans5 += n/f;
		f *= 5;
	}
	cout << min(ans2,ans5) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int max=0, i, cnt, flag, ans;
    char b[10];

    scanf("%s", b);

    for (i=0; i<10; i++){
        if (b[i] == 'A' || b[i] == 'T' || b[i] == 'C' || b[i] == 'G'){
            cnt++;
        }else{
            if (max < cnt){
                max = cnt;
            }
            cnt = 0;
        }
    }

            if (max < cnt){
                max = cnt;
            }


    printf("%d", max);

    return 0;
}

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

using namespace std;

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

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

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	LL N, A, B;
	cin >> A >> B >> N;

	LL ret = A * min(N, (B - 1)) / B - A * min(N, ((B - 1)) / B);

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    rep(i, r + 1) {
        if(d * i >= l && d * i <= r) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3612
MOD = 10**9 + 7
MAX = 5*10**6 + 1

fact = [0 for _ in range(MAX)]
factinv = [0 for _ in range(MAX)]

fact[0] = 1
for k in range(1, MAX):
    fact[k] = fact[k - 1]*k
    fact[k] %= MOD

factinv[MAX - 1] = pow(fact[MAX - 1], MOD - 2, MOD)
for k in range(MAX - 1, 0, -1):
    factinv[k - 1] = factinv[k]*k
    factinv[k - 1] %= MOD

def nCk(n, k):
    return fact[n]*factinv[k]*factinv[n - k] % MOD

def nPk(n, k):
    return fact[n]*factinv[n - k] % MOD

K = int(input())
S = input()
N = len(S)

ans = 0
for k in range(K + 1):
    ans += nCk(N + K - k - 1, N - 1)*pow(26, k, MOD)*pow(25, K - k, MOD) % MOD
    ans %= MOD

print(ans)

Measured memory_bytes: 306912
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */

#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

class CPyramid {
public:

    void solve(std::istream &cin, std::ostream &cout) {
        int n;
        cin >> n;
        vector<vector<int>> abc_vec(n, vector<int>(3));
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 3; ++j) {
                cin >> abc_vec[i][j];
            }
        }
        int base_pyramid[101][101];
        int refer_pyramid[101][101];
        int cnt_pyramid[101][101];
        for (int i = 0; i < 101; ++i) {
            for (int j = 0; j < 101; ++j) {
                base_pyramid[i][j] = 0;
                refer_pyramid[i][j] = 0;
                cnt_pyramid[i][j] = 0;
            }
        }
        sort(abc_vec.begin(), abc_vec.end(), [](auto &x, auto &y) { return x[2] > y[2]; });
        for (int num = 0; num < n; ++num) {
            int x = abc_vec[num][0];
            int y = abc_vec[num][1];
            int h = abc_vec[num][2];
            for (int i = 0; i < 101; ++i) {
                for (int j = 0; j < 101; ++j) {
                    if (num == 0) {
                        base_pyramid[i][j] = h + abs(x - i) + abs(y - j);
                    } else {
                        if (h == 0 && base_pyramid[i][j] < (h + abs(x - i) + abs(y - j))) {
                            cnt_pyramid[i][j]++;
                        }
                        if (h + abs(x - i) + abs(y - j) == base_pyramid[i][j])
                            cnt_pyramid[i][j]++;
                    }
                }
            }
        }
        int ans_x = 0;
        int ans_y = 0;
        int cnt = 1;
        for (int k = 0; k < 101; ++k) {
            for (int l = 0; l < 101; ++l) {
                if (cnt_pyramid[k][l] > cnt) {
                    cnt = cnt_pyramid[k][l];
                    ans_x = k;
                    ans_y = l;
                } else if (cnt_pyramid[k][l] == cnt && base_pyramid[k][l] < base_pyramid[ans_x][ans_y]) {
                    cnt = cnt_pyramid[k][l];
                    ans_x = k;
                    ans_y = l;
                }
            }
        }
        cout << ans_x << " " << ans_y << " " << base_pyramid[ans_x][ans_y] << endl;
    }
};


int main() {
    CPyramid solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
n = int(input())
sl = list(input())
q = int(input())


# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.el = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


dic = defaultdict(lambda: BIT(n))
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
for idx, s in enumerate(sl):
    dic[s].add(idx+1, 1)
for _ in range(q):
    a, b, c = map(str, input().split())
    if a == "1":
        b = int(b)
        dic[sl[b-1]].add(b, -1)
        dic[c].add(b, 1)
        sl[b-1] = c
    else:
        b = int(b)
        c = int(c)
        ans = 0
        for s in ascii_lowercase:
            if dic[s].get(b-1, c) > 0:
                ans += 1
        print(ans)

Measured memory_bytes: 267452
import bisect
N=int(input())

rllist=[]
for _ in range(N):
  X,L=map(int,input().split())
  rllist.append((X+L,X-L))
rllist.sort()
#print(rllist)

dp=[0]*N
for i in range(N):
  r,l=rllist[i]
  
  pos=bisect.bisect(rllist,(l,float("inf")))
  #print(i,pos)
  dp[i]=max(dp[i-1],dp[pos-1]+1)
  
#print(dp)
print(dp[-1])

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

using namespace std;

int dp[60][60][60];

int recur(int a, int b, int c){
	if(a > 55 || b > 55 | c > 55) return 10000;
	if(a == b && b == c) return 0;
	if(dp[a][b][c] != -1) return dp[a][b][c];
	int ans = 10000;
	ans = min(ans, 1 + recur(a + 1, b + 1, c));
	ans = min(ans, 1 + recur(a + 1, b, c + 1));
	ans = min(ans, 1 + recur(a, b + 1, c + 1));
	ans = min(ans, 1 + recur(a + 2, b, c));
	ans = min(ans, 1 + recur(a, b + 2, c));
	ans = min(ans, 1 + recur(a, b, c + 2));
	return dp[a][b][c] = ans;
}

int main(){
	memset(dp, -1, sizeof(dp));
	int a, b, c;
	cin >> a >> b >> c;
	cout << recur(a, b, c) << endl;
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define LL long long
string a,b,c;

int main(){
cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES";
  else cout<<"NO";
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main()
{
    ios_base::sync_with_stdio (false);
    int n,k;
    cin >> n >> k;
    vector<long long> heights(n);
    vector<long long> costs(n);
    fill (costs.begin() + 1, costs.end(), LLONG_MAX);
    for (int i =0; i < n; i++){
        cin >> heights[i];
        for (int j = max(0, i - k); j < i; j++ ){
            costs[i] = min(costs[j] + abs(heights[i] - heights[j]), costs[i]);
        }
    }
    cout << costs[n-1];
    return 0;
}


Measured memory_bytes: 1792
import math

x,y = map(int, input().split())
# (i,j)->(i+1,j+2) continues a times.
# (i,j)->(i+2,j+1) continues b times.
temp = 2*x-y

a = -1
b = -1
if temp%3==0 and temp>=0:
  b = temp//3
  if x-2*b>=0:
    a = x-2*b

if a==-1 or b==-1:
  print(0)
else:
  #このままではansは非常に大きい数になりメモリ使用量が大きくなる。
  #よって、メモリ使用量削減のために"逆元とフェルマーの小定理"を活用する。
  A = 1
  B = 1
  mod = 10**9+7
  for i in range(min(a,b)):
    A *= a+b-i
    A %= mod
    B *= i+1
    B %= mod
  print(A*pow(B,mod-2,mod)%mod)

Measured memory_bytes: 3064
#include <iostream>

#define int long long int
using namespace std;

void solve() {
  int N, K;
  cin >> N >> K;

  N = N % K;
  if (N > K/2) {
    N = K - N;
  }

  cout << N << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

int main()
{
    int d;
    cin >> d;
    int c[26];
    for(int i = 0; i < 26; i++) cin >> c[i];
    int s[400][26];
    for(int i = 0; i < d; i++){
        for(int j = 0; j < 26; j++) cin >> s[i][j];
    }
    int last[26];
    for(int i = 0; i < 26; i++) last[i] = -1;
    for(int i = 0; i < d; i++){
        int l = 0;
        for(int j = 0; j < 26; j++){
            if(s[i][j] + (i - last[j]) * c[j] > s[i][l] + (i - last[l]) * c[l] &&
               (i - last[l]) * c[l] > min(i * 15, 300)){
                l = j;
            }
        }
        last[l] = i;
        cout << l + 1 << endl;
    }
}


Measured memory_bytes: 3664
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vll a(n+1,0);
    vll b(n);
    REP(i,n+1) cin >> a[i];
    REP(i,n) cin >> b[i];
    ll ans = 0;
    REP(i,n){
        if(b[i]<=a[i]){
            a[i]-=b[i];
            ans+=b[i];
        }else{
            ans+=a[i];
            ll tmp = min(a[i+1],b[i]-a[i]);
            ans+= tmp;
            a[i+1]-=tmp;
        }
    }
    cout << ans << endl;
    return 0;
}

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

ll a, b, ans;

int main()
{
    cin >> a >> b;
    if(abs(a) < abs(b)){
        if(a < 0){
            ans++;
            a = -a;
        }
        if(b < 0){
            ans++;
            b = -b;
        }
        cout << ans + b - a << endl;
    }
    else if(abs(a) > abs(b)){
        if(a > 0){
            ans++;
            a = -a;
        }
        if(b > 0){
            ans++;
            b = -b;
        }
        cout << ans + b - a << endl;
    }
    else {
        cout << 1 << endl;
    }


    return 0;
}


Measured memory_bytes: 256
import collections

N = int(input())
A = [int(i) for i in input().split()]

stick_num = collections.Counter(A)
flag = True
ans = 0
for i in sorted(stick_num, reverse=True):
    if stick_num[i] >= 4:
        ans = i * i if flag else a * i
        break
    elif stick_num[i] >= 2:
        if flag:
            a = i
            flag = False
        else:
            ans = a * i
            break

print(ans)

Measured memory_bytes: 18600
"""
A<=0.08x<A+1
C<=0.1x<C+1
"""

A,C = (input()).split(" ")
A = (int)(A)
C = (int)(C)

leftA = A/0.08
rightA = (A+1)/0.08

leftC = C/0.1
rightC = (C+1)/0.1



if rightC<=leftA or rightA<=leftC:
    print(-1)
else:
    max_line = max(leftA,leftC)
    if max_line == (int)(max_line):
        print((int)(max_line))
    else:
        print((int)(max_line)+1)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cfloat>
#define zero(x) (((x)>0?(x):-(x))<eps)

#define pause cout << " press ansy key to continue...",  cin >> chh
#define file_r(x) freopen(x,  "r",  stdin)
#define file_w(x) freopen(x,  "w",  stdout)
#define lowbit(x) ((x) & (-x))
#define repit(i, c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, u) for (int i = head[u]; i != -1; i = nxt[i])
#define repd(i, n) for (int i = (n - 1); i >= 0; i--)
#define FOR(i, n, m) for (int i = (n); i <= (m); i++)
#define FORD(i, n, m) for (int i = (n); i >= (m); i--)
#define pb push_back
#define X first
#define Y second
#define ins insert
#define rb rbegin
#define be begin
#define er erase
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define SZ(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define sqr(r) ((r) * (r))
#define dis(x1, y1, x2, y2) (((x1) - (x2)) * ((x1) - (x2)) + ((y1) - (y2)) * ((y1) - (y2)))
#define FASTIO ios::sync_with_stdio(false);cin.tie(0)

#define sc(x) cout << #x" = " << x << endl, pause
#define sc2(x, y) cout << #x" = " << x << " " << #y" = " << y << endl, pause
#define sc3(x, y, z) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << endl, pause
#define sc4(x, y, z, w) cout << #x" = " << x << " " << #y" = " << y << " " << #z" = " << z << " " << #w" = " << w << endl, pause

#define in(n) scanf("%d", &n)
#define in2(n, m) scanf("%d %d", &n, &m)
#define in3(x, y, z) scanf("%d %d %d", &x, &y, &z)

using namespace std;
int chh;

typedef vector<int> vi;
typedef set<int> si;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<int, pii> pi3;
typedef vector< pair<int, int> > vpii;
typedef long long LL;

const int N = 100005;

int n, m;
vi g[N];
bool f[N];
vi ans;

void dfs(int p) {
    int v;
    ans.pb(p);
    f[p] = 1;
    repit (it, g[p]) {
        v = *it;
        if (f[v]) continue;
        dfs(v);
        break;
    }
}

int main() {
    int x, y;
    while (~in2(n, m)) {
        FOR (i, 1, n) g[i].clear();
        rep (i, m) {
            in2(x, y);
            g[x].pb(y);
            g[y].pb(x);
        }
        FOR (i, 1, n) f[i] = 0;
        ans.clear();
        dfs(1);
        reverse(ALL(ans));
        repit (it, g[1]) {
            x = *it;
            if (f[x]) continue;
            dfs(x);
            break;
        }
        x = SZ(ans);
        printf("%d\n", x);
        rep (i, x - 1) printf("%d ", ans[i]);
        printf("%d\n", ans[x - 1]);
    }
    return 0;
}


Measured memory_bytes: 9720
#include<bits/stdc++.h>
#define M 100006
using namespace std;
int dp[M][4],a[M];
int max(int a,int b)
{
	if(a>b)return a;
	return b;
 } 
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	for(int j=1;j<=3;++j)cin>>dp[i][j];
	for(int i=2;i<=n;++i)
	{
		for(int j=1;j<=3;++j)
		{
			int mx=0;
			for(int k=1;k<=3;++k)
			{
				if(k!=j)mx=max(mx,dp[i-1][k]);
			}
			dp[i][j]+=mx;
		}
	}
	int mx=0;
	for(int i=1;i<=3;++i)
	{
		mx=max(mx,dp[n][i]);
	}
	cout<<mx;
}

Measured memory_bytes: 1792