akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] money = { 300000, 200000, 100000 };
		int sum = 0;
		if (X <= 3) {
			sum += money[X - 1];
		}
		if (Y <= 3) {
			sum += money[Y - 1];
		}
		if (X == 1 && Y == 1) {
			sum += 400000;
		}
		System.out.println(sum);
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 22996
N = int(input())
A = list(int(input()) for _ in range(N))
asc, des = [0], [0]
for i in range(N-1):
    asc.append(max(asc[-1], A[i]))
    des.append(max(des[-1], A[-1-i]))

for i in range(N):
    print(max(asc[i], des[-1-i]))


Measured memory_bytes: 15668
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
#include<sstream>
#include<iomanip>
using namespace std;

#define ll long long
#define MP make_pair

int main(void) {
    int n,r;
    while(1){
        cin>>n>>r;
        if(n==0&&r==0)break;
        vector<int> v(50);
        for (int i = 0; i < n; i++) {
            v[i]=n-i;
        }



        int p,c;
        for (int i = 0; i < r; i++) {
            vector<int> tmp;
            cin>>p>>c;
            copy(v.begin()+p-1,v.begin()+p+c-1,back_inserter(tmp));
            /*for (int l = 0; l < tmp.size(); l++) {
                cout<<"tmp"<<tmp[l]<<"\n";
            }*/
            v.erase(v.begin()+p-1,v.begin()+p+c-1);
            v.insert(v.begin(),tmp.begin(),tmp.begin()+c);
            /* for (int k = 0; k < n; k++) {
                cout<<"v"<<v[k]<<"\n";
            }*/
        }

        cout<<v[0]<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <cstring>
#define maxn 1005
using namespace std;
string QAQ;
int main()
{
	int move;
	cin>>move;
	cin>>QAQ;
	for(int i=0;i<QAQ.length();i++)
	{
		if(int(QAQ[i]+move)<='Z')
		{
			QAQ[i]=char(QAQ[i]+move);	
		}
		else
		{
			QAQ[i]=char(QAQ[i]+move-26);
		}
	}
	cout<<QAQ<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    

    class Program
    {

        static int[] data;

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            data = new int[100000 + 1];

            int max = 0;

            for(int i = 0; i < input.Count(); i++)
            {
                data[input[i]]++;
                if(input[i] > max)
                {
                    max = input[i];
                }
            }

            /*
            for(int i = 0; i <= max; i++)
            {
                Console.WriteLine($"{i} : {data[i]}");
            }
            */

            int sum = 0;
            int ans = 0;
            
            for(int x = 0; x <= max; x++)
            {
                sum += data[x];

                if(x > 0)
                {
                    sum += data[x - 1];
                }

                if(x < max)
                {
                    sum += data[x + 1];
                }

                if(ans < sum)
                {
                    ans = sum;
                }
                sum = 0;
            }


            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 17376
import numpy as np

S = np.array([ord(i) for i in input()], dtype=int)
T = np.array([ord(i) for i in input()], dtype=int)
NS = len(S)
NT = len(T)
equal = np.equal.outer(S, T).astype(int)

dp = [np.zeros(NT + 1, dtype=int)]
for i in range(NS):
    x = dp[-1].copy()
    ndp = x.copy()
    ndp[1:] = np.maximum(x[:-1] + equal[i], ndp[1:])
    np.maximum.accumulate(ndp, out=ndp)
    dp.append(ndp)


ans = []
i, j = NS, NT
while i > 0 and j > 0:
    if S[i - 1] == T[j - 1]:
        ans.append(chr(S[i - 1]))
        i -= 1
        j -= 1
        continue
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    else:
        j -= 1
ans.reverse()
print("".join(ans))


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

#define ull unsigned long long
#define ll long long


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    
    sort(a.begin(), a.end());

    double x = (double)(a[0]+a[1])/2;
    for(int i=2; i<n; ++i){
        x = (x+a[i])/2;
    }

    cout << x;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <random>
#define FOR(x, to) for(x=0; x<(to); x++)
#define DUMP(ar) for(int i=0; i<ar.size(); i++) cout << "[" << i << "]:" << ar[i] << endl
#define COUT(x) cout << x << endl
#define ALL(ar) ar.begin(), ar.end()
using namespace std;

struct coord{
    int x;
    int y;
    int h;
};

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

    int n, i;
    vector<coord> p;
    cin >> n;
    p.resize(n);
    FOR(i, n)
        cin >> p[i].x >> p[i].y >> p[i].h;
    
    sort(ALL(p), [](coord c1, coord c2) -> bool { return c1.h > c2.h; });

    // COUT("---");
    
    int cx=0, cy=0, h;
    bool flag;
    FOR(cx, 101){
        FOR(cy, 101){
            flag = true;
            FOR(i, n){
                if(i==0){
                    h = p[i].h + abs(p[i].x-cx) + abs(p[i].y-cy);
                }else{
                    if(p[i].h != max(h - abs(p[i].x-cx) - abs(p[i].y-cy), 0)){
                        // if(cx == 100 && cy == 0) cout << "[out case] i:" << i << " x:" << p[i].x << " y:" << p[i].y << endl;
                        flag = false;
                        break;
                    }
                }
            }
            // if(cx == 100 && cy == 0) cout << "[h]:" << h << endl;
            if(flag) break;
        }
        if(flag) break;
    }

    cout << cx << ' ' << cy << ' ' << h << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import("fmt")

func main(){
  var s string
  fmt.Scanf("%s",&s)
  switch s{
  case "SUN": fmt.Print(7)
  case "MON": fmt.Print(6)
  case "TUE": fmt.Print(5)
  case "WED": fmt.Print(4)
  case "THU": fmt.Print(3)
  case "FRI": fmt.Print(2)
  case "SAT": fmt.Print(1)  
	} 
}

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

using namespace std;

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

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const long double PI = 3.14159265358979323846;







// ****************************************CODE***************************************//







int main(){
    _upgrade;



    int n,a,b;
    cin >> n >> a >> b;

    int tmp = n * a;
    int ans = min(tmp,b);

    cout << ans << endl;










}











Measured memory_bytes: 256
let k, s = Scanf.scanf "%d %d" (fun x y -> x, y);;
let f s = if s + 1 <= 0 then 0
                        else (s+1)*(s+2)/2;;
print_int @@ f s - 3*(f (s-(k+1))) + 3*(f (s-(k+1)*2)) - f (s-(k+1)*3);;
print_newline ();;                                                           



Measured memory_bytes: 384
local N = io.read("n")

local MOD = 1000000007
local chars = {'A', 'C', 'G', 'T'}
local tbl = {}

function tbl.lookup(n, c1, c2, c3)
    local val = tbl[tostring(n) .. c1 .. c2 .. c3]
    if not val then
        val = 0
        tbl[tostring(n) .. c1 .. c2 .. c3] = val
    end
    return val
end

function tbl.update(n, c1, c2, c3, val)
    tbl[tostring(n) .. c1 .. c2 .. c3] = val
end

tbl.update(0,'T','T','T',1)

for i=1,N do
    for k=0,63 do
        local c1 = chars[(k & 3) + 1]
        local c2 = chars[((k >> 2) & 3) + 1]
        local c3 = chars[((k >> 4) & 3) + 1]
        if tbl.lookup(i-1, c1, c2, c3) ~= 0 then
            for _,a in pairs(chars) do
                local ng_cond = a .. c1 .. c2 == 'AGC'
                            or a .. c1 .. c2 == 'ACG'
                            or a .. c1 .. c2 == 'GAC'
                            or a .. c2 .. c3 == 'AGC'
                            or a .. c1 .. c3 == 'AGC'
                if not ng_cond then
                    local old = tbl.lookup(i, a, c1, c2)
                    local origin = tbl.lookup(i-1, c1, c2, c3)
                    tbl.update(i, a, c1, c2, (old + origin) % MOD)
                end
            end
        end
    end
end

local ans = 0
for k=0,63 do
    local c1 = chars[(k & 3) + 1]
    local c2 = chars[((k >> 2) & 3) + 1]
    local c3 = chars[((k >> 4) & 3) + 1]
    ans = (ans + tbl.lookup(N, c1, c2, c3)) % MOD
end

print(ans)


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

int main () {
  int n, k; cin >> n >> k;
  
  vector<int> tree(n);
  for (int i = 0; i < n; i++) cin >> tree[i];
  sort(tree.begin(), tree.end());
  
  int ans = (1<<30);
  
  for (int i = 0; i <= n - k; i++) {
    ans = min(ans, tree[i + k - 1] - tree[i]);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new ChooseIntegers();
			Instance.Exec();
		}
	}

	public class ChooseIntegers
	{
		public void Exec()
		{
			var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
			long a = inputLongArray[0];
			long b = inputLongArray[1];
			long c = inputLongArray[2];

			long total = 0;
			for (long i = 1; i < 1000000; ++i) {
				total = a * i;

				//Console.WriteLine($"{total}");
				if (total % b == c) {
					Console.WriteLine("YES");
					Console.ReadKey();
					return;
				}
			}

			Console.WriteLine("NO");

			Console.Out.Flush();

			Console.ReadKey();
		}
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    string s; cin>>s;
    rep(i,s.size()) cout<<'x';
}


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

using namespace std;

namespace Tzh{
	
	typedef long long ll;
	const int maxn=200010;
	const ll p=1e9+7;
	int st[maxn],top,all,vis[maxn],head[maxn],cnt=1,n,fa[maxn],eid[maxn],flag,size[maxn],point[maxn],num;
	ll fac[maxn],ans; int val[maxn];

	ll qpow(ll a,ll b){ ll sum=1;
		while(b){
			if(b&1) sum=sum*a%p;
			a=a*a%p; b>>=1;
		}	
		return sum;
	}

	struct ed{
		int next,to,w,vis;
	}e[maxn<<1];

	void add(int u,int v,int w){
		e[++cnt]=(ed){head[u],v,w,0}; head[u]=cnt;
		e[++cnt]=(ed){head[v],u,w,0}; head[v]=cnt;
	}

	void dfs(int now,int f){ vis[now]=1; all++;
		for(int i=head[now];i;i=e[i].next){
			int tt=e[i].to; if(tt==f) continue;
			st[++top]=i; if(vis[tt]){
				if(flag) {top--; continue;}
				int tmp=top; int mx=0,pos=0;
				while(e[st[tmp]^1].to!=e[i].to) tmp--;
				for(int i=tmp;i<=top;i++) 
					if(e[st[i]].w>mx) mx=e[st[i]].w,pos=st[i];	
				flag=pos; top--; continue;
			} dfs(tt,now); top--; 
		}
	}

	void dfs2(int now,int f){ fa[now]=f; 
		for(int i=head[now];i;i=e[i].next){
			int tt=e[i].to; if(tt==f||e[i].vis) continue;
			point[++num]=tt; eid[num]=i; dfs2(tt,now);
		}
	}

	void dfs3(int now,int f){ size[now]=1;
		for(int i=head[now];i;i=e[i].next){
			int tt=e[i].to; if(tt==f||e[i].vis) continue;
			dfs3(tt,now); size[now]+=size[tt];
		}
		ans=ans*size[now]%p;
	}

	ll suan(int now){
		ans=1; dfs3(now,0); ans=fac[size[now]]*qpow(ans,p-2)%p;
		return ans;
	}

	ll cal(int now,int f){
		num=0; dfs2(now,0); static int st[maxn],top; top=0;
		static ll g[maxn],sz[maxn]; st[++top]=now; fa[now]=f;
		for(int i=1;i<=num;i++){int cur=point[i];
			if(fa[fa[cur]]&&fa[fa[cur]]<cur) 
			   e[eid[i]].vis=e[eid[i]^1].vis=1,st[++top]=cur;
		} ll sum=0;
		for(int i=1;i<=top;i++) g[i]=suan(st[i]),sz[i]=size[st[i]];
		for(int i=1;i<=top;i++) sum=sum+sz[i]; sum=fac[sum];
		for(int i=1;i<=top;i++) sum=sum*qpow(fac[sz[i]],p-2)%p;
		for(int i=1;i<=top;i++) sum=sum*g[i]%p;
		for(int i=1;i<=num;i++) e[eid[i]].vis=e[eid[i]^1].vis=0;
		return sum;
	}

	int ffa(int x){return fa[x]==x?x:fa[x]=ffa(fa[x]);}

	void work(){
		scanf("%lld",&n); n*=2; fac[0]=1;
		for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%p;
		static int sz[maxn],tot; static ll F[maxn]; int x,y;
		for(int i=1;i<=n;i++) fa[i]=i,val[i]=1;
		for(int i=1;i<=n;i++){
			scanf("%lld%lld",&x,&y),add(x,y+(n>>1),x+y);
			int a=x,b=y+(n>>1); 
			if(ffa(a)==ffa(b)) val[ffa(a)]--;
			else val[ffa(b)]+=val[ffa(a)]-1,fa[ffa(a)]=ffa(b);
		}
		for(int i=1;i<=n;i++) if(val[ffa(i)]!=0) {puts("0"); return ;}
		memset(fa,0,sizeof(fa));
		for(int i=1;i<=n;i++) if(!vis[i]){
			flag=0; all=0; dfs(i,0); 
			if(!flag) {puts("0"); return ;}
			e[flag].vis=e[flag^1].vis=1; 
			F[++tot]=(cal(e[flag^1].to,e[flag].to)+cal(e[flag].to,e[flag^1].to))%p;
			sz[tot]=all; 
		} ll sum=0;
		for(int i=1;i<=tot;i++) sum+=sz[i]; sum=fac[sum];
		for(int i=1;i<=tot;i++) sum=sum*qpow(fac[sz[i]],p-2)%p;
		for(int i=1;i<=tot;i++) sum=sum*F[i]%p;
		printf("%lld",sum);
		return ;
	}
}

signed main(){
	Tzh::work();
	return 0;	
}

Measured memory_bytes: 35456
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] a = new int[2][M];
        int[] c = new int[N];
        for(int i = 0; i < M; i++){
            a[0][i] = sc.nextInt();
            c[a[0][i]-1]++;
            a[1][i] = sc.nextInt();
            c[a[1][i]-1]++;
        }
        sc.close();

        for(int i = 0; i < N; i++){
            if(c[i]%2!=0){
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }
}

Measured memory_bytes: 90540
def resolve():
    MOD = 10 ** 9 + 7
    def COMinit(n, MOD):
        fact = [1, 1]
        fact_inv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fact.append((fact[-1] * i) % MOD)
            inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
            fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
        return fact, fact_inv
 
    # 二項係数計算
    def Combination(n, k, MOD=10 ** 9 + 7):
        # fac, finv = COMinit(n, MOD)
        if n < k: return 0
        if n < 0 or k < 0: return 0
        ret = fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
        return ret
 
    K = int(input())
    S = input()
    N = len(S)
 
    fac, finv = COMinit(N + K, MOD)
    v = 1
    ans = 0
    for i in range(K + 1):
        ans += Combination(N + K, i) * v
        ans %= MOD
        v *= 25
        v %= MOD
    print(ans)
    
if __name__ == "__main__":
    resolve()

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

const int N=100020;
char ans[N];
char op[N][4];
int suf[N][3];
int n,a[3]={0};

void dfs(int dep)
{
    if (dep>n) {
        puts("Yes");
        for (int i=1;i<=n;i++) {
            printf("%c\n",ans[i]);
        }
        exit(0);
    }
    int b[3]={a[0],a[1],a[2]};
    for (int i=dep;i<=n+1;i++) {
        if (i>n) dfs(i);
        int x=op[i][0]-'A';
        int y=op[i][1]-'A';
        if (a[x]==0 && a[y]==0) return;
        if (a[x]<a[y]) {
            ans[i]=x+'A';
            a[x]++;
            a[y]--;
        } else if (a[x]>a[y]) {
            ans[i]=y+'A';
            a[y]++;
            a[x]--;
        } else {
            ans[i]=x+'A';
            a[x]++;
            a[y]--;
            dfs(i+1);
            ans[i]=y+'A';
            a[x]-=2;
            a[y]+=2;
            dfs(i+1);
            a[0]=b[0];
            a[1]=b[1];
            a[2]=b[2];
            return;
        }
    }
}

int main()
{
    scanf("%d%d%d%d",&n,a,a+1,a+2);
    for (int i=1;i<=n;i++) {
        scanf("%s",op[i]);
    }
    dfs(1);
    puts("No");
    return 0;
}

Measured memory_bytes: 6992
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[3] = {};
  int b[3] = {};
  for (int i = 0; i < 3; ++i) {
    cin >> a[i] >> b[i];
  }
  bool can = false;

  int order[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
                     {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};

  for (int o = 0; o < 6; ++o) {
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 2; ++j) {
        for (int k = 0; k < 2; ++k) {
          int x[6];
          if (i == 0) {
            x[0] = a[order[o][0]];
            x[1] = b[order[o][0]];
          } else {
            x[0] = b[order[o][0]];
            x[1] = a[order[o][0]];
          }

          if (j == 0) {
            x[2] = a[order[o][1]];
            x[3] = b[order[o][1]];
          } else {
            x[2] = b[order[o][1]];
            x[3] = a[order[o][1]];
          }

          if (k == 0) {
            x[4] = a[order[o][2]];
            x[5] = b[order[o][2]];
          } else {
            x[4] = b[order[o][2]];
            x[5] = a[order[o][2]];
          }

          // int y[5];
          // for (int z = 0; z < 6; ++z) {
          //   y[x[z]] = 1;
          // }
          // bool ok = true;
          // for (int v = 1; v < 5; ++v) {
          //   if (y[v] == 0) {
          //     ok = false;
          //   }
          // }

          if (x[1] == x[2] && x[3] == x[4]) {
            can = true;
            goto BREAK;
          }
        }
      }
    }
  }

BREAK:
  if (can) {
    cout << "YES"
         << "\n";
  } else {
    cout << "NO"
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<Endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3648
class WeightedUnionFind(object):
    __slots__ = ["nodes", "weight"]

    def __init__(self, n: int) -> None:
        self.nodes = [-1]*n
        self.weight = [0]*n

    def get_root(self, x: int) -> int:
        if x < 0:
            raise ValueError("Negative Index")

        if self.nodes[x] < 0:
            return x
        else:
            root = self.get_root(self.nodes[x])
            self.weight[x] += self.weight[self.nodes[x]]
            self.nodes[x] = root
            return root

    def relate(self, smaller: int, bigger: int, diff_weight: int) -> None:
        if smaller < 0 or bigger < 0:
            raise ValueError("Negative Index")

        root_a, root_b = self.get_root(smaller), self.get_root(bigger)
        new_weight = diff_weight + self.weight[smaller] - self.weight[bigger]

        if root_a == root_b:
            # 問題によっては必要かも（情報に矛盾があるなら-1を出力など）
            if self.weight[smaller] + diff_weight == self.weight[bigger]:
                return
            raise ValueError("relateに矛盾あり")

        if self.nodes[root_a] > self.nodes[root_b]:
            root_a, root_b, new_weight = root_b, root_a, -new_weight

        self.nodes[root_a] += self.nodes[root_b]
        self.nodes[root_b] = root_a
        self.weight[root_b] = new_weight

    def diff(self, x: int, y: int) -> int:
        root_x, root_y = self.get_root(x), self.get_root(y)
        if root_x != root_y:
            return None
        return self.weight[y] - self.weight[x]


import sys
while True:
    N, M = map(int, input().split())
    if N == 0:
        break
    uf = WeightedUnionFind(N+1)
    for qtype, a, b, *c in (sys.stdin.readline().split() for _ in [0]*M):
        if qtype == "!":
            uf.relate(int(a), int(b), int(c[0]))
        else:
            diff = uf.diff(int(a), int(b))
            print(diff if diff is not None else "UNKNOWN")


Measured memory_bytes: 10800
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
    long H;
    cin >>H;
    
    long x=floor(log2(H));
  	long result=1;
  	for(int i=0;i<x+1;i++){
      result*=2;
    }
  	cout<<result-1<<endl;
             
  	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int n;
    cin >> n ;
    int ans;

    if(n<10)            ans=n;
    else if(n<100)      ans=9;
    else if(n<1000)     ans=n-90;
    else if(n<10000)    ans=909;
    else if(n<100000)   ans=n-9090;
    else                ans=90909;

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

Measured memory_bytes: 256
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include <iomanip> 
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    long long a, b;
    string s, t, u;
    while (cin >> s >> t >> a >> b >> u)
    {
        if (u == s) cout << a - 1 << " ";
        else cout << a << " ";
        if(u==t) cout << b - 1 <<'\n';
        else cout << b << '\n';
    }
}



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

int main() {
    int a, b;
    cin >> a >> b;
    int d = (a*b)%2;
  	if(d == 1){
      cout << "Odd" << endl;
    }
  	else{
      cout << "Even" << endl;
    }
}

Measured memory_bytes: 256
it = lambda: list(map(int, input().strip().split()))

def solve():
    S = input().strip()
    assert len(S) == 3
    if S[0] == S[1] == S[2] == 'R':
        return 3
    elif S[0] == S[1] == 'R' or S[1] == S[2] == 'R':
        return 2
    elif S[0] == 'R' or S[1] == 'R' or S[2] == 'R':
        return 1
    return 0

if __name__ == '__main__':
    ans = solve()
    print(ans)

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

vector<char> v;

bool contains(string a)
{
    for(int i = 0; i < a.size(); i++)
        for(int j = 0; j < v.size(); j++)
            if(a[i]==v[j]) return true;
    return false;
}

int main()
{
    int a, n;
    char k;
    cin >> a >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> k;
        v.push_back(k);
    }
    for(int i = a; ; i++)
    {
        if(!contains(to_string(i)))
        {
            cout << i;
            return 0;
        }
    }
}



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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int N, M, X;
int A[15][15];
int C[15];

int solve(vector<int> work){
    vector<int> res(M, 0);
    int cost = 0;
    rep(i, work.size()){
        if(work[i]){
            cost += C[i];
            rep(j, M){
                res[j] += A[i][j];
            }
        }
    }
    bool ok = true;
    rep(i, M) if(res[i] < X) ok = false;
    if(ok) return cost;
    else return mod;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M >> X;
    rep(i, N){
        cin >> C[i];
        rep(j, M){
            cin >> A[i][j];
        }
    }
    int loop = (1 << N);
    int ans = mod;
    rep(i, loop){
        int val = i;
        vector<int> work;
        rep(j, N){
            work.push_back(val % 2);
            val /= 2;
        }
        ans = min(ans, solve(work));
    }
    if(ans != mod) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3664
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

A, B = l_inpl()

if A >= 13:
    print(B)
elif A >= 6:
    print(B//2)
else:
    print(0)

Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
	
int main(){
	init();
	ll N;cin>>N;
	vector<ll>A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	vector<bool>dp(10006,false);
	dp[0]=true;
	for(int i=0;i<N;i++){
		for(int j=10005;j>=0;j--){
			if(j-A[i]>=0){
				if(dp[j-A[i]])dp[j]=true;
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<10006;i++){
		if(i%10==0)continue;
		if(dp[i])ans=max(ans,i);
	}
	cout<<ans<<endl;
}


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

void f(vector<int> v) {
  for (int i = 0; i < v.size(); i++) {
    if (i == v.size() - 1)
    cout << v.at(i) << endl;
    else
    cout << v.at(i) << " ";
  }
}

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    v.at(i) = i + 1;
  }
  do {
    f(v);
  } while (next_permutation(v.begin(), v.end()));
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n,m,x,temp;
    bool flag=false;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep0(i,m){
        cin >> a[i];
        if(x<a[i]){
            temp=i;
            break;
        }
    }
    int q=0,w=0;
    rep0(i,temp)
        q++;
    rep0(i,m-temp)
        w++;
    cout << min(q,w) << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) > "Yes" : "No" ) << endl


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

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int h, w, j;
	cin >> h >> w;

	vector<vector<char>> box;
	box.resize(h);
	REP(i, h) {
		box[i].resize(w);
	}

	REP(i, h) {
		REP(j, w) {
			cin >> box[i][j];
		}
	}

	REP(i, h) {
		for (j = 0; j < w; j++) {
			if (box[i][j] != '.') {
				break;
			}
		}
		if (j == w) {
			box.erase(box.begin() + i);
			i--; h--;
		}
	}

	REP(i, w) {
		for (j = 0; j < h; j++) {
			if (box[j][i] != '.') break;
		}
		if (j == h) {
			REP(k, h) {
				box[k].erase(box[k].begin() + i);
			}
			i--; w--;
		}
	}

	REP(i, h) {
		REP(j, w) {
			cout << box[i][j];
		}
		cout << endl;
	}

	return;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 2e5+7;

LL a[MAXN], b[MAXN];

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

    LL n, m, k;
    cin >> n >> m >> k;

    for (LL i = 1; i <= n; i++) cin >> a[i];

    LL bsum = 0;
    for (LL j = 1; j <= m; j++) {
        cin >> b[j];
        bsum += b[j];
    }

    LL ans = 0;
    LL asum = 0;
    for (LL j = m, i = 0; j >= 0; j--) {
        bsum -= b[j+1];
        if (bsum > k) continue;
        while (i < n && bsum+asum+a[i+1] <= k) {
            asum += a[i+1];
            i++;
        }
//        cout << j << " -> " << i << endl;
//        cout << bsum << " => " << asum << endl;
        ans = max(ans, i+j);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6764
#include<stdio.h>
int main(void)
{
	double m,n;
	int cnt[4]={0},cnt1[4]={0},i;
	while (scanf("%lf %lf",&m,&n)!=EOF){
		if(m>=1.1) cnt[0]++;
		else if(m>=0.6) cnt[1]++;
		else if(m>=0.2) cnt[2]++;
		else cnt[3]++;
		if(n>=1.1) cnt1[0]++;
		else if(n>=0.6) cnt1[1]++;
		else if(n>=0.2) cnt1[2]++;
		else cnt1[3]++;
	}
	for(i=0;i<=3;i++) printf("%d %d\n",cnt[i],cnt1[i]);
	return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int x, a, b; cin >> x >> a >> b;
    if(abs(x-a)> abs(x-b)) cout << 'B' << endl;
    else cout << 'A' << endl;
}

Measured memory_bytes: 256
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A = sorted(A)
C = sorted(C)
ans = 0
for i in range(N):
    a = bisect.bisect_left(A, B[i])
    c = bisect.bisect_right(C, B[i])
    ans += a*(N-c)
print(ans)
    
    


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

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>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(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()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,k;
    cin >> n >> k;

    vll h(n);
    rep(i,n)cin >> h[i];

    vll dp(n,0);
    
    if(k + 1 >= n){
        cout << abs(h[0] - h[n-1]) << endl;
        return 0;
    }
    else REP(i,1,k + 1)dp[i] = abs(h[0] - h[i]);



    REP(i,k+1,n){
        ll tmp,min=M;
        REP(j,1,k+1){
            tmp = dp[i-j] + abs(h[i] - h[i-j]);

            if(min >= tmp)min = tmp;
        }
        dp[i] = min;
    }

    cout << dp[n-1] << endl;

    /*cout << endl;
    rep(i,n)cout << dp[i] << " ";
    cout << endl;
*/
    return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3

# 親の頂点和を遷移させていく感じ

from collections import deque

N, Q = [int(s) for s in input().split()]
edge = [[int(s) - 1 for s in input().split()] for _ in range(N-1)]

v_value = [0]*N

for _ in range(Q):
    p, x = [int(s) for s in input().split()]
    v_value[p - 1] += x
    
tree = [[] for _ in range(N)]

for i, j in edge:
    tree[i].append(j)
    tree[j].append(i)

## bfs
dq = deque([0])
visited = [False]*N

while dq:
    v_parent = dq.pop()
    for v_child in tree[v_parent]:
        if not visited[v_child]:
            dq.appendleft(v_child)
            v_value[v_child] += v_value[v_parent]
    visited[v_parent] = True

for v in v_value:
    print(v, end=' ')

Measured memory_bytes: 76672
#include <cstdio>

int main(){
	int n,h[20],ans;

	ans=1;

	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&h[i]);
	}

	for(int i=1;i<n;i++){
		for(int k=0;k<i;k++){
			//printf("[%d,%d]%d-%d\n",i,k,h[i],h[k]);
			if(h[i]<h[k]){
				//printf("no\n");
				break;
			}
			if(i==k+1){
				//printf("+\n");
				ans++;
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
def gen_primes(N):
    from itertools import compress
    sieve = list(range(N))
    sieve[1] = 0
    for i in range(2, int(N**.5) + 1):
        sieve[i * 2::i] = [0] * len(sieve[i * 2::i])
    return list(compress(range(N), sieve))

N = int(input())
cnt = 0
ans = []
for p in gen_primes(55555):
    if p % 5 == 1:
        ans += [p]
        cnt += 1
        if cnt == N:
            break
print(*ans)

Measured memory_bytes: 5656
#include <cstdio>
#include <cstring>
int main(){
	char s[105];
	int a[26]={0};
	scanf("%s",s);
	if(strlen(s)%2==1){
		printf("No\n");
		return 0;
	}
	else {
		for(int i=0;i<strlen(s);i++){
				a[s[i]-'a']++;
		}
		for(int i=0;i<26;i++){
			if(a[i]%2==0)continue;
			else {
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}
}


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

vector<int> rui={1,3,9,27,81,243,729,2187,6561,19683,59049,
                 177147,531441,1594323,4782969,14348907
                };

int main(){
  while(1){
    int n,m;
    cin>>n>>m;
    if(n==0&&m==0) break;
    
    int bit=0;
    rep(i,3){
      int x;
      cin>>x;
      rep(j,x){
        int y;
        cin>>y;
        y--;
        bit+=rui[y]*i;
      }
    }
    vector<int> seen(14348907,-1);
    seen[bit]=0;
    queue<int> que;
    que.push(bit);
    
    while(!que.empty()&&seen[0]==-1&&seen[rui[n]-1]==-1){
      int x=que.front();
      que.pop();
      
      vector<set<int>> ue(3);   
      rep(i,3) ue[i].insert(-1);
      int cx=x;
      rep(i,n){
        ue[cx%3].insert(i);
        cx/=3;
      }
      
      int a=*ue[0].rbegin();
      int b=*ue[1].rbegin();
      int c=*ue[2].rbegin();

      if(a>b){
        if(seen[x+rui[a]]==-1){
          que.push(x+rui[a]);
          seen[x+rui[a]]=seen[x]+1;
          ue[0].erase(a);
          ue[1].insert(a);
        }
      }
      if(a<b){
        if(seen[x-rui[b]]==-1){
          que.push(x-rui[b]);
          seen[x-rui[b]]=seen[x]+1;
          ue[1].erase(b);
          ue[0].insert(b);
        }
      }
      if(b>c){
        if(seen[x+rui[b]]==-1){
          que.push(x+rui[b]);
          seen[x+rui[b]]=seen[x]+1;
          ue[1].erase(b);
          ue[2].insert(b);
        }
      }
      if(b<c){
        if(seen[x-rui[c]]==-1){
          que.push(x-rui[c]);
          seen[x-rui[c]]=seen[x]+1;
          ue[2].erase(c);
          ue[1].insert(c);
        }
      }
    }
    if(seen[0]!=-1){
      if(seen[0]<=m) cout<<seen[0]<<endl;
      else cout<<-1<<endl;
    }
    else if(seen[rui[n]-1]!=-1){
      if(seen[rui[n]-1]<=m) cout<<seen[rui[n]-1]<<endl;
      else cout<<-1<<endl;
    }
    else cout<<-1<<endl;
  }
}



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

int xyh[100][3], t = 0;

int height(int cx, int cy)
{
    int ch = xyh[0][2] + abs(xyh[0][0] - cx) + abs(xyh[0][1] - cy);
    for(int i = 1; i < t; i++){
        if(xyh[i][2] != ch - abs(xyh[i][0] - cx) - abs(xyh[i][1] - cy)){
            return 0;
        }
    }
    return ch;
}

int main()
{
    int n, x, y, h;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x >> y >> h;
        if(h != 0){
            xyh[t][0] = x;
            xyh[t][1] = y;
            xyh[t][2] = h;
            t += 1;
        }
    }
    if(t == 1){
        cout << xyh[0][0] << ' ' << xyh[0][1] << ' ' << xyh[0][2] << endl;
        return 0;
    }
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            int ch = height(i, j);
            if(ch != 0){
                cout << i << ' ' << j << ' ' << ch << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
n=int(input())
numbers=input().split()
nums=list(map(int,numbers))
#print(nums)
mx=0
for num in nums:
    if num>mx:
        mx=num
#print(mx)
j=0
ans=0
while 2**j<=mx:
    sm=0
    for num in nums:
        sm+= num>>j &1
    ans+=(sm)*(n-sm)*2**j
    j=j+1
#print(ans)
print(ans%1000000007)

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

using namespace std;

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


typedef long long ll;


int lp;
int lpcnt = 0;


string str;

bool input(){

  if(lpcnt==0)cin>>lp;

  if(lpcnt==lp)return false;
  cin>>str;

  lpcnt++;
  return true;
}


class S{
public:
  bool isnum;
  bool isc;
  char c;
  int num;
  S(bool isnum, bool isc, char c, int num):isnum(isnum),isc(isc),c(c),num(num){}
  S(){isnum=isc=false; c='#'; num=0;}
  void print(){
    printf("%d %d %d %c\n",isnum,isc,num,c);
  }
};

typedef pair<int,string> pis;
typedef pair<char,string> pcs;

bool isnum(char c){
  return '0'<=c && c<='9';
}

int ctonum(char c){
  return c-'0';
}

pis getHeadNum(string str){

  pis ret = pis(0,"");
  int st = 0;
  while(str.size()!=st && isnum(str[st])){
    ret.first *= 10;
    ret.first += ctonum(str[st]);
    st++;
  }

  ret.second = str.substr(st);
  return ret;
}

pcs getHeadChar(string str){
  return pcs(str[0], str.substr(1));
}

bool iscalc(char c){
  if(c=='*' || c=='+' || c=='-' || c=='/')return true;
  return false;
}


vector<S> getEq(string str){
  vector<S> eq;
  string sc = str;
  eq.clear();

  while(sc.size()!=0){
    int hu = 1;
    S add;
    if(sc[0]=='-' && ((eq.size()!=0 && iscalc(eq[eq.size()-1].c))||eq.size()==0)){
      hu = -1;
      sc = sc.substr(1);
    }
    if(isnum(sc[0])){
      add.isnum = true;
      pis res = getHeadNum(sc);
      add.num = hu*res.first;
      sc = res.second;
    }else{
      add.isc = true;
      pcs res = getHeadChar(sc);
      add.c = res.first;
      sc = res.second;
    }
    eq.push_back(add);
  }
  return eq;
}

int calc(int st, int en, vector<S>& eq){
  
  
  /*
  for(int i=st;i<en;i++){
    eq[i].print();
  }puts("");
  */



  if(st>=en){
    printf("%d %d\n",st,en);
    assert(0);
  }

  int num = eq[st].num;
  if(st+1==en)return num;
  int a=0;

  for(int i=en-1;i>=st;i--){

    if(eq[i].c=='(')a++;
    if(eq[i].c==')')a--;


    if(a==0){
      if(eq[i].c=='-'){
	return calc(st, i, eq) - calc(i+1, en, eq);
      }
      if(eq[i].c=='+'){
	return calc(st, i, eq) + calc(i+1, en, eq);
      }
    }

  }

  a=0;

  for(int i=en-1;i>=st;i--){

    if(eq[i].c=='(')a++;
    if(eq[i].c==')')a--;
    if(a==0){
      if(eq[i].c=='*'){
	return calc(st, i, eq) * calc(i+1, en, eq);
      }
      if(eq[i].c=='/'){
	return calc(st, i, eq) / calc(i+1, en, eq);
      }
    }

  }

  if(eq[st].c=='('){
    return calc(st+1, en-1, eq);
  }
  puts("AAA");
  assert(0);
  return -1;
  
}
int solve(){
  vector<S> eq = getEq(str);
  return calc(0,eq.size()-1, eq);
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1220
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

typedef unsigned long long ull;

//return 1??????a?????§???????????°
ull len(ull a) {
	//cout << "len " << a << endl;
	//ret = Fizz Buzz??????????????°
	ull ret = (a / 3 + a / 5) * 4;

	// [ 10^n -1 , 10^(n+1) -1 ) n=1,2,...,18
	// [0,9),[9,99),... ??¨???????????????????????°????¨????
	int l = 0; //?????°
	for (ull pow = 1; a >= pow; pow *= 10) {
		l++;
		ull L = pow - 1,
			R = min(a, pow * 10 - 2);
		//cout << " pow " << pow << " L " << L << " R " << R << endl;

		//ret += Fizz Buzz?????????????????????????????°
		ret += ((R - R / 3 - R / 5 + R / 15) - (L - L / 3 - L / 5 + L / 15))*l;
	}
	//cout << " return " << ret << endl;
	return ret;
}

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

	//????????¢?´¢
	//???????????¶ L+1 == R == t????§????????????°
	ull L = 0,
		R = 100000000000000000;
	while (L + 1 < R) {
		//cout << "L " << L << " R " << R << endl;
		ull M = (L + R) / 2;
		if (len(M) >= s)
			R = M;
		else 
			L = M;
	}

	//L: R-1
	//R: t????§????????????°
	//cout << "L " << L << " R " << R << endl;

	string t = "";
	for (int i = 1; i < 20; i++) {
		if ((L + i) % 15 == 0)
			t += "FizzBuzz";
		else if ((L + i) % 3 == 0)
			t += "Fizz";
		else if ((L + i) % 5 == 0)
			t += "Buzz";
		else 
			t += to_string(L + i);
	}
	//????????°-(t????§????????????°-1)?????§???????????°-1
	//s=4; 4-len(2)-1 == (Fizz???F)
	int beg = s - len(L) - 1;
	cout << t.substr(beg, 20) << endl;

	return 0;
}

Measured memory_bytes: 3284
R,G,B,n=map(int,input().split())
r=n//R
g=n//G
b=n//B
ans=0
for i in range(r+1):
  for j in range((n-R*i)//G+1):
    if (n-i*R-j*G)%B==0:
      ans+=1
print(ans)

Measured memory_bytes: 9028
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

S = list(input())

p = 0
g = 0
w = 0
for s in S:
    # 出せるのならpを出す
    t = 'p' if p < g else 'g'
    p += 1 if t == 'p' else 0
    g += 1 if t == 'g' else 0
    # あいこでない
    if s != t:
        # 負け確
        if s == 'p':
            w -= 1
        # 勝ち確
        elif s == 'g':
            w += 1

print(w)


Measured memory_bytes: 3956
A, B, C, D = map(int, input().split())
CC = B // C - A // C + (A % C == 0)
DD = B // D - A // D + (A % D == 0)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
E = lcm(C, D)
EE = B // E - A // E + (A % E == 0)
print(B - A + 1 - CC - DD + EE)

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

int main(){
    int N;
    cin >> N;
    
    int sum = 0;
    set<int> ans;
    for(int i = 1; i <= N; i++){
        sum += i;
        ans.insert(i);
        if(N <= sum)break;
    }
    
    int dis = sum - N;
    if(0 < dis)ans.erase(dis);
    for(auto v : ans){
        cout << v << endl;
    }
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	if(n%m==0)
        cout<<n/m;
    else
        cout<<n/m+1;
}


Measured memory_bytes: 256