akhauriyash/Code-Regression huggingface dataset:
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N, M,X = isRaw()
    CAs = [isRaw() for n in range(N)]
    ans = INF
    for dbit in range(2**N):
        cb = [(dbit & (1 << n)) for n in range(N)]
        flg = 1
        for m in range(M):
            x = sum([CAs[n][m+1] for n in range(N) if cb[n]])
            if x<X:
                flg=0
                break
        if flg == 1:
            cost = sum([CAs[n][0] for n in range(N) if cb[n]])
            ans = min(ans,cost)
    return ans if ans!=INF else -1


print(main())


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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int g[60][60];

int main(){
    int n, m; cin>>n>>m;
    vector<int> a(m), b(m);
    for(int i=0; i<m; i++){
        cin>>a[i]>>b[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]]=1, g[b[i]][a[i]]=1;
    }

    int ans=0;
    for(int i=0; i<m; i++){
        g[a[i]][b[i]]=0, g[b[i]][a[i]]=0;

        vector<bool> visited(n, false);
        queue<int> que;
        que.push(0);
        visited[0]=true;
        while(!que.empty()){
            int cur=que.front(); que.pop();
            for(int j=0; j<n; j++){
                if(g[cur][j]==1 && !visited[j]){
                    visited[j]=true;
                    que.push(j);
                }
            }
        }

        bool f=true;
        for(int j=0; j<n; j++){
            if(!visited[j]) f=false;
        }

        if(f) ans++;

        g[a[i]][b[i]]=1, g[b[i]][a[i]]=1;
    }
    cout << m - ans << endl;
}

Measured memory_bytes: 256
S = input()

year = int(S[0:4])
month = int(S[5:7])
day = int(S[8:])

if(year < 2019):  # ~2018年
    print("Heisei")
else:  # 2019~
    if(month == 4):
        if(day <= 30):
            print("Heisei")
        else:
            print("TBD")
    elif(month < 4):
        print("Heisei")
    else:  # 5月~
        print("TBD")


Measured memory_bytes: 3060
N, K = map(int, input().split())
A = list(map(int, input().split()))

table = {}
init_table = {}
move = {}

for i in range(N):
    if A[i] in table:
        move[table[A[i]]], move[i] = i+1, init_table[A[i]]+1
    else:
        if A[i] not in init_table:
            init_table[A[i]] = i
    table[A[i]] = i

T = K
idx = 0
remain = [0]
for i in range(1, K+1):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    remain.append(idx)
    if(idx == N and i != K):
        T = K % i
        break
    if idx in move:
        idx = move[idx]
    else:
        idx += 1

if(T == 0):
    print()
    exit()
idx = remain[T]
ret = []
while idx < len(A):
    while idx in move and idx < move[idx]:
        idx = move[idx]
    if(idx >= len(A)):
        break
    ret.append(A[idx])
    idx += 1

print(*ret)



Measured memory_bytes: 122816
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <set>
#define INF 100000
using namespace std;

struct spell{
    string name;
    long long int mp;
    string target;
    long long int damage;
};
long long int max(long long int n,long long int m){
    if (n<m) {
        return m;
    }else{
        return n;
    }
}

long long int min(long long int n, long long int m){
    if (n<m) {
        return n;
    }else{
        return m;
    }
}

int main() {
    for (; ;) {
        int n;
        cin >> n;
        if (n==0) break;
        vector<long long int> hp(n);
        long long int max_hp=0;
        for (int i=0; i<n; i++) {
            cin >> hp[i];
            max_hp = max(max_hp,hp[i]);
        }
        int m;
        cin >> m;
        vector<spell> sp(m);
        for (int i=0; i<m; i++) {
            cin >> sp[i].name>> sp[i].mp>> sp[i].target >> sp[i].damage;
        }
        long long int smp=1000,amp=1000,sdm=10,adm=10;
        for (int i=0; i<m; i++) {
            if (sp[i].target=="Single") {
                if (smp>sp[i].mp) {
                smp=sp[i].mp;
                sdm=sp[i].damage;
                }
            }
        }
        for (int i=0; i<m; i++) {
            if (sp[i].target=="All") {
                if (amp>sp[i].mp) {
                    amp=sp[i].mp;
                    adm=sp[i].damage;
                }
            }
        }
        vector<long long int> single(max_hp+1,INF);
        if (smp!=100) {
            single[0]=0;
            for (int i=1; i<=sdm && i<=max_hp; i++) {
                single[i]=smp;
                //if(i/100==0) cout << single[i]<<endl;
            }
            for (long long int i=smp+1; i<=max_hp; i++) {
                long long int res = 114514;
                for (int k=0; k<m; k++) {
                    if (sp[k].target=="Single" && single[max(0,i-sp[k].damage)]+sp[k].mp<=res) res = single[max(0,i-sp[k].damage)]+sp[k].mp;
                }
                if(res!=114514) single[i]=res;
            }
        }
        
        vector<long long int> all(max_hp+1,INF);
        if (amp!=100) {
            all[0]=0;
            for (int i=1; i<=adm && i<=max_hp; i++) {
                all[i]=amp;
            }
            for (long long int i=adm+1; i<=max_hp; i++) {
                long long int res = 114514;
                for (int k=0; k<m; k++) {
                    if (sp[k].target== "All"  && all[max(0,i-sp[k].damage)]+sp[k].mp<=res){
                        res = all[max(0,i-sp[k].damage)]+sp[k].mp;
                    }
                }
                if(res!=114514) all[i]=res;
            }
        }
        long long int ans=100000;
        for (int i=0; i<=max_hp; i++) {
            vector<long long int> hpp(hp);
            int hoge=0;
            for (int j=0; j<n; j++) {
                hpp[j]=max(0,hpp[j]-i);
                hoge += single[hpp[j]];
            }
            ans = min(ans,all[i]+hoge);
        }
        cout << ans <<endl;
    }
}

Measured memory_bytes: 2692
#include <cstdio>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;


int main(void) {
  int n;
  scanf("%d", &n);
  int res = 1;
  int maxi = 0;
  for(int i = 1; i <= n; ++i) {
    int cur = 0;
    int tmp = i;
    while(tmp % 2 == 0) {
      cur++;
      tmp /= 2;
    }
    if(cur > maxi) {
      maxi = cur;
      res = i;
    }
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>

const long long INF = 1000000007;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int , pii> piii;
typedef pair<pii, pii> piiii;

int n;
vector<int> adj[100011];
bool visit[100011];
ll db[100011];
ll dw[100011];

ll dp(int x) {
	if (visit[x]) return (db[x] + dw[x])%INF;
	ll ansb = 1, answ = 1;
	visit[x] = true;
	for (int v : adj[x]) {
		if (visit[v]) continue;
		answ = (answ*dp(v)) % INF;
		ansb = (ansb*dw[v])%INF;
	}
	dw[x] = answ;
	db[x] = ansb;
	return (answ + ansb) % INF;
}


int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	

	fill(visit + 1, visit + n + 1, false);

	printf("%d\n",dp(1));


}


Measured memory_bytes: 12928
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
#define all(x) x.begin(),x.end()
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

    using Graph = vector<vector<pint>>;
    int n;
    Graph G;

    void dfs(int v, int p, int pc, vec &res){
        int color = 1;
        if(color == pc) ++color;
        for(auto e : G[v]) {
            if(e.first == p) continue;
            res[e.second] = color;
            dfs(e.first, v ,color, res);
            ++color;
            if(color == pc) ++color;
        }
    }

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

    cin>>n;
    G.assign(n, vector<pint>());
    rep(i,n-1){
        int a,b;cin>>a>>b;
        --a;--b;
        G[a].emplace_back(b,i);
        G[b].emplace_back(a,i);
    }

    int max_color = 0; 
    rep(i,n){
        chmax(max_color, (int)G[i].size());
    }

    vec res(n-1, -1);
    dfs(0, -3, -3, res);
    cout<<max_color<<endl;
    for(auto v : res) cout << v << endl;

}

Measured memory_bytes: 10988
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

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

		while (true) {

			int w = s.nextInt(), h = s.nextInt();
			if (w == 0 && h == 0) {
				return;
			}

			String[][] map = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					map[i][j] = "";
				}
			}

			for (int i = 0; i < w; i++) {
				map[0][i] = "U";
				map[h - 1][i] = "D";
			}
			for (int i = 0; i < h; i++) {
				map[i][0] += "L";
				map[i][w - 1] += "R";
			}

			for (int i = 0; i < 2 * h - 1; i++) {

				if (i % 2 == 0) {
					for (int j = 0; j < w - 1; j++) {

						int in = s.nextInt();
						if (in == 1) {
							map[i / 2][j] += "R";
							map[i / 2][j + 1] += "L";
						}

					}
				} else {
					for (int j = 0; j < w; j++) {

						int in1 = s.nextInt();
						if (in1 == 1) {
							map[i / 2][j] += "D";
							map[i / 2 + 1][j] += "U";

						}
					}
				}

			}

			Deque<int[]> q = new ArrayDeque<>();
			q.add(new int[] { 0, 0, 1 });
			boolean[][] cst = new boolean[h][w];
			boolean flag = false;

			while (!q.isEmpty()) {

				int[] u = q.poll();

				if (u[0] == h - 1 && u[1] == w - 1) {
					System.out.println(u[2]);
					flag = true;
					break;
				}
				cst[u[0]][u[1]] = true;

				if (!map[u[0]][u[1]].contains("U")) {
					if (!cst[u[0] - 1][u[1]]) {
						q.add(new int[] { u[0] - 1, u[1], u[2] + 1 });

						cst[u[0] - 1][u[1]] = true;
					}
				}
				if (!map[u[0]][u[1]].contains("R")) {
					if (!cst[u[0]][u[1] + 1]) {
						q.add(new int[] { u[0], u[1] + 1, u[2] + 1 });

						cst[u[0]][u[1] + 1] = true;
					}
				}

				if (!map[u[0]][u[1]].contains("D")) {
					if (!cst[u[0] + 1][u[1]]) {
						q.add(new int[] { u[0] + 1, u[1], u[2] + 1 });

						cst[u[0] + 1][u[1]] = true;
					}
				}

				if (!map[u[0]][u[1]].contains("L")) {
					if (!cst[u[0]][u[1] - 1]) {
						q.add(new int[] { u[0], u[1] - 1, u[2] + 1 });

						cst[u[0]][u[1] - 1] = true;
					}
				}

			}
			if (!flag) {
				System.out.println(0);
			}
		}
	}
}

Measured memory_bytes: 81212
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    Console.WriteLine((b - a) * (b - a + 1) / 2 - b);
  }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod=1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
using P = pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>21){
    cout<<"bust"<<endl;
  }
  else{
    cout<<"win"<<endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<tuple>
#include<cmath>
#include<algorithm>

using namespace std;

int V;
vector<int> G[200];
int match[200];
int used[200];

bool dfs(int v){
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    int u=G[v][i],w=match[u];
    if(w<0||!used[w]&&dfs(w)){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int main(){
  for(int N,M;cin>>N>>M,N;){
    for(auto &e:G){
      e.clear();
    }
    V=N+M;
    int x[100],y[100],v[100];
    for(int i=0;i<N;i++){
      cin>>x[i]>>y[i]>>v[i];
    }
    int xx[100],yy[100];
    vector<tuple<double,int,int> > vt;
    for(int i=0;i<M;i++){
      cin>>xx[i]>>yy[i];
      for(int j=0;j<N;j++){
	vt.emplace_back(hypot(xx[i]-x[j],yy[i]-y[j])/v[j],i,j+N);
      }
    }
    sort(begin(vt),end(vt));
    fill(begin(match),end(match),-1);
    int res=0;
    for(auto e:vt){
      int u=get<1>(e);
      int v=get<2>(e);
      G[u].push_back(v);
      G[v].push_back(u);
      for(int i=0;i<V;i++){
	if(match[i]<0){
	  fill(begin(used),end(used),0);
	  if(dfs(i)){
	    res++;
	  }
	}
      }
      if(res>=M){
	cout.precision(8);
	cout<<fixed<<get<0>(e)<<endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
signed main(){
	ll n,m; cin>>n>>m;
	priority_queue<ll, vector<ll>, greater<ll>> q;
	rep(i,0,n){
		ll a; cin>>a;
		q.push(a);
	}
	vector<pl> vec(m);
	ll ans=0;
	rep(i,0,m)cin>>vec[i].second>>vec[i].first;
	sort(all(vec));
	for(int i=m-1;i>=0;--i){
		ll cnt=0;
		ll a=vec[i].first;
		ll b=vec[i].second;
		rep(j,0,b){
			ll k=q.top();
			if(a<=k)break;
			q.pop();
			q.push(a);
			cnt++;
		}
		if(cnt==0)break;
	}
	rep(i,0,n)ans+=q.top(),q.pop();
	cout<<ans<<endl;




	return 0;
}

Measured memory_bytes: 5612
def inpl():
    return list(map(int, input().split()))

import numpy as np

N = int(input())
X = np.zeros(N, dtype=np.int64)
Y = np.zeros(N, dtype=np.int64)
H = np.zeros(N, dtype=np.int64)

# Hの降順でリストに入れてる
Q = sorted([inpl() for _ in range(N)], key=lambda x: x[2], reverse=True)

for i, q in enumerate(Q):
    X[i], Y[i], H[i] = q

for cx in range(101):
    for cy in range(101):
        cH = H[0] + np.abs(X[0] - cx) + np.abs(Y[0] - cy)
        if np.all(H == np.maximum(cH - np.abs(X - cx) - np.abs(Y - cy), 0)):
            print(cx, cy, cH)

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

int main(){
    int A,B;cin>>A>>B;
    int ans=0;
    if(A>B){
        ans+=A;
        --A;
    }else{
        ans+=B;
        --B;
    }
    if(A>B){
        ans+=A;
        --A;
    }else{
        ans+=B;
        --B;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 divisor[1001];

void solve(int x)
{
    for (int i = 2; i * i <= x; ++i)
    {
        while (x % i == 0)
        {
            x /= i;
            ++divisor[i];
        }
    }
    ++divisor[x];
}

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

    int N;
    cin >> N;

    for (int i = 2; i <= N; ++i)
    {
        solve(i);
    }

    s64 ans = 1;
    for (int i = 2; i <= N; ++i)
    {
        ans *= (divisor[i] + 1);
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

struct Sin
{
	int hin, min, sin;
	int hout, mout, sout;
};

struct Sout
{
	int h, m, s;
};

int main(void)
{
	//freopen("C:\\Users\\h2539\\Desktop\\in.txt","r",stdin);
	//freopen("C:\\Users\\h2539\\Desktop\\out.txt","w",stdout);

	Sin Zin[3];

	Sout Zout[3];

	for(int i = 0; i< 3; i++)
	{
		cin >> Zin[i].hin >> Zin[i].min >> Zin[i].sin >> Zin[i].hout >> Zin[i].mout >> Zin[i].sout;
	}
	
	for(int i = 0; i < 3; i++)
	{
		Zout[i].h = Zin[i].hout - Zin[i].hin;
		
		Zout[i].m = Zin[i].mout - Zin[i].min;

		Zout[i].s = Zin[i].sout - Zin[i].sin;

		if(Zout[i].s >= 60)
		{
			Zout[i].m++;
			Zout[i].s -= 60;
		}

		if(Zout[i].s < 0)
		{
			Zout[i].m--;
			Zout[i].s += 60;
		}

		if(Zout[i].m >= 60)
		{
			Zout[i].h++;
			Zout[i].m -= 60;
		}

		if(Zout[i].m < 0)
		{
			Zout[i].h--;
			Zout[i].m += 60;
		}

		cout << Zout[i].h << " " << Zout[i].m << " " << Zout[i].s << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(val,times) for(int val;val < times;val++)
using namespace std;

int main(){
    string p,s;
    cin >> p >> s;
    p = p + p;
    bool flag = false;
    REP(i,(int)p.size()-(int)s.size()+1){
        string t = p.substr(i, s.size());

        if(t == s){
            flag = true;
            break;
        }
    }
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <math.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(){
  int n;
  cin >> n;
  long int a[n+1],b[n];
  REP(i,n+1) cin >> a[i];
  REP(i,n) cin >> b[i];
  long int count=0;
  for(int i=0;i<n;i++){
    if(b[i]>=a[i]){
      b[i] -= a[i];
      count += a[i];
      if(b[i]>=a[i+1]){
        count += a[i+1];
        a[i+1] = 0;
      }
      else{
        count += b[i];
        a[i+1] -= b[i];
      }
    }
    else{
      count += b[i];
    }
  }
  printf("%ld\n",count);
  return 0;
}

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

import static java.lang.System.in;

public class Main {
    static long mod = 1000000000+7;
    static int maxn = 1000*1000;
    static long[] fac = new long[1000*1000+1], inv = new long[1000*1000+1];
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        // 原有想法是错的，很难得到正确结果。
        // 应该从每一个值填坑的角度来思考
        int n = sc.nextInt(),m = sc.nextInt();
        int[] a = new int[n], b=new int[m];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        for(int i=0;i<m;i++) b[i]=sc.nextInt();
        System.out.println(help(n,m,a,b));
    }
    static long help(int n, int m, int[] a, int[] b){
        Arrays.sort(a);
        Arrays.sort(b);
        if(a[n-1]!=n*m||b[m-1]!=n*m) return 0;
        for(int i=0;i<n-1;i++){
            if(a[i]==a[i+1]) return 0;
        }
        for(int j=0;j<m-1;j++){
            if(b[j]==b[j+1]) return 0;
        }
        long ans = 1;
        for(int k=n*m;k>0;k--){
            int i=Arrays.binarySearch(a,k);
            int j=Arrays.binarySearch(b,k);
            if(i>=0&&j>=0) continue;
            if(i>=0&&j<0){
                j = -(j+1);
                ans = ans*(m-j)%mod;
            }else if(i<0&&j>=0){
                i = -(i+1);
                ans = ans*(n-i)%mod;
            }else{
                j = -(j+1);
                i = -(i+1);
                ans = ans*((n-i)*(m-j)-(n*m-k))%mod;
            }
        }
        return ans;
    }
}


Measured memory_bytes: 43072
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

pair<int,int> judge(vector<int> a, vector<int> b){
    int suma=0,sumb=0;
    REP(i,a.size())suma+=a[i];
    REP(i,b.size())sumb+=b[i];
    
    int minv=1e9;
    pair<int,int> res=make_pair(-1,-1);
    REP(i,a.size()){
        REP(j,b.size()){
            if(suma-a[i]+b[j]==sumb-b[j]+a[i]){
                if(minv>a[i]+b[j]){
                    minv=a[i]+b[j];
                    res=make_pair(a[i],b[j]);
                }
            }
        }
    }
    
    return res;
}

int main(){
    while(true){
        int n,m;
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<int> a(n),b(m);
        REP(i,n)cin>>a[i];
        REP(i,m)cin>>b[i];
        
        pair<int,int> ans=judge(a,b);
        if(ans.first!=-1){
            cout<<ans.first<<" "<<ans.second<<endl;
        }else{
            cout<<-1<<endl;
        }
    
    }
    
    return 0;
}

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

#define all(x) (x).begin(),(x).end()

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    int n, x, y, ans = 0;
    cin >> n;
    vector < pair<ll, ll> > r, b;
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        r.push_back({x, y});
    }
    for (int i = 0; i < n; i++) {
        cin >> x >> y;
        b.push_back({x, y});
    }
    sort(r.rbegin(), r.rend());
    sort(all(b));

    for (int i = 0; i < n; i++) {
        ll ymax = -1, pos = -1;
        for (int j = 0; j < n; j++) {
            if ((r[j].first < b[i].first) && (r[j].second < b[i].second)) {
                if (ymax < r[j].second) {
                    ymax = r[j].second;
                    pos = j;
                }
            }
        }
        if (ymax == -1) continue;
        else {
            r[pos].first = inf;
            r[pos].second = inf;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int n,i; cin>>n>>i;
  cout<<n-i+1<<endl;

  return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";

ll mod = 1000000007;

using namespace std;

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

	ll a,b;
	cin>>a>>b;
	cout<<a+b/2<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static int N;
    static int[] A;

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

        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println( solve() );
    }

    static long solve() {
        for (int i = 0; i < N; i++) {
            A[i] -= (i+1);
        }
        Arrays.sort(A);

        int med = A[N/2];

        long sad = 0;
        for (int i = 0; i < N; i++) {
            sad += Math.abs(A[i] - med);
        }
        return sad;
    }

    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

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

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

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

            return tokenizer.nextToken("\n");
        }

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

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

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

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


Measured memory_bytes: 46220
#include<stdio.h>
int main(void){
	int n,m,i,a,f=-1;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d",&a);
		n-=a;
	}
	printf("%d",0<=n?n:f);
	return 0;
}


Measured memory_bytes: 1704
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

int N,fi,se;

int main(){
    cin>>N;
    int a[N],b[N];
    rep(i,N){
        cin>>a[i];
        b[i]=a[i];
    }
    
    sort(a,a+N);
    fi=a[N-1];
    se=a[N-2];
    rep(i,N){
        if(b[i]==fi)out(se);
        else out(fi);
    }

    
    
}


Measured memory_bytes: 3200
#include<stdio.h>

int main(void)
{
	int i, j, n;
	int ar[101], gy[101];
	
	scanf("%d", &n);
	for(i = 0; i < n; i++)scanf("%d", &ar[i]);
	
	for(i = n - 1, j = 0; i >= 0; i--, j++)
	{
		 gy[j] = ar[i];
	}
	
	for(i = 0; i < n; i++)
	{
		printf("%d", gy[i]);
		if(i != n-1)printf(" ");
	}
	
	printf("\n");
	
	return 0;
	
}




Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)





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

  int n;
  cin >> n;
  string s;
  cin >> s;
  map<pair<string, string >, ll> smap;
  rep(i,(1<<n)){
    string ss,tt;
    rep(j,n){
      if(i & (1<<j)) ss.pb(s[j]);
      else tt.pb(s[j]);
    }
    smap[mp(ss,tt)]++;      
  }
  ll ans=0;
  rep(i,(1<<n)){
    string ss,tt;
    rep(j,n){
      if(i & (1<<j)) ss.pb(s[2*n-1-j]);
      else tt.pb(s[2*n-1-j]);
    }
    ans += smap[mp(ss,tt)];
  }
  cout << ans << endl;
  //  cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;
  return 0;
    

}


Measured memory_bytes: 91904
W = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')
M = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
 
while True:
    m, d = map(int, input().split())
    if m == d == 0: break
 
    total = sum(M[i] for i in range(m - 1)) + d - 1
    print(W[(total + 4) % 7])


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 40;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    vector<int> A;
    FOR(i,0,N){
        int a; cin >> a;
        a--; 
        A.push_back(a);
    }
    int res = 0;
    int ind = 0;
    bool f = false;
    FOR(i,0,N){
        res ++ ;
        ind = A[ind];
        if (ind==1){
            f = true;
            break;
        }
    }
    if(f) cout << res << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 892
#coding:utf-8

S = input()
evenstr =[S[i] for i in range(len(S)) if i % 2 == 0]
oddstr = [S[i] for i in range(len(S)) if i % 2 != 0]

for i in evenstr:
    if i in ['R','U','D']:
        jud = True
    else:
        jud = False
        break
if jud:
    for i in oddstr:
        if i in ['L','U','D']:
            jud = True
        else:
            jud = False
            break

if jud:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

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

    

    for(int i = 0;i < s.size();i++){
        if(s[i]+n >=91)
            cout << (char)(((s[i]+n)%91)+65);
        else 
            cout << (char)(s[i]+n);
    }

    cout << endl;

    return 0;
}

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

struct UnionFind {
    vector<int> par;
    vector<int> sz;

    UnionFind(int n=0){ if(n>0) initialize(n); }
    void initialize(int n){
        par.resize(n);
        sz.assign(n, 1);
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(sz[x] > sz[y]) swap(x, y);
        par[x] = y;
        sz[y] += sz[x];
        return true;
    }

    bool same(int x, int y){ return find(x) == find(y); }
    int size(int x){ return sz[find(x)]; }
};

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M), B(M), C(K), D(K);
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    for(int i=0; i<K; i++){
        cin >> C[i] >> D[i];
        C[i]--; D[i]--;
    }

    UnionFind uf(N);
    for(int i=0; i<M; i++) uf.unite(A[i], B[i]);

    vector<int> ans(N);
    for(int i=0; i<N; i++) ans[i] = uf.size(i)-1;
    for(int i=0; i<M; i++){
        ans[A[i]]--;
        ans[B[i]]--;
    }
    for(int i=0; i<K; i++) if(uf.same(C[i], D[i])){
        ans[C[i]]--;
        ans[D[i]]--;
    }
    for(int i=0; i<N; i++) cout << ans[i] << " \n"[i==N-1];
    return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MN 20
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll ans,d,pw[MN],dig;
inline ll absol(ll x){return (x>0ll)?x:-x;}
inline ll dfs(ll x,int l,int len){
	if (l>=len-l) {return x?0:((l==len-l)?10:1);}
	ll wy=(10-x%10)%10,rem=x-(wy*pw[len-(l<<1)]-wy);
	return ((l?10:9)-wy)*dfs(absol(rem)/10,l+1,len);
}
int main()
{
	d=in();for (int t=d;t;t/=10) ++dig;pw[0]=1;
	for (int i=1;i<=(dig<<1);++i) pw[i]=pw[i-1]*10ll; 
	for (int i=0;i<=(dig<<1);++i) ans+=dfs(d,0,i);
	printf("%lld",ans);return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

int main(int argc, char const* argv[])
{
    std::string in_str;
    std::cin >> in_str;;

    auto head = in_str.front();
    auto back = in_str.back();
    in_str.pop_back();
    in_str.erase(0, 1);

    std::cout << head << in_str.length() << back << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a[2]={0,0,0};
  int flag_A=0;
  int flag_B=0;
  //in
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  //read
  for(int n=0;n<3;n++){
    if(a[n]==5) flag_A++;
    else if(a[n]==7) flag_B++;
  }
  //out
  if(flag_A==2&&flag_B==1) printf("YES\n");
  else printf("NO\n");
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import java.util.stream.Stream;
public class Main {
	public static Scanner stdIn = new Scanner(System.in);
	public static void main(String[] args){
		String L1 = stdIn.nextLine();
		String L2 = stdIn.nextLine();
		String[] s1 = L1.split(" ", 0);
		String[] s2 = L2.split(" ", 0);
		long[] i2 = Stream.of(s2).mapToLong(Long::parseLong).toArray();
		long r= 9223372036854775807L;
		int n=Integer.parseInt(s1[0]);
		long x=0L,y=0L;
		int i=0;
		for (i=0;i<n;i++){
			y+=i2[i];
		}
		for (i=0;i<n-1;i++){
			x=x+i2[i];
			y=y-i2[i];
			r=Math.min(r,Math.abs(x-y));
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 60424
line = input()
n = int(input())
for i in range(n):
    order = input().split()
    if order[0] == "print":
        print(line[int(order[1]):int(order[2])+1])
    elif order[0] == "reverse":
        tmp = line[int(order[1]) :int(order[2])+1 ]
        line = line[:int(order[1])] + tmp[::-1] + line[int(order[2])+1:]
    elif order[0] == "replace":
        line = line[:int(order[1])] + order[3] + line[int(order[2])+1:]

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

int main(){
  ll n;
  cin >> n;
  string s;
  cin >> s;
  s+=s[0];
  string A,B,C,D;
  
  vector<char>a(n+2),b(n+2),c(n+2),d(n+2);
  a[0]='S',a[1]='W';
  b[0]='S',b[1]='S';
  c[0]='W',c[1]='W';
  d[0]='W',d[1]='S';
  
  
  for(ll i=1; i<n+1; i++){
    if(s[i]=='o' && a[i]=='S') a[i+1]=a[i-1];
    else if(s[i]=='x' && a[i]=='W') a[i+1]=a[i-1];
    else{
      if(a[i-1]=='W') a[i+1]='S';
      else a[i+1]='W';
    } 
  }
  
  for(ll i=1; i<n+1; i++){
    if(s[i]=='o' && b[i]=='S') b[i+1]=b[i-1];
    else if(s[i]=='x' && b[i]=='W') b[i+1]=b[i-1];
    else{
      if(b[i-1]=='W') b[i+1]='S';
      else b[i+1]='W';
    } 
  }
  
  for(ll i=1; i<n+1; i++){
    if(s[i]=='o' && c[i]=='S') c[i+1]=c[i-1];
    else if(s[i]=='x' && c[i]=='W') c[i+1]=c[i-1];
    else{
      if(c[i-1]=='W') c[i+1]='S';
      else c[i+1]='W';
    } 
  }
  
  for(ll i=1; i<n+1; i++){
    if(s[i]=='o' && d[i]=='S') d[i+1]=d[i-1];
    else if(s[i]=='x' && d[i]=='W') d[i+1]=d[i-1];
    else{
      if(d[i-1]=='W') d[i+1]='S';
      else d[i+1]='W';
    } 
  }
  
  
  if(a[0]==a[n] && a[1]==a[n+1]){
    for(ll i=0; i<n; i++) A+= a[i]; 
    cout << A << endl;
    return 0;
  }
  
  if(b[0]==b[n] && b[1]==b[n+1]){
    for(ll i=0; i<n; i++) B+= b[i];
    cout << B << endl;
    return 0;
  }
  
  if(c[0]==c[n] && c[1]==c[n+1]){
    for(ll i=0; i<n; i++) C+= c[i];
    cout << C << endl;
    return 0;
  }
  
  if(d[0]==d[n] && d[1]==d[n+1]){
    for(ll i=0; i<n; i++) D+= d[i];
    cout << D << endl;
    return 0;
  }
  
  cout << -1 << endl;
  
  
}
  


Measured memory_bytes: 4032
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    x = -1
else:
    x = 1
    y = 7
    z = 7
    while y % k != 0:
        z = (z * 10) % k
        y += z
        x += 1
print(x)

Measured memory_bytes: 9068
#include <iostream>

using namespace std;

int main()
{
	for (int i = 1; ; i++)
	{
		int x;
		cin >> x;
		if (x == 0)
		{
			break;
		}
		else
		{
			cout << "Case " << i << ": " << x << endl;
		}
	}
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}"; 
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}"; 
}

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

int main() {
    buff();
    ll d, t, s;
    cin >> d >> t >> s;
    ll take = (d / s) + !!(d % s);
    if(take <= t) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}



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

int main(){
  int n, i, max=-1000000000, min;
  int R[200000];

  scanf("%d",&n);
  if( n<2 || 200000<n ) exit(1);

  min = R[0];
  for( i=0 ; i<n ; i++ ){
    scanf("%d",&R[i]);
    if( R[i]<1 || 1000000000<R[i] ) exit(1);
  }

  min = R[0];
  
  for( i=1 ; i<n ; i++ ){
    if( max < R[i]-min ){
      max = R[i] - min;
    }

    if( min > R[i] ){
      min = R[i];
    }
  }

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

Measured memory_bytes: 1376
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define INF 1000000000000000000

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n, wm;

ll dp[110][100010];
ll wt[110];
ll v[110];
ll solve(int i, int w) {
    if(w > wm) return -INF; 
    if(i == n) return 0;
    if(dp[i][w] != -1) return dp[i][w];
    return dp[i][w] = max(v[i] + solve(i+1, w+wt[i]), solve(i+1, w));
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n >> wm;
    for(int i = 0; i < n; i++) {
        cin >> wt[i] >> v[i];
    }
    cout << solve(0,0) << "\n";
}


Measured memory_bytes: 86272
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  string S;
  int al[27] = {0}, c;
  char ans;
  bool flag = false;

  cin >> S;

  for(int i = 0; i < S.size(); i++){
    c = S[i] - 'a';
    al[c]++;
  }


  for(int i = 0; i < 26; i++){
    if(al[i] == 0){
        ans = i + 'a';
        flag = true;
        break;
    }
  }

  if(flag) cout << ans << endl;
  else cout << "None" << endl;

	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<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; }

map<lli,lli> makePrimeList2(lli n){
    map<lli,lli> m;
    lli a = 2;
    while(n>=a*a){
        if(n%a==0){
            m[a]++;
            n /= a;
        }
        else a++;
    }
    if(n!=1)m[n]++;
    return m;
}

void func(long long N, long long P){

    map<lli,lli> d = makePrimeList2(P);

    lli ans = 1;

    for(auto e:d){
        while(e.second>=N){
            ans*=e.first;
            e.second-=N;
        }
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long P;
    scanf("%lld",&P);
    func(N, P);
    return 0;
}


Measured memory_bytes: 256
N, x = map(int,input().split())
a = list(map(int,input().split()))
Nc = 0
if a[0] > x:
    Nc += a[0] - x
    a[0] = x
for i in range(N-1):
    if (a[i] + a[i+1] - x) > 0:
        Nc += a[i] + a[i+1] -x
        a[i+1] = x - a[i]

print(Nc)

Measured memory_bytes: 14668
#include<iostream>
#include <fstream>
#include <vector>

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    long A, B, T;
    
    cin >> A >> B >>T;

    cout << (int)((T+0.5)/A)*B << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10005], b[10005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;

int h, w;
char s[25][25];

int bfs(int sx,int sy) {
	int dist[25][25];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dist[i][j] = inf;
		}
	}
	dist[sx][sy] = 0;
	queue<P>v;
	v.push(P{ sx,sy });
	while (v.size()) {
		P now = v.front();
		v.pop();
		for (int i = 0; i < 4; i++) {
			int nextx = now.second + dx[i];
			int nexty = now.first + dy[i];
			if (dist[nexty][nextx] == inf && s[nexty][nextx] != '#') {
				dist[nexty][nextx] = dist[now.first][now.second] + 1;
				v.push(P{ nexty,nextx });
			}
		}
	}
	int res = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (dist[i][j] != inf) {
				res = max(dist[i][j], res);
				
			}
		}
	}
	return res;
}

int main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}
	int kai = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') {
				int ans = bfs(i, j);
				kai = max(ans, kai);
			}
		}
	}
	cout << kai << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e6+3);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}



ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p%2){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p /= 2;
	}
	return ret;
}

ll fc[1001001],nv[1001001];

int main(void){
	ll i,q,x,d,n,p,ans;
	fc[0] = 1ll; nv[0] = 1ll;
	for(i=1; i<MOD; ++i){
		fc[i] = fc[i-1];
		mul_mod(fc[i],i);
		nv[i] = rwpw(fc[i],MOD-2);
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> x >> d >> n;
		if(!d){
			ans = rwpw(x,n);
			cout << ans << endl;
			continue;
		}
		if(n>=MOD){
			cout << 0 << endl;
			continue;
		}
		p = (x*(rwpw(d,MOD-2)))%MOD;
		if(p+n-1 >= MOD || (!p)){
			cout << 0 << endl;
			continue;
		}
		ans = fc[p+n-1];
		mul_mod(ans,nv[p-1]);
		mul_mod(ans,rwpw(d,n));
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 16512
// E - Coprime
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rpd(i,s,e,d) for(int i=(s);i<(int)(e);i+=(d))
#define MAX_A 1000000 + 1

int sum_array(vi &C, int start, int end, int step){
	int c = 0;
	rpd(i, start, end, step) c += C[i];
	return c;
}

bool is_pairwise(vi &C){
	if(sum_array(C, 2, MAX_A, 2) > 1) return false;
	rpd(i, 3, MAX_A, 2) if(sum_array(C, i, MAX_A, i) > 1) return false;
	return true;
}

int is_type(vi &C, int g){
	if(is_pairwise(C)) return 0;
	if(g == 1) return 1;
	return 2;
}

int main(){
	int N; cin>>N;
	vi C(MAX_A, 0);
	int g = 0;
	rpd(i, 0, N, 1){
		int a; cin>>a;
		C[a]++;
		g = gcd(g, a);
	}
	cout<< vector<string>{"pairwise","setwise","not"}[is_type(C, g)] <<" coprime\n";
}


Measured memory_bytes: 7172
// http://drken1215.hatenablog.com/entry/2019/05/19/224500
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
using Graph = vector<vector<pair<int, int>>>;
typedef long long ll;

vector<int> res;

void dfs(const Graph &G, int v, int p, int c) {
    res[v] = c;
    for (auto nv : G[v]) {
        if (nv.first == p) continue;
        if (nv.second & 1) dfs(G, nv.first, v, 1-c);
        else dfs(G, nv.first, v, c);
    }
}

int main()
{
    int N;
    cin >> N;
    Graph G(N, vector<pair<int, int>>());
    rep(i, N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    res.assign(N, 0);
    dfs(G, 0, -1, 1);

    for (int i = 0; i < N; i++) {
        cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 11648