akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define mp make_pair
#define ft first
#define sd second
int n;
int V[200005];
int ll[200005],rr[200005];
pii L[20][200005],R[20][200005];
int d[200005];
int fr[200005],nex[200005],vi[200005],totv=0;
void add(int x,int y){
    vi[++totv]=y;nex[totv]=fr[x];fr[x]=totv;
}
vector<pii >res;
int rres[200005],ToT=0;
bool cp(int a,int b){
    return res[a].ft>res[b].ft;
}
void init(){
    for(int i=1;i<=n/2;++i)L[0][i]=mp(ll[i],i),R[0][i]=mp(rr[i],i);
    for(int i=1;i<=17;++i){
        for(int j=1;j<=n/2;++j){
            if((1<<i)+j-1>n/2)break;
            L[i][j]=min(L[i-1][j],L[i-1][j+(1<<i-1)]);
            R[i][j]=min(R[i-1][j],R[i-1][j+(1<<i-1)]);
        }
    }
}
pii getL(int l,int r){
    for(int i=18;~i;--i){
        if(r-l+1>=(1<<i)){
            return min(L[i][l],L[i][r-(1<<i)+1]);
        }
    }
}
pii getR(int l,int r){
    for(int i=18;~i;--i){
        if(r-l+1>=(1<<i)){
            return min(R[i][l],R[i][r-(1<<i)+1]);
        }
    }
}
void f__k(int l,int r,int fa){
    if(l>=r)return;
    int Lr=r/2+(r&1),Rr=r/2,Ll=l/2+1,Rl=l/2+(l&1);
    if(l&1){
        pii LLL=getL(Ll,Lr);
        if(LLL.sd==r)LLL=getL(Ll,Lr-1);
        pii RRR=getR(LLL.sd,Rr);
        res.push_back(mp(LLL.ft,RRR.ft));
        int tot=res.size()-1;
        if(fa!=-1){
            ++d[tot];
            add(fa,tot);
        }
        f__k(l,LLL.sd*2-2,fa);
        f__k(LLL.sd*2,RRR.sd*2-1,tot);
        f__k(RRR.sd*2+1,r,fa);
    }else{
        pii RRR=getR(Rl,Rr);
        if(RRR.sd==r)RRR=getR(Rl,Rr-1);
        pii LLL=getL(RRR.sd+1,Lr);
        res.push_back(mp(RRR.ft,LLL.ft));
        int tot=res.size()-1;
        if(fa!=-1){
            ++d[tot];
            add(fa,tot);
        }
        f__k(l,RRR.sd*2-1,fa);
        f__k(RRR.sd*2+1,LLL.sd*2-2,tot);
        f__k(LLL.sd*2,r,fa);
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",V+i);
        if(i&1)ll[i/2+1]=V[i];
        else rr[i/2]=V[i];
    }
    init();
    f__k(1,n,-1);
    priority_queue<pii > Q;
    // for(int i=0;i<n/2;++i){cout<<res[i].ft<<' '<<res[i].sd<<endl;for(int j=fr[i];j;j=nex[j])cout<<vi[j]<<' ';cout<<endl;}
    for(int i=0;i<n/2;++i)if(d[i]==0)Q.push(mp(-res[i].ft,i));
        while(!Q.empty()){
            pii x=Q.top();Q.pop();
            rres[++ToT]=res[x.sd].ft;
            rres[++ToT]=res[x.sd].sd;
            for(int i=fr[x.sd];i;i=nex[i]){
                if((--d[vi[i]])==0)Q.push(mp(-res[vi[i]].ft,vi[i]));
            }
        }
    for(int i=1;i<=n/2;++i)printf("%d %d ",rres[i*2-1],rres[i*2]);
    return 0;
}

Measured memory_bytes: 71540
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader rd = new MyReader();        
        int N = rd.i();
        int[] A = rd.ii();
        int[] l = new int[N];
        int[] r = new int[N];
        l[1] = A[0];
        r[N-2] = A[N-1];
        for(int i = 2; i < N; i++)
            l[i] = gcd(l[i-1], A[i-1]);
        for(int i = N-3; i >= 0; i--)
            r[i] = gcd(r[i+1], A[i+1]);
        l[0] = r[0];
        r[N-1] = l[N-1];
        int max = 1;
        for(int i = 0; i < N; i++){
            int temp = gcd(l[i], r[i]);
            if(max < temp)
                max = temp;
        }
        println(max);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static int gcd(int... ii){
        int N = ii.length;
        int gcd = ii[0];
        for(int i = 1; i < N; i++){
            int a = gcd;
            int b = ii[i];
            if(b < a){
                int c = a;
                a = b;
                b = c;
            }
            int r;
            while((r=b%a)>0){
                b = a;
                a = r;
            }   
            gcd = a;
        }
        return gcd;
    }  
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 45336
#include <bits/stdc++.h>
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}
using namespace std;
 

int main() 
{
	fast;
    int n,k,c;
    cin>>n>>k>>c;
    string s;
    cin>>s;
    int l[k],r[k];
    int b=0,e=k-1;
    int ind=-1;
    for(int i=0;i<n && b<k;i++)
	{
        if(s[i]=='o' && i>ind)
		{
            l[b]=i;
            b++;
            ind=i+c;
        }
    }
    ind=n;
    for(int i=n-1;i>=0 && e>=0;i--)
	{
        if(s[i]=='o' && i<ind)
		{
            r[e]=i;
            e--;
            ind=i-c;
        }
    }
  //  for(ll i = 0; i < k; i++) {cout << l[i] << " ";}cout << endl;
   // for(ll i = 0; i < k; i++) {cout << r[i] << " ";}cout << endl;
    for(int i=0;i<k;i++){
        if(l[i]==r[i])cout<<l[i]+1<<endl;
        //cout<<l[i]<<" "<<r[i]<<endl;
    } 
	return 0;
}

Measured memory_bytes: 3348
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MOD 1000000007
#define ll long long
using namespace std;
ll n;
ll f[5100][5100],len;
char s[5100];

ll ksm(ll a,ll b){
	b%=MOD;a%=MOD;
	ll ans=1;
	while(b){
		if (b&1) ans=(ans*a)%MOD;
		a=(a*a)%MOD;b>>=1;
	}
	return ans;
}

int main(){
	cin>>n;
	scanf("%s",s);
	len=strlen(s);
	f[1][1]=2;f[1][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			f[i+1][j+1]=(f[i+1][j+1]+2*f[i][j])%MOD;
			f[i+1][max(0,j-1)]=(f[i+1][max(0,j-1)]+f[i][j])%MOD;
		}
	}
	cout<<f[n][len]*ksm(ksm(2,len),MOD-2)%MOD<<endl;
	return 0;
}

Measured memory_bytes: 120760
import java.util.Scanner;

// MainT1P2018D
public class Main {

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			final int N = in.nextInt();
			int d = 8*N + 1;
			int dr = (int)Math.sqrt(d);
			if (dr * dr != d) {
				System.out.println("No");
				return;
			}

			final int k = (1 + dr) / 2;

			final int[][] sets = new int[k - 1][];
			{
				int idx = 1;
				for (int i = 0; i < k - 1; ++i) {
					sets[i] = new int[i + 1];
					for (int j = 0; j < sets[i].length; ++j) {
						sets[i][j] = idx++;
					}
				}
			}

			System.out.println("Yes");
			System.out.println(k);
			for (int i = 0; i < k - 1; ++i) {
				System.out.print(k - 1);
				for (int j = 0; j < i; ++j) {
					System.out.printf(" %d", sets[i][j]);
				}
				for (int j = i; j < k - 1; ++j) {
					System.out.printf(" %d", sets[j][i]);
				}
				System.out.println();
			}
			{
				System.out.print(k - 1);
				for (int i = 0; i < k - 1; ++i) {
					System.out.printf(" %d", sets[i][i]);
				}
				System.out.println();
			}
		}
	}
}


Measured memory_bytes: 60916
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 2e5 + 50;
cs int INF = 1e9 + 7;
int n, a[N];
struct my{ 
	int l, r, v; 
	bool emp(){ return l > r; }
	my(int _l = 0, int _r = 0, int _v = 0){
		l = _l, r = _r, v = _v;
	} my operator & (cs my &a){ return my(max(l,a.l),min(r,a.r), v); }
	bool operator < (cs my &a) cs{ return v < a.v; }
	my operator ^ (cs my &a){ return l == a.l ? my(a.r + 1, r, v) : my(l, a.l - 1, v); }
};
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
	scanf("%d",&a[i]);
	vector<my> now, nxt;
	now.pb(my(0, 0, 0));
	for(int i=1; i<=n+1; i++){
		nxt.clear(); int dt = a[i] - a[i-1];
		my lm(0, a[i]); 
		for(my t : now){
			my z = my(0, min(t.r - 1, t.r - 1 + dt), t.v + 2) & lm;
			if(!z.emp()) nxt.pb(z);
			z = my(t.l + dt, t.r - 1, t.v + 1) & lm;
			if(!z.emp()) nxt.pb(z);
			z = my(t.l, t.r + dt - 1, t.v + 1) & lm;
			if(!z.emp()) nxt.pb(z);
			z = my(max(t.l, t.l + dt), a[i], t.v) & lm;
			if(!z.emp()) nxt.pb(z);
		} sort(nxt.begin(), nxt.end());
		now.clear();
		for(my t : nxt){
			my z = t; for(my o : now){
				my p = o & z;
				if(!p.emp()) z = z ^ p;
				if(z.emp()) break;
			} if(!z.emp()) now.pb(z);
		}
	} int ans = INF;
	for(my t : now) ans = min(ans, t.v);
	cout << ans; return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

int N,X,Y,Z;

int S;

ll dp[41][1<<16];
ll dfs(int now, int state)
{
    if(dp[now][state]>=0) return dp[now][state];

    if(now==N) return 1;

    //直前の状態を復元
    vector<int> b;
    int st=0;
    rep(i,S)
    {
        if(state>>i&1)
        {
            b.pb(i-st+1);
            st=i+1;
        }
    }

    ll ret=0;

    //次に選ぶ数
    for(int i=1; i<=10; ++i)
    {
        bool ok=true;
        //iを次に選んだ時にXYZを含まないかチェック
        //直前から順番に見ていき貪欲に足していく
        int x=0,y=0,z=i;
        int bidx=0;
        while(bidx<b.size() && z<Z) z+=b[bidx++];
        while(bidx<b.size() && y<Y) y+=b[bidx++];
        while(bidx<b.size() && x<X) x+=b[bidx++];
        if(x==X && y==Y && z==Z) ok=false;

        if(ok)
        {
            ret+=dfs(now+1, ((state<<i)+(1<<(i-1)))%(1<<S));
            ret%=mod;
        }
    }

    return dp[now][state]=ret;
}

int main()
{
    cin >>N >>X >>Y >>Z;
    S=X+Y+Z-1;

    ll p10=1;
    rep(i,N) p10=(p10*10)%mod;

    memset(dp,-1,sizeof(dp));
    //XYZを含まない数列の個数
    ll r=dfs(0,0);
    //全体から引く
    ll ans=(p10-r+mod)%mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 21248
//Author: 23forever
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <bitset>
const int MAXN = 1000;
const int INF = 0x3f3f3f3f;
using namespace std;

inline int read() {
  int x = 0, w = 1;
  char c = ' ';

  while (c < '0' || c > '9') {
    c = getchar();
    if (c == '-') w = -1;
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }

  return x * w;
}

int n, m, ga[MAXN + 5][MAXN + 5], belong[MAXN + 5], vis[MAXN + 5], sum[2];
bool f;

void dfs(int u, int col) {
  if (f) return;

  belong[u] = col;
  vis[u] = true;
  ++sum[col];

  for (int i = 1; i <= n; ++i) {
    if (i != u && !ga[u][i]) {
      int v = i;

      if (!vis[v]) {
        dfs(v, col ^ 1);
      } else if (col == belong[v]) {
        f = true;
        return;
      }
    }
  }
}

void init() {
  n = read();
  m = read();

  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    ga[u][v] = true;
    ga[v][u] = true;
  }
}

bitset<705>S;

int main() {
  init();
  
  S[0] = 1;

  for (int i = 1; i <= n; ++i) {
    if (!vis[i]) {
      memset(sum, 0, sizeof(sum));
      dfs(i, 0);

      S = (S << sum[0]) | (S << sum[1]);
    }
  }

  if (f) {
    puts("-1");
    return 0;
  }
  
  int ans = INF;

  for (int i = 0; i < n; ++i) if (S[i]) ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
  
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 2944
use std::io;

#[allow(unused_macros)]
macro_rules! read {
    ($t: ty) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            input.trim().parse::<$t>().unwrap()
        };
    };
    ($($t: ty),*) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            let mut iter = input.trim().split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()), *)
        };
    }
}
#[allow(unused_macros)]
macro_rules! read_vec {
    ($t: ty) => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            let iter = input.trim().split_whitespace();
            iter.map(|x| x.parse::<$t>().unwrap()).collect::<Vec<$t>>()
        };
    }
}
#[allow(unused_macros)]
macro_rules! read_chars {
    () => {
        {
            let mut input = String::new();
            io::stdin().read_line(&mut input).expect("could not read input");
            input.trim().chars().collect::<Vec<char>>()
        };
    }
}

#[allow(dead_code)]
static M: u64 = 1000000007;

fn main() {
    let (n, a, b) = read!(i32, u32, u32);
    let mut s = 0;
    for i in 1..n+1 {
        let c: u32 = i.to_string().chars().map(|i| i.to_digit(10).unwrap()).sum();
        if c >= a && c <= b {
            s += i;
        }
    }
    println!("{}", s);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int multi = a*b;
        final String result;
        if(multi % 2 == 0){
            result = "Even";
        } else {
            result = "Odd";
        }
        System.out.println(result);
        sc.close();   
    }
}

Measured memory_bytes: 21844
#include<cstdio>

int a, b, c, d;
int tim = 0;

int main() {
	scanf("%d%d%d%d", &a, &b, &c, &d);
	while(a > 0 && c > 0) {
		++tim;
		if(tim & 1) c -= b;
		else a -= d;
	}
	puts(c <= 0 ? "Yes" : "No");
}

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

using namespace std;

#define int long long
#define pii pair<int,int>
#define F first
#define S second
#define mpr make_pair
typedef long long ll;

const int maxn = 210;
const int mod = 1e9+7;
const ll inf = 1e18+10;

bool good[maxn];
bool is(vector<int> a, int x)
{
    int n = a.size();

    memset(good, 0, sizeof good);
    int X = x;
    for(int j = 0; j <= 60; j++)
        for(int i = 0; i < n; i++)
            if((a[i]&(1ll<<j)) && !good[i])
            {
                good[i] = 1;
                for(int k = 0; k < n; k++)
                    if(k != i && !good[k] && (a[k] & (1ll<<j)))
                        (a[k] ^= a[i]);
                if((X&(1ll<<j))) (X ^= a[i]);
                break;
            }
    return (X == 0);
}

int a[maxn];
signed main()
{
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int q; cin>> q;
    while(q--)
    {
        int n; cin>> n;
        for(int i = 0; i < n; i++) cin>> a[i];
        string s; cin>> s;

        vector<int> ve;
        bool ans = 0;

        for(int i = n-1; i >= 0; i--)
        {
            if(s[i] == '0') ve.push_back(a[i]);
            else
                if(!is(ve,a[i]))
                {
                    ans = 1;
                    break;
                }
        }
        cout<< ans <<"\n";
    }
}


Measured memory_bytes: 3652
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int n;
     cin >> n;
    cout << "ABC" << n << endl;
}

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

int main() {
  long long int h, w;
  cin >> h >> w;
  if ( h == 1 || w ==1 ){
    cout << 1 << endl;
  }
  else if ( h%2 == 1 && w%2 == 1){
    cout << (h*w + 1)/2 << endl;
  }
  else{
    cout << h*w/2 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const lli inf = 1e18;

int main(){
    int n;
    cin >> n;
    vector<lli> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    if(*min_element(a.begin(), a.end()) == 0){
        cout << 0 << endl;
        return 0;
    }
    bool overflow = false;
    lli ans = 1;
    for(int i=0; i<n; i++){
        if(a[i] > 2*inf/ans){
            overflow = true;
            break;
        }
        ans *= a[i];
        if(ans > inf){
            overflow = true;
            break;
        }
    }
    if(overflow){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4000
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  long long a[3];
  int k;
  cin >> a[0] >> a[1] >> a[2];
  cin >> k;
  sort(a,a+3);
  REP(i,k){
    a[2]=a[2]*2;
  }
  cout << a[0]+a[1]+a[2] << endl;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;

// 1. dp?????????
ll dp[1001][1001];
// 2. n????????????
int n,m;
ll d[1001],c[1001];
const ll INF=-1000000000000;
// ???. calc????????????
ll calc(int k,int p){
	// 8. dp???????????°??????
	if(dp[k][p]>=0)return dp[k][p];
	if(k==p){
		dp[k][p]=calc(k-1,p-1)+d[k]*c[p];
	}else{
	dp[k][p]=min(calc(k,p-1),calc(k-1,p-1)+d[k]*c[p]);
	}

	return dp[k][p];

}

int main() {

	cin>>n>>m;

	// 3. ?????????
	for(int i=0;i<1001;++i){
		for(int j=0;j<1001;++j){
			dp[i][j]=-1;

		}
	}
	// 4.??\???



	for(int i=1; i<n+1; ++i){
		cin>>d[i];
	}
	for(int j=1; j<m+1; ++j){
		cin>>c[j];
	}

	// 5. ???????????¨??????
	for(int i=0; i<m+1; ++i){
		dp[0][i]=0;
	}

	// 6. ??????





	cout<<calc(n,m)<<endl;
	return 0;

}

Measured memory_bytes: 10960
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll k;
  cin >> k;
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  for (int i=a; i<=b; i++) {
    if (i%k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}


Measured memory_bytes: 3520
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <tuple>
#include <functional>

using namespace std;

#define ll long long

int main() {
	int n;
	int a[100050] = {};
	int b[100050] = {};
	ll ans = 0;

	cin >> n;
	for (int i = 0; i < n + 1; i++)
	{
		cin >> a[i];
	}

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

	for (int i = 0; i < n; i++) {
		int left = min(a[i], b[i]);
		ans += left;
		a[i] -= left;
		b[i] -= left;

		int right = min(a[i + 1], b[i]);
		ans += right;
		a[i + 1] -= right;
		b[i] -= right;
	}

	cout << ans << endl;

}


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

struct Triplet {
   int L1, L2, L3; 
};

bool isTriangle(const Triplet& t) {
	return (t.L1 + t.L2 > t.L3) &&
      	   (t.L1 + t.L3 > t.L2) &&
           (t.L2 + t.L3 > t.L1);
}

bool isDifferent(const Triplet& t) {
	return (t.L1 != t.L2) &&
      	   (t.L2 != t.L3) &&
           (t.L3 != t.L1);
}

const vector<Triplet> createFilteredTriplets(const vector<int>& sticks) {
  int sticks_size = sticks.size();
  vector<Triplet> triplets;
  for (int i = 0; i <= sticks_size - 3; ++i) {
    for (int j = i + 1; j <= sticks_size - 2; ++j) {
      for (int k = j + 1; k < sticks_size; ++k) {
        Triplet t = {sticks[i], sticks[j], sticks[k]};
        if (isDifferent(t) && isTriangle(t))
          triplets.push_back({sticks[i], sticks[j], sticks[k]});
      }
    }
  }
  return triplets;
}

int main() {
  int N, stick;
  vector<int> sticks;
  cin >> N;
  for (int i = 0; i < N; ++i) {
  	cin >> stick;
    sticks.push_back(stick);
  }
  const vector<Triplet>& triplets = createFilteredTriplets(sticks);
  printf("%d", triplets.size());
  return 0;
}

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

int pos;
vector<int> pre, in, post;

void rec(int l, int r)
{
	if (l >= r)
		return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l, m);
	rec(m + 1, r);
	post.push_back(root);
}

void solve() {
	pos = 0;
	rec(0, pre.size());

	int i;
	for (i = 0; i < post.size(); i++) {
		if (i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

int main(void) {
	int n, i, k;
	cin >> n;
	for (i = 0; i < n; i++)
	{
		cin >> k;
		pre.push_back(k);
	}
	for (i = 0; i < n; i++)
	{
		cin >> k;
		in.push_back(k);
	}
	solve();

}


Measured memory_bytes: 3164
def main():
    from collections import Counter
    from itertools import combinations

    n, *s = map(lambda x: str(x)[0], open(0).read().split())
    c = Counter(s)

    m = [c.get(x) if c.get(x) != None else 0 for x in ["M", "A", "R", "C", "H"]]
    ans = 0
    if len(m) >= 3:
        for (i, j, k) in combinations(m, 3):
            ans += i * j * k

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11412
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int add(int x,int y){return x+y<mod?x+y:x+y-mod;}
void ade(int& x,int y){x+=y;if(x>=mod)x-=mod;}
int n;
char s[300300];
int tran[2][9]={{1,3,4,1,6,7,4,8,7},{2,0,5,1,2,5,4,5,7}};
int dp[300300][10];
int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    dp[0][0]=1;
    for(int i=0;i<n;++i)
        for(int j=0;j<=8;++j)
        {
            if(s[i+1]!='1')ade(dp[i+1][tran[0][j]],dp[i][j]);
            if(s[i+1]!='0')ade(dp[i+1][tran[1][j]],dp[i][j]);
        }
    printf("%d\n",add(dp[n][2],add(dp[n][5],add(dp[n][7],dp[n][8]))));
    return 0;
}


Measured memory_bytes: 12288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

bool comp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    int s=a.first.first+a.first.second;
    int t=b.first.first+b.first.second;
    return s<t;
}

ll dp[10002];

int main(){
    int n;
    cin>>n;
    pair<pair<int,int>,int> b[n];
    for(int i=0;i<n;i++){
        int w,s,v;
        cin>>w>>s>>v;
        b[i]={{w,s},v};
    }
    sort(b,b+n,comp);
    for(int i=0;i<n;i++){
        int w=b[i].first.first;
        int s=b[i].first.second;
        ll v=b[i].second;
        for(int j=s;j>=0;j--){
            int to=min(10001,j+w);
            dp[to]=max(dp[to],dp[j]+v);
        }
    }
    ll ans=-1;
    for(int i=0;i<=10001;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
x = [0 for _ in range(10**5+1)]
for ai in a:
  x[ai] += 1
q = int(input())
for _ in range(q):
  b,c = map(int,input().split())
  xb = x[b]
  x[b] = 0
  s+= xb*(c-b)
  x[c] += xb
  print(s)

Measured memory_bytes: 83520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
#define MP make_pair
#define FF first
#define SS second




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n  = s.size();
    if(s[n - 1] == '2' || s[n - 1] == '4' || s[n-1] == '5' ||s[n-1] == '7' || s[n-1] == '9'){
        cout << "hon" << "\n";
    }
    if(s[n-1] == '3'){
        cout << "bon" << "\n";
    }
    if(s[n-1] == '0' || s[n-1] == '1' || s[n-1] == '6' || s[n-1] == '8'){
        cout << "pon" << "\n";
    }

}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    char s[2];
    scanf("%s", s);

    if (s[0]=='A') {
        printf("T");
    }else if(s[0]=='T') {
        printf("A");        
    } else if (s[0] == 'C') {
        printf("G");
    }else{
        printf("C");
    }
    return 0;

}


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

int main()
{    
    int h, w;
    while (true) {
        std::cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }

        for (int j = 0; j < w; j++) {
            std::printf("#");
        }
        std::printf("\n");

        for (int i = 1; i < h - 1; i++) {
            std::printf("#");
            for (int j = 0; j < w-2; j++) {
                std::printf(".");
            }
            std::printf("#");
            std::printf("\n");
        }

        for (int j = 0; j < w; j++) {
            std::printf("#");
        }
        std::printf("\n\n");
    }

    return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;
import java.lang.Math;
public class Main {
    static int W;
    static int H;
    public static int[][] mp = new int[51][51];
    public static int countIsland(int h, int w){
        mp[h][w]=0;
        for(int i=-1;i<2;i++){
            for(int j = -1;j<2;j++){
                if(h+i>=H||h+i<0||w+j>=W||w+j<0||(i==0&&j==0)){
                    
                }
                else {
                    //System.out.printf("%d,%d%n",h+i,w+j);
                    if(mp[h+i][w+j]==1){
                        countIsland(h+i,w+j);
                    }
                }
                
            }
        }
        return 1;
    }
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true) {
            for(int i=0;i<51;i++){
                for(int j=0;j<51;j++){
                    mp[i][j] = 0;
                }
            }
            W = sc.nextInt();
            H = sc.nextInt();
            if(W==0&&H==0) break;
            int cnt=0;
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    mp[i][j] = sc.nextInt();
                }
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(mp[i][j]==1){
                        countIsland(i,j);
                        cnt++;
                    }
                }
            }
            System.out.println(cnt);
        }
    }
}



Measured memory_bytes: 44600
#!/usr/bin/env python3
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
#print(len(a))
print(a[int(input())-1])

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

int main() {
    int N, D;
    cin >> N >> D;
    int ans = N / (2 * D + 1);
    if(N % (2 * D + 1) != 0) ans++;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <random>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(g);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
ll mod = 1e9 + 7;


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

	int a, b;
	cin >> a >> b;
	cout << (a-1) * (b-1) << endl;
	return 0;
}

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

vector<int> pattern;
int c;

void check(int combi) {
	int size = pattern.size();
	for(int i = 0; i < size; i++) {
		if(pattern[i] == combi)
			return;
	}
	pattern.resize(size+1);
	pattern[size] = combi;
}

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int n, k, i, j, l, m, temp;
	int card[10];

	while(cin >> n >> k, n != 0 || k != 0) {

		pattern.resize(0);

		for(i = 0; i < n; i++) {
			cin >> card[i];
		}
	
		for(i = 0; i < n; i++) {
			for(j = 0; j < n; j++) {
				if(i == j)
					continue;
				if(k == 2) {
					temp = card[i];
					if(card[j] >= 10) {
						temp *= 100;
					} else {
						temp *= 10;
					}
					temp += card[j];
					check(temp);
				} else {
					for(l = 0; l < n; l++) {
						if(i == l || j == l)
							continue;
						if(k == 3) {
							temp = card[i];
							if(card[j] >= 10) {
								temp *= 100;
							} else {
								temp *= 10;
							}
							temp += card[j];
							if(card[l] >= 10) {
								temp *= 100;
							} else {
								temp *= 10;
							}
							temp += card[l];
							check(temp);
						} else {
							for(m = 0; m < n; m++) {
								if(i == m || j == m || l == m)
									continue;
								temp = card[i];
								if(card[j] >= 10) {
									temp *= 100;
								} else {
									temp *= 10;
								}
								temp += card[j];
								if(card[l] >= 10) {
									temp *= 100;
								} else {
									temp *= 10;
								}
								temp += card[l];
								if(card[m] >= 10) {
									temp *= 100;
								} else {
									temp *= 10;
								}
								temp += card[m];
								check(temp);
							}
						}
					}
				}
			}
		}

		cout << pattern.size() << endl;

	}

	return 0;

}

Measured memory_bytes: 1244
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
	int a[3];
	for(int i=0;i<3;i++)cin>>a[i];
	sort(a,a+3);
	if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
   return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int S(int n) {
    int ans = 0;
    while (n) {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

vector<int> kouho;

signed main() {
    int K;
    cin >> K;
    int prev = 0, m = 1;
    rep(i, K) {
        int x1 = prev + m, x2 = prev + 10 * m;
        if (x1 * S(x2) <= x2 * S(x1)) {
            prev = x1;
        } else {
            prev = x2;
            m *= 10;
        }
        cout << prev << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF = 1000000000;

int n, m, a[100001], c1[20], c2[20][100001];
int bit[1<<20], len[1<<20];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) c1[i] = 0;
  for (int i = 0; i < m; i++) c2[i][0] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    a[i]--;
    c1[a[i]]++;
    for (int j = 0; j < m; j++) c2[j][i] = c2[j][i - 1];
    c2[a[i]][i]++;
  }
  for (int i = 0; i <= (1 << m) - 1; i++) bit[i] = INF;
  bit[0] = 0, len[0] = 0;
  for (int i = 0; i <= (1 << m) - 1; i++) {
    for (int j = 0; j < m; j++) {
      if (i & (1 << j)) continue;
      int newi = i + (1 << j);
      len[newi] = len[i] + c1[j];
      int temp = c1[j] - (c2[j][len[newi]] - c2[j][len[i]]);
      bit[newi] = min(bit[newi], bit[i] + temp);
    }
  }
  printf("%d\n", bit[(1 << m) - 1]);
}



Measured memory_bytes: 19008
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int main()
{
  int n;
  ll k;
  ll a[100000];
  ll result = 0;
  ll mask = 1;

  ll list0[40];
  ll list1[40];

  cin >> n >> k;
  k++;
  REP(i, n)
  {
    cin >> a[i];
  }

  REP(j, 40)
  {

    int on = 0;
    int off = 0;

    REP(i, n)
    {
      if (a[i] & (mask << j))
      {
        on++;
      }
      else
      {
        off++;
      }
    }

    list0[j] = (mask << j) * off;
    list1[j] = (mask << j) * on;
  }

  REP(i, 40)
  {
    if (!(k & (mask << i)))
    {
      continue;
    }
    ll tmp = 0;
    {
      for (int j = 39; j > i; j--)
      {
        if (k & (mask << j))
        {

          tmp += list0[j];
        }
        else
        {
          tmp += list1[j];
        }
      }

      tmp += list1[i];

      for (int j = 0; j < i; j++)
      {
        if (list0[j] < list1[j])
        {
          tmp += list1[j];
        }
        else
        {
          tmp += list0[j];
        }
      }

      if (result < tmp)
      {
        result = tmp;
      }
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 1024
#include<cstdio>

char s[10];
bool f[500];

int main()
{
	scanf("%s",s+1);
	for(int i=1;i<=3;i++)
		f[s[i]]++;
	
	if(f['a']&&f['b']&&f['c'])
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 128
function Main(input){
	input = input.split("\n");
	var arr = input[1].split("");
	var n = input[0]-0;
	var rgb = [0,0,0];
	for(var i=0;i<arr.length;i++){
		switch(arr[i]){
			case "R":
			rgb[0]++;
			break;
			case "G":
			rgb[1]++;
			break;
			case "B":
			rgb[2]++;
			break;
		}
	}
	var sum = rgb[0]*rgb[1]*rgb[2];

	for(i=1;i<=n;i++){
		for(var j=i;j<arr.length-i+1;j++){
			var p = [];
			p.push(arr[j]);
			p.push(arr[j-i]);
		    p.push(arr[j+i]);
		    p=p.sort();
		    //console.log(p)
			if(p[0]=="B"&&p[1]=="G"&&p[2]=="R") sum--;
		}
	}
	console.log(sum);
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

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

using namespace std;
#define int int64_t
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define gsort(x) sort((x).begin(), (x).end(), greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define pii pair<int, int>
#define re(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int n, k;
   cin >> n >> k;
   int a;
   vector<int> x;
   double cnt = 0.0, ans = 0.0;

   rep(i, n)
   {
      cin >> a;
      x.push_back(a);
      cnt += (double)(a + 1.0);

      if (i >= k)
      {
         cnt -= (double)x[i - k] + 1.0;
         //cout << cnt << ' ';
      }

      if (i >= k - 1)
      {
         ans = max(ans, cnt / 2.0);
         //cout << ans << ' ' << cnt / 2.0 << '\n';
      }
   }

   cout << setprecision(10) << ans << '\n';
}

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

int main(){
  ll i,N,p,q;
  cin>>N;
  if(N==0){cout<<N;return 0;}
  stack<int> st;
  while(N){
    q=(N%2+2)%2;
    st.push(q);
    p=(N-q)/2;
    N=0-p;
  }
  while(!st.empty()){
    p=st.top();
    st.pop();
    cout<<p;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define p pair<int,int>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
using namespace std;
int POW(int x,int y){return int(pow(double(x),double(y)));}
int ketasum(int n){ //各桁の和を返す
	int k=int(log10(double(n)))+1;
	int sum=0;
	FOR(i,1,k+1){
		sum+=(n/int(pow(10,double(i-1))))%10;
	}
	return sum;
}

int main(){
	
	int n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	FOR(i,1,n+1){
		int sum=ketasum(i);
		if(a<=sum && sum<=b){
			ans+=i;
		}
	}
	cout<<ans<<endl;

}

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

using namespace std;
int N;
int x[100005], y[100005];
long long int W[100005], B[100005];

long long int MOD = 1000000007;

vector<int> Adj[100005];

long long int CALC_W(int k, int p);
long long int CALC_B(int k, int p);


int main(void) {

	cin >> N;
	for (int i = 1; i <= N-1; i++) {
		cin >> x[i] >> y[i];
	}

	for (int i = 1; i <= N-1; i++) {
		Adj[x[i]].push_back(y[i]);
		Adj[y[i]].push_back(x[i]);
	}


	cout << (CALC_W(1, 1) + CALC_B(1, 1)) % MOD << endl;

	//system("pause");
	return 0;
}

long long int CALC_W(int k, int p) {

	if (W[k] > 0) { return W[k]; }

	long long int ret = 1;

	for (int i = 0; i < (int)Adj[k].size(); i++) {
		int u = Adj[k][i];
		if (u == p) { continue; }
		ret *= (CALC_W(u, k) + CALC_B(u, k));
		ret %= MOD;
	}

	W[k] = ret;
	return ret;

}

long long int CALC_B(int k, int p) {

	if (B[k] > 0) { return B[k]; }

	long long int ret = 1;

	for (int i = 0; i < (int)Adj[k].size(); i++) {
		int u = Adj[k][i];
		if (u == p) { continue; }
		ret *= CALC_W(u, k);
		ret %= MOD;
	}

	B[k] = ret;

	return ret;
}

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

template <std::uint_fast64_t mod>
class ModInt {
    using u64 = std::uint_fast64_t;

   public:
    u64 x;
    ModInt(const ll x = 0) : x(x < 0 ? (mod - (-x % mod)) % mod : x % mod) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod;
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod) x %= mod;
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod - 2;
        while (p > 0) {
            if (p & 1) *this *= r;
            r *= r;
            p >>= 1;
        }
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod; }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        ll a;
        in >> a;
        if (a < 0) a = mod - (-a % mod);
        if (a >= mod) a %= mod;
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }
};
constexpr std::uint_fast64_t mod = 1e9 + 7;
using mint = ModInt<mod>;

mint solve(string &s, int k = 0, bool status = 1) {
    // dp[k][status] := 上(k+1)桁が定まっていてその時点で
    //                  status(:=上限値と一致するかの真偽値 )のときの場合の数
    static mint dp[100010][2];
    static bool visited[100010][2] = {};
    static int max_num = 1;

    if (k == s.size()) {
        return 1;
    }

    mint &res = dp[k][status];
    if (visited[k][status])
        return res;
    else
        res = 0;
    visited[k][status] = true;

    int r = (status ? s[k] - '0' : max_num);

    for (int i = 0; i <= r; i++) {
        mint cnt = solve(s, k + 1, status && i == r);
        res += i ? cnt * 2 : cnt;
    }
    return res;
}

int main() {
    string s;
    cin >> s;
    cout << solve(s) << endl;
    return 0;
}

Measured memory_bytes: 9984
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<map>
#include<string>
using namespace std;
int main() {
	string S;
	string T;
	int N;
	cin >> N >> S >> T;
	int A;
	A = 0;
	while (A < N) {
		char c = S[A];
		char d = T[A];
		cout << c << d ;
		A++;
	}
  cout<<endl;
return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = I()
    h = LI()
    dp = [float("inf") for i in range(n)]
    dp[0] = 0
    for i in range(n-2):
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]))
    dp[n-1] = min(dp[n-1],dp[n-2]+abs(h[n-1]-h[n-2]))
    print(dp[n-1])
#B
def B():
    n,k = LI()
    h = LI()
    dp = [float("inf") for i in range(n)]
    dp[0] = 0
    for i in range(n):
        for j in range(1,min(n-i,k+1)):
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
    print(dp[n-1])

#C
def C():
    n = I()
    v = LIR(n)
    dp = [[0,0,0] for i in range(n+1)]
    for i in range(n):
        dp[i+1][0] = max(dp[i+1][0],dp[i][1]+v[i][0],dp[i][2]+v[i][0])
        dp[i+1][1] = max(dp[i+1][1],dp[i][2]+v[i][1],dp[i][0]+v[i][1])
        dp[i+1][2] = max(dp[i+1][2],dp[i][0]+v[i][2],dp[i][1]+v[i][2])
    print(max(dp[n]))

#D
def D():
    n,W = LI()
    g = LIR(n)
    dp = [[0 for i in range(W+1)] for j in range(n+1)]
    for i in range(n):
        for j in range(W+1)[::-1]:
            w,v = g[i]
            if j >= w:
                dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
            else:
                dp[i+1][j] = max(dp[i+1][j],dp[i][j])
    print(max(dp[n]))
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


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

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

  if (s == "SAT")
    cout << 1;
  else if (s == "MON")
    cout << 6;
  else if (s == "TUE")
    cout << 5;
  else if (s == "WED")
    cout << 4;
  else if (s == "THU")
    cout << 3;
  else if (s == "FRI")
    cout << 2;
  else if (s == "SUN")
    cout << 7;
}


Measured memory_bytes: 3568
#include<iostream>
using namespace std;
int main(){
  
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i+=2){
    int count=0;
    for(int j=1;j<=n;j+=2){
      if(i%j==0)count++;
    }
    if(count==8)ans++;
  }
  cout<<ans<<endl;
  
  return 0;
}

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

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

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

std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

int main()
{
    int n; cin >> n;
    ll a[n];
    rep(i,n) cin >> a[i];
    map<int,int> m;
    vector<int> min_fac = sieve(2000000);
    rep(i,n){
        set<int> s;
        if(a[i] == 1)continue;
        vector<int> v = factor(a[i],min_fac);
        for(auto j : v){
            s.insert(j);
        }
        for(auto j : s){
            m[j]++;
        }
    }
    bool f = false;
    for(auto i : m){
        if(i.second == n) f = true;
    }
    if(f){
        cout << "not coprime";
    }else{
        bool pw = true;
        for(auto i : m){
            if(i.second > 1){
                pw = false;
            }
        }
        if(pw){
            cout << "pairwise coprime";
        }else{
            cout << "setwise coprime";
        }
    }
}

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

int binarySearch(int *, int, int);

int main(){

  int i,cnt=0;
  int n,*S,q,*T;

  //入力
  scanf("%d",&n);
  S=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  T=(int *)malloc(sizeof(int)*q);
  for(i=0;i<q;i++) scanf("%d",&T[i]);

  //search
  for(i=0;i<q;i++) cnt+=binarySearch(S,T[i],n);

  //表示
  printf("%d\n",cnt);


  return 0;

}
int binarySearch(int *A,int key,int n){

  int left=0,right=n,mid;

  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key) return 1;
    else if(key<A[mid]) right=mid;
    else left=mid+1;
  }

  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e5 + 7;

int dp[N];
vector<int> g[N];

void dfs(int cur, int p) {
	int c = 0;
	for (auto t : g[cur]) {
		if (t != p) {
			dfs(t, cur);
			dp[cur] += dp[t];
			if (!dp[t]) {
				c++;
			}
		}
	}
	dp[cur] += max(0, c - 1);
}

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

	int n;
	cin >> n;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	for (int i = 0; i < n; i++) {
		if ((int)g[i].size() > 2) {
			dfs(i, -1);
			cout << dp[i] << '\n';
			return 0;
		}
	}
	cout << 1 << '\n';
}


Measured memory_bytes: 13640