akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		String[] t = saori.nextHayami().split("");
		String str1 = Arrays.stream(s)
			.sorted()
			.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
			.toString();
		String str2 = Arrays.stream(t)
			.sorted(Collections.reverseOrder())
			.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
    		.toString();
		if(str1.compareTo(str2) < 0){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 27988
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long A1,A2,V1,V2,count,sw = 0;
  cin >> A1 >> V1 >> A2 >> V2 >> count;
  long long dist = A2 - A1;
  if(dist < 0){
    sw = 1;
  }
  long long step = V1 - V2;
  froop1(0,count){
    if(sw == 1){
      dist += step;
    }else{
   dist -= step;
    }
  }
  if(sw == 0){
  if(dist <= 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  }else{
      if(dist >= 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  }
return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int maxarray(int* a,int s){
    int b = 0;
    rep(i,s)if(a[i]>b)b=a[i];
    return b;
}
int main(void){
    int n,mw;
    cin >> n >> mw;
    int dp[mw+1];
    rep(i,mw+1)dp[i]=0;
    rep(i,n){
        int v,w;
        cin >> v >> w;
        for(int j = mw;j >= 0;j--)if((j == 0||dp[j]!=0)&&w+j<=mw&&dp[w+j]<dp[j]+v)dp[w+j]=dp[j]+v;
    }
    cout << maxarray(dp,mw+1) << endl;
    return 0;
}


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

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

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

const int MAX = 2 * 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

struct Combination{
    vector<long long> fac, finv, inv;
    
    Combination(int n=1001001):fac(n+1), finv(n+1), inv(n+1) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i <= n; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    long long operator()(int n, int k) const {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

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

    Combination com(N);

    ll ans = 0;
    rep(i, min(K + 1, N)) {
        int m = N - i;
        ans += com(N, i) * com(N-1, m-1) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}

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

int main() {
    double R;
    cin >> R;
    cout << 2 * R * 3.14159265358979323846264338327950288 << endl;
    return 0;
}


Measured memory_bytes: 3784
n=int(input())
l=list(map(int,input().split()))
k=[]
for i in range(1,n+1):
    k.append(i)

c=0
for i in range(n):
    if k[i]!=l[i]:
        c+=1

if c==0 or c==2:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main(){
  int A, B;
  cin >> A >> B;
  if(B==1){
    printf("0\n");
  }else if(A >= B){
    printf("1\n");
  }
  else{
    if((B-A)%(A-1)==0){
      printf("%d\n", 1 + (B-A)/(A-1));
    }else{
      printf("%d\n", 2 + (B-A)/(A-1));
    }
 
  }
}

Measured memory_bytes: 3760
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * 0007:Debt Hell
 * 
 * @author MS14A
 * @version 2015/04/09
 */
public class Main {

    /** 初期借金額：10万円 */
    private static final BigDecimal INITIAL_DEBT = new BigDecimal("100000");

    /** 利子：5% */
    private static final BigDecimal INTEREST_RATE = BigDecimal.valueOf(0.05);

    /** 繰り上げ計算用 */
    private static final BigDecimal DIVISOR = BigDecimal.valueOf(1000);

    /**
     * 某国に住んでいる友達がお金に困って、あるヤミ金融業者から 10 万円の借金をしたまま、<br>
     * 全く返済していないといいます。<br>
     * この業者は、一週間ごとに 5% の利子を借金に加え、さらに借金の 1,000 円未満を切り上げます。<br>
     * n を入力したとき、n 週間後の借金の残高を出力し終了するプログラムを作成して下さい。<br>
     * n は 100 以下とします。
     * 
     * @param args
     */
    public static void main(String[] args) {
        // 標準入力読み取り
        int weeks = getWeeks();

        // n週間後の借金額計算
        calcDebt(weeks);
    }

    /**
     * 標準入力を読み取り、"n"の値を返す。
     * 
     * @return n：入力値
     */
    private static int getWeeks() {
        Scanner scanned = new Scanner(System.in);
        return scanned.nextInt();
    }

    /**
     * n週間後の借金額を計算する。
     * 
     * @param weeks
     */
    private static void calcDebt(int weeks) {
        BigDecimal finalDebt = INITIAL_DEBT;

        for (int i = 0; i < weeks; i++) {
            // 利子額計算。1000で割った小数部を繰り上げる。
            BigDecimal interestAmount = finalDebt.multiply(INTEREST_RATE)
                    .divide(DIVISOR, 0, BigDecimal.ROUND_UP);

            // 借金額 = 前週の借金額 + 利子額
            finalDebt = finalDebt.add(interestAmount.multiply(DIVISOR));
        }

        System.out.println(finalDebt);
    }

}

Measured memory_bytes: 17236
#include <bits/stdc++.h>
using namespace std;
const int num = 100001;
vector <int> adj[num];
int vis[num],level[num];
void dfs(int cur)
{
	vis[cur] = 1;
	for(int i=0;i<adj[cur].size();i++)
	{
		int child = adj[cur][i];
		if(!vis[child])
		{
			dfs(child);
		}
	}
	for(int i=0;i<adj[cur].size();i++)
	{
		int child = adj[cur][i];
		level[cur] = max(level[cur],1+level[child]);
	}
}
int main()
{
	int n,m,x,y;
	cin >> n >> m;
	for(int i=0;i<m;i++)
		cin >> x >> y,adj[x].push_back(y);
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
			dfs(i);
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
		ans = max(ans,level[i]);
	cout << ans << "\n";
}
	


Measured memory_bytes: 11664
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=10010;
int pre[maxn], nxt[maxn], to[maxn], A[maxn], tot=1;
bool vis[maxn],res[maxn];
vector<int>ans;
bool dfs(int x){
	if(vis[x])return res[x];
	vis[x]=1;
	bool flag=false;
	for(int t=pre[x];t;t=nxt[t])if(A[to[t]]<A[x]){
		if(!dfs(to[t])){
			flag=true;
			break;
		}
	}
	if(flag)ans.push_back(x);
	return res[x]=flag;
}
int main(){
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%d",A+i);
	for(int i=1;i< N;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		to[tot]=v, nxt[tot]=pre[u], pre[u]=tot++;
		to[tot]=u, nxt[tot]=pre[v], pre[v]=tot++;
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=N;i++)dfs(i);
	sort(ans.begin(), ans.end());
	if(ans.empty())puts(""); else{
		for(int i=0; i<ans.size()-1; i++)printf("%d ", ans[i]);
		printf("%d\n", ans[ans.size()-1]);
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.contains("RRR")) {
			System.out.println(3);
		}
		else if(s.contains("RR")) {
			System.out.println(2);
		}
		else if(s.contains("R")) {
			System.out.println(1);
		}
		else
		System.out.println(0);

	}
}



Measured memory_bytes: 35564
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		sc.close();
		
		int x3 = x2 - (y2 - y1);
		int y3 = y2 + (x2 - x1);
		int x4 = x1 - (y2 - y1);
		int y4 = y1 + (x2 - x1);
		
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
	}
}

Measured memory_bytes: 23124
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define speed                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define oprecision                                                             \
  cout.precision(30);                                                          \
  cerr.precision(7);
#define int long long
using namespace std;
int n, W, wt[500005], val[500005];
int knapSack(int W, int wt[], int val[], int n) {
  int i, w;
  int K[n + 1][W + 1];
  for (i = 0; i <= n; i++) {
    for (w = 0; w <= W; w++) {
      if (i == 0 || w == 0)
        K[i][w] = 0;
      else if (wt[i - 1] <= w)
        K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
      else
        K[i][w] = K[i - 1][w];
    }
  }
  return K[n][W];
}
main() {
  speed;
  oprecision;
  /*#ifndef ONLINE_JUDGE
freopen("outd.txt", "rt", stdin);
#endif*/
  // code
  cin >> n >> W;
  for (int i = 0; i < n; i++) {
    cin >> wt[i] >> val[i];
  }
  cout << knapSack(W, wt, val, n);
// endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 81280
# coding: utf-8
# Your code here!

N,H=[int(i) for i in input().split()]

a = [0 for i in range(N)]
b = [0 for i in range(N)]
ll = []
for i in range(N):
    x,y=([int(i) for i in input().split()])
    ll.append([x,y])
    a[i] = x
    b[i] = y
amax = max(a)
bmax = max(b)

lll=sorted(ll,key=lambda x: x[1])


amaxind = [i for i in range(N) if lll[i][0] == amax]
#print(amaxind)
#print(lll)
c=0
while H > 0:
    if len(lll) > 0 and lll[-1][1] > amax:
        X = lll.pop()
        H -= X[1]
        c +=1
      #  print(H,c)
    else:
        num = (H-1)//amax
        H = -1
        c += num+1
    #    print(H,c)
print(c)                

            
    
    





Measured memory_bytes: 26528
def inserrtionsort(l,n):
  for i in range(1,n):
    print(" ".join(l))
    v=l[i]
    j=i-1
    while int(v)<int(l[j]) and j>=0:
      l[j+1]=l[j]
      j-=1
    l[j+1]=v
  print(" ".join(l))
m=int(input())
n=list(input().split())
inserrtionsort(n,m)


Measured memory_bytes: 5600
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
map<ll,ll> mp;
for(ll i = 1; i < 101; i++){
    for(ll j = 1; j < 101; j++){
        for(ll k = 1; k < 101; k++){
            mp[(i + j + k) * (i + j + k) - (i * j + j * k + k * i)]++;
        }
    }
}
for(ll i = 1; i <= n; i++){
    cout << mp[i] << endl;
}
}

Measured memory_bytes: 5996
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long ;

int main() {
  int n;
  cin >> n;
  int mn,cnt=0;
  for(int i=0;i<n;i++){
    int num;
    cin >> num;
    if( mn >= num || i == 0){
      cnt++;
      mn = num;
    }
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    cout << s[0] << s.length()-2 << s[s.length()-1] << endl;
}


Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple

string s, t, temp;
int n;
bool flag ;


bool match(int k){

    rep(i, 0, n){

        if(k>n)k=0;
        if(s[i]==t[k]){k++;continue;}
        else return false;

    }
return true;

}

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

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



cin >>  s >> t;

n = s.size()-1;



    rep(j, 0, n){

    temp = t.substr(j,(n-j+1)) + t.substr(0, j);
        flag = true;
        rep(i, 0, n){
        if(s[i]==temp[i])continue;
        else flag = false;
        }

    if(flag){
        cout << "Yes"<<endl;
        return 0;
    }

    }



cout << "No" << endl; ;





return 0;}
///.... Maria Otonashi


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int E;
int solve(int E);

int solve(int E) {
  int x,y,z;
  int min = E;
  for (z=0;z*z*z<=E;z++) {
    for (y=0;y*y<=E-z*z*z;y++) {
      x = E-z*z*z-y*y;
      if (x>=0 && x+y+z<min) {
	min = x+y+z;
      }
    }
  }
  return min;
}
int main() {
  while (cin >> E && E>0) {
    cout << solve(E) << endl;
  }
}

Measured memory_bytes: 1160
use proconio::input;

fn main() {
    input!(n: usize);
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for _ in 0..n {
        input!(s: String);
        match &*s {
            "AC" => ac += 1,
            "WA" => wa += 1,
            "TLE" => tle += 1,
            "RE" => re += 1,
            _ => (),
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


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

  
int main(){
 ll n,k;
  cin >> n>> k;
  vector<ll> h(n);
  rep(i,n) cin >> h.at(i);
  ll sum=0;
  sort(h.begin(),h.end());
  rep(i,n-k){
    sum+=h.at(i);
  }
  cout << sum <<endl;
  
 
}
  
  

Measured memory_bytes: 1792
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

S = int(input())
ans = 0
mod = 10 ** 9 + 7
for i in range(1,700):
    x = S - 3 * i
    if x < 0:
        break
    ans += (combinations_count(x + i - 1, i - 1)) % mod
    ans %= mod
print(ans)


Measured memory_bytes: 73264
from copy import deepcopy

d=int(input())
c=list(map(int,input().split())) #scoreを減らす
s=[] #scoreを増やす
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)
last=[0]*26 #それぞれのコンテストが最後に行われたのは何日目か
ans_lst=[]

for i in range(1,d): #364日、1日目ならi=1
    temp_best=-100000000
    for j in range(26): #それぞれの日において、26個のコンテストを順番にピックアップ
        temp=s[i-1][j]
        for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
            if j!=k:
                temp-=(c[k]*(i-last[k]))
        temp_last=deepcopy(last)
        temp_last[j]=i
        for k in range(26):
            temp+=s[i][k]
            for l in range(26):
                if k!=l:
                    temp-=(c[l]*(i+1-temp_last[l]))
        if temp>temp_best:
            temp_best=temp
            rem=j
    ans_lst.append(rem)
    last[rem]=i
    
temp_best=-100000000 #365日目は、次の日のことは考えなくてよい
for j in range(26): #26個のコンテストを順番にピックアップ
    temp=s[i-1][j]
    for k in range(26): #ピックアップされていないコンテストは、スコアを減らす
        if j!=k:
            temp-=(c[k]*(i-last[k]))
    if temp>temp_best:
        temp_best=temp
        rem=j
ans_lst.append(rem) #AtCoder運営お疲れ様です

score=0
las=[0]*26
for i in range(d):
    for j in range(26):
        las[j]+=1
    score+=s[i][ans_lst[i]]
    las[ans_lst[i]]=0
    for j in range(26):
        score-=c[j]*las[j]

for p in range(d-1):
    las=[0]*26
    temp_score=0
    temp_ans_lst=deepcopy(ans_lst)
    temp_ans_lst[p],temp_ans_lst[p+1]=temp_ans_lst[p+1],temp_ans_lst[p]
    for i in range(d):
        for j in range(26):
            las[j]+=1
        temp_score+=s[i][temp_ans_lst[i]]
        las[temp_ans_lst[i]]=0
        for j in range(26):
            temp_score-=c[j]*las[j]
    if temp_score>score:
        score=temp_score
        ans_lst=temp_ans_lst

for i in ans_lst:
    print(i+1)

Measured memory_bytes: 77236
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int dp[101][(1 << 15)];
int sm[(1 << 15)];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0){
            break;
        }
        vector<int> s(n),d(m);
        rep(i,n){
            cin >> s[i];
        }
        rep(i,m){
            cin >> d[i];
        }
        sort(all(d));
        rep(i,m+1){
            rep(j,(1<<n)){
                dp[i][j] = INF;
            }
        }
        sm[0] = 0;
        srep(i,1,(1 << n)){
            rep(j,n){
                if(i & (1 << j)){
                    sm[i] = sm[i^(1<<j)]+s[j];
                }
            }
        }
        rep(i,(1<<n)){
            dp[0][i] = 0;
        }
        rep(i,m){
            rep(j,(1 << n)){
                cmn(dp[i+1][j],dp[i][j]+abs(d[i]-sm[j]));
                rep(k,n){
                    if(j & (1 << k)){
                        cmn(dp[i+1][j],dp[i+1][j^(1<<k)]);
                    }
                }
            }
        }
        cout << dp[m][(1<<n)-1] << "\n";
    }
    return 0;
}

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


int main()
{
	
	char S[10];
	int i, j;
	int c = 0;
	scanf("%s", S);
	for (i = 0;i < 4;i++)
	{
		for (j = i + 1;j < 4;j++)
		{
			if (S[i] == S[j])c++;
		}
	}
	if(c==2)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
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
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll X;
    cin >> X;
    if(X>=400 && X<=599){
        cout << 8 << endl;
    }
    else if(X>=600 && X<=799){
        cout << 7 << endl;
    }
    else if(X>=800 && X<=999){
        cout << 6 << endl;
    }
    else if(X>=1000 && X<=1199){
        cout << 5 << endl;
    }
    else if(X>=1200 && X<=1399){
        cout << 4 << endl;
    }
    else if(X>=1400 && X<=1599){
        cout << 3 << endl;
    }
    else if(X>=1600 && X<=1799){
        cout << 2 << endl;
    }
    else if(X>=1800 && X<=1999){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3652
K = int(input())

N0 = K % 50
A = K//50+49
a = [0] * 50

for i in range(0,50-N0):
    a[i] = A - N0
for i in range(50-N0,50):
    a[i] = A - N0 + 51

print(50)
print(" ".join(list(map(str,a))))

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

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

int N, K;

int main(void){
    cin >> N >> K;
    
    ll ans = 0;
    for(int b=1;b<=N;b++){
        int p = N / b;
        int q = N % b;
        ans += p * max(0, b-K);
        ans += max(0, q-K+1);
    }
    
    if(K == 0)  ans -= N;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn  main() {

    let n = read::<i32>();
    let mut an:Vec<i32> = Vec::new();
    an.push(0);
    // for _ in 0..n {
    //     an.push(read::<i32>());
    // }
    let mut sub= read_vec::<i32>();
     an.append(&mut sub);
    an.push(0);
    let mut costmas = 0;
    // let mut ans = Vec::new();
    for i in 1..n+2{
            let cost  = (an[i as usize-1] - an[i as usize]).abs();
            
            costmas += cost;
    }
   
    for i in 1..n+1 {
        let sub = (an[i  as usize-1] - an[i  as usize] ).abs();
        let div1 = (an[i as usize] - an[i as usize + 1]).abs();
        let div2 = (an[i as usize-1] - an[i as usize + 1]).abs();
        println!("{}",costmas-sub - div1+ div2);
    }

}

Measured memory_bytes: 7036
#include <string>
using std::string;

#include <iostream>
using std::cout;
using std::cin;

int main(){
    string num;

    cin >> num;

    for(int i = 0; i < 3; ++i){
        if(num[i]==num[i+1]){
            cout << "Bad";
            return 0;
        }
    }

    cout << "Good";
  	return 0;
}

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

int N;
vector<P> XD;
vector<int> X, D;
int rit[200100];
int dp[200100];

struct segtree {
    int size;
    vector<int> node;
    
    segtree(int n) {
        size = 1;
        while (size<n) size *= 2;
        node.resize(2*size-1);
        fill(node.begin(), node.end(), -1000000000);
    }

    void update(int k, int a) {
        k += size-1;
        node[k] = a;
        while (k>0) {
            k = (k-1)/2;
            node[k] = max(node[2*k+1], node[2*k+2]);
        }
    }
    
    int query(int a, int b, int k, int l, int r) {
        if (r<=a || b<=l) return -1000000000;
        if (a<=l && r<=b) return node[k];
        else {
            int vl = query(a, b, 2*k+1, l, (l+r)/2);
            int vr = query(a, b, 2*k+2, (l+r)/2, r);
            return max(vl, vr);
        }
    }
    
    int get(int a, int b) {
        return query(a, b, 0, 0, size);
    }
};

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) {
        int Xi, Di; cin >> Xi >> Di;
        XD.pb(P(Xi, Di));
    }
    sort(XD.begin(), XD.end());
    rep(i, N) X.pb(XD[i].first);
    rep(i, N) D.pb(XD[i].second);
    
    segtree st(N);
    rep(i, N) {
        rit[i] = lower_bound(X.begin(), X.end(), X[i]+D[i])-X.begin();
        st.update(i, rit[i]);
    }
    dp[N] = 1;
    for (int i=N-1; i>=0; i--) {
        rit[i] = st.get(i, rit[i]);
        st.update(i, rit[i]);
        dp[i] = (dp[i+1]+dp[rit[i]])%MOD;
    }
    cout << dp[0] << endl;
}

Measured memory_bytes: 17004
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll mn = min({a,b,c,d,e});
  ll ans = (n+mn-1)/mn + 4;
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}



int main()
{
    int n,aoki,takahashi;
    cin>>n>>takahashi>>aoki;
    aoki--,takahashi--;
    vector<vector<int>> g(n,vector<int>());
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dist_aoki(n,-1),dist_taka(n,-1);
    
    dist_aoki[aoki] = 0;
    dist_taka[takahashi] = 0;
   queue<int> que;

   que.push(aoki);
   while(!que.empty()){
       int node = que.front();
       que.pop();
       for(auto x: g[node]){
           if(dist_aoki[x]<0){
               dist_aoki[x] = dist_aoki[node]+1;
               que.push(x);
           }
       }
   }
   que.push(takahashi);
   while(!que.empty()){
       int node = que.front();
       que.pop();
       for(auto x: g[node]){
           if(dist_taka[x]<0){
               dist_taka[x] = dist_taka[node]+1;
               que.push(x);
           }
       }
   }

    int ans = 0;
    rep(i,n){
        // cout<<dist_taka[i]<<" "<<dist_aoki[i]<<endl;

        if(dist_aoki[i]>dist_taka[i])ans = max(ans,dist_aoki[i]);
    }
    cout<<ans-1<<endl;

	return 0;
}

Measured memory_bytes: 6656
#include <stdio.h>

int main(void)
{
	int i, N, M, red[100010][2] = {{0, 0}, {1, 1}}, red_count = 0;
	//0:count 1: redがある可能性の時1
	int src, dst;


	scanf("%d%d", &N, &M);
	for (i = 2; i <= N; i++) {
		red[i][0] = 1;
	}
	for (i = 0; i < M; i++) {
		scanf("%d%d", &src, &dst);
		if (red[src][1] == 1)
			red[dst][1] = 1;
		if (red[src][0] == 1)
			red[src][1] = 0;
		red[src][0]--;
		red[dst][0]++;
	}
	for (i = 0; i < M; i++) {
	}

	for (i = 1; i <= N; i++) {
		if (red[i][1] == 1)
			red_count++;
	}

	printf("%d\n", red_count);

	return 0;
}

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

int main() {
    long long a ,b , k;
    cin >> a >> b >> k;

    if (k > a) {
        k -= a;
        a = 0;
        if (k > b) {
            b = 0;
        } else {
            b -= k;
        }
    } else {
        a = a - k;
    }

    cout << a << " " << b << endl;

    return 0;
}


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

const int vmax=10010;
const int inf=1<<25;

int N,M;
int dist[vmax][vmax];

bool warshall_floyd(){
	rep(k,N)rep(i,N)rep(j,N)dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	rep(i,N) if(dist[i][i]<0) return true;
	return false;
}

int main(void){
	cin >> N >> M;
	rep(i,N)rep(j,N) dist[i][j]=(i==j)?0:inf;
	rep(i,M){
		int a,b;
		cin >> a >> b;
		dist[a][b]=-1;
	}
	cout << warshall_floyd() << endl;
	return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    map<int,int>m;
    int N; cin >> N;
    int D[N];
    rep(i,N) cin >> D[i];
    int M; cin >> M;
    int T[M];
    rep(i,M) cin >> T[i];
    rep(i,N){
        m[D[i]]++;
    }
    rep(i,M){
        m[T[i]]--;
        if(m[T[i]]<0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

}

Measured memory_bytes: 15872
#pragma GCC optimize("Ofast","-funroll-loops","-fdelete-null-pointer-checks")
#pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx","popcnt")
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define endl '\n'

const ll MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	map<int, int> mp;
	ll ans = 0ll;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans += mp[i-x];
		mp[i+x]++;
	}
	cout << ans << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	ll t=1;
	for(ll tt=1; tt <= t; tt++) {
		//cout << "case #" << tt << ":\n";
		solve();
	}

	return 0;
}



Measured memory_bytes: 20700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	string a,b;
  	cin >> a >> b;
  	if (a[0]==b[2] and a[1]==b[1] and a[2]==b[0]){
      cout << "YES";
    }
  	else{
      cout << "NO";
    }
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define rint register int
#define INF ((1 << 30) - 1)
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define Pair pair < int, int >
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i, k, j) for(rint i = (k); i >= (j); i--)
#define For(i, k, j) for(rint i = (k); i <= (j); i++)
#define Foe(i, u) for(rint i = lst[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
#define int long long
const int P = 998244353; //
using namespace std;
inline void ckmax(int &a, int b) {a = max(a, b);}
inline void ckmin(ll &a, ll b) {a = min(a, b);}
inline void mulmod(int &a, int b) {a = 1ll * a * b % P;}
inline void addmod(int &a, int b) {int t = a + b; a = (t >= P ? t - P : t); }
inline int ksm(int a, int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline int inv(int a) {return ksm(a, P-2);}
namespace FastIO {
    const int SIZE=1<<16; char buf[SIZE], obuf[SIZE], str[64]; int bi=SIZE, bn=SIZE, opt;
    int read(char *s) {
        while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
        int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
    }
    bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n)return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
    void write(int x) {
        if(!x) obuf[opt++] = '0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
        if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}
    }
    void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf, 1, opt, stdout); opt=0;}}
    void Fflush() { if (opt) fwrite(obuf, 1, opt, stdout); opt=0;}
}
const int MAXN = 5e5 + 5;
int l[MAXN], r[MAXN], n, k, dp[MAXN], sum[MAXN];

signed main()
{
	#ifndef ONLINE_JUDGE
		file("pro");
	#endif
	FI(n), FI(k);
	For(i, 1, k) {
		FI(l[i]), FI(r[i]);
		if(l[i] > r[i]) swap(l[i], r[i]);
	}
	dp[1] = sum[1] = 1;
	For(i, 2, n) {
		For(j, 1, k) {
			int L = i - r[j], R = i - l[j];
			if(R <= 0) continue;
			if(L <= 0) {
				addmod(dp[i], sum[R]);
			} else {
				addmod(dp[i], sum[R]);
				addmod(dp[i], P - sum[L - 1]);
			}
		}
		sum[i] = (sum[i-1] + dp[i]) % P;
	}
	cout << dp[n] << endl;
    return FastIO::Fflush(), 0;
}
/*

*/



Measured memory_bytes: 6696
import java.util.Scanner;

class Main {

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

        int a = scan.nextInt();
        int b = scan.nextInt();
                
        int A = a;
        int B = b;
        while(A%B != 0){
            int C = A;
            A = B;
            B = C % A;
            
        }System.out.println( a + b - B + 1);
}
}


Measured memory_bytes: 26396
#include <bits/stdc++.h>
using i64 = long long;

constexpr i64 mod = 1000000007;
std::vector<std::deque<int>> g;
long long *fact, *inv;

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int n;
std::vector<int> centroids, ch;
void dfs(int v, int p) {
    ch[v] = 1;
    bool flg = true;
    for (auto to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        ch[v] += ch[to];
        if (ch[to] > n / 2) flg = false;
    }
    if (flg && n - ch[v] <= n / 2) centroids.push_back(v);
}

int dfs2(int v, int p) {
    ch[v] = 1;
    for (auto to : g[v]) {
        if (to == p) continue;
        ch[v] += dfs2(to, v);
    }
    return ch[v];
}

int main() {
    std::cin >> n;
    g.resize(n); ch.resize(n);
    init_factorial(n, mod);
    for (int i = 1; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        --x; --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    dfs(0, -1);

    if (centroids.size() == 2) {
        std::cout << fact[n / 2] * fact[n / 2] % mod << std::endl;
        return 0;
    }

    int c = centroids.front();
    int m = g[c].size();

    dfs2(c, -1);

    std::vector<std::vector<i64>> dp(m + 1, std::vector<i64>(n));
    dp[0][0] = 1;
    int max = 0;
    for (int i = 1; i <= m; i++) {
        for (int j = 0, tot = ch[g[c][i - 1]]; j <= tot; j++) {
            for (int k = 0; k <= max; k++) {
                dp[i][j + k] = (dp[i][j + k] + dp[i - 1][k] * fact[tot] % mod * fact[tot] % mod * inv[j] % mod * inv[j] % mod * inv[tot - j] % mod * inv[tot - j] % mod * fact[j] % mod) % mod;
            }
        }
        max += ch[g[c][i - 1]];
    }

    i64 ret = 0;
    for (int i = 0; i < n; i++) {
        ret = (ret + (mod + (i % 2 ? -1 : 1) * fact[n - i]) % mod * dp[m][i] % mod) % mod;
    }
    std::cout << ret << std::endl;

    return 0;
}


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

int main(){
  int s;
  cin >> s;
  vector<int> v;
  for(int i=0; i<4; i++){
    int a=s/pow(10,3-i);
    a%=10;
    v.push_back(a);
  }
  for (int i=0 ; i<(1<<(3)); i++){
    bitset<3> p(i);
    int ans=v[0];
    for (int j=0; j<3; j++){
      if(p[j]==1){
        ans += v[j+1];
      }
      else{
        ans -= v[j+1];
      }
    }
    if (ans==7){
      cout << v[0];
      for(int i=0; i<3; i++){
        if(p[i]==1) cout << "+";
        else cout << "-" ;
        cout << v[i+1];
      }
      cout << "=7";
      break;
    }
  }
}

Measured memory_bytes: 3996
#include <stdio.h>
#include <string.h>
  
#define Max 500000
  
void insert(int); 
void find(int, int);
int successor(int);
void delete(int);
void Preorder(int);    /* ??????????????? */
void Inorder(int);     /* ??????????????? */
  
  
typedef struct{    /* p = parent, l = child, s = brother */
  int key;
  int p;
  int l[2];
} Node;
  
Node T[Max];
  
int main(){
  int i, n, k;
  char s[7];
  
  scanf("%d", &n);
  
  T[0].key = -1;
  
   
  for(i = 0; i < n; i++){
    T[i].l[0] = -1;
    T[i].l[1] = -1;
  
    scanf("%s", s);
  
    if(strcmp(s, "insert") == 0){
      scanf("%d", &T[i].key);
      insert(i);
    }
    else if(strcmp(s, "print") == 0){
      Inorder(0);
      printf("\n");
      Preorder(0);
      printf("\n");
    }
    else if(strcmp(s, "find") == 0){
      scanf("%d", &k);
      find(0, k);
    }
    else if(strcmp(s, "delete") == 0){
      scanf("%d", &k);
      delete(k);
    }
  }
    
  return 0;
}
  
  
void insert(int z){
  int x, y;
  
  y = -1;
  x = 0;
  
  if(z != 0){
    while(x != -1){
      y = x;
      if(T[z].key < T[x].key) x = T[x].l[0];
      else x = T[x].l[1];
    }
  }
  
  T[z].p = y;
  
  if(y != -1){
    if(T[z].key < T[y].key) T[y].l[0] = z;
    else T[y].l[1] = z;
  }
}
  
void find(int x, int k){
  
  if(x == -1) printf("no\n");
  else if(T[x].key == k) printf("yes\n");
  else if(k < T[x].key) find(T[x].l[0], k);
  else find(T[x].l[1], k);
}
  
int successor(int x){
  int y;
  
  if(T[x].l[1] != -1){
    x = T[x].l[1];
    while(T[x].l[0] != -1) x = T[x].l[0];
    return x;
  }
    
  else {
    y = T[x].p;
    while(y != -1 && x == T[y].l[1]){
      x = y;
      y = T[y].p;
    }
    return y;
  }
}
  
void delete(k){
  int x, y, z = 0;
  
  while(1){
    if(T[z].key == k) break;
    else if(k < T[z].key) z = T[z].l[0];
    else z = T[z].l[1];
  }
  
  if(T[z].l[0] == -1 || T[z].l[1] == -1) y = z;
  else y = successor(z);
  
  if(T[y].l[0] != -1) x = T[y].l[0];
  else x = T[y].l[1];
  
  if(x != -1) T[x].p = T[y].p;
  
  if(T[y].p != -1){
    if(y == T[T[y].p].l[0]) T[T[y].p].l[0] = x;
    else T[T[y].p].l[1] = x;
  }
  
  if(y !=  z) T[z].key = T[y].key;
  
}
  
  
void Preorder(int a){
  printf(" %d", T[a].key);
  
  if(T[a].l[0] != -1) Preorder(T[a].l[0]);
  if(T[a].l[1] != -1) Preorder(T[a].l[1]);
}
  
  
void Inorder(int a){
  if(T[a].l[0] == -1){
    printf(" %d", T[a].key);
    if(T[a].l[1] != -1) Inorder(T[a].l[1]);
  }
  else{
    Inorder(T[a].l[0]);
    printf(" %d", T[a].key);
    if(T[a].l[1] != -1) Inorder(T[a].l[1]);
  }
}

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


struct P
{
    int x,y,z;

    /*bool operator<(const P &a)const{
        if(x!=a.x)
        return x>a.x;
              return y>a.y;
    }*/
};

vector<int> v[2];
//bitset<4001000> b;
int a,c,i,b,k,n,d,e,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[2252];

int o[251111];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={-1,0,1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};


long long x,y,mod=1000000007;
long long z;
int j[330][111];
P u[221110];
stack<int> s;

//set<int> s;
queue<int > q;

//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p[2];
//list<int> l;
//string r1,r;
char r[115][111];
//deque<int> de;

//20921
bool as(P a,P b)
{
    return a.x<b.x;
}


int main()
{
    scanf("%d",&a);
    for(int t=1;t<=a;t++)
        scanf("%d",&o[t]);
    sort(o+1,o+a+1);
    n=o[1];
    for(int t=2;t<a;t++)
    if(min(n,o[a]-n)<min(o[t],o[a]-o[t])) n=o[t];
    printf("%d %d",o[a],n);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int> > D(100005);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    D[a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  REP(i, 1, M+1) {
    for(int d: D[i])
      q.push(d);
    if(!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

result = 0
for i in range(N):
  if B[i] < A[i]:
    result += B[i]
    B[i] = 0
  elif B[i] >= A[i]:
    result += A[i]
    B[i] -= A[i]

  if B[i] != 0:
    if B[i] < A[i+1]:
      result += B[i]
      A[i+1] -= B[i]
    elif B[i] >= A[i+1]:
      result += A[i+1]
      A[i+1] = 0

print(result)

Measured memory_bytes: 19648
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	string str, str2;
	cin >> str;

	int count = 0;
	while(cin >> str2) {
		if(str2 == "END_OF_TEXT") break;
		for(int i = 0; i < str2.size(); i++) str2[i] = tolower(str2[i]);
		if(str2 == str) count++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define F(x, y, d) while (f[x+dx[d]][y+dy[d]] != '#') x+=dx[d], y+=dy[d]
inline int h(int x, int y, int d) { return (x<<8) | (y<<2) | d; }
inline int h(int x1, int y1, int d1, int x2, int y2, int d2) {
    return (h(x1, y1, d1) << 16) | h(x2, y2, d2);
}

int H, W;
char f[16][64], h1[16][64][4];
int sx, sy, sd, tx, ty, td;
std::unordered_set<int> h2;

bool reach(int x, int y, int d) {
    F(x, y, d);
    if (x == tx && y == ty) return true;
    if (h1[x][y][d]) return false;
    h1[x][y][d] = 1;
    if (reach(x, y, (d+1)%4)) return true;
    if (reach(x, y, (d+3)%4)) return true;
    return false;
}

bool acc(int cx, int cy, int cd, int x, int y, int d) {
    if (f[x+dx[d]][y+dy[d]] != '#') return false;
    F(cx, cy, cd);
    const bool p = cx == tx && cy == ty && d == td;
    while (f[x][y] != '#') {
        if (!h2.insert(h(cx, cy, cd, x, y, d)).second) break;
        if (p && x == tx && y == ty) return true;
        if (acc(cx, cy, (cd+1)%4, x, y, (d+1)%4)) return true;
        if (acc(cx, cy, (cd+3)%4, x, y, (d+3)%4)) return true;
        x -= dx[d], y -= dy[d];
    }
    return false;
}

void solve() {
    memset(h1, 0, sizeof(h1));
    rep (i, H) rep (j, W) if (f[i][j] == 'K') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') sx = i, sy = j, sd = d;
    }
    rep (i, H) rep (j, W) if (f[i][j] == 'M') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') tx = i, ty = j, td = d;
    }
    if (!reach(sx, sy, sd)) puts("He cannot bring tea to his master.");
    else {
        h2.clear();
        rep (d, 4) if (acc(sx, sy, sd, sx, sy, d)) {
            puts("He can accomplish his mission.");
            return ;
        }
        puts("He cannot return to the kitchen.");
    }
}

int main() {
    char buf[80];
    for (;;) {
        fgets(buf, 80, stdin);
        sscanf(buf, "%d%d", &W, &H);
        if (W == 0) return 0;
        rep (i, H) {
            fgets(buf, 80, stdin);
            memcpy(f[i], buf, W);
        }
        solve();
    }
}

Measured memory_bytes: 6064
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int>a(N);
	for(auto&e:a)cin >> e;
	int acc = accumulate(a.begin(),a.end(),0);
	int ma = *max_element(a.begin(),a.end());
	acc -= ma;
	if(ma < acc)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[3010][3010];


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int slen = s.size(), tlen = t.size();
    rep(i, slen) {
        rep(j, tlen) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
            else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
    }
    /*
    rep(i, slen) {
        rep(j, tlen) {
            cout << dp[i + 1][j + 1] << " ";
        }
        cout << endl;
    }
    */
    string ans;
    while(dp[slen][tlen] > 0) {
        //cout << slen << " " << tlen << " " << dp[slen][tlen] << "->";
        if (dp[slen][tlen] == dp[slen - 1][tlen]) {
            slen--;
        } 
        else if (dp[slen][tlen] == dp[slen][tlen - 1]){
            tlen--;
        }
        else {
            slen--; tlen--;
            ans = s[slen] + ans;
            //cout << ans << endl;
        }
        //cout << slen << " " << tlen << " " << dp[slen][tlen] << " " << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 35584