akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int[] A = new int[N];
        SegmentTree st = new SegmentTree(N);
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
            st.update(i, A[i]);
        }
        int check;
        check = st.getIn(0, N-1);
        // System.out.println(check);
        ans = Math.max(ans,check);
        check = st.getIn(1, N);
        // System.out.println(check);
        ans = Math.max(ans,check);
        for (int i = 1; i < N-1; i++) {
            check = gcd(st.getIn(0, i),st.getIn(i+1, N));
            // System.out.println(check);
            ans = Math.max(ans,check);
        }

        
        
        System.out.println(ans);
    }

    static int gcd(int m, int n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }

    public static void main(String[] args) {
        new Main();
    }
}

class SegmentTree {
    int[] data;
    int size;
    int rawsize;
    int rawindex;

    SegmentTree(int size) {
        this.size = size;
        int n = 2;
        while (n < size)
            n <<= 1;
        rawsize = n;
        rawindex = n - 1;
        n = n * 2 - 1;
        data = new int[n];
    }

    void update(int index, int val) {
        data[rawindex + index] = val;
        innerUpdate((rawindex + index - 1) / 2);
    }

    private void innerUpdate(int index) {
        /* structing tree */
        data[index] = gcd(data[index * 2 + 1], data[index * 2 + 2]);
        if (index == 0)
            return;
        innerUpdate((index - 1) / 2);
    }

    int getIn(int left, int right) {
        return innerGetIn(left, right, 0, 0, rawsize);
    }

    static int gcd(int m, int n) {
        if (m < n)
            return gcd(n, m);
        if (n == 0)
            return m;
        return gcd(n, m % n);
    }

    private int innerGetIn(int left, int right, int index, int l, int r) {
        if (r <= left || right <= l)
            throw new Error(String.format("%d %d - %d - %d %d", left,right,index,l,r));
        if (left <= l && r <= right)
            return data[index];
        int mid = (l + r) / 2;
        if (right <= mid) {
            return innerGetIn(left, right, index * 2 + 1, l, mid);
        } else if (mid <= left) {
            return innerGetIn(left, right, index * 2 + 2, mid, r);
        } else {
            int lm = innerGetIn(left, right, index * 2 + 1, l, mid);
            int rm = innerGetIn(left, right, index * 2 + 2, mid, r);
            /* restruct here */
            return gcd(lm, rm);
        }
    }

    int getAt(int index) {
        return data[rawindex + index];
    }
}


Measured memory_bytes: 50172
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
LL a[MAXN];
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif
    LL n;
    cin>>n;
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    if(a[n-1]!=2) return cout<<"-1"<<endl,0;
    LL ul = 2,ur=3,dl=2,dr=2;
    for (int i = n-2; i > -1; --i)
    {
    	// debug(ul);
    	// debug(ur);
    	if(ur<a[i]) return cout<<"-1"<<endl,0;
    	dl = ul%a[i]==0?ul:(ul/a[i]*a[i]+a[i]);
    	dr = ur%a[i]==0?ur:(ur/a[i]*a[i]);
    	if(dr<dl) return cout<<"-1"<<endl,0;
    	ul = dl;
    	ur = dr+a[i]-1;
    	if(ur<ul) return cout<<"-1"<<endl,0;
    	// debug(dl);
    	// debug(dr);
    	// debug(ul);
    	// debug(ur);
    	// cerr<<endl;
    }
    cout<<ul<<" "<<ur<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int a;
  cin>>a;
  vector<int> b(a - 1),c(a);
  for(int i = 0;i < a - 1;i++){
   cin>>b.at(i);
    c.at(b.at(i) - 1)++;
  }
    for(int i = 0;i < a;i++){
    cout<<c.at(i)<<endl;
  }
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a;
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputDoubleArray(a,N) double a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
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; }

/*学習のまとめ
グラフ→頂点のベクトル→頂点は辺のベクトル。辺を行き先と長さの情報を持つ構造体として定義。
頂点のステータスを定義。-1→未探索。1/0→色が付いている。
return a = b; aにbを代入しながらリターン。
if(!a) return false; 再帰。再帰して一個でも不可能であればその時点で終わり。
*/


//参考
/*int rec(int v) {
    if (dp[v] != -1) return dp[v]; // 既に更新済み

    int res = 0;
    for (auto nv : G[v]) {//要素nvについてループを回す。
        chmax(res, rec(nv) + 1);
    }
    return dp[v] = res; // メモしながらリターン
}*/

struct Edge {
  int to;
  int weight;
  Edge(int t, int w):to(t),weight(w){}
};

typedef vector<vector<Edge>> Graph;//グラフ→ノードの配列→辺の構造体を持った配列という抽象化
//Edgeのベクトル→ノード。ノードのベクトル→グラフ。

vector<int> status;

bool dfs(const Graph &G, int v, int cur = 0){//default
  status[v] = cur;//まず塗る
  
    for(auto edge : G[v]){//隣接する辺について
      
      if(status[edge.to] == -1){//未探索なら
        if(edge.weight%2 == 0){//辺の重みが偶数の時
          if(!dfs(G,edge.to,cur)) return false;//同じ色で塗る→再帰
        }else{
          if(!dfs(G,edge.to,1-cur)) return false;
        }
      }else if(status[edge.to] == cur){
        if(edge.weight%2 == 0){
          continue;
        }else{
          return false;
        }
      }else{
        if(edge.weight%2 == 0){
          return false;
        }else{
          continue;
        } 
      } 
    }
  return true;
}

int main() {
    // 入力受け取り
    inputInt(N);
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        int from, to, weight;
        cin >> from >> to >> weight;
        --from, --to; // 0-indexed にする
        G[from].push_back(Edge(to,weight));//GraphVector[x]にyを追加
        G[to].push_back(Edge(from,weight));
    }
  
    //二部グラフ判定
    // 探索
    status.assign(N, -1);//初期化
    bool is_bipartite = true;
    for (int v = 0; v < N; ++v) {
        if (status[v] != -1) continue; // v が探索済みだったらスルー
        if (!dfs(G, v)) is_bipartite = false; //DFSの結果がfalseの時。今回の場合はtrueが保証されている。
    }

    if (is_bipartite) {
      fN(i,N) cout << status[i] << endl;  
    }
}

Measured memory_bytes: 8192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <deque>
#include <string>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <map>
#include <unordered_map>
#include <bitset>

#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 1000001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;


int num_of_divs(int n, set<int> &s){
    int cnt = 0;
    for (int i = 2; i * i <= n; i++){
        if (n % i == 0) {
            cnt++;
            while(n % i == 0) n /= i;
            s.insert(i);
        }
    }
    if (n > 1) s.insert(n), cnt++;
    return cnt;
}

int gcd(int a, int b){
    return (!b) ? a : gcd(b, a % b);
}
int v[MAX];
int main(){
    FREEELO
    int s_c;
    int n; cin >> n;
    int cnt = 0;
    set<int> s;
    loop(i, n){
        cin >> v[i];
        if (i == 1) s_c = v[i];
        s_c = gcd(s_c, v[i]);
    }
    if (s_c != 1) {
        cout << "not coprime" << endl;
        return 0;
    }
    int p_c = 1;
    loop(i, n){
        cnt += num_of_divs(v[i], s);
        if (cnt != sz(s)) {
            p_c = 0;
            break;
        }
    }
    if (p_c) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;

}

Measured memory_bytes: 7044
/*
by.YXH_XianYu
   2018.8.25
 */
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
#define REG register
#define rep(i, j, k) for(int i = j, lim = k; i <= lim; i++)
#define req(i, j, k) for(int i = j, lim = k; i >= lim; i--)
#define MXN 100005

int n,
	a[MXN],
	s[MXN];

#define Lowbit(x) ((x)&(-(x)))
int bit[MXN << 1], bitLim = 200000;
void Modify(int x) {
	for(; x <= bitLim; x += Lowbit(x)) bit[x] ++;
}
LLI Query(int x) {
	LLI res = 0; for(; x; x -= Lowbit(x)) res += bit[x]; return res;
}
void Init() {
	for(REG int i = 1; i <= bitLim; i ++) bit[i] = 0;
}

bool Judge(int x) {
	REG int i;
	Init();
	s[0] = 0;
	for(i = 1; i <= n; i ++)
		s[i] = s[i-1] + (a[i]>=x?1:-1);
	LLI sum = 0;
	for(i = 0; i <= n; i ++) {
		sum += Query(s[i] + MXN);
		Modify(s[i] + MXN);
	}
	return sum >= 1ll*n*(n+1)/4;
}

int main() {
	//freopen("TEMPLATE.in", "r", stdin);
	//freopen("TEMPLATE.out", "w", stdout);
	REG int i, l, r, md;

	scanf("%d", &n);
	l = 1; r = 0;
	for(i = 1; i <= n; i ++)
		scanf("%d", &a[i]), r = std::max(r, a[i]);
	while(l <= r) {
		md = (l + r) >> 1;
		if(Judge(md))
			l = md + 1;
		else
			r = md - 1;
	}
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 1792
word = input()
nums = word.split()
numin = [0,0,0]
seiko = 0
for j in range(3):
    numin[j] = int(nums[j])
k = int(input())

for i in range(k+1):
    if numin[0] >= numin[1]:
        numin[1] *= 2
    elif numin[1] >= numin[2]:
        numin[2] *= 2
    else:
        seiko = 1
        print('Yes')
        break

if seiko == 0:
    print('No')

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

int main(){
  string str;
  int ab[26]={0};

  while(getline(cin,str)){
    for(int i=0;i<str.size();i++){
      if(str[i]>='a' && str[i]<='z')
        ab[str[i]-'a']++;
      else if(str[i]>='A' && str[i]<='Z')
        ab[str[i]-'A']++;
    }
  }
  for(int i=0;i<26;i++){
    cout << (char)('a' + i) << " : " << ab[i] << endl;
  }
}



Measured memory_bytes: 3184
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		long a[] = fs.nextLongArray(n);
		Arrays.sort(a);
		
		long ans[][] = new long[n-1][2];
		//最初の２数の符号が一致する場合はダメなので、一致してたら配列の最初と最後を入れ替え
		long tmp = a[1];
		a[1] = a[n-1];
		a[n-1] = tmp;	
		
		long now = a[0];
		for(int i=1;i<n-1;i++) {
			if(a[i+1]>=0) {
				if(now>=a[i]) {
					ans[i-1][0] = a[i];
					ans[i-1][1] = now;
				}
				else {
					ans[i-1][0] = now;
					ans[i-1][1] = a[i];	
				}				
				now = Math.min(a[i] - now,now - a[i]);
			}
			else {
				if(now<a[i]) {
					ans[i-1][0] = a[i];
					ans[i-1][1] = now;
				}
				else {
					ans[i-1][0] = now;
					ans[i-1][1] = a[i];	
				}		
				now = Math.max(a[i] - now,now - a[i]);
			}
		}
		//最後は引き算の大きい方を出力
		if(now >= a[n-1]) {
			ans[n-2][0] = now;
			ans[n-2][1] = a[n-1];
		}
		else {
			ans[n-2][0] = a[n-1];
			ans[n-2][1] = now;
		}
		now = Math.max(a[n-1] - now,now - a[n-1]);
		
		System.out.println(now);
		for(int i=0;i<n-1;i++) {
			System.out.println(ans[i][0] + " " + ans[i][1]);
		}
		
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

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

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

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

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

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

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

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

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

Measured memory_bytes: 63556
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] d = nextIntArray(sc, N);

		sc.close();

		int ans = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				ans += d[i] * d[j];
			}
		}

		out.println(ans);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
using namespace std;
int main() {
    string s;
    cin >> s;
    int n = s.size();
    int b, e;
    for(int i = 0; i < n; i++){
        if(s[i]=='A') {   
            b = i;
            break;
        }
    }

    for(int j = 0; j < n; j++){
        if(s[j] == 'Z') {
            e = j;
        }
    }

    cout  << e - b + 1 << endl;
    return 0;
}

Measured memory_bytes: 3720
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w, n;
        int[] amida;

        w = sc.nextInt();
        n = sc.nextInt();
        amida = new int[w];
        for(int j=0;j<w;j++)
            amida[j]=j+1;
        for(int i=0;i<n;i++){
            String s = sc.next();
            String[] sp = s.split(",");
            int c;
            int a=Integer.parseInt(sp[0]);
            int b=Integer.parseInt(sp[1]);
            c = amida[a-1];
            amida[a-1]=amida[b-1];
            amida[b-1]=c;
        }
        for(int k=0;k<w;k++){
            System.out.println(amida[k]);
        }


    }
}



Measured memory_bytes: 25912
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <queue>
#include <string>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll          = long long;
using db          = double;
using ld          = long double;
using uint        = unsigned int;
using ull         = unsigned long long;

using pii         = pair<int, int>;
using pll         = pair<ll, ll>;
using tiii        = tuple<int, int, int>;

#define mod7        1000000007
#define mod9        1000000009

#define forall(v)   v.begin(), v.end()
#define prec(x)     setprecision(x) << fixed

/* [💭] [💡] [🎈] */

int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ld t, x;
    cin >> t >> x;
    cout << prec(10) << t / x;


    return 0;
}

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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll a, b;
    cin >> a >> b;

    ll x = a & 1L;
    ll y = b & 1L;

    ll l = a;
    ll r = b;

    ll ans = 0;
    if(x == 1) {
        ans ^= a++;
    }
    if(y == 0) {
        ans ^= b--;
    }
    // cout << (123 ^ 456) << endl;
    // cout << a << " " << b << " " << ans << endl;

    ll c = (b - a + 1) % 4L;

    if(c / 2 == 1)
        ans ^= 1L;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <climits>
#include <bitset>
#include <cassert>

using namespace std;

const int SIZE = 1 << 17;

int pointer = SIZE;
char buffer[SIZE];

char Advance() {
    if (pointer == SIZE) {
        fread(buffer, 1, SIZE, stdin);
        pointer = 0;
    }
    return buffer[pointer++];
}

int Read() {
    int answer = 0,sign = 1;
    char ch = Advance();
    while (!isdigit(ch) && ch != '-')
        ch = Advance();
    if (ch == '-') {
        ch = Advance();
        sign = -1;
    }
    while (isdigit(ch)) {
        answer = answer * 10 + ch - '0';
        ch = Advance();
    }
    return answer * sign;
}

char ReadCh() {
    char ch = Advance();
    while (!isalpha(ch))
        ch = Advance();
    return ch;
}

const int MAXN = 300;

int dp[1 + MAXN + 1][1 + MAXN + 1][1 + MAXN + 1];
char s[1 + MAXN + 1];

int main() {
    //freopen("tema.in", "r", stdin);
    //freopen("tema.out", "w", stdout);
    scanf("%s", s + 1);
    int p, n = strlen(s + 1);
    scanf("%d", &p);
    for (int i = 1; i <= n; i++)
        for (int j = n; j > i; j--)
            for (int k = 0; k <= p; k++) {
                dp[i][j][k] = max(dp[i - 1][j][k], dp[i][j + 1][k]);
                if (s[i] == s[j])
                    dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j + 1][k] + 1);
                else
                    if (k > 0)
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j + 1][k - 1] + 1);
            }
    int answer = 0;
    for (int i = 1; i < n; i++)
        answer = max(answer, 2 * dp[i][i + 1][p]);
    for (int i = 1; i <= n; i++)
        answer = max(answer, 2 * dp[i - 1][i + 1][p] + 1);
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 106240
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main() {
    int K, T;
    cin >> K >> T;

    vector<int> cake(T);
    for (int i = 0; i < T; i++)
        cin >> cake[i];

    sort(cake.begin(), cake.end(),greater<int>());
  
    int total = 0;
    for (int i = 1; i < T; i++) 
        total += cake[i];
    
    int ans = 0;
    if (cake[0] - 1 > total)
        ans = cake[0] - 1 - total;

    cout << ans << endl;
    
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    map<ll, ll> mp;
    for (int i = 0; i <= n; i++) {
        mp[a[i]]++;
    }

    ll ans = 0;
    for (auto& p : mp) {
        ans += p.second * (p.second - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define loop(i,a,b) for(ll i=a; i<b; i++)
#define revloop(i,a,b) for(ll i=a; i>=b; i--)
#define pb push_back
#define vl vector<ll>
#define vvl vector<vl>
#define pl pair<ll,ll>
#define vpl vector<pl>
#define all(c) (c).begin(), (c).end()
#define sz(a) ((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i!=(c).end(); i++))
#define mp make_pair
#define ss second
#define ff first
#define ld long double
const ll INF = 1e13;
const ll N = 301;
const ll mod= 1000000007;
bool prime(ll x)
{
	if(x<2) return false;
	for(ll i=2; i*i<=x; i++) if(x%i==0) return false;
	return true;
}
vl fac(N);
void fact()
{
	fac[0]=1;
	loop(i,1,N) fac[i]=(fac[i-1]*i)%mod;
}
 ld dp[N][N][N];
void solve()
{
  
  ll n,x;
  ll c1=0, c2=0, c3=0;
  cin>>n;
  loop(i,0,n)
  {
  	cin>>x;
  	if(x==1) c1++;
  	if(x==2) c2++;
  	if(x==3) c3++;
  }
  loop(i,0,n+1)
  {
  	loop(j,0,n+1)
  	{
  		loop(k,0,n+1)
  		{
  			ll sum = i+j+k;
  			if(sum==0)
  			{
  				dp[i][j][k]=0;
  				continue;
			}
			dp[i][j][k]+=n;
			if(i) dp[i][j][k]+=dp[i-1][j+1][k]*i;
			if(j) dp[i][j][k]+=dp[i][j-1][k+1]*j;
			if(k) dp[i][j][k]+=dp[i][j][k-1]*k;
			dp[i][j][k]/=sum;
		}
	}
  }
  cout<<fixed<<setprecision(13)<<dp[c3][c2][c1];
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--) solve();
 return 0;
}

Measured memory_bytes: 426368
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();

        if(a>b){
            System.out.println("a > b");
        }else if(a<b){
            System.out.println("a < b");
        }else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26152
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var x int
	card := make([]string, 9)
	for i := range card {
		fmt.Scan(&x)
		card[i] = strconv.Itoa(x)
	}

	var n int
	fmt.Scan(&n)
	arr := make([]string, n)
	for i := range arr {
		fmt.Scan(&x)
		arr[i] = strconv.Itoa(x)
	}

	line := [][]int{{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}}

	chk := make([]int, 9)
	for i, _ := range chk {
		for _, v2 := range arr {
			if card[i] == v2 {
				// カードの数字と玉の数字が一致したら、chkに1でマークする
				chk[i] = 1
				break
			}
		}
	}

	result := false
	for i, _ := range line {
		if chk[line[i][0]] == 1 && chk[line[i][1]] == 1 && chk[line[i][2]] == 1 {
			result = true
			break
		}
	}

	if result == true {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}


Measured memory_bytes: 512
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X = int(readline())

    if X < 600:
        ans = 8
    elif X < 800:
        ans = 7
    elif X < 1000:
        ans = 6
    elif X < 1200:
        ans = 5
    elif X < 1400:
        ans = 4
    elif X < 1600:
        ans = 3
    elif X < 1800:
        ans = 2
    else:
        ans = 1

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61772
#include<stdio.h>

#define MAXN 2000001

void CountingSort(int *,int *,int);

int n;
int A[MAXN];
int B[MAXN];
int C[MAXN];

int main()
{
  int i;
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  
  CountingSort(A,B,10000);

  for(i=1;i<=n;i++)
    {
      if(i>1) printf(" ");
  printf("%d",B[i]);
    }
  printf("\n");
  
  return 0;

}


void CountingSort(int A[], int B[], int k)
{
  int i,j;
  for (i=0;i<=k;i++)
    {
      C[i]=0;
    }

  for (j=0;j<n;j++)
    {
      C[A[j]]++;
    }
  for (i=1;i<=k;i++)
    {
      C[i]+=C[i-1];
    }
  
  for (j=n;j>=0;j--)
    {
      B[C[A[j]]]=A[j];
      C[A[j]]--;
    }
}

Measured memory_bytes: 17896
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from fractions import gcd
from functools import lru_cache

#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
a = inputIL()
b = inputIL()

difa = [0]*N
difb = [0]*N
for i in range(N-1):
  difa[i] = a[i]^a[i+1]
  difb[i] = b[i]^b[i+1]
difa[N-1] = a[0]^a[N-1]
difb[N-1] = b[0]^b[N-1]

if set(difa) != set(difb):
  exit()

memo = []
for i in range(N):
  j = 0
  while difa[(i+j)%N] == difb[j%N]:
    j += 1
    if j == N:
      print(i,a[i]^b[0])
      memo.append(i)
      break
  if len(memo) == 2:
    break

if len(memo) == 2:
  d = memo[1]-memo[0]
  k = memo[1]+d
  while k < N:
    print(k,a[k]^b[0])
    k += d


Measured memory_bytes: 128628
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
long long a,b;
int ans;
int gcd(long long x,long long y){
  ans+=1;
  if(x%y==0){
    return y;
  }else{
    gcd(y,x%y);
  }
}
int main()
{
  while(cin>>a>>b,a||b){
    ans = 0;
    if(a>=b){
      cout<< gcd(a,b)<<" ";
      cout <<ans<<endl;
    }else{
      cout<<gcd(b,a)<<" ";
      cout <<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
 
int main()
{
  int N, A[100001];
  int ret = 0;
 
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  A[N] = A[N - 1];
 
  vector< int > data = {0, 0};
  int dec = 1;
  for(int i = 1; i <= N; i++) {
    if(A[i - 1] == A[i]) data.push_back(dec), dec = 1;
    else ++dec;
  }
   
  for(int i = 2; i < data.size(); i++) {
    ret = max(ret, data[i - 2] + data[i - 1] + data[i]);
  }
 
  cout << ret << endl;
}

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

int main() {

  long long int e;

  while( true ) {

    cin >> e;

    if ( e == 0 ) break;

    long long int ans = 10000000;

    for ( long long int z = 0; z * z * z <= e; z++ ) {

      long long int e2 = e - z * z * z;

      for ( long long int y = 0; y * y <= e2; y++ ) {

	ans = min( ans, e2 - y * y + y + z );

      }

    }

    cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
vector<int> row[2020],col[2020];
char grid[2020][2020];
int main()
{
	int H,W;
	cin>>H>>W;
	for(int i=0;i<W;i++)
		col[i].push_back(-1);
	for(int i=0;i<H;i++)
	{
		row[i].push_back(-1);
		for(int j=0;j<W;j++)
		{
			cin>>grid[i][j];
			if(grid[i][j]=='#')
				row[i].push_back(j),
				col[j].push_back(i);
		}
		row[i].push_back(W);
	}
	for(int i=0;i<W;i++)
		col[i].push_back(H);
	int ans=0;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			if(grid[i][j]=='.')
			{
				int r=*lower_bound(row[i].begin(),row[i].end(),j)-*(lower_bound(row[i].begin(),row[i].end(),j)-1)-1;
				int c=*lower_bound(col[j].begin(),col[j].end(),i)-*(lower_bound(col[j].begin(),col[j].end(),i)-1)-1;
				ans=max(ans,r+c-1);
			}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 38400
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N, K; cin >> N >> K;
    vector<bool> A(N);
    rep(i,K) {
        int d; cin >> d;
        rep(j,d) {
            int a; cin >> a;
            A[a-1] = true;
        }
    }
    int ans = 0;
    rep(i,N) if(!A[i]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <map>
#include <functional>
#include <cmath>
using namespace std;
#pragma warning(disable: 4996)
long long X, Y, C = 0;
int main() {
	cin >> X >> Y;
	while (X <= Y) { C++; X *= 2; }
	cout << C << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

def lcm(a, b):
    return a * b // gcd(a, b)

def calc(n, a, b):
    return n//a + n//b - n//lcm(a,b)

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ## これで通った
    # num1 = b - calc(b,c,d)
    # num2 = (a-1) - calc(a-1, c,d)
    # print(num1-num2)

    ## これはとおらない
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(int(b - a + 1 - ans))


Measured memory_bytes: 6356
import sys
input = sys.stdin.readline

def factors(x: int) -> list:
    s, xx = [], x
    for i in range(2, int(x ** 0.5 + 1)):
        if xx % i == 0:
            c = 0
            while xx % i == 0: c += 1; xx //= i
            s.append((i, c))
    if xx != 1: s.append((xx, 1))
    if s == []: s.append((x, 1))
    return s

n, res = int(input()), 0
f = factors(n)
pre = [1, 3, 6, 10, 15, 21, 28, 36, 43]
flag = False
if len(f) == 1 and f[0][0] == 1: print(0); flag = True
if not flag:
    for fact in f:
        for i in range(len(pre)):
            if pre[i] > fact[1]: res += i; break
    print(res)

Measured memory_bytes: 63460
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = (n - 1) / (k - 1);
  if ((n - 1) % (k - 1)){
    cout << ans + 1 << endl;
  } else {
    cout << ans << endl;
  }

}



Measured memory_bytes: 640
#include<iostream>
#include<queue>
#include<algorithm>
#include<string.h>
using namespace std;
struct nagase {
		int x;
		int y;
		int c;
		int r;
};
int kani[4]={0,1,-1,0};
int ebi[4]={1,0,0,-1};
long long map[1001][1001]={0};
int s[1001][1001];
int main(){
	queue<nagase>Q;
	nagase kotani;
	nagase yanagi;
	int h,w,n;
	cin>>h>>w>>n;
	char a;
	memset(s,0,sizeof(s));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>a;
			if(a=='S'){
				kotani.x=i;
				kotani.y=j;
				kotani.c=1;
				kotani.r=0;
				s[i][j]=1;
				Q.push(kotani);
			}
			else if(a=='X'){
				map[i][j]=-1;
			}
			else if(a=='.'){
				map[i][j]=0;
			}
			else{
				map[i][j]=(int)(a-48);
			}
		}
	}
	while(!Q.empty()){
		yanagi=Q.front();
		Q.pop();
		if(yanagi.c==map[yanagi.x][yanagi.y]){
			if(yanagi.c==n){
				cout<<yanagi.r<<endl;
				break;
			}
			while(!Q.empty()){
				Q.pop();
			}
			yanagi.c++;
			memset(s,0,sizeof(s));
			s[yanagi.x][yanagi.y]=1;
			Q.push(yanagi);
		}
		else{
			for(int i=0;i<4;i++){
				if(yanagi.x+kani[i]>=0&&yanagi.x+kani[i]<h&&yanagi.y+ebi[i]>=0&&yanagi.y+ebi[i]<w&&map[yanagi.x+kani[i]][yanagi.y+ebi[i]]!=-1&&s[yanagi.x+kani[i]][yanagi.y+ebi[i]]!=1){
					kotani=yanagi;
					kotani.x=yanagi.x+kani[i];
					kotani.y=yanagi.y+ebi[i];
					kotani.c;
					kotani.r++;
					s[yanagi.x+kani[i]][yanagi.y+ebi[i]]=1;
					Q.push(kotani);
				}
			}
		}
	}
}

		

			
	

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

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

#define N_MAX 1001010
ll inv[N_MAX];

ll pow(ll x,ll n){  // xのn乗 (mod m)
    ll res = 1;
    if(n > 0){
        res = pow(x,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }else{
            res = (((res * res) % mod) * x) % mod;
        }
    }
    return res;
}

ll init()
{
    rep(i,N_MAX) inv[i] = pow((ll)i,mod-2);
}

int main()
{
    init();
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    ll tmp = 1;
    map<int,int> mp;
    rep(i,n){
        int x = a[i];
        for(int i = 2; i * i <= x; i++){
            int cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            if(cnt > 0) mp[i] = max(mp[i],cnt);
        }
        if(x != 1){
            mp[x] = max(mp[x],1);
        }
    }
    ll lcm = 1, ans = 0;
    for(auto i : mp){
        lcm *= pow(i.first,i.second);
        lcm %= mod;
    }
    rep(i,n){
        ans += lcm * inv[a[i]];
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8576
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;

int main(){
  int num;
  while(cin >> num){
    int sum =0;
    int count =0;
    for(int a=0 ; a<=9 ; a++){
      for(int b=0 ; b<=9 ; b++){
	for(int c=0 ; c<=9 ; c++){
	  for(int d=0 ; d<=9 ; d++){
	    if(a+b+c+d == num)count++;
	  }
	}
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
A = "012345678954321012345678"
B = "6789543210123456789"
n = int(input())
for i in range(n):
    a, b = input().split()
    if int(a) < int(b):
        print(" ".join(A[A.index(a):A.index(b,A.index(a))+1]))
    else:
        print(" ".join(B[B.index(a):B.index(b,B.index(a))+1]))


Measured memory_bytes: 5600
import sys
from operator import itemgetter
def main():
	inputs = sys.stdin.readline
	N, Q= map(int,inputs().split())
	E = [None]*2*N
	for n in range(N):
		a,b,c = map(int,inputs().split())
		E[2*n] = (a - c, 1, c)
		E[2*n + 1] = (b - c, -1, c)
	E.sort(key=itemgetter(0))
	tuple(tuple(E))
	mini = 1000000001
	kouho = {1000000001}
	my_add = kouho.add
	my_discard = kouho.discard
	q = 0
	d = int(inputs())
	flag = False
	cont = False
	for e in E:
		while e[0] > d:
			if cont == True:
				print(mini-(mini//1000000001)*1000000002)
			else:
				mini = min(kouho)
				print(mini-(mini//1000000001)*1000000002)
			cont = True
			q = q + 1
			if q > Q-1:
				flag = True
				break
			d = int(inputs())
		if flag == True:
			break
		if e[1] == 1:
			my_add(e[2])
			if mini > e[2]:
				mini = e[2]
		elif e[1] == -1:
			my_discard(e[2])
			if mini == e[2]:
				cont = False
	for t in [None]*(Q-q):
		print(-1)
main()

Measured memory_bytes: 69268
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	vector<ll>A(N + 1), B(N);
	for (int i = 0; i < N + 1; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}
	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		if (i == N - 1) {
			ans += min(B[N - 1], A[N - 1] + A[N]);
			break;
		}
		if (B[i] <= A[i]) {
			ans += B[i];
		}
		else {
			ans += min(B[i], A[i] + A[i + 1]);
			A[i + 1] -= (B[i] - A[i]);
			if (A[i + 1] < 0)A[i + 1] = 0;
		}
	}
	cout <<ans<< endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (int i = 1;; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                System.exit(0);
            }
            System.out.printf("Case %d: %d\n", i, x);
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}


int po[33];

signed main(){
	po[0]=1;
	for(int i=1;i<33;i++)po[i]=po[i-1]*26;
	
	int N;cin>>N;N--;
	int L=1;
	while(po[L]<=N){
		N-=po[L];
		L++;
	}
	string ans(L,'a');
	for(int i=L-1;i>=0;i--){
		ans[i]=N%26+'a';
		N/=26;
	}

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


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long modpow(long long x, int n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}
long long inv(long long n){
    return modpow(n,mod-2);
}
long long binom(long long n, long long r){
    long long top=1, bot=1;
	r=min(r,n-r);
    for(long long i=0; i<r; ++i) top = top*(n-i) %mod;
    for(long long i=r; i>1; --i) bot = bot*i %mod;
    return top*inv(bot)%mod;
}
int main(){
	int n, a, b;
	cin >> n >> a >> b;

	int ans=modpow(2,n)-1;
	ans -= binom(n,a);
	if(ans<0) ans+=mod;
	ans -= binom(n,b);
	if(ans<0) ans+=mod;

	cout << ans%mod << endl;
}

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

int main(){
  int r0, w0, c, r;
  while(true){
    cin >> r0 >> w0 >> c >> r;
    if(r0 == 0)
      break;

    int res = c * w0 - r0;
    int ans = 0;
    if(res > 0){
      if(res % r == 0){
        ans = res / r;
      }else{
        ans = res / r + 1;
      }
    }
        
    cout << ans << endl;
  } 
  
  return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,a,b=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        while(a%2==0){
            a/=2;
            b++;
        }
    }cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false)
#define pdl cout << "*" << endl
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define INFLL 1000000000000000000ll
#define ff first
#define ss second
#define long int64_t
using namespace std;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<> dis(0, INF<<1);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args)
{ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma+1, args...); }

int main()
{
	fio;
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	int m = n+1 >> 1;
	cout << double(m) / n << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
)

func main() {
        var w, h, n int
        fmt.Scan(&w, &h, &n)
        current := map[int]int{1: 0, 2: w, 3: 0, 4: h}
        sc := bufio.NewScanner(os.Stdin)
        sc.Split(bufio.ScanWords)
        for i := 0; i < n; i++ {
                sc.Scan()
                x, _ := strconv.Atoi(sc.Text())
                sc.Scan()
                y, _ := strconv.Atoi(sc.Text())
                sc.Scan()
                a, _ := strconv.Atoi(sc.Text())
                if a == 1 {
                        if current[1] < x {
                                current[1] = x
                        }
                } else if a == 2 {
                        if current[2] > x {
                                current[2] = x
                        }
                } else if a == 3 {
                        if current[3] < y {
                                current[3] = y
                        }
                } else {
                        if current[4] > y {
                                current[4] = y
                        }
                }
        }
        var restHight, restWidth int
        if w := current[2] - current[1]; w > 0 {
                restWidth = w
        }
        if h := current[4] - current[3]; h > 0 {
                restHight = h
        }
        restArea := restWidth * restHight
        fmt.Printf("%d\n", restArea)
}

Measured memory_bytes: 640
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
for check in range(len(s) - 2, -1, -2):
    if s[check // 2:check] == s[:check // 2]:
        print(check)
        exit()


Measured memory_bytes: 3064