akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int x[125252];

ll modpow(ll a, ll b){
    ll r = 1;
    while(b){
        if(b&1)r=r*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return r;
}
ll modinv(ll a){
    return modpow(a, MOD-2);
}

ll inv[125252];
ll isum[125252];
ll fact[125252];
ll ifact[125252];
ll ifsum[125252];
ll asum[125252];

int main(){
    scanf("%d", &n);
    REP(i,n)scanf("%d", x+i);
    inv[0] = 0;
    FOR(i,1,125252)inv[i] = modinv(i);
    FOR(i,1,125252)isum[i] = (isum[i-1] + inv[i]) % MOD;
    fact[0] = 1;
    FOR(i,1,125252)fact[i] = fact[i-1]*i%MOD;
    ifact[0] = 1;
    FOR(i,1,125252)ifact[i] = ifact[i-1]*inv[i]%MOD;
    FOR(i,2,125252)ifsum[i] = (ifsum[i-1] + ifact[i]) % MOD;

    FOR(i,1,125252){
        asum[i] = (asum[i-1] + modinv(1ll*i*(i+1)%MOD)) % MOD;
    }

    ll ans = 0;
    REP(l,n-1){
        ll p = inv[n-1-l];
        ans += (x[n-1] - x[l]) % MOD * p % MOD;
        ans %= MOD;
    }

    // REP(l,n)FOR(r,l+1,n-1){
    //     ll p = modinv(1ll*(r-l)*(r-l+1)%MOD);
    //     // ans += (x[r] - x[l]) % MOD * p % MOD;
    //     ans += (x[r]) % MOD * p % MOD;
    //     ans %= MOD;
    // }
    FOR(r,1,n-1){
        ans += x[r] * asum[r] % MOD;
        ans %= MOD;
    }
    REP(l,n-2){
        ans += MOD - x[l] * asum[n-2-l] % MOD;
        ans %= MOD;
    }

    ans = ans * fact[n-1] % MOD;
    // FOR(i,1,n)ans = ans * i % MOD;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 6528
let n = Scanf.scanf "%d\n" (fun x -> x)

let ar =
  Array.init (n - 1) (fun _ ->
      Scanf.scanf "%d %d %d\n" (fun c s f -> (c, s, f)) )


let () =
  for i = 0 to n - 2 do
    let c, s, f = ar.(i) in
    let tmp = ref (c + s) in
    for j = i + 1 to n - 2 do
      let nc, ns, nf = ar.(j) in
      if ns < !tmp then
        let ns' =
          if !tmp mod nf = 0 then !tmp else !tmp + nf - !tmp mod nf
        in
        tmp := ns' + nc
      else tmp := ns + nc
    done ;
    Printf.printf "%d\n" !tmp
  done ;
  Printf.printf "%d\n" 0

Measured memory_bytes: 896
def check(l):
    globals()
    for i in range(1,n):
        d = 1 if s[i]=='o' else -1
        l.append(l[i-1]*l[i]*d)
    d = 1 if s[0]=='o' else -1
    if l[-2]*l[0]*d==l[1] and l[-1]==l[0]:
        for i in l[:n]:
            c = 'S' if i == 1 else 'W'
            print(c, end='')
    return l[-2]*l[0]*d==l[1] and l[-1]==l[0]
n = int(input())
s = input()
tests = [[1,1],[1,-1],[-1,1],[-1,-1]]
for t in tests:
    if check(t):
        exit()
print(-1)

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

int main()
{
    string s;
    cin >> s;
    int a_ans = 0, z_ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'A')
        {
            a_ans = i;
            break;
        }
    }
    for (int i = s.size(); i >= 0; i--)
    {
        if (s[i] == 'Z')
        {
            z_ans = i;
            break;
        }
    }
    cout << z_ans - a_ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 3700
#include <stdio.h>
#define MAX 100000
int main(){
  int a,b,A[MAX]={-1},B[MAX],count=0,i,j,c,t;
  scanf("%d",&a);
  scanf("%d",&A[0]);
  for(i=1,c=1;i<a;i++){
    scanf("%d",&t);
    if(A[c-1]<t){A[c]=t;c++;}
  }

  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
  }
  i=c;
  for(i=0;i<b;i++){
    for(j=0;j<a;j++){
      if(A[j]==B[i]){count++;break;}
      if(A[j]>B[i]){break;}
    }
  }
  printf("%d\n",count);
  return 0;
}
//

Measured memory_bytes: 1200
//Create Time: 2018-05-08 11:30:47
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <functional>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility>
#include <complex>
#include <cassert>
#include <climits>
#include <iterator>
#include <tuple>
using namespace std;
#define snuke(i,x) for (__typeof((x).begin()) i = (x).begin(); i != (x).end(); ++i)
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,n,a) for (int i=(n)-1;i>=(a);i--)
// #define OUT(x) std::cout<<(#x)<<":"<<(x)<<std::endl
// #define TST(x) std::cout<<(#x)<<":"<<(x)<<" "
#define OUT(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);OUT_TST("\n",_it,args);}
#define TST(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);OUT_TST("",_it,args);}
#define SZ(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define unq(x) sort(all(x)),(x).erase(unique(all(x)),(x).end())
#define mem(f,x) memset((f), (x), sizeof(f))
#define clr(f) mem(f,0)
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define DEBUG
void OUT_TST(string s,istream_iterator<string> it) {cerr<<s;}
template<typename T, typename... Args> void OUT_TST(string s,istream_iterator<string> it,T a,Args... args){cerr<<*it<<"="<<a<<" ";OUT_TST(s,++it,args...);}
template<class T> void rd(T&ret){ret=0;bool ok=0,u=0;for(;;){int c=getchar();if(c>='0'&&c<='9')ret=(ret<<3)+(ret<<1)+c-'0',ok=1;else if(c=='-')u=1;else if(ok){if(u)ret*=-1;return;}}}
long long powmod(long long p,long long n,long long mod){long long ret=1;for(;n;n>>=1){if(n&1)ret=ret*p%mod;p=p*p%mod;}return ret;}
template <class T> bool chmin(T& a, const T &b) {return b < a? a = b, 1: 0;}
template <class T> bool chmax(T& a, const T &b) {return b > a? a = b, 1: 0;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef tuple<int,int,int> tp;
/****head****/
const int N=2e5+9;
int nxt[N][27],stk[N],top,n,last[27];
char s[N],ans[N];
int main(){
    scanf("%s",s);n=strlen(s);
    rep(i,0,26)last[i]=n;
    stk[top++]=n;
    int cnt=0;
    per(i,n,0){
        rep(j,0,26)nxt[i][j]=last[j];
        int x=s[i]-'a';
        if(last[x]>=stk[top-1]){
            ++cnt;
        }
        last[x]=i;
        if(cnt==26){
            stk[top++]=i;
            cnt=0;
        }
    }
    int p,m=0;
    rep(i,0,26){
        if(last[i]>=stk[top-1]){
            p=last[i];
            ans[m++]=i+'a';
            break;
        }
    }
    per(i,top-1,0){
        rep(j,0,26){
            if(nxt[p][j]>=stk[i]){
                p=nxt[p][j];
                ans[m++]=j+'a';
                break;
            }
        }
    }
    ans[m]=0;
    puts(ans);
    return 0;
}


Measured memory_bytes: 21632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <cstring>

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

#define INF (int)1e9+7

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

using namespace std;

int main(){
    int a[5];
    int k;

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

    bool flag = true;

    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            if(a[j] - a[i] > k) flag = false;        
        }
    }

    if(flag) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    
    return 0;
}

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

using namespace std;

long long solve(long long a, long long b){
	if(a == 0 || b == 0) return 0;
	if(a > b){
		return solve(a % b, b) + b * (a / b) * 2;
	}else{
		return solve(a, b % a) + a * (b / a) * 2;
	}
}
int main(){
	long long n,x;
	cin >> n >> x;
	cout << solve(x, n - x) + n - __gcd(n, x);
}

Measured memory_bytes: 384
from bisect import*
class SqrtSet:
    def __init__(self,block_limit=201):
        self.key=[]
        self.child=[[]]
        self.block_limit=block_limit
    def le(self,key):
        ret=key
        i=bisect_left(self.key,key)
        if i:ret=self.key[i-1]
        block=self.child[i]
        i=bisect_left(block,key)
        if i:ret=block[i-1]
        return ret
    def ge(self,key):
        ret=key
        i=bisect(self.key,key)
        if i<len(self.key):ret=self.key[i]
        block=self.child[i]
        i=bisect(block,key)
        if i<len(block):ret=block[i]
        return ret
    def insert(self,key):
        i=bisect(self.key,key)
        block=self.child[i]
        insort(block,key)
        if len(block)==self.block_limit:
            sep=self.block_limit//2
            self.key.insert(i,block[sep])
            self.child.insert(i+1,block[sep+1:])
            self.child[i]=block[:sep]
def main():
    n,*p=map(int,open(0).read().split())
    l=[0]*n
    for i,v in enumerate(p,1):l[v-1]=i
    t=SqrtSet()
    insert,le,ge=t.insert,t.le,t.ge
    insert(0),insert(n+1)
    a=0
    for i,v in list(enumerate(l,1))[::-1]:
        f,b=ge(v),le(v)
        g,c=ge(f),le(b)
        a+=i*((f-v)*(b-c)+(v-b)*(g-f))
        insert(v)
    print(a)
main()

Measured memory_bytes: 101832
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<char> s(3);
    bool flag = false;
    for(int i = 0; i < 3; i++)
        cin >> s[i];
    for(int i = 0; i < 2; i++){
        if(s[i] != s[i + 1])
            flag = true;
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
}

Measured memory_bytes: 256
import math

A,B,degree=map(int,input().split())
C=math.sqrt(A*A+B*B-2*A*B*math.cos(math.radians(degree)))
S=A*B*math.sin(math.radians(degree))/2
h=S*2/A
print(S)
print(A+B+C)
print(h)




Measured memory_bytes: 5712
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    string s;
    cin>>s;
    if(s.size()>=10){
        cout<<"NO"<<endl;
        return 0;
    }
    string ss = "";
    rep(i,s.size()){
        if(s[i]!='A'){
            ss += s[i];
        }
        if(i+1<s.size()&&s[i]=='A'&&s[i+1]=='A'){
            cout<<"NO"<<endl;
            return 0;
        }
        if(s[i]=='K'&&s[i+1]=='A'&&i+1<s.size()){
            cout<<"NO"<<endl;
            return 0;
        }
        if(s[i]=='I'&&s[i+1]=='A'&&i+1<s.size()){
            cout<<"NO"<<endl;
            return 0;
        }
       
    }
    if(ss=="KIHBR"){
        cout<<"YES"<<endl;
        return 0;
    }else{
        cout<<"NO"<<endl;
        return 0;
    }


return 0;
}


Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s = list(input()[:-1])[::-1]
    N = len(s)
    p10 = [1]
    tmp = 1
    for _ in range(N - 1):
        tmp = tmp * 10 % 2019
        p10.append(tmp)
    mod = []
    tmp = 0
    for num, p in zip(s, p10):
        tmp = (tmp + int(num) * p) % 2019
        mod.append(tmp)

    mod.sort()
    mod.insert(0, 0)

    ans = 0
    count = 1
    for i in range(1, N + 1):
        if mod[i] == mod[i - 1]:
            count += 1
        else:
            ans += count * (count - 1) // 2
            count = 1
    ans += count * (count - 1) // 2
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 95968
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * b / g;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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 COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using Graph = vector<VE>;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h; cin >> h;
	int n; cin >> n;
	rep(i, n) {
		int a; cin >> a; h -= a;
	}
	Yes(h <= 0);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = 0
for n in range(1,N+1):
    if n%10==0:continue
    s = str(n)
    if s[0]==s[-1]:ans+=1
    for i in range(10):
        a = int(s[-1]+"9"*i+s[0])
        b = int(s[-1]+"0"*i+s[0])
        if a<=N:ans+=pow(10,i)
        elif b<=N:
            ans+=(N-b)//10+1
        else:
            break
print(ans)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    cout << (A % 2 == 0 ? -1 : 0) << '\n';
    return 0;
  }
  int res = 0;
  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    int a, b, c;
    a = (B + C) / 2;
    b = (A + C) / 2;
    c = (A + B) / 2;
    A = a;
    B = b;
    C = c;
    res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int my_6shin(int a){
    int sum=0;
    int x;
    while(1){
        x=a%6;
        sum+=x;
        a=(a-x)/6;
        if(a==0)break;
    }
    return sum;
}
int my_9shin(int a){
    int sum=0;
    int x;
    while(1){
        x=a%9;
        sum+=x;
        a=(a-x)/9;
        if(a==0)break;
    }
    return sum;
}
int main(void){
    int N;cin>>N;
    int ans=100000;
    for(int i=0;i<N+1;i++){
        ans=min(ans,my_6shin(i)+my_9shin(N-i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)
mod=10**9+7
MAX=10**5+100
g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(pow(num_1,mod-2,mod))
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

N,K = I()
A = l()
A.sort()
ans = 0
for i in range(N-K+1):
    ans -= A[i]*cmb(N-i-1,K-1)
    ans %= mod
A = A[::-1]
for i in range(N-K+1):
    ans += A[i]*cmb(N-i-1,K-1)
    ans %= mod
print(ans%mod)

Measured memory_bytes: 97440
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int D=sc.nextInt();
		int X=sc.nextInt();
		int[] A=new int[N];
		for(int i=0;i<A.length;i++) {
			A[i]=sc.nextInt();
		}
		int sum=0;
		for(int i=0;i<A.length;i++) {
			sum++;
			sum+=(D-1)/A[i];
		}
		System.out.println(sum+X);


	}
}


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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  
  int n;
  for (int i=1 ; ; i++){
    if (a*i > b){
      n = i-1;
      break;
    }
  }
  
  if (n > c)
    cout << c << endl;
  else
    cout << n << endl;
}

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

using namespace std;
using ll = long long;

int main() {
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    int ans=60*h2+m2-60*h1-m1;
    cout<<ans-k<<endl;
    return 0;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        Map<Integer, List<Integer>> map = new HashMap<>();
        Integer[] parr = new Integer[m];
        Integer[] yarr = new Integer[m];
        for(int i = 0; i < m;i++){
            int p = sc.nextInt();
            int y = sc.nextInt();
            parr[i] = p;
            yarr[i] = y;

            if(map.containsKey(p)){
                map.get(p).add(y);
            } else {
                List<Integer> list = new ArrayList<>();
                list.add(y);
                map.put(p, list);
            }
        }

        Map<Integer, Map<Integer, String>> ansmap = new HashMap<>();
        for(Integer key : map.keySet()){
            List<Integer> list = map.get(key);
            Collections.sort(list);
            Map<Integer, String> tmpmap = new HashMap<>();
            int index = 1;
            String pre = String.format("%06d",key);
            for(Integer num : list){
                tmpmap.put(num, pre + String.format("%06d",index++));
            }
            ansmap.put(key, tmpmap);
        }

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < m;i++){
            sb.append(ansmap.get(parr[i]).get(yarr[i]));
            sb.append("\n");
        }
        System.out.println(new String(sb));
    }

}

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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int aoki[100005];

int main() {
	int n, u, v, a, b, aoki[100005], taka[100005], ans = 0;
	vector<int> adj[100005];
	queue<int> q;
	scanf("%d %d %d", &n, &u, &v);
	for (int i = 1; i < n; i++) {
		scanf("%d %d", &a, &b);
		adj[a].pb(b);
		adj[b].pb(a);
	}
	memset(aoki, -1, sizeof aoki);
	memset(taka, -1, sizeof taka);
	aoki[v] = 0;
	q.push(v);
	while (!q.empty()) {
		a = q.front();
		q.pop();
		b = adj[a].size();
		for (int i = 0; i < b; i++) {
			v = adj[a][i];
			if (aoki[v] == -1) {
				aoki[v] = aoki[a] + 1;
				q.push(v);
			}
		}
	}
	taka[u] = 0;
	q.push(u);
	while (!q.empty()) {
		a = q.front();
		q.pop();
		b = adj[a].size();
		if (b == 1) {
			ans = max(ans, aoki[a] - 1);
		}
		for (int i = 0; i < b; i++) {
			v = adj[a][i];
			if ((taka[v] == -1) && (taka[a] + 1 < aoki[v])) {
				taka[v] = taka[a] + 1;
				q.push(v);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <iomanip> // << fixed << precision(10)
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"
#define NEWMAT(N, M, ini) MAT(N, vector<lint>(M, ini))
#define MOD 1000000007
#define INF 1000000000000

#define lint_in(A) lint A; cin >> A

typedef long long lint;
typedef pair<lint, lint> P;
typedef vector<lint> V;
typedef vector<vector<lint>> MAT;
bool lessPair(const P& l, const P& r){return l.second < r.second;}

void warshall_floyd(int n, MAT& d) {
  for (int k = 0; k < n; k++){
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

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

  lint_in(N);lint_in(M);lint_in(L);

  MAT d1 = NEWMAT(N, N, INF);
  REP(i, N) d1[i][i] = 0;

  REP(i, M) {
    lint_in(A);lint_in(B);lint_in(C);
    d1[A-1][B-1]=C;
    d1[B-1][A-1]=C;
  }

  warshall_floyd(N, d1);

  MAT d2 = NEWMAT(N, N, INF);

  REP(i, N) REP(j, N) {
    if(d1[i][j] <= L) d2[i][j] = 1;
  }
  REP(i, N) d2[i][i] = 0;

  warshall_floyd(N, d2);

  lint_in(Q);

  REP(_, Q) {
    lint_in(s);lint_in(t);

    lint res = -1;
    if(d2[s-1][t-1] != INF) res = d2[s-1][t-1]-1;
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 1920
import heapq as hq

N, M = map(int, input().split())
A = list(map(int, input().split()))

B = [-i for i in A]
hq.heapify(B)
for i in range(M):
    x = hq.heappop(B)
    hq.heappush(B, -(-x//2))
print(-1*sum(B))

Measured memory_bytes: 14180
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		long sum = 0;

		int num = sc.nextInt();

		for(int i = 0;i<num;i++){

			sum += sc.nextInt();

		}

		System.out.println(sum/num);

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ll l;
	cin >> l;
	double side = l / 3.0;
	cout << side * side * side;
	return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  int n, y;
  cin >> n >> y;
  rep(i,n+1) {
    rep(j,n+1) {
      int k = n - i - j;
      if(k < 0) continue;
      if(i*10000 + j*5000 + k*1000 == y) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    //ここから累積和のやつ
    long[] s = new long[N + 1];
    for(int i = 1; i <= N; i++){
      s[i] = sc.nextLong();
      s[i] += s[i - 1];
    }
    //累積和のやつここまで

    int L = 1;
    int R = 3; //切り口Lと切り口Rを定義
    long ans = s[N];

    for(int i = 2; i < N - 1; i++){
      long last = s[N];
      while(L < i){ //切り口Lは中央より左に来る
        long dist = Math.abs(s[i] - s[L]*2); //1番左の塊の長さと左から2番目の塊の長さとの差の絶対値
        if(dist > last){break;} //distが単調増加しはじめたら探索をやめる
        else{last = dist; //distが単調減少している間はlastを更新し探索続行
        L++; //切り口Lを右に寄せる
        }
      }
      L--; //単調減少するギリギリのところにLを戻す

      //ここからは同様のことをRでやる
      last = s[N];
      while(R < N){
        long dist = Math.abs(s[N] + s[i] - s[R]*2);
        if(dist > last){break;}
        else{last = dist;
        R++;
        }
      }
      R--;
      //同様のやつここまで

      long max = Math.max(Math.max(Math.max(s[L], s[i] - s[L]), s[R] - s[i]), s[N] - s[R]);
      long min = Math.min(Math.min(Math.min(s[L], s[i] - s[L]), s[R] - s[i]), s[N] - s[R]);
      ans = Math.min(max - min, ans);
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 72080
h, w = map(int,input().split())
maps = [None]*h
for i in range(h):
    maps[i] = input()
hashes = []
for i in range(h):
    if "#" in maps[i]:
        hashes.append(i)
white = []
for i in range(w):
    flag = 0
    for j in range(h):
        if maps[j][i] == "#":
            flag = 1
    if flag == 1:
        white.append(i)
for i in hashes:
    for j in white:
        print(maps[i][j],end="")
    print()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	u64 S;
	cin >> S;

	u64 mod = pow(10, 9) + 7;

	vector<u64> dp(4);
	dp[0] = 1;
	u64 sum_dp = 0;

	for(s64 i=3; i<=S; i++) {
		s64 i3 = (i - 3) %  4;
		sum_dp = (dp[i3] + sum_dp) % mod;
		dp[i%4] = sum_dp % mod;
	}
	
	cout << dp[S%4] << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n;
  cin >> n;
  vector <pair <ll, ll>> v(n);
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    v.at(i) = make_pair(a+b, a-b);
  }
  sort(v.begin(), v.end());
  ll ans = 1, l = v.at(0).first;
  rep(i, n) {
    if (l <= v.at(i).second) {
      ans++;
      l = v.at(i).first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long A, long long B){
    cout << max(A - 2*B, 0LL) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int dis[N],n;
deque<int>q;
int main()
{
	scanf("%d",&n);
	memset(dis,0x3f,sizeof(dis));
	dis[1]=1;
	q.push_back(1);
	while(1)
	{
		int k=q.front(),x=k*10%n,y=(k+1)%n;
		q.pop_front();
		if(k==0)
			break;
		if(dis[x]>dis[k])
		{
			dis[x]=dis[k];
			q.push_front(x);
		}
		if(dis[y]>dis[k]+1)
		{
			dis[y]=dis[k]+1;
			q.push_back(y);
		}
	}
	printf("%d\n",dis[0]);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int n, m, a, b;
vector<int> to[10];
vector<int> arr;


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

  rep(i, m){
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i, n){
    arr.push_back(i);
  }
  int ans=0;
  do {
    bool flag=true;
    rep(i, n-1){
      if(find(to[arr[i]].begin(), to[arr[i]].end(), arr[i+1])==to[arr[i]].end()){
        flag=false;
        break;
      }
    }
    if(flag)ans++;
  } while (next_permutation(arr.begin()+1, arr.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

class MyLong{
public:
	int n[10];
	MyLong operator+=(MyLong myLong){
		int i;
		for(i=0;i<9;i++){
			this->n[i]+=myLong.n[i];
			if(this->n[i]>=1000000){
				this->n[i+1]++;
				this->n[i]-=1000000;
			}
		}
		return *this;
	}
};

MyLong dp[110][30];
int x[110];

int main() {
	int n;
	cin>>n;
	int i;
	for(i=0;i<n;i++)cin>>x[i];
	int j;
	dp[0][x[0]].n[0]=1;
	for(i=1;i<n-1;i++){
		for(j=0;j<=20;j++){
			if(j-x[i]>=0)dp[i][j]+=dp[i-1][j-x[i]];
			if(j+x[i]<=20)dp[i][j]+=dp[i-1][j+x[i]];
//cout<<i<<" "<<j<<" "<<dp[i][j].n[0]<<endl;
		}
	}
	int go=0;
	for(i=9;i>=0;i--){
		if(dp[n-2][x[n-1]].n[i]>0){
			go++;
		}
		if(go==1){
			cout<<dp[n-2][x[n-1]].n[i];
			go++;
		}else if(go>1){
			printf("%06d",dp[n-2][x[n-1]].n[i]);
		}
	}
	cout<<endl;
	return 0;
}

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

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

	int x1 = (int)((float)A / 0.08f);
	if (x1 * 0.08f < A) x1++;
	int x2 = (int)((float)B / 0.1f);
	if (x2 * 0.1f < B) x2++;

	while (((int)(x1 * 0.08f) <= A) 
		&& ((int)(x2 * 0.1f) <= B)) 
	{
		if (x1 == x2)
		{
			cout << x1;
			return 0;
		}
		else
		{
			if (x1 < x2) 
			{
				x1++;
			}
			else 
			{
				x2++;
			}
		}
	}
	cout << -1;

	return 0;
}

Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if n == 0:
        break

    count = 0
    for n1 in range(1, n+1):
        for n2 in range(n1+1, n+1):
            for n3 in range(n2+1, n+1):
                if n1 + n2 + n3 == x:
                    count += 1

    print(count)

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

typedef long long int lli;

const int MOD = 1e9 + 7;

lli powTable[401][401]; //[a][b] has a^b
lli sumPowTable[401][401]; //[a][b] has sum(i^b), i = 1 to a

lli dp[401][401];

int n, c;
int a[401];
int b[401];

int main() {
	ios_base::sync_with_stdio(false);
	for(int i = 0; i < 401; i++) for(int j = 0; j < 401; j++) {
		powTable[i][j] = sumPowTable[i][j] = 0;
	}
	for(int i = 0; i < 401; i++) {
		powTable[i][0] = 1; //Yes, we're assuming 0^0 = 1.
		for(int j = 1; j < 401; j++) {
			powTable[i][j] = i*powTable[i][j-1];
			powTable[i][j] %= MOD;
		}
	}
	for(int j = 0; j < 401; j++) {
		sumPowTable[0][j] = powTable[0][j];
		for(int i = 1; i < 401; i++) {
			sumPowTable[i][j] = sumPowTable[i-1][j] + powTable[i][j];
			sumPowTable[i][j] %= MOD;
		}
	}

	cin >> n >> c;

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

	for(int i = 0; i<=n; i++) {
		if(i==0) {
			for(int j=0; j<=c; j++) {
				dp[0][j] = ((j==0)?1:0);
			}
		} else {
			for(int j=0; j<=c; j++) {
				for(int k=0; j+k <=c; k++) {
					dp[i][j+k] += (sumPowTable[b[i-1]][k] - sumPowTable[a[i-1]-1][k])*dp[i-1][j];
					dp[i][j+k] %= MOD;
					if(dp[i][j+k] < 0) dp[i][j+k] += MOD;
				}
			}
		}
	}

	cout << dp[n][c] << endl;

	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long

using namespace std;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N,0);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    vector<pair<ll,ll>> BC;
    int b,c;
    for(int i=0;i<M;i++){
        cin >> b >> c;
        BC.push_back(make_pair(c,b));
    }
    sort(BC.rbegin(),BC.rend());
    ll cnt=0;
    ll keep=0;
    for(ll i=0;i<M;i++){
        cnt=0;
        for(ll j=keep;j<N;j++){
            if(A[j]<BC[i].first){
                while(A[j]<BC[i].first&&cnt<BC[i].second){
                    cnt++;
                    A[j]=BC[i].first;
                    j++;
                    keep=j;
                }
            }
            if(A[j]>BC[i].first){
                break;
            }
            if(cnt>=BC[i].second){
                break;
            }
        }
    }
    ll ans=0;
    for(int i=0;i<N;i++){
        ans+=(ll)A[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3188
import fractions
A, B, C, D = map(int, input().split())
E = C*D//fractions.gcd(C, D)
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
Z = B//E - (A-1)//E
print(B-A+1-X-Y+Z)

Measured memory_bytes: 5048
H, W = list(map(int, input().split()))
Ch, Cw = list(map(lambda x:int(x)+1, input().split()))
Dh, Dw = list(map(lambda x:int(x)+1, input().split()))
S = []

S.append(list('#'*(W+4)))
S.append(list('#'*(W+4)))
for i in range(H):
    S.append(list('#'*2+input()+'#'*2))
S.append(list('#'*(W+4)))
S.append(list('#'*(W+4)))

from collections import deque

q1 = deque()
q2 = deque()
inf = 10**10


#cost
T = []
for w in S:
    T_W = [-1 if s=='#' else inf for s in w]
    T.append(T_W)

# print(T)
move1 = [(1,0),(0,1),(-1,0),(0,-1)]
move2 = [(i-2,j-2) for i in range(5) for j in range(5)]
move2.remove((0,0))
for t in move1:
    move2.remove(t)
d = 0
h, w = Ch, Cw
T[Ch][Cw] = d
q1.append((h,w))
q2.append((h,w))

ans = -1

while len(q2)>0 or len(q1)>0:
    while len(q1)>0:
        v = q1.popleft()
        for t in [(1,0),(0,1),(-1,0),(0,-1)]:
            h, w = v[0]+t[0], v[1]+t[1]
            if T[h][w] > d:
                if (h,w) == (Dh,Dw):
                    ans = d
                T[h][w] = d
                q1.append((h,w))
                q2.append((h,w))

    d += 1
    while len(q2)>0:
        v = q2.popleft()
        for t in move2:
            h, w = v[0]+t[0], v[1]+t[1]
            if T[h][w] > d:
                if (h,w) == (Dh,Dw):
                    ans = d
                T[h][w] = d
                q1.append((h,w))
    q2.extend(q1)



print(ans)



Measured memory_bytes: 134404
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]+[0]
    bs.sort(reverse = True)
    i = 0
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

    print(res)





if __name__ == '__main__':
    main()


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

int main() {
	string str;
	cin >> str;
	int n ;
	cin >> n;
	for(int i = 0; i < n; ++i){
		string com;
		int a, b;
		cin >> com; cin >> a; cin >> b;
		if(com == "replace"){
			string p;
			cin >> p;
			str = str.substr(0, a) + p + str.substr(b + 1);
		}
		if(com == "reverse"){
			for(int j = 0; j < (b - a + 1) / 2; ++j){
				swap(str[a + j], str[b - j]);
			}
		}
		if(com == "print"){
			cout << str.substr(a, b - a + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
<?php
list($a,$v)=explode(" ",trim(fgets(STDIN)));
list($b,$w)=explode(" ",trim(fgets(STDIN)));
$t=trim(fgets(STDIN));
if($a<$b){
  echo ($a+($v*$t)>=$b+($w*$t))?"YES":"NO";
}else{
  echo ($a-($v*$t)<=$b-($w*$t))?"YES":"NO";
}

Measured memory_bytes: 16100
s = input().split()
n = int(s[0])
a = int(s[1])
b = int(s[2])

sums = []

for i in range(1, n + 1):
    x = i
    check = 0
    while (x > 0):
        y = x % 10
        x = int(x / 10)
        check += y
    if a <= check <= b:
        sums.append(i)

answer = 0
for i in range(len(sums)):
    answer += sums[i]

print(answer)

Measured memory_bytes: 9244
#include <iostream>

using namespace std;

int main() {
   char S[105];
   long long K;
   cin >> S;
   cin >> K;
   K=K-1;
   for (int i=0;S[i] != '\0';i++) {
      if (K == i) {
	 cout << S[i] << endl;
	 return 0;
      }
      if (S[i] != '1') {
	 cout << S[i] << endl;
	 return 0;
      }

   }
   return 0;
}


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

using namespace std;
using ll = long long;

ll INF = 1000000000;

int main()
{
    ll n, W;
    cin >> n >> W;
    vector<ll> v(n), w(n);
    for(ll i = 0; i < n; i++)cin >> v[i] >> w[i];
    vector<vector<ll>> dp(n + 1,vector<ll>(120000, -INF)); //dp[i][j] := i個目まで観た時に重さiでの最大の価値
    for(ll i = 0; i <= n; i++)dp[i][0] = 0;

    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < 100100; j++){
            dp[i + 1][j + w[i]] = max(dp[i][j] + v[i], dp[i][j + w[i]]);
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
        }
    }

    ll nax = -INF;
    for(ll i = 0; i <= W; i++)nax = max(nax, dp[n][i]);
    if(nax == -INF)assert(0);
    cout << nax << endl;
}


Measured memory_bytes: 98712
#include <stdio.h>

int main(void)
{
	int n, c, f;
	int i;
	
	while (scanf("%d", &n), n){
		c = 0;
		for (i = 5; i <= n; i += 5){
			f = i;
			while (f % 5 == 0){
				c++;
				f /= 5;
			}
		}
		printf("%d\n", c);
	}
	return (0);
}

Measured memory_bytes: 600
import numpy as np

n,m = map(int, input().split())

connect = np.zeros((n,n))

for i in range(m):
    a, b = map(int, input().split())
    connect[a-1, b-1] = 1
    connect[b-1, a-1] = 1

notbridge = 0


for i in range(n):
    for j in range(n):
        if connect[i,j] == 1:
            connect[i,j] = 0
            connect[j,i] = 0
            stack =[1]
            visited = [1]
            while stack:
                p = stack.pop()
                for k in range(n):
                    if connect[p,k] == 1:
                        if k not in visited:
                            stack.append(k)
                            visited.append(k)
            if len(visited) == n:
                notbridge += 1
            connect[i,j] = 1
            connect[j,i] = 1



print(m-notbridge//2)




Measured memory_bytes: 21148
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n+1, vector<int>(n+1, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%d", &v[i+1][j+1]);
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= n; ++j) {
            v[i+1][j] += v[i][j];
        }
    }
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < n; ++j) {
            v[i][j+1] += v[i][j];
        }
    }
    int ans = -INF<int>;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = i+1; k <= n; ++k) {
                for (int l = j+1; l <= n; ++l) {
                    ans = max(ans, v[k][l]-v[k][j]-v[i][l]+v[i][j]);
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  if(s.size()<26){
    int a[26];
    for(int i=0;i<26;i++)a[i]=0;
    for(int i=0;i<s.size();i++)a[s[i]-'a']++;
    for(int i=0;i<26;i++){
      if (a[i]==0){
        s+='a'+i;
        break;
      }
    }
    cout << s <<endl;
  }
  else{
    if (s=="zyxwvutsrqponmlkjihgfedcba")cout << -1 <<endl;
    else{
      int count=0;
      for(int i=s.size()-1;i>=0;i--){
        if(s[i-1]>s[i])count++;
        else break;
      }
      s.erase(s.end()-1-count,s.end());
      int a[26];
      for(int i=0;i<26;i++)a[i]=0;
      for(int i=0;i<s.size();i++)a[s[i]-'a']++;
      for(int i=0;i<26;i++){
        if (a[i]==0 && s[s.size()-1]<'a'+i){
          s.pop_back();
          s+='a'+i;
          break;
        }
      }
      cout <<s <<endl;
    }
  }
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    char a[n][n], b[m][m];

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

    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> b[i][j];
        }
    }
    int /*my,mx,*/c=0;
    for (int ny = 0; ny < n; ny++)
    {
        for (int nx = 0; nx < n; nx++)
        {
            for (int my = 0; my < m; my++)
            {
                for (int mx = 0; mx < m; mx++)
                {   
                    if(a[ny+my][nx+mx]==b[my][mx]) c++;
                }
            }
            if(c==m*m) 
            {
                cout << "Yes" << endl;
                return 0;
            }
            /*cout << ">>>" << 'n' << ny+my << ',' << nx+mx << '|' << 'm' << my << ',' << mx << ':' << a[ny+my][nx+mx] << '|' << b[my][mx] << "C=" << c << endl;*/
            c = 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] s=br.readLine().split(" ");
        int K=Integer.parseInt(s[0]);
        int N=Integer.parseInt(s[1]);
        int arr[]=new int[2*N];
        StringTokenizer st=new StringTokenizer(br.readLine()," ");
        for(int i=0;st.hasMoreTokens();i++){
            arr[i]=Integer.parseInt(st.nextToken());
            arr[N+i]=K+arr[i];
        }
        int ans=Integer.MAX_VALUE;
        for(int i=0;i<N;i++){
            int dist=arr[N-1+i]-arr[i];
            if(dist<ans) ans=dist;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 45908
# -*- coding: utf-8 -*-
import itertools

def part_sum(S, clist):
    start = 0
    sum = 0
    for c in clist:
        sum += int(S[start:c])
        start = c
    sum += int(S[start:])
    return sum

def main():
    s = input()
    # output = int(input())
    length = len(s)
    numlist = list(range(1, length))
    ans = 0
    for i in range(length):
        combi = list(itertools.combinations((numlist), i))
        for clist in combi:
            clist = list(clist)
            ans += part_sum(s, clist)
    print(ans)
    # if ans == output:
    #     print('OK')
    # else:
    #     print('No')
                
            
        
    
if __name__ == '__main__':
    main()

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

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

using namespace std;

int n;

void dfs(string s){
	if(s.length()==n){ cout<<s<<'\n'; return; }
	char mx=*max_element(s.begin(),s.end());
	for(char c='a';c<=mx+1;c++) dfs(s+c);
}

int main(){ cin>>n; dfs("a"); return 0; }


Measured memory_bytes: 1536