akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <regex>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stack>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main () {
    string s;
    cin >> s;
    ll one = -INT64_MAX, nonone = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i] == '1') {
            one = i;
        }else {
            nonone = (int)(s[i] - '0');
            break;
        }
    }
    ll k, ans = 0;
    cin >> k;
    if(one + 1 >= k) {
        ans = 1;
    }else {
        ans = nonone;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;


int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll mi = a * x + b * y;
    int X = x, Y = y;
    for (int i = 0; i <= max(X, Y) * 2; i += 2, x--, y--) {
        if (x < 0) x = 0;
        if (y < 0) y = 0;
        mi = min(mi, (ll)(a * x + b * y + c * i));
    }
    cout << mi << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

const int MAX_A = 1000 * 1000;

vector<int> as;
int ns[MAX_A + 1];

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

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());

    for (int i = 0; i < N; i++) {
        int x = as[i];
        ns[x]++;
        if (ns[x] >= 2) {
            continue;
        }
        for (int j = x + x; j <= MAX_A; j += x) {
            ns[j]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (ns[as[i]] == 1) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7952
n,x,y = map(int, input().split())

l = [0] * n


for i in range(1,n):
    for j in range(i+1,n+1):
        if j < x or i > y:
            a = j-i
            l[a] += 1
        else:
            p = j-i
            q = abs(j-y)+abs(i-x)+1
            a = min(p,q)
            l[a] +=1

for i in range(1,n):
    print(l[i])

Measured memory_bytes: 3444
using System;
        using System.Linq;
        using System.Collections.Generic;
        using static System.Math;

        public class Program
        {
            public static void Main(string[] args)
            {
            int n = int.Parse(Console.ReadLine());
            int[] ta = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            double abs = Abs(ta[1] - (ta[0] - h[0] * 0.006));
            int answer = 0;

            for(int i = 0; i < n; i++)
            {
                double stock = Abs(ta[1] - (ta[0] - h[i] * 0.006));
                if(stock < abs)
                {
                    abs = stock;
                    answer = i;
                }
            }
            Console.WriteLine(answer + 1);
            }
        }

Measured memory_bytes: 13332
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    long long H, W, A, B;
    cin >> H >> W >> A >> B;

    vector<vector<bool>> m(H, vector<bool>(W, 0));
    for(long long i = 0; i < A; i++)
        for(long long j = 0; j < B; j++)
            m[j][i] = 1;

    for(long long i = A; i < W; i++)
        for(long long j = B; j < H; j++)
            m[j][i] = 1;


    for(long long i = 0; i < H; i++){
        long long c = 0;
        for(long long j = 0; j < W; j++){
            if(m[i][j])
                c++;
        }
        if(min(c, W - c) != A){
            cout << "No" << endl;
            return 0;
        }
    }

    for(long long i = 0; i < W; i++){
        long long c = 0;
        for(long long j = 0; j < H; j++){
            if(m[j][i])
                c++;
        }
        if(min(c, H - c) != B){
            cout << "No" << endl;
            return 0;
        }
    }

    for(long long i = 0; i < H; i++){
        for(long long j = 0; j < W; j++){
            cout << m[i][j];
        }
        cout << endl;
    }

}

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

int main() {
	string s;
	cin >> s;
	int counter = 0;
	if (s[0] == '1') ++counter;
	if (s[1] == '1') ++counter;
	if (s[2] == '1') ++counter;
	cout << counter << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc116/submissions/5667980
# 写経

from heapq import heappush, heappop
import sys

input = sys.stdin.readline

n, k = map(int, input().split())
kind_value = [[] for _ in range(n)]
for _ in range(n):
    t, d = map(int, input().split())
    kind_value[t - 1].append(d)

for lis in kind_value:
    lis.sort()

kind_value = sorted(
    (lis for lis in kind_value if lis),
    key=lambda x: x[-1], reverse=True)

ret = 0
curr = 0
kind = 0
remains = []
for lis in kind_value:
    kind += 1
    if kind > k:
        break
    curr += lis[-1]
    for d in lis[:-1]:
        heappush(remains, d)
        curr += d
    while len(remains) > k - kind:
        curr -= heappop(remains)
    ret = max(ret, curr + kind * kind)

print(ret)


Measured memory_bytes: 70448
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<s.length();i++){
            char c = s.charAt(i);
            if(Character.isUpperCase(c)){
                c = Character.toLowerCase(c);
            }else if(Character.isLowerCase(c)){
                c = Character.toUpperCase(c);
            }
            sb.append(c);
        }
        System.out.println(sb.toString());
        
    }
}




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

const int maxn=2e5+10;

int n,m,f[maxn],fk[maxn],dep[maxn];
LL k,x[maxn],y[maxn];

int main()
{
	int i,pos;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%lld",&x[i]);
	for (i=n;i>=1;i--) x[i]-=x[i-1];
	for (i=1;i<=n;i++) f[i]=i;
	scanf("%d%lld",&m,&k);
	for (i=1;i<=m;i++)
	{
		scanf("%d",&pos);
		swap(f[pos],f[pos+1]);
	}
	for (i=1;i<=n;i++)
		if (!dep[i])
		{
			int u=i,v,move;
			while (1)
			{
				dep[f[u]]=dep[u]+1;
				u=f[u];
				if (u==i) break;
			}
			for (move=k%dep[i],v=i;move--;) v=f[v];
			for (fk[i]=v;u=f[u],v=f[v],u!=i;) fk[u]=v;
		}
	for (i=1;i<=n;i++) y[i]=x[fk[i]];
	for (i=1;i<=n;i++)
		y[i]+=y[i-1],printf("%lld\n",y[i]);
}


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

class Cube {
public:
	int f[6];
	Cube() {}
	void roll_z() { roll(1, 2, 4, 3); }
	void roll_y() { roll(0, 2, 5, 3); }
	void roll_x() { roll(0, 1, 5, 4); }
	void roll(int i, int j, int k, int l) {
		int t = f[i]; f[i] = f[j], f[j] = f[k]; f[k] = f[l]; f[l] = t;
	}
};

bool eq(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++)
		if (c1.f[i] != c2.f[i])return false;
	return true;
}

bool equal(Cube c1, Cube c2) {
	for (int i = 0; i < 6; i++){
		for (int j = 0; j < 4; j++) {
			if (eq(c1, c2))return true;
			c1.roll_z();
		}
		if (i % 2 == 0)c1.roll_y();
		else c1.roll_x();
	}
	return false;
}

Cube C[100]; int n;

bool check() {
	for (int i = 0; i < n - 1; i++)
		for (int j = i + 1; j < n; j++)if (equal(C[i], C[j]))return false;
	return true;
}

int main() {
	cin >> n;
	for (int j = 0; j < n; j++)
		for (int i = 0; i < 6; i++)cin >> C[j].f[i];

	if (check())cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3076
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N := ReadInt()
	S := make([]string, N)
	for i := 0; i < N; i++ {
		S[i] = ReadString()
	}
	c := 0
	m := make(map[string]int)
	for _, b := range S {
		m[b]++
		if m[b] > c {
			c = m[b]
		}
	}
	a := make([]string, 0)
	for k, v := range m {
		if v == c {
			a = append(a, k)
		}
	}
	sort.Strings(a)
	for _, s := range a {
		fmt.Println(s)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A.at(i);
    }

    int sum = 0;
    for (int i = 0; i < M; i++) {
        sum = sum + A.at(i);
    }

    if (sum <= N) {
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3668
import math
import random
class Prime:
    seed_primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
    def is_prime(self,n):
        is_prime_common=self.is_prime_common(n)
        if is_prime_common is not None:return is_prime_common
        if n<2000000:return self.is_prime_brute_force(n)
        return self.is_prime_miller_rabin(n)
    def is_prime_common(self,n):
        if n==1:return False
        if n in Prime.seed_primes:return True
        if any(map(lambda x:n%x==0,self.seed_primes)):return False
    def is_prime_brute_force(self,n):
        for k in range(2,int(math.sqrt(n))+1):
            if n%k==0:return False
        return True
    def is_prime_miller_rabin(self,n):
        d=n-1
        while d&1==0:d>>=1
        witnesses=self.get_witnesses(n)
        for w in witnesses:
            y=pow(w,d,n)
            while d!=n-1and y!=1and y!=n-1:
                y=y*y%n
                d<<=1
            if y!=n-1and d&1==0:return False
        return True
    def get_witnesses(self,num):
        def _get_range(num):
            if num<2047:return 1
            if num<1373653:return 2
            if num<25326001:return 3
            if num<3215031751:return 4
            if num<2152302898747:return 5
            if num<3474749660383:return 6
            if num<341550071728321:return 7
            if num<3825123056546413051:return 9
            return 12
        return self.seed_primes[:_get_range(num)]
    def gcd(self,a,b):
        if a<b:return self.gcd(b,a)
        if b==0:return a
        while b:a,b=b,a%b
        return a
    @staticmethod
    def f(x,n,seed):
        p=Prime.seed_primes[seed%len(Prime.seed_primes)]
        return(p*x+seed)%n
    def find_factor(self,n,seed=1):
        if self.is_prime(n):return n
        x,y,d=2,2,1
        count=0
        while d==1:
            count+=1
            x=self.f(x,n,seed)
            y=self.f(self.f(y,n,seed),n,seed)
            d=self.gcd(abs(x-y),n)
        if d==n:
            return self.find_factor(n,seed+1)
        return self.find_factor(d)
    def find_factors(self,n):
        primes={}
        if self.is_prime(n):
            primes[n]=1
            return primes
        while n>1:
            factor=self.find_factor(n)
            primes.setdefault(factor,0)
            primes[factor]+=1
            n//=factor
        return primes
*d,=sorted(Prime().find_factors(math.factorial(int(input()))).values())
a=0
n=len(d)
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            a+=3*(d[i]>3)or d[i]>1and d[j]>3and d[k]>3
        a+=(2*(d[i]>13)or d[i]>3and d[j]>13)+(2*(d[i]>23)or d[i]>1and d[j]>23)
    a+=d[i]>73
print(a)

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

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

using namespace std;
using ll = long long;

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

    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    ll ans = 0;
    if(x / k >= d) {
        ans = x - k * d;
    } else {
        ans = x % d;
        if((k - x / d) & 1) ans = abs(ans - d);
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int k,a,b;
  string ans = "NG";
  cin >> k >> a >> b;
  for(int i=b;i>=a;--i) {
    if(i%k == 0) ans = "OK";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void dk()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int dp[100000];
vector<int> g[100000];
int vis[100000];
int longestPath(int n, int k)
{
    if (1)
    {
        vis[k] = true;
        int flag = 0;
        for (auto x : g[k])
        {
            if (vis[x] == false)
            {
                flag = 1;
                //cout << x << endl;
                dp[k] = max(dp[k], longestPath(n, x))  ;
            }
            else
            {
                dp[k] = max(dp[k], dp[x]);
            }
        }
        return ++dp[k];
    }
}
int32_t main()
{
    //dk();
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
    }
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < n; i++)
    {
        if (vis[i] == false)
            int k = longestPath(n, i);
    }

    int mm = 0;
    for (int i = 0; i < n; i++)
    {
        // cout << dp[i] << " ";
        mm = max(mm, dp[i]);
    }
    cout << mm;
    return 0;
}

Measured memory_bytes: 9344
using System;
class A
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int A = int.Parse(s[1]);
        if (A == 1)
        {
            Console.WriteLine(N);
            return;
        }
        if (N % A == 0){
            Console.WriteLine(N / A);
            return;
        }
        Console.WriteLine(N / A + 1);
    }
}

Measured memory_bytes: 13140
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N+1];
		int[] w = new int[N+1];
		for(int i = 1; i <= N; i++){
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		
		//dp[i][j]:i番目までの荷物で重さjを超えないような取り方の価値の最大値
		int[][] dp = new int[N+1][W+1];
		
		/*
		for(int i = 0; i <= N; i++)
			dp[i][0] = 0;
		for(int j = 0; j <= W; j++)
			dp[0][j] = 0;
		*/
		
		for(int i = 1; i <= N; i++){
			for(int j = 0; j <= W; j++){
				if(j - w[i] >= 0)
					dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
				else
					dp[i][j] = dp[i-1][j];
			}
		}
		
		System.out.println(dp[N][W]);
	}
}


class Queue{
	int n;
	int p, q, r;
	public Queue(int n, int p, int q, int r){
		this.n = n;
		this.p = p;
		this.q = q;
		this.r = r;
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    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: 29032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  ll n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  rep(i,n-k){
    if(a[i] < a[k+i]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> V(2, vector<int>(100005, 0));
  vector<int> maxv(2, 0), to(2);
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    V[i & 1][v]++;
    if (maxv[i & 1] < V[i & 1][v]) {
      maxv[i & 1] = V[i & 1][v];
      to[i & 1]   = v;
    }
  }
  sort(V[0].begin(), V[0].end(), greater<int>());
  sort(V[1].begin(), V[1].end(), greater<int>());
  int res = 0;
  if (to[0] != to[1])
    res = n - maxv[0] - maxv[1];
  else
    res = min(n - maxv[0] - V[1][1], n - maxv[1] - V[0][1]);
  cout << res << '\n';
  return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
vector<vector<int>> G;
int S, T;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  G.assign(N, vector<int>());
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    G[--u].emplace_back(--v);
  }
  cin >> S >> T;
  S--, T--;

  vector<vector<ll>> res(N, vector<ll>(3, -1));
  res[S][0] = 0;
  queue<pii> que;
  que.push(make_pair(S, 0));
  while (!que.empty()) {
    pii cur = que.front();
    que.pop();

    int v = cur.first;
    int p = cur.second;
    for (auto nv : G[v]) {
      int np = (p + 2) % 3;
      if (res[nv][np] == -1) {
        res[nv][np] = res[v][p] + 1;
        que.push(make_pair(nv, np));
      }
    }
  }

  if (res[T][0] == -1)
    cout << -1 << '\n';
  else
    cout << res[T][0] / 3 << '\n';
  return 0;
}


Measured memory_bytes: 11264
s=input()
if s=="SUN":
  print("7")
if s=="MON":
  print("6")
if s=="TUE":
  print("5")
if s=="WED":
  print("4")
if s=="THU":
  print("3")
if s=="FRI":
  print("2")
if s=="SAT":
  print("1")

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl; 

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  //cout<<"input"<<endl;freopen("input.txt","r",stdin);
  //cout<<"output"<<endl;freopen("output.txt","w",stdout);
  int n;
  cin>>n;
  int sum = 0;
  bool bisa = false;
  while(n--){
    int x,y;
    cin>>x>>y;
    if(x==y)
      sum+=1;
    else  sum = 0;
    if(sum == 3){
      bisa = true;
    }
  } 
  bisa == true ? cout<<"Yes" : cout<<"No";
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 3648
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

max_A = max(a for a, _ in AB)
inf = float('inf')
dp = [inf] * (H + max_A + 1)
dp[0] = 0
for i in range(1, H + max_A + 1):
    for a, b in AB:
        t1 = i - a
        if t1 < 0:
            continue
        t2 = dp[t1]
        if t2 == inf:
            continue
        if t2 + b < dp[i]:
            dp[i] = t2 + b
print(min(dp[H:]))


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

int main(){
  int n, q;
  cin >> n >> q;
  priority_queue<int> s[n];
  while(q--){
    long a, b, c;
    cin >> a >> b;
    if(!a){
      cin >> c;
      s[b].push(c);
    }
    else if(a == 1){
      if(!s[b].empty())cout << s[b].top() << endl;
    }
    else{
      if(!s[b].empty()) s[b].pop();
    }
  }
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){ 
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  REP(i, N-2){
    if(S.substr(i, 3) == "ABC"){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))

BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda bc: bc[1], reverse=True)
update_bc = [0 for _ in range(N)]
cnt = 0
for b, c in BC:
    for i in range(b):
        if cnt < N:
            update_bc[cnt] = c
            cnt += 1
        else:
            break
    if cnt >= N:
        break
for i in range(N):
    if A[i] < update_bc[i]:
        A[i] = update_bc[i]
    else:
        break
print(sum(A))


Measured memory_bytes: 32960
fn main() {
    let n: usize = read_line_as_value();
    let mut v: Vec<usize> = read_line_as_vector();

    v.sort();
    let mut ans = 0;
    for i in 0..n {
        for j in i+1..n {
            let target = v[i] + v[j];
            let mut left = j;
            let mut right = n;
            while right - left > 1 {
                let mid = (left + right) / 2;
                if v[mid] >= target {
                    right = mid;
                } else {
                    left = mid;
                }
            }
            ans += right - 1 - j;
        }
    }
    println!("{}", ans);
}

fn read_line_as_value<T: std::str::FromStr>() -> T {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().parse() {
        Ok(val) => val,
        _ => panic!("error while parsing input: {}", input)
    }
}

fn read_line_as_vector<T: std::str::FromStr>() -> Vec<T> {
    let mut input = String::new();
    let res = std::io::stdin().read_line(&mut input);
    if let Err(error) = res {
        panic!("io error at stdin.read_line: {}", error);
    };
    match input.trim().split_whitespace().map(|x| x.parse()).collect::<Result<Vec<T>, _>>() {
        Ok(vec) => vec,
        _ => panic!("error while parsing input: {}", input)
    }
}

Measured memory_bytes: 2140
#include <stdio.h>

#define FALSE 1
#define TRUE 0
#define MAX 36

typedef struct {
    char s;
    int value;
} T;


void print(T C[],int N){
    int i;
    for(i=0;i<N;i++){
        printf("%c%d",C[i].s,C[i].value);
        if(i!=N-1) printf(" ");
        else printf("\n");
    }
}


void Bubble(T C[],int N){
    int i,j;
    T t;
    
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(C[j].value<C[j-1].value){
                t=C[j];
                C[j]=C[j-1];
                C[j-1]=t;
            }
        }
    }
    print(C,N);
    printf("Stable\n");
}

void Select(T C[],int N){
    int i,j;
    int minj;
    T t;
    
    for(i=0;i<N;i++){
        minj=i;
        for(j=i;j<N;j++){
            if(C[j].value<C[minj].value) minj=j;
        }
        t=C[i];
        C[i]=C[minj];
        C[minj]=t;
    }
    print(C,N);
}

int Stable(T A[],T B[],int N){
    int i;
    for(i=0;i<N;i++){
        if(A[i].s!=B[i].s) return FALSE;
    }
    return TRUE;
}

int main(){
    int n;
    int i;
    T A[MAX],B[MAX];

    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf(" %c%d",&A[i].s,&A[i].value);
        B[i]=A[i];
    }
    
    Bubble(A,n);
    Select(B,n);
    
    for(i=0;i<n;i++){
        if(A[i].s!=B[i].s)break;
    }
    
    if(Stable(A,B,n)==TRUE) printf("Stable\n");
    else printf("Not stable\n");    
    
    return 0;
}



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

int main (){
    int n;
    cin>>n;
    vector<int> v(n);
    int i;
    for(i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    double c=(double)v[0];
    for(i=1;i<n;i++){
        c=(double)(c+v[i])/2;
        
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
X = list(map(int, input().split()))

# print(X)

time = float('inf')
for n_i in range(n-k+1):
  r_side = X[n_i+k-1]
  l_side = X[n_i]
  time = min(time, min(abs(r_side), abs(l_side)) + abs(r_side-l_side))
  
print(time)

Measured memory_bytes: 14392
#include <bits/stdc++.h>
#define ll  long long
#define pb push_back
#define ff first
#define ss second
#define br cout <<"\n";
#define all(x)  (x).begin(),(x).end()
#define rall(x)  (x).rbegin(),(x).rend()
#define tr(c,i) for(auto i : c)
#define pii pair< int,int >
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define pq priority_queue< pair<ll,pii> ,vector<pair<ll,pii>>,greater <pair<ll,pii>> >p;//container adapter makes ascending q
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7 ;
const int MAXN = 1000*100 + 1  ;
const int INF = INT_MAX;
int main (){
	fast_io();
	int s , w ;
	cin >> s >> w ;
	cout << ( w >= s ?"unsafe" : "safe") ;
	br  
	 
	return 0 ;

}
 


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
void setIO(string name = "b") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen((name+".in").c_str(), "r", stdin);
    freopen((name+".out").c_str(), "w", stdout);
}

int main() {
    //setIO();
    ll a, b, x; cin >> a >> b >> x;
    a += (x - a % x) % x; b -= b % x;
    if (b < a) {
        cout << 0 << "\n";
    } else {
        cout << (b - a) / x + 1 << "\n";
    }
}

Measured memory_bytes: 3636
/*
  This C++ Source Is
  Writen By syksykCCC
  (2020)
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for(register int i = x; i < y; i++)
#define REP(i, x, y) for(register int i = x; i <= y; i++)
#define per(i, x, y) for(register int i = x; i > y; i--)
#define PER(i, x, y) for(register int i = x; i >= y; i--)
#define repl(i, x, y) for(register long long i = x; i < y; i++)
#define REPL(i, x, y) for(register long long i = x; i <= y; i++)
#define perl(i, x, y) for(register long long i = x; i > y; i--)
#define PERL(i, x, y) for(register long long i = x; i >= y; i--)
#define LLL __int128
#define int128 __int128
#define DEBUG(x) cerr << #x << " : " << x << endl
using namespace std;
typedef unsigned int uint;
typedef long long int64;
typedef long long LL;
typedef unsigned long long uint64;
typedef long long ULL;
typedef long double LLF;
template<typename T> inline void read(T &val)
{
	val = 0; char c = getchar(); int f = 1;
	while(!isdigit(c)) { if(c == '-') f = -1; c = getchar(); }
	while(isdigit(c)) { val = (val << 3) + (val << 1) + (c ^ 48); c = getchar(); }
	val *= f;
}
template<typename T> void write_(T val) { if(!val) return; write_(val / 10); putchar(val % 10 + 48); }
template<typename T> inline void write(T val)
{
	if(val == 0) putchar(48);
	else if(val < 0) { putchar('-'); write_(-val); }
	else write_(val);
}

const int N = 55;
int n, m, q, arr[N], ans;
int a[N], b[N], c[N], d[N];

void check()
{
	int res = 0;
	REP(i, 1, q)
	{
		if(arr[b[i]] - arr[a[i]] == c[i]) res += d[i];
	}
	ans = max(ans, res);
}

void dfs(int k)
{
	if(k > n)
	{
		check();
		return;
	}
	REP(i, arr[k - 1], m)
	{
		arr[k] = i;
		dfs(k + 1);
	}
}

int main()
{
#ifdef LOCAL
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin >> n >> m >> q;
	REP(i, 1, q)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}
	arr[0] = 1;
	dfs(1);
	cout << ans << endl;
	return 0;
}


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

int main() {
  string s; cin >> s;
  int K; cin >> K;
  int L = s.size();
  vector<int> A(L);
  for (int i = 0; i < L; i++) A.at(i) = (26 - (s.at(i) - 'a')) % 26;
  string alp = "abcdefghijklmnopqrstuvwxyz";
  for (int i = 0; i < L; i++) {
    if (A.at(i) > K) continue;
    if (A.at(i) <= K) {
      s.at(i) = 'a';
      K -= A.at(i);
    }
  }
  if (K > 0) s.at(L-1) = alp.at(((s.at(L-1) - 'a') + K) % 26);
  cout << s << endl;
}

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

int main() {
    string N;
    cin >> N;
    if((N[0]==N[1] && N[1]==N[2]) || (N[1]==N[2] && N[2]==N[3])){
        cout << "Yes";
    }else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int take = A - B;
    take = min(C, take);
    C -= take;
    cout << C << '\n';
    return 0;
}

Measured memory_bytes: 3612
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []
    n = I()
    a = [LS() for _ in range(n)]

    def f(s):
        r = 0
        c = 1
        for t in s:
            if t == 'm':
                r += c * 1000
                c = 1
            elif t == 'c':
                r += c * 100
                c = 1
            elif  t == 'x':
                r += c * 10
                c = 1
            elif t == 'i':
                r += c
                c = 1
            else:
                c = int(t)
        return r

    def g(i):
        r = ''
        if i >= 1000:
            k = i // 1000
            if k > 1:
                r += str(k)
            r += 'm'
            i %= 1000
        if i >= 100:
            k = i // 100
            if k > 1:
                r += str(k)
            r += 'c'
            i %= 100
        if i >= 10:
            k = i // 10
            if k > 1:
                r += str(k)
            r += 'x'
            i %= 10
        if i >= 1:
            k = i
            if k > 1:
                r += str(k)
            r += 'i'
        return r

    for s,t in a:
        rr.append(g(f(s)+f(t)))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9428
N = int(input())
s = []

for i in range(N):
    s.append(int(input()))

s.sort(reverse = True)
ans = sum(s)

if ans % 10 == 0:
    #どれかを引く必要が有る
    for i in range(1,N+1):
        if s[-i] % 10 != 0:
            ans -= s[-i]            
            break

if ans % 10 == 0:
    ans = 0 

print(ans)


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

int main(){
    long long int n,a=100,ans=0;
    cin>>n;
    for(int i=0;a<n;i++){
        a=a*1.01;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
using namespace std;
long long int asum = 0;

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

	int amax = -1e7, amin = 1e7;
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		amax = max(amax, tmp);
		amin = min(amin, tmp);
		asum += tmp;
	}
	cout << amin << " " << amax << " " << asum << endl;

	return 0;
}


Measured memory_bytes: 3104
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int T = Integer.parseInt(sc.next());
		ArrayList<Integer> cost = new ArrayList<>();
		ArrayList<Integer> time = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			cost.add(Integer.parseInt(sc.next()));
			time.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int ansCost = Integer.MAX_VALUE;
		for(int i = 0; i < N; i++) {
			if(time.get(i) <= T) {
				ansCost = Math.min(ansCost, cost.get(i));
			}
		}
		if(ansCost == Integer.MAX_VALUE) {
			System.out.println("TLE");
		}else {
			System.out.println(ansCost);
		}

	}
}

Measured memory_bytes: 21844
# include<iostream>
# include<algorithm>
# include<cctype>
# include<cstdio>
# include<cstring>
# include<cmath>
using namespace std;
int main()
{
      int a, b;
      cin >> a >> b;
      if (a>=13) cout << b << endl;
      else if (a<13&&a>=6) cout << b/2 << endl;
      else cout << 0 << endl;
      return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <ctype.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;

	int C = N * A;
	cout << min(C, B) << endl;
}

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

using namespace std;

typedef long long int Int;

int main(void)
{
    int n;
    set<Int> a;

    cin>>n;
    for(int i = 0;i < n;i++)
    {
	Int temp;
	cin>>temp;

	set<Int>::iterator it = a.find(temp);
	if(it != a.end())
	{
	    a.erase(it);
	}
	else
	    a.insert(temp);
    }

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

    return 0;
}


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

using namespace std;

const long long MOD = 1000000007;
int main() {
    string S;
    cin>>S;
    long long dp[S.size()+1][13];
    for(long long i=0;i<S.size()+1;i++){
        for(long long j=0;j<13;j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;

    for(long long i=0;i<S.size();i++){
        if(S[i]=='?'){
            for(long long j=0;j<13;j++){
                for(long long k=0;k<10;k++){
                    dp[i+1][(10*j+k)%13]+=dp[i][j];
                    dp[i+1][(10*j+k)%13]%=MOD;
                }
            }
        }else{
            for(long long j=0;j<13;j++){
                dp[i+1][(10*j+(S[i]-'0'))%13]+=dp[i][j];
                dp[i+1][(10*j+(S[i]-'0'))%13]%=MOD;
            }
        }
    }

    cout<<dp[S.size()][5]<<endl;





}













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

#define ll long long

ll n, m, k;
ll a[3001][3001] ;
ll dp[3001][3001][4] ;
ll dfs(ll x, ll y, ll cur) {
    if ( x == n && y == m ) {
        return 0 ;
    }
    if ( x == n ) return 0 ;
    if ( y == m ) return 0 ;
    if ( dp[x][y][cur] != -1 ) return dp[x][y][cur] ;
    ll ans = 0 ;
    if ( a[x][y] == 0 ) {
        ans = max(dfs(x + 1, y, 0), dfs(x, y + 1, cur)) ;
    }
    else {
        ll value = a[x][y] ;
        if ( cur < 3 ) {
            ans = max(ans, value + dfs(x, y + 1, cur + 1)) ;
            ans = max(ans, value + dfs(x + 1, y, 0)) ;
        }
        ans = max(ans, dfs(x, y + 1, cur)) ;
        ans = max(ans, dfs(x + 1, y, 0)) ;
    }
    return dp[x][y][cur] = ans ;
}
signed main() {
    // fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n >> m >> k ;
    for (ll i = 0; i < k; i++) {
        ll x , y , z;
        cin >> x >> y >> z ;
        x--, y-- ;
        a[x][y] = z ;
    }
    ll ans = dfs(0, 0, 0) ;
    cout << ans << endl;
    return 0;
}

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

int main() {
    double n;
    cin >> n;
    double t,a;
    cin >> t >> a;
    vector<double> h(n);
    vector<double> ans(n);
    int count;
    double com=1000;
    for(int i=0;i<n;i++){
        cin >> h.at(i);
        ans.at(i) = t-h.at(i)*0.006-a;
        if(com > abs(ans.at(i))){
            com = abs(ans.at(i));
            count = i;
        }
    }
    cout << count+1 << endl;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

m = [0] * M
x = [0] * M
y = [0] * M
for i in range (M):
    x[i], y[i], m[i] = map(int, input().split())
    

discount = [0] * M
for i in range(M):
    discount[i] = a[x[i]-1] + b[y[i]-1] - m[i]
    
    
discount_ab = min(a) + min (b)
if discount_ab > min(discount):
    print(min(discount))
else:
    print(discount_ab)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int a_min = numeric_limits<int>::max();
  int a_max = numeric_limits<int>::min();
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    a_min = min(a, a_min);
    a_max = max(a, a_max);
  }
  cout << a_max - a_min;

  return 0;
}


Measured memory_bytes: 256
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}

bool ok[40001];

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)cin >> a[i];
  ok[0] = true;
  for(int i = 0; i < n; i++){
    for(int j = 40000; j >= 0; j--){
      if(ok[j] && j+a[i] < 40001)ok[j+a[i]] = true;
    }
  }
  int q;
  cin >> q;
  rep(i, q){
    int x;
    cin >> x;
    if(ok[x])cout << "yes" << endl;
    else cout << "no" << endl;
  }
	return 0;
}



Measured memory_bytes: 3120
#!/usr/bin/env python3
from queue import Queue
h, w = map(int, input().split())
s = [input() for _ in range(h)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

ans = 0
for sx in range(h):
    for sy in range(w):
        if s[sx][sy] == "#":
            continue

        q = Queue()
        q.put((sx, sy))
        dist = [[10 ** 9] * w for _ in range(h)]
        dist[sx][sy] = 0
        while not q.empty():
            cx, cy = q.get()
            for k in range(4):
                tx = cx + dx[k]
                ty = cy + dy[k]
                if not (0 <= tx < h and 0 <= ty < w and s[tx][ty] == "."):
                    continue
                if dist[tx][ty] > dist[cx][cy] + 1:
                    dist[tx][ty] = dist[cx][cy] + 1
                    q.put((tx, ty))

        for tx in range(h):
            for ty in range(w):
                if s[tx][ty] == ".":
                    ans = max(ans, dist[tx][ty])

print(ans)


Measured memory_bytes: 3944
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
map<ll,ll> prime(ll n){
	map<ll,ll> mp;
	ll maki = ll(sqrt(n));
	for(ll i=2;i<=maki;i++){
		while(n % i == 0){
			mp[i]++;
			n /= i;
		}
	}
	if(n > 1LL) mp[n]++;
	return mp;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    for(auto& i: prime(n)){
    	ll le = 1, ri = 1000, mid;
    	while(ri - le > 1LL){
    		mid = (le + ri) / 2;
    		if(i.second * 2 >= mid * (mid + 1)){
    			le = mid;
    		}else{
    			ri = mid;
    		}
    	}
    	ans += le;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
X = input()
Y = input()
dp = [[0 for j in range(len(Y)+1)] for i in range(len(X)+1)]
fxy = [[(0, 0) for j in range(len(Y)+1)] for i in range(len(X)+1)]
for i in range(len(X)):
    for j in range(len(Y)):
        if X[i] == Y[j]:
            dp[i+1][j+1] = dp[i][j] + 1
            fxy[i+1][j+1] = (i, j)
        elif dp[i+1][j] >= dp[i][j+1]:
            dp[i+1][j+1] = dp[i+1][j]
            fxy[i+1][j+1] = (i+1, j)
        else:
            dp[i+1][j+1] = dp[i][j+1]
            fxy[i+1][j+1] = (i, j+1)
ans = ''
px, py = -1, -1
while not(px == py == 0):
    cx, cy = fxy[px][py]
    if dp[px][py] != dp[cx][cy]:
        ans += X[cx]
    px, py = cx, cy
print(ans[::-1])
# for i in range(len(X)+1):
#     print(dp[i])
# for i in range(len(X)+1):
#     print(fxy[i])


Measured memory_bytes: 392840
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=a&&c<=b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1
#define sosuu 1000000007

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
int X;
  cin >>X;
  if(IsPrime(X)){
cout << X << endl;  
    return 0;
  }
  if(X%2==0)
    X++;
  while(IsPrime(X)==false){
  X+=2;
  }
  
cout << X << endl; 
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i+K-1]-h[i])
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))

Measured memory_bytes: 10828
#include <algorithm>
#include <utility> 
#include <iostream>
using namespace std;
int main()
{	
	int T, N, K, M, X[100000+10], ans[50+1], dis[1000000+10];
	cin >> T;
	for (int t=0; t<T; ++t) {
		cin >> N >> M;
		for (int i=0; i<N; ++i) cin >> X[i];
		for (int i=0; i<N-1; ++i) dis[i] = X[i+1]-X[i];
		ans[t] = X[N-1] - X[0];
		sort(dis,dis+(N-1));
		for (int i=0; i<M-1; i++){
			ans[t] = ans[t]-dis[N-i-2];		
		}
	}
	for (int t=0; t<T; ++t){
		cout << ans[t] << endl;
	}
	return 0;
}

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

long long k, a, b;

long long solve();

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

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long now = 1, ans = 0;
  now += min(a - 1, k);
  k -= min(a - 1, k);
  if(k <= 1)
    ans = now + k;
  else {
    if(b - a > 2) {
      now += (k / 2) * (b - a);
      k %= 2;
    }
    ans = now + k;
  }
  return ans;
}

Measured memory_bytes: 256
a, b, c, d = map(int,input().split())
turn_t = c//b
if c %  b!= 0:
    turn_t += 1
turn_a = a//d 
if a % d != 0:
    turn_a += 1
if turn_a >= turn_t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;cin>>s;
	bool fn = false;bool fS = false;bool fe = false;bool fw = false;
	for(int i = 0; i < s.size(); i++) {
		if (s[i] == 'N')fn = true;
		if (s[i] == 'S')fS = true;
		if (s[i] == 'E')fe = true;
		if (s[i] == 'W')fw = true;
	}
	if (fn ^ fS){
		cout << "No" << endl;
		return 0;
	}
	if (fe ^ fw){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {

    let mut scan = std::io::stdin();

    let mut line = String::new();

    /* 読み込んで  */
    let _ = scan.read_line(&mut line);
    /* 空白で分割してからベクタにまとめる */
    let vec: Vec<&str> = line.split_whitespace().collect();

    /* それぞれを変換 */
    let r: i32 = vec[0].parse().unwrap_or(0);
    let g: i32 = vec[1].parse().unwrap_or(0);
    let b: i32 = vec[2].parse().unwrap_or(0);

    let ans : &str =  if (r*100+g*10+b)%4==0 { "YES" } else { "NO" };
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N,R;
  cin>>N>>R;
  if(N>=10) {
cout<<R<<endl;
  }
else {
  cout<<R+100*(10-N) <<endl;
}
}


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

int main () {

    string s; cin >> s;
    ll q; cin >> q;
    bool reversed = false;
    while(q--) {
        int op; cin >> op;
        if(op == 2) {
            int f; cin >> f;
            string c; cin >> c;
            if(f == 1) {
                if(reversed) {
                    s.append(c);
                } else {
                    s.insert(0, c);
                }
            } else if(f == 2) {
                if(reversed) {
                    s.insert(0, c);
                } else {
                    s.append(c);
                }
            }
        } else {
            reversed = !reversed;
        }
        
        // cout << s << endl;
    }
    if(reversed) {
        for (int i=s.length()-1; i>=0; i--) 
            cout << s[i];  
    } else {
        cout << s;
    }
    return 0;
}

Measured memory_bytes: 900