akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextInt();
        long B = sc.nextInt();
        long C = sc.nextInt();
        System.out.println(C - (A - B) >= 0 ? C - (A - B) : 0);
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1,	 -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 211;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, v, u, a, b, d1[N], d2[N];
vi g[N];	
queue < int > q;

main () {				
	cin >> n >> u >> v;
	forn (i, 1, n - 1) {
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	}	        	

	memset(d1, -1, sizeof(d1));
	q.push(v);
	d1[v] = 0;
	while (sz(q)) {
		int vv = q.front();
		q.pop();
		for (auto to : g[vv])
			if (d1[to] == -1) {
				d1[to] = d1[vv] + 1;
				q.push(to);
			}
		
	}

	memset(d2, -1, sizeof(d2));
	q.push(u);
	d2[u] = 0;
	while (sz(q)) {
		int vv = q.front();
		q.pop();
		for (auto to : g[vv])
			if (d2[to] == -1) {
				d2[to] = d2[vv] + 1;
				q.push(to);
			}
	}

	int ans = 0;
	forn (i, 1, n)
		if (d1[i] >= d2[i]) {
			ans = max(ans, d1[i] - 1); 
		}


	cout << ans << endl;
}                  	

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
const int inf = 1 << 30;
int N, K, Q;
int datl[2010][2010], datr[2010][2010];
int A[2010], L[2010], R[2010];
vector<pii> vs;

void update(pii p){
    int val = p.first;
    int idx = p.second;
    for(int i = 0; i < idx; i++){
        R[i] = min(datr[idx][i], R[i]);
    }
    for(int i = idx + 1; i < N; i++){
        L[i] = min(datl[idx][i], L[i]);
    }
}

int solve(){
    int ans = inf;
    for(int i = 0; i < N; i++){
        int val = vs[i].first;
        int idx = vs[i].second;
        if(L[idx] + R[idx] + 1 >= K){
            int cnt = 1;
            for(int j = i + 1; j < N; j++){
                idx = vs[j].second;
                if(L[idx] + R[idx] + 1 >= K) cnt++;
                if(cnt == Q){
                    ans = min(ans, vs[j].first - val);
                    break;
                }
            }
        }
        update(vs[i]);
    }
    if(Q == 1) ans = 0;
    return ans;
}

void init(){
    cin >> N >> K >> Q;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        vs.push_back({A[i], i});
    }
    sort(vs.begin(), vs.end());
    for(int i = 0; i < N; i++){
        for(int j = i - 1; j >= 0; j--){
            if(A[j] > A[i]) datl[j][i]++;
            if(j > 0) datl[j - 1][i] = datl[j][i];
        }
        L[i] = datl[0][i];
        for(int j = i + 1; j < N; j++){
            if(A[j] >= A[i]) datr[j][i]++;
            datr[j + 1][i] = datr[j][i];
        }
        R[i] = datr[N][i];

    }
}

int main(){
    init();
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 30592
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		if(n==1){
			System.out.println(1);
			return;
		}
		long prev=0;
		long now=0;
		int ans=1;
		int joutai=-1; //-1=最初、0=未確定、1=単調増加、2=単調減少
		int p=1;
		
		while(p<=n){
			switch(joutai){
			case -1:
				prev = sc.nextLong();
				joutai = 0;
				break;
			case 0:
				now = sc.nextLong();
				if(now > prev){
					joutai = 1;
				}else if(now < prev){
					joutai = 2;
				}
				prev = now;
				break;
			case 1:
				now = sc.nextLong();
				if(now < prev){
					ans++;
					joutai = 0;
				}
				prev = now;
				break;
			case 2:
				now = sc.nextLong();
				if(now > prev){
					ans++;
					joutai = 0;
				}
				prev = now;
				break;
			}
			p++;
		}
		
		System.out.println(ans);
		return;
	}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22088
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int test[200001];
int main() {
	long long n, d; cin >> n >> d;
	if (n % (d + d + 1) == 0) {
		cout << n / (d + d + 1) << endl;
	}
	else {
		cout << n / (d + d + 1) + 1 << endl;
	}
	cin >> n;
}

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

#define NDEBUG

// for DEBUG {{{
#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))
// }}}

#define N_MIN 1
#define N_MAX 100000

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}
void merge_int(int *a, int *b, int lower, int sep, int upper) {// {{{
	int i_lower = lower;
	int i_upper = sep;
	int i_b = 0;
	while ((i_lower < sep) && (i_upper < upper)) {
		if (a[i_lower] < a[i_upper]) {
			b[i_b++] = a[i_lower++];
		} else {
			b[i_b++] = a[i_upper++];
		}
	}
	if (i_lower >= sep) {
		while (i_upper < upper) {
			b[i_b++] = a[i_upper++];
		}
	} else {
		while (i_lower < sep) {
			b[i_b++] = a[i_lower++];
		}
	}
	for (i_lower = 0; i_lower < i_b; i_lower++) {
		a[i_lower+lower] = b[i_lower];
	}
}// }}}
void merge_sort_int(int *a, int *b, int lower, int upper) {// {{{
	int sep;
	if ((lower == upper) || (lower + 1 == upper)) {
		return;
	}
	sep = (lower + upper) / 2;
	merge_sort_int(a,b,lower,sep);
	merge_sort_int(a,b,sep,upper);
	merge_int(a,b,lower,sep,upper);
}// }}}

int main(int argc, char **argv) {
	int N;
	char S[N_MAX+1];
	fscanf(stdin,"%d",&N);
	ASSERT_RANGE(N_MIN,N,N_MAX);
	fscanf(stdin,"%s",S);
	assert(strlen(S) == N);

	{
		int ret = 1;
		char pre = S[0];
		int i;
		for (i = 1; i < N; i++) {
			if (S[i] != pre) {
				ret++;
				pre = S[i];
			}
		}
		fprintf(stdout,"%d\n",ret);
	}
	return 0;
}



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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);

int const N = 2e5 + 7;
int ds[N];
int group_size[N];

int frep(int x)
{
	return ds[x] == x ? x : ds[x] = frep(ds[x]);
}

void join(int x, int y)
{
	x = frep(x); y = frep(y);

	if (x != y)
	{
		ds[y] = x;
		group_size[x] += group_size[y];
		group_size[y] = 0;
	}
}

int main()
{
	fastio;

	for (int i = 0; i < N; ++i)
		ds[i] = i, group_size[i] = 1;

	int n, m;
	cin >> n >> m;

	int a, b;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		join(a, b);
	}

	cout << *max_element(group_size, group_size + N) << '\n';;
	return 0;
}


Measured memory_bytes: 5212
/**
 * 
 */

import java.util.Scanner;

/**
 * @author kumar1
 * 
 */
public class Main {

	void solve() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int i = 0; i < n; i++) {
			int y = scanner.nextInt();
			int m = scanner.nextInt();
			int d = scanner.nextInt();
			int ans = 0;
			while(y < 1000) {
				while(m <= 10) {
					int md = y % 3 == 0 ? 20 : m % 2 == 0 ? 19 : 20;
					while(d <= md) {
						d++;
						ans++;
					}
					d = 1;
					m++;
				}
				m = 1;
				y++;
			}
			System.out.println(ans);
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().solve();
	}

}

Measured memory_bytes: 20468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    int k;
    cin>>k;
    ll ans=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int z=1;z<=k;z++){
                ans+=gcd(i,gcd(j,z));
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3632
def solve():
  n = int(input())
  query = []
  for i in range(n):
    tmp = input()
    s,p = tmp.split()
    query.append((s,p,i+1))
  query.sort()
  count = 0
  while count<1000:
    count += 1
    for i in range(n):
      for j in range(i+1,n):
        if query[i][0] == query[j][0]:
          if int(query[i][1]) <int(query[j][1]):
            buf = query[i]
            query[i] = query[j]
            query[j] = buf
            
    
  for i in range(n):
    print(query[i][2])
solve()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#define ll long long
using namespace std;
int n,m;
int w[500][500];
bool flow[500][500];
int totNum=0;
ll num[500][500];
ll numa[200000];
ll numb[200000];
ll ans=0;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};

void flowAlg(int x,int y)
{
    flow[x][y]=1;
    num[x][y]=totNum;
    int newx,newy;
    for (int i=0; i<4; ++i)
    {
        newx=x+dx[i];
        newy=y+dy[i];
        if (newx>=0 && newx<n &&newy>=0 && newy<m && w[x][y]!=w[newx][newy] && flow[newx][newy]==0)
        {
            flowAlg(newx,newy);
        }
    }
}

int main()
{
    char c;
    cin>>n>>m;
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
        {
            scanf("%c",&c);
            while (c!='#' && c!='.') scanf("%c",&c);
            w[i][j]=(c=='#');
        }
    for (int i=0; i<n; ++i)
        for (int j=0;j<m; ++j)
            if (!flow[i][j])
            {
                flowAlg(i,j);
                totNum++;
            }
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
            if (w[i][j]==1)
            numb[num[i][j]]++;else numa[num[i][j]]++;
    for (int i=0; i<totNum; ++i)
    {
        ll tb=numb[i];
        tb*=numa[i];
        ans+=tb;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11904
s=sorted(list(input()))
t=sorted(list(input()),reverse=True)
s2=""
t2=""
for x in s:
    s2+=x
for y in t:
    t2+=y
if s2==t2:
    print("No")
    exit()
c=sorted([s2,t2])
if c[0]==s2:
    print("Yes")
else:
    print("No")




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

#define int long long
#define INF 1e18

signed main() {
    int n, k; cin >> n >> k;
    vector<int> v(n + 1, 1);

    for(int i = 1; i < n + 1; i++) {
        v[i] = min(v[i - 1] * 2, v[i - 1] + k);
    }

    cout << v[n] << endl;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

int main() {
    ll n;
    cin >> n;
    vector<char> muki_list(n);

    rep(i, n) {
        char c;
        cin >> c;
        muki_list[i] = c;
    }

    vector<ll> rui_nishi(n + 1);
    vector<ll> rui_higashi(n + 1);
    rui_higashi[0] = 0;
    for (ll i = 0; i < n; i++) {
        rui_higashi[i + 1] = rui_higashi[i];
        if (muki_list[i] == 'W') {
            rui_higashi[i + 1]++;
        }
    }

    rui_nishi[n] = 0;
    for (ll i = n - 1; i >= 0; i--) {
        rui_nishi[i] = rui_nishi[i + 1];
        if (muki_list[i] == 'E') {
            rui_nishi[i]++;
        }
    }

    ll ans = INF;
    for (int i = 0; i < n; i++) {
        ll now = rui_higashi[i] +rui_nishi [i + 1];
        cmin(ans, now);
    }

    cout << ans << endl;

}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

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

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

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();

    int n;
    cin>>n;
    int t, a;
    cin>>t>>a;
    int b[n];
    for (int i=0;i<n;i++)
    {
        cin>>b[i];
    }
    int ans=0;
    double c;
    double d=INT_MAX;
    for (int i=0;i<n;i++)
    {
        c=t-b[i]*0.006;
        if (d>abs(a-c))
        {
            d=abs(a-c);
            ans=i;
        }
    }
    cout<<ans+1;
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  char a[4];
  rep(i,0,4) cin >> a[i];
  if(a[0]==a[1] || a[1]==a[2] || a[2]==a[3]) co("Bad");
  else co("Good");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    rep(i, s.size()){
        if (s[i] == 'a') a++;
        if (s[i] == 'b') b++;
        if (s[i] == 'c') c++;
    }
    bool flag = true;
    if (a*b*c == 0) flag = false;

    else if (abs(a-b) > 1 || abs(b-c) > 1 || abs(c-a) > 1) flag = false;

    if (s=="ab" || s=="ba" || s=="bc" || s=="cb" || s=="ca" || s=="ac" || s.size()==1) flag = true;

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.equals("ABC")) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
        sc.close();
    }

}


Measured memory_bytes: 35732
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long[] price = new long[3];
        for(int i=0;i<3;i++) price[i]=sc.nextLong();
        long[] piece = new long[2];
        piece[0] = sc.nextLong();
        piece[1] = sc.nextLong();
        if(piece[0]>piece[1]){ // piece[0] is always the pizza less needed
            long med = piece[0];
            piece[0] = piece[1];
            piece[1] = med;
            long priceMed = price[0];
            price[0] =price[1];
            price[1] = priceMed;
        }
        long ans = 0;
        ans += Math.min(price[0]*piece[0]+price[1]*piece[0],price[2]*2*piece[0]);
        ans += Math.min(price[1]*(piece[1]-piece[0]),price[2]*2*(piece[1]-piece[0]));
        System.out.print(ans);
    }
}

Measured memory_bytes: 21716
N, M = map(int,input().split(' '))
H = list(map(int,input().split(' ')))

L = []
for l in range(N):
    tmp=[]
    L.append(tmp)

for m in range(M):
    a,b = map(int,input().split(' '))
    L[a-1].append(b-1)
    L[b-1].append(a-1)

cnt=0
for l in range(len(L)):
    good=True
    for t in range(len(L[l])):
        if H[l] <= H[L[l][t]]:
            good=False
    if good:
        cnt+=1

print(cnt)

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  CIN(D, G);
  vector< int > p(D);
  vector< int > c(D);
  REP(i, D) {
    cin >> p[i] >> c[i];
  }

  int ans = INF;
  REP(bit, (1 << D)) {
    int sm, tmp, mx;
    sm = tmp = mx = 0;
    REP(i, D) {
      if ((bit >> i) & 1) {
	sm += 100 * (i + 1)* p[i] + c[i];
	tmp += p[i];
      } else {
	mx = max(mx, i);
      }
    }
    if (sm < G) {
      int tmpMx = 100 * (mx + 1);
      int tmpNum = (G - sm + tmpMx - 1) / tmpMx;
      if (tmpNum >= p[mx]) continue;
      tmp += tmpNum;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}



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

using namespace std;

#define int long long

const int MAXN = 5007;
const int MOD = 1000 * 1000 * 1000 + 7;

inline int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}

int n;
int cnt[MAXN];
vector <int> g[MAXN];
int dp[MAXN][2][MAXN];
int dp1[2][MAXN], dp2[2][MAXN];
int f[MAXN];

void precalc() {
    f[0] = 1;
    for (int i = 2; i < MAXN; i += 2) {
        f[i] = mod(f[i - 2] * (i - 1));
    }
}

void read() {
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
}

int mf(int a, int b, int c) {
    return mod(a * mod(b * c));
}

void calc(int u, int parent) {
    for (int i = 0; i < MAXN; ++i) {
        dp1[0][i] = dp1[1][i] = dp2[0][i] = dp2[1][i] = 0;
    }

    int sum = 1;
    dp1[0][1] = 1;
    for (int v : g[u]) {
        if (v == parent) continue;

        for (int pu = 0; pu <= 1; ++pu) {
            for (int i = 0; i <= sum; ++i) {
                for (int pv = 0; pv <= 1; ++pv) {
                    for (int j = 0; j <= cnt[v]; ++j) {
                        dp2[pu ^ pv][i + j] = mod(dp2[pu ^ pv][i + j] + mod(dp1[pu][i] * dp[v][pv][j]));
                        dp2[pu ^ pv ^ 1][i] = mod(dp2[pu ^ pv ^ 1][i] + mf(dp1[pu][i], dp[v][pv][j], f[j]));
                    }
                }
            }
        }   

        sum += cnt[v];

        for (int i = 0; i < MAXN; ++i) {
            dp1[0][i] = dp2[0][i];
            dp2[0][i] = 0;
            dp1[1][i] = dp2[1][i];
            dp2[1][i] = 0;
        }
    }
    for (int i = 0; i < MAXN; ++i) {
        dp[u][0][i] = dp1[0][i];
        dp[u][1][i] = dp1[1][i];
    }         
}

void dfs(int u, int parent) {
    cnt[u] = 1;
    for (int v : g[u]) {
        if (v == parent) continue;
        dfs(v, u);
        cnt[u] += cnt[v];
    }
    calc(u, parent);
}

void solve() {
    dfs(0, 0);
}

void print() {
    /*
    for (int u = 2; u <= 2; ++u) {
        for (int p = 0; p <= 1; ++p) {
            for (int i = 0; i <= cnt[u]; ++i) {
                cout << "vert: " << u + 1 << "\nedge parity: " << p << "\nlast comp: " << i << '\n' << dp[u][p][i] << "\n\n";  
            }
        }
    }
    */

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = mod(ans + mod(dp[0][0][i] * f[i]));
        //cout << " + " << mod(dp[0][0][i] * f[i]) << '\n';
        ans = mod(ans - mod(dp[0][1][i] * f[i]));
        //cout << " - " << mod(dp[0][1][i] * f[i]) << '\n';
    }
    //cout << '\n';
    cout << ans << '\n';
}

signed main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    precalc();
    read();
    solve();
    print();
    return 0;
}

Measured memory_bytes: 392192
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp = input[0].split(" ");
    var hp = parseInt(tmp[0], 10);
    var n = parseInt(tmp[1], 10);
	//文字列から10進数に変換するときはparseIntを使います
    var command = input[1].split(" ");
    var m = command.length;
    var total = 0;

    for(var i = 0; i < m ; i++){
        var a = parseInt(command[i],10);
        total += a;

        if(hp<=total){
            console.log("Yes");
            break;
        }
        
    }
    if(i>=n){
        console.log("No");
    }
}
// *この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 16716
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T>
void DEBUG(T e)
{
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T>
void DEBUG(const std::vector<T> &v)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v)
  {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T>> &vv)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv)
  {
    DEBUG(v);
  }
}
template <class T, class... Ts>
void DEBUG(T d, Ts... e)
{
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T>
void corner(bool flg, T hoge)
{
  if (flg)
  {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int l;
  cin >> l;
  int n = 0;
  while (1 << n <= l)
    n++;
  vector<vector<int>> res;
  for (int i = 1; i < n; i++)
  {
    res.push_back({i, i + 1, 1 << (i - 1)});
    res.push_back({i, i + 1, 0});
  }
  int now = (1 << (n - 1)) - 1;
  for (int i = n - 1; i >= 0; i--)
  {
    if (now == l - 1)
      break;
    int gain = 1 << (i - 1);
    if (now + gain <= l - 1)
    {
      res.push_back({i, n, now + 1});
      now += gain;
    }
  }
  cout << n << " " << res.size() << endl;
  for (auto &&i : res)
  {
    cout << i[0] << " " << i[1] << " " << i[2] << endl;
  }
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3640
ABC = list(map(int, input().split()))
ABC.sort()
if ((ABC[0] % 2) == (ABC[1] % 2) and (ABC[1] % 2) == (ABC[2] % 2)) :
    print( (2 * ABC[2] - ABC[0] - ABC[1])//2)
elif (ABC[0] % 2) == (ABC[1] % 2):
    print( (2 * ABC[2] - ABC[0] - ABC[1])//2)
else:
    print( (2 * (ABC[2] + 1) - ABC[0] - ABC[1] - 1)//2 + 1)

Measured memory_bytes: 3192
#include <bits/stdc++.h>
typedef long long ll;
ll mod=1e9+7;
ll MOD=1e18;
using namespace std;
/*bool comp(pair<int,int>p,pair<int,int>q)
{
    if(p.first!=q.first)
    {
        return (p.first<q.first);
    }else
    {
        return (p.second<q.second);
    }
}
*/
int main()
{
    string s;
    cin>>s;
    if(s=="SUN") cout<<7<<endl;
    else if(s=="MON") cout<<6<<endl;
    else if(s=="TUE") cout<<5<<endl;
    else if(s=="WED") cout<<4<<endl;
    else if(s=="THU") cout<<3<<endl;
    else if(s=="FRI") cout<<2<<endl;
    else cout<<1<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    string s;
    IN s;
    string t;
    IN t;
    s+=t[t.size()-1];
    if(s==t)
    {
        OUT "Yes"<<endl
    }
    else
    {
        OUT "No"<<endl
    }
    return 0;
}

Measured memory_bytes: 3652
import datetime
L = [ "Monday", "Tuesday", "Wednesday", "Thursday","Friday",
      "Saturday", "Sunday" ]

while True:
    m, d = [int(x) for x in input().split()]
    if m == 0 and d == 0:
        break
    dt = datetime.datetime(2004, m, d)
    w = dt.weekday()
    print(L[w])



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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define each(i, mp) for (auto &i : mp)

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i, n)
  {
    int a, b;
    cin >> a >> b;
    if (a > m)
      continue;
    jobs[m - a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--)
  {
    for (int b : jobs[i])
    {
      q.push(b);
    }
    if (!q.empty())
    {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5504
#include <stdio.h>
int main(){
        int a,b,c,d,n,ans;
        ans =0;
        while(scanf("%d", &n) != EOF){
        ans =0;
        for(a=0;a<=9;a++){
                for(b=0;b<=9;b++){
                        for(c=0;c<=9;c++){
                                for(d=0;d<=9;d++){
                                        if(a + b + c + d == n){
                                                ans++;
                                        }
                                }
                        }
                }
        }
        printf("%d\n", ans);
        }
return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<functional>

int main(){
  long  n;unsigned long tmp; long m=0;
  std::vector<std::pair<unsigned long,unsigned long> > ls;
  std::cin >> n;
  std::vector<unsigned long long> ans(n);
  ls.reserve(n+1);
  for(long i=0; i<n; ++i) {std::cin >> tmp;ls.emplace_back(std::make_pair(tmp,i));}
  ls.emplace_back(std::make_pair(0,n));
  std::sort(ls.begin(),ls.end(),std::greater<>());
  auto target=ls.begin();
  for(auto it=ls.begin();it!=ls.cend()-1;){
    if(target->second>it->second)target=it;
    ans[target->second]+=(it->first-(++it)->first)*(++m);
  }
  for(auto x : ans) std::cout<< x <<'\n';
  std::cout.flush();
  return 0;
}

Measured memory_bytes: 3456
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    L = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    L.sort()
    Min = L[0]
    Mid = L[1]
    Max = L[2]
    s = (Max - Mid)/2
    s += (Max - Min)/2
    if (Max - Mid)%2 != 0 and (Max - Min)%2 != 0:
        s += 1
    elif (Max - Mid)%2 != 0 or (Max - Min)%2 != 0:
        s += 2

    print s



if __name__ == '__main__':
    main()


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	long long int w1;
	
	cin>>n>>w1;
	long long v[n];
	long long w[n];
	long long sum=0;
	for(int i=0;i<n;i++)
	{
	cin>>w[i]>>v[i];
	sum+=v[i];
	}
	long long dp[n+1][sum+1]={};
	
	for(int i=0;i<=n;i++)
	{
		for(long long j=0;j<=sum;j++)
		{
		
		dp[i][j]=std::numeric_limits<long long>::max()>>2;
		
	}
	}
	dp[0][0]=0;
	
	
	for(int i=0;i<n;i++)
	{
		for(long long j=0;j<=sum;j++)
		{
			//dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j-v[i]>=0)
		{
				dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
		}
			else
			dp[i+1][j]=dp[i][j];
		}
	}
	long long ans=0;
	/*	for(int i=0;i<=n;i++)
	{
		for(long long j=0;j<sum;j++)
		{
		
	//	dp[i][j]=std::numeric_limits<long long>::max();
	cout<<dp[i][j]<<" ";	
	}
	cout<<endl;
	}*/
	for(int i=0;i<=sum;i++)
	{
		if(dp[n][i]<=w1)
		ans=i;
	}
	cout<<ans;
}

Measured memory_bytes: 79104
#include<stdio.h>
#include<iostream>

using namespace std;

int gcd(int,int);

int main(){
  int x,y;
  cin >> x >> y;
  cout << gcd(x,y) <<endl;
  return 0;
}

int gcd(int n,int m){
  int q,r;
  if(n<m){
    q=n;
    n=m;
    m=q;
  }  
  while(m>0){
    r=n%m;
    n=m;
    m=r;
  }
  return n;
}

Measured memory_bytes: 3080
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	a := getNextInt(scanner)
	p := getNextInt(scanner)
	fmt.Fprintln(writer, (a*3+p)>>1)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
int main()
{
    double l;
    cin>>l;
    cout<<fixed<<setprecision(7);
    cout<<l*l*l/27<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;
    cout << a+b/2 << endl;
    return 0;
}

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

using i64 = int64_t;

vector<int> z_algorithm(const string &s){
    vector<int> prefix(s.size());
    int i = 1, j = 0;
    while(i < s.size()){
        while(i+j < s.size() && s[j] == s[i+j])j++;
        prefix[i] = j;
        if(j == 0){
            i++;
            continue;
        }
        int k = 1;
        while(i+k < s.size() && k+prefix[k] < j){
            prefix[i+k] = prefix[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return prefix;
}

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

    int ans = 0;
    for(int i=0;i<n;++i){
        string str = s.substr(i);
        auto res = z_algorithm(str);
        for(int j=1;j<res.size();++j){
            int tmp = min(res[j], j);
            ans = max(ans, tmp);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
string S;

bool check()
{
	int curr = 0;
	FOR(i,0,N){
		if(S [i] == '('){
			curr++;
		}
		else{
			curr--;
		}
		if(curr < 0) return false;
	}
	return true;
}

int main()
{
	cin >> N >> S;

	while(check() == false){
		S = '(' + S;
		N++;
	}

	int x = count(S.begin(),S.end(),'(') - count(S.begin(),S.end(),')');
	S += string(x,')');

	cout << S << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    vi b(n);
    REP(i, n) {
        cin >> a[i] >> b[i];
    }
    SORT(a);
    SORT(b);
    if (n % 2 == 0) {
        cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1 << endl;
    } else {
        cout << abs(b[n / 2] - a[n / 2]) + 1 << endl;
    }
}


Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
  string S;
  cin>>S;
  
  int ans=0;
  for(int i=0;i<S.size();++i){
    int count=0;
    for(int j=i;j<S.size();++j){
      if(S[j]=='A' || S[j]=='T' || S[j]=='C' || S[j]=='G')
        ++count;
      else
        break;
    }
    
    ans=max(ans,count);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 384
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = List.fill(n)(sc.nextLong())
  val sumL = a.scanLeft(0L)(_ + _).init.tail
  val sumR = a.scanRight(0L)(_ + _).init.tail
  val ans = sumL.zip(sumR).map{case (l, r) => (l - r).abs}.min
  println(ans)
}


Measured memory_bytes: 123296
#include<stdio.h>
int main()
{
	int n;
	long long int T;
	scanf("%d %lld", &n, &T);
	int i;
	long long int t[200005];
	for (i = 0; i < n; i++)
		scanf("%lld", &t[i]);
	long long int ans = 0;
	for (i = 1; i < n; i++)
	{
		if (t[i] - t[i - 1] < T)
			ans += t[i] - t[i - 1];
		else
			ans += T;
	}
	ans += T;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1664
use proconio::*;
use proconio::marker::Chars;

// 中のカッコは消し飛ばす
// )))
// (((
// ))(((
// 無
// の4つになる
// 括弧の数が一致するのは必須
// (( -> ))(( -> ))
// の順で使って大丈夫か判定?
// mahoutukaippoi

fn run() {
    input! {
        n: usize,
        s: [Chars; n],
    }
    let mut a = vec![];
    let mut b = vec![];
    for s in s {
        let mut pos = 0i64;
        let mut min = 0i64;
        for c in s {
            if c == '(' {
                pos += 1;
            } else {
                pos -= 1;
            }
            min = std::cmp::min(min, pos);
        }
        let down = -min;
        let up = pos - min;
        if up >= down {
            a.push((down, up));
        } else {
            b.push((down, up));
        }
    }
    a.sort_by_key(|a| a.0);
    b.sort_by_key(|b| b.1);
    let mut s = 0;
    let mut ans = true;
    for (d, u) in a.into_iter() {
        s -= d;
        ans &= s >= 0;
        s += u;
    }
    for (d, u) in b.into_iter().rev() {
        s -= d;
        ans &= s >= 0;
        s += u;
    }
    ans &= s == 0;
    let out = if ans {
        "Yes"
    } else {
        "No"
    };
    println!("{}", out);
}

fn main() {
    run();
}


Measured memory_bytes: 66680
inf=float('inf')
s=input()[::-1]
n=len(s)
dp=[2*[inf]for _ in range(n)]
dp[0]=[int(s[0]),10-int(s[0])]
for i in range(1,n):
  if s[i]=="9":
    dp[i][1]=min(dp[i-1][1],dp[i-1][0]+1)
    dp[i][0]=dp[i-1][0]+9
  else:
    dp[i][0]=int(s[i])+min(dp[i-1][0],dp[i-1][1]+1)
    dp[i][1]=min(9-int(s[i])+dp[i-1][1],10-int(s[i])+dp[i-1][0])
print(min(dp[n-1][0],dp[n-1][1]+1))
#for i in dp:print(*i)

Measured memory_bytes: 199632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException, NumberFormatException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		if( line != null ){
			int input = Integer.parseInt(line);
			int HH = input/3600;
			int mi = input%3600/60;
			int SS = input%60;

			System.out.println(HH+":"+mi+":"+SS);
		}
	}

}

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

using namespace std;

int main() {
    int X, Y;
    cin >> X >> Y;

    X = min(X, 4);
    Y = min(Y, 4);
    int ans = (4 - X) + (4 - Y);
    if (X == 1 and Y == 1) ans += 4;
    ans *= 100000;

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


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, q, p[100000];
int m[100000], v[100000];
char type[100000];
vector<vi> e;

int pa[100000];
int root(int x){
	if(x == pa[x]) return x;
	return pa[x] = root(pa[x]);
}

int main(){
	while(scanf("%d%d", &n, &q), n){
		e.clear(); e.resize(n);
		memset(m, 0, sizeof(m));
		
		rep(i, n - 1){
			scanf("%d", p + i + 1), p[i + 1]--;
			e[i + 1].pb(p[i + 1]);
			e[p[i + 1]].pb(i + 1);
		}
		rep(i, q){
			scanf(" %c%d", type + i, v + i);
			v[i]--;
			if(type[i] == 'M') m[v[i]]++;
		}
		m[0] = 1;
		
		queue<pi> Q;
		rep(i, n){
			pa[i] = i;
			if(m[i]) Q.push(mp(i, i));
		}
		
		while(!Q.empty()){
			int c = Q.front().first, r = Q.front().second;
			Q.pop();
			rep(i, e[c].size()) if(e[c][i] != p[c] && !m[e[c][i]]){
				pa[e[c][i]] = r;
				Q.push(mp(e[c][i], r));
			}
		}
		ll ans = 0;
		for(int i = q - 1; i >= 0; i--){
			if(type[i] == 'M'){
				if(--m[v[i]] == 0) pa[v[i]] = root(p[v[i]]);
			}
			else ans += root(v[i]) + 1;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
  long long a,b,c,d,N;
  scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&N);
  long long M=min(4*a,min(2*b,c));
  long long MM=min(2*M,d);
  printf("%lld\n",MM*(N/2)+(N%2)*M);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int dp[100000];

void stones(int* A,int N,int K){

	for(int i = 0;i <= K ;i++){
		
		if( i < A[0])
			dp[i] = 2;


		else{
			int m = 0;
			for(int j = 0; j < N && i >= A[j] ;j++){
				m = max(m,dp[i-A[j]]);
				if(m == 2){
					dp[i] = 1;
					break;
				}				
			}
			
			if(m == 1) dp[i] = 2;
		}

	}


}



int main(){

	int N,K;
	cin >> N >> K;

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

	stones(A,N,K);
	
	if (dp[K] == 1) cout << "First" <<'\n';
	else if (dp[K] == 2) cout << "Second" <<'\n';
	
	/*
	for(int i = 0;i <= K ;i++)
		cout << dp[i] << ' ';
	*/

	return 0;
}

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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	sort(a.begin(),a.end());

	if(count(a.begin(),a.end(),0)==n) return puts("Yes"),0;

	if(n%3!=0 || (a[0]^a[n/3])!=a[2*n/3]) return puts("No"),0;

	if(count(a.begin()      ,a.begin()+n/3  ,a[0]    )!=n/3
	|| count(a.begin()+n/3  ,a.begin()+2*n/3,a[n/3]  )!=n/3
	|| count(a.begin()+2*n/3,a.end()        ,a[2*n/3])!=n/3) return puts("No"),0;

	puts("Yes");

	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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

    int a[n][m], b[m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) cin >> a[i][j];
    for (int i = 0; i < m; i++) cin >> b[i];

    int sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) sum += a[i][j] * b[j];
        cout << sum << endl;
        sum = 0;
    }
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int A, B;
    cin >> A >> B;

    if(A < 10 && B < 10 && A != 0 && B != 0)cout << A * B;
    else cout << -1;
}

Measured memory_bytes: 256