akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR(i,x,y) for(int i=(x),i##END=(y);i<=i##END;++i)
#define DOR(i,x,y) for(int i=(x),i##END=(y);i>=i##END;--i)
template<typename T,typename _T>inline bool chk_min(T &x,const _T y){return y<x?x=y,1:0;}
template<typename T,typename _T>inline bool chk_max(T &x,const _T y){return x<y?x=y,1:0;}
typedef long long ll;
const int P=1e9+7;
const int N=100005;
template<const int maxn,const int maxm,typename T>struct LinkedList
{
	int head[maxn],nxt[maxm],tot;T to[maxm];
	LinkedList(){clear();}
	T &operator [](const int x){return to[x];}
	void clear(){memset(head,-1,sizeof(head)),tot=0;}
	void add(int u,T v){to[++tot]=v,nxt[tot]=head[u],head[u]=tot;}
	#define EOR(i,G,u) for(int i=G.head[u];~i;i=G.nxt[i])
};
LinkedList<N,N<<1,int>G;
int n,K;
int ans=1;

void dfs(int u,int f,int d,int r)
{
	ans=1ll*ans*std::max(0,K-std::min(2,d)-r)%P;
	int R=0;
	EOR(i,G,u)
	{
		int v=G[i];
		if(v==f)continue;
		dfs(v,u,d+1,R);
		R++;
	}
}

int main()
{
	scanf("%d%d",&n,&K);
	FOR(i,1,n-1)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		G.add(u,v),G.add(v,u);
	}
	dfs(1,0,0,0);
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;
const int MAXN = 1e5 + 10;
int n, m, path[MAXN], sz;
bool vis[MAXN];
vector<int> adj[MAXN];

void dfs(int v){
    if (!vis[v])
        path[sz++] = v;
    vis[v] = 1;
    for (int u:adj[v])
        if (!vis[u]){
            dfs(u);
            break;
        }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    while (m--){
        int u, v;	cin >> u >> v, u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    dfs(0);

    reverse(path, path + sz);
    dfs(0);
    
    cout << sz << "\n";
    for (int i = 0; i < sz; i++)
        cout << path[i]+1 << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0; i < (n); ++i)
 
    using namespace std;
     
    int main(){
        int K,N;
        cin >> K >> N;

        vector<int> place(N);

        REP(i,N) cin >> place[i];
        place.push_back(place[0]+K);

        int max_cost = 0;
        REP(i,N){
            max_cost = max(max_cost,place[i+1]-place[i]);
        }
 
        int ans = K - max_cost;
 
        cout << ans << endl;
     
        return 0;
    }

Measured memory_bytes: 1792
# -*- coding:utf-8 -*-
def solve():
    import sys
    sys.setrecursionlimit(100*100)

    anss = []
    while True:
        W, H = list(map(int, input().split()))

        if W==0 and H==0:
            break

        grid = [[] for _ in range(H)]
        for h in range(H):
            Cs = list(map(int, input().split()))
            grid[h] = Cs

        visited = [[0 for _ in range(W)] for __ in range(H)]  # 探索済みか？

        def dfs(h, w, depth):
            if w<0 or h<0 or w>=W or h>=H:
                return 0

            if visited[h][w] == 1:
                return 0
            visited[h][w] = 1

            if grid[h][w] == 0:
                return 0

            ret = 0
            for hh in range(h-1, h+2):
                for ww in range(w-1, w+2):
                    ret += dfs(hh, ww, depth+1)

            return ret+depth

        ans = 0
        for h in range(H):
            for w in range(W):
                if dfs(h, w, grid[h][w]) != 0:
                    ans += 1

        anss.append(ans)

    for ans in anss:
        print(ans)


if __name__ == "__main__":
    solve()



Measured memory_bytes: 8808
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

b = [0] * (n + 1)
for i in a:
    b[i] = 1
    
l_s = 0
r_s = 0
for i in range(x + 1):
    l_s += b[i]
    
for i in range(x, n + 1):
    r_s += b[i]
print(min(l_s, r_s))

Measured memory_bytes: 3064
from collections import deque
import numpy as np
H, W = map(int, input().split())
c = np.array([list(map(int, input().split())) for i in range(10)])
A = [list(map(int,input().split())) for i in range(H)]
d = c[:, 1]
d[1] = 0
ans = 0
for i in range(10):
    if i == 1:
        continue
    q = deque([[i, 0]])
    while len(q) > 0:
        p = q.popleft()
        d[i] = min(d[i], p[1] + c[p[0]][1])
        for j in range(10):
            if j == p[0] or j == 1:
                continue
            if p[1] + c[p[0]][j] < d[i]:
                q.append([j, p[1] + c[p[0]][j]])

for i in range(H):
    for j in range(W):
        if A[i][j] >= 0:
            ans += d[A[i][j]]
print(ans)

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

using namespace std;

#define ll long long

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s, t;
	int slen, tlen, dp[3005][3005]={0};
	cin>>s;
	cin>>t;
	slen = s.length();
	tlen = t.length();
	s = " "+s;
	t = " "+t;
	for(int i=1; i<=slen; i++){
		for(int j=1; j<=tlen; j++){
			if(s[i] == t[j]){
				dp[i][j]= dp[i-1][j-1] +1;
			}
			else{
				dp[i][j]= max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	// cout<<"  ";
	// for(auto x:t){
	// 	cout<<x<<" ";
	// }
	// cout<<endl;
	// for(int i=0;i<=slen; i++){
	// 	cout<<s[i]<<" ";
	// 	for(int j=0; j<=tlen; j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	vector<char> ans;
	int i=slen, j=tlen;
	while(i>0 && j>0){
		while(i>0 && dp[i-1][j] == dp[i][j]){i--;}
		while(j>0 && dp[i][j-1] == dp[i][j]){j--;}

		ans.push_back(s[i]);
		i--; j--;
	}
	reverse(ans.begin(), ans.end());
	for(auto x:ans){cout<<x;}
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
#define Mod 1000000007
LL ksm(int a,int x){
	LL ans=1,w=a;
	while(x){
		if(x&1)ans=ans*w%Mod;
		x>>=1;
		w=w*w%Mod;
	}
	return ans;
}
int n,k;
LL f[MN],ans;
int main(){
	n=3;k=read();
	for(int i=k;i;--i){
		f[i]=ksm(k/i,n);
		for(int j=i*2;j<=k;j+=i)
			f[i]=(f[i]-f[j]+Mod)%Mod;
		ans+=(LL)f[i]*i%Mod;
	}
	printf("%lld\n",ans%Mod);
	return 0;
}





















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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[333];


inline li calc(li x, li y, li target) {
    if ((x + y - target) % 2 > 0) {
        return -1;
    }
    li an = (x + y - target) / 2;
    if (an < 0 || (an & target) > 0) {
        return -1;
    }
    if (an > x) {
        return -1;
    }
    li res = an;
    bitset<55> bs(target);
    for (li i = 54; i >= 0; i--) {
        if (bs[i]) {
            if (res + bit(i) <= x) {
                res += bit(i);
            }
        }
    }
    if (res == 0) {
        return -1;
    }
    return x - res;
}

int main() {
    cin >> n;
    rin{
        cin >> a[i];
    }
    li target = 0;
    repp(i, 2, n) {
        target ^= a[i];
    }

    cout << calc(a[0], a[1], target) << endl;


    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(int argc, char const *argv[]) {
  int i,j,a[3];
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(a[i]<a[j]){
      int temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
    }
  }
  printf("%d\n",a[0]-a[2]);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int i,j,k,l,n,c,a[100],b[100][100];
scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&a[i-1],&a[i]);
  }

  for(i=1;i<=n;i++){
    b[i][i]=0;
  }
  for(k=2;k<=n;k++){
    for(i=1;i<=n+1-k;i++){
      j=i+k-1;
      b[i][j]=100000000;
      for(l=i;l<=j-1;l++){
    if(b[i][j]>(c=b[i][l]+b[l+1][j]+a[i-1]*a[l]*a[j])){
      b[i][j]=c;
    }
      }
    }
  }
  printf("%d\n",b[1][n]);
  return 0;
}



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

class Pos
{
public:
	double x, y;
};

bool isHit(Pos p1, Pos p2, Pos p3, Pos p4)
{
	if (p1.x > p4.x) return false;
	if (p2.x < p3.x) return false;
	if (p1.y > p4.y) return false;
	if (p2.y < p3.y) return false;

	return true; 
}

int main(){

	Pos p[4];

	while (cin >> p[0].x >> p[0].y){
		for (int i = 1; i < 4; i++)
		{
			cin >> p[i].x >> p[i].y;
		}
		

		if (isHit(p[0], p[1], p[2], p[3])) cout << "YES" << endl;
		else cout << "NO" << endl;

	}

	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int h, w;
vector<string> s(50);
typedef pair<int, int> P;

int main() {
    cin >> h >> w;
    int count = 0;
    int xp[4] = {0, 1, 0, -1};
    int yp[4] = {1, 0, -1, 0};
    vector<vector<int>> flag(h, vector<int> (w, 0));
    for(int i = 0; i < h; i++) {
        cin >> s[i];
        for(int j = 0; j < w; j++) {
            if(s[i][j] == '#') count++;
        }
    }
    queue<P> que;
    que.push({0, 0});
    vector<vector<int>> dist(h, vector<int>(w, 0));
    dist[0][0] = 0;
    while(!que.empty()) {
        P p = que.front(); que.pop();
        int x = p.second; int y = p.first;
        for(int i = 0; i < 4; i++) {
            int px = xp[i]+x;
            int py = yp[i]+y;
            if(px < w && px >= 0 && py < h && py >= 0 && s[py][px] == '.' && flag[py][px] == 0) {
                que.push({py, px});
                flag[py][px] = 1;
                dist[py][px] += dist[y][x]+1;
            }
        }
    }
    if(dist[h-1][w-1] == 0) cout << -1 << endl;
    else cout << h*w-dist[h-1][w-1]-count-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

using namespace std;

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

    int count = 0;
    int minus = 0;

    if (0 <= L) {
        minus = L;
    } else {

        minus = (L + N - 1);
        if (0 <= minus) {
            minus = 0;
        }
    }

    for (int i = 0; i < N; i++) {
        count += L + i;
    }

    cout << (count - minus) << endl;


    return 0;
}

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

int main() {
	int N, K;
	cin >> N >> K ;
	int Kyori = 0;
	int Ball_X_Zahyo;
	for(int i=0; i < N; i++){
    	cin >> Ball_X_Zahyo;
      	if(Ball_X_Zahyo < (K - Ball_X_Zahyo)){
        	Kyori += Ball_X_Zahyo * 2;
        }else{
        	Kyori += (K - Ball_X_Zahyo) * 2;
        }
    }
  	cout << Kyori << endl;
}

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

int S, W;
vector<int> vec;
string s;

bool solve() {


    return (W >= S);

}

int main() {

    cin >> S >> W;
    //vec.resize(N);
    //for (int i = 0; i < N; i++) {
    //    cin >> vec.at(i);
    //}

    if (solve()) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }


    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define N 200000
int a, b, c, cnt = 0;
int query[N];
int pushBack(void);
int randomAccess(void);
int popBack(void);
int main(void){
     scanf("%d", &a);
     for (int i=0; i<a; i++){
          scanf("%d", &b);
          if (b == 0) pushBack();         
          else if (b == 1) randomAccess();
          else if (b == 2) popBack();
     }
     return 0;
}
int pushBack(void){
     scanf("%d", &c);
     query[cnt] = c;
     cnt++;
     return 0;
}
int randomAccess(void){
     scanf("%d", &c);
     if (cnt == 0){printf("%d\n", query[0]); return 0;}
     printf("%d\n", query[c]);
     return 0;
}
int popBack(void){
     if (cnt == 0){ query[cnt] = 0; return 0;}
     query[cnt-1] = 0;
     cnt--;
     return 0;
}
      
      


Measured memory_bytes: 2484
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main(){

    int n,k;
    cin>>n>>k;
    int ki[n];
    for(int i=0;i<n;i++){
        cin>>ki[i];
    }
    sort(ki,ki+n);
    int mi=1e9;
    for(int i=0;i<=n-k;i++){
        int a=ki[i];
        int b=ki[i+k-1];
        int h=b-a;
        mi=min(mi,h);
    }

    cout<<mi<<endl;



return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
using namespace std;
typedef long long ll;

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

ll calc(ll n, ll x) {
  ll g = gcd(n, x);
  if(g != 1)
    return calc(n / g, x / g) * g;
  if(n % 2 == 1) {
    return n / 2 * 6;
  } else if(x == n / 2) {
    return n / 2 * 3;
  } else {
    return n / 2 * 6 - 3;
  }
}

int main(void) {
  ll n, x;
  cin >> n >> x;
  cout << calc(n, x) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <limits>
using namespace std;

double D(double x[],double y[],int n,double p){
  double d = 0;
  for(int i=0;i<n;i++){
    d += pow(abs(x[i]-y[i]),p);
  }
  return pow(d,1/p);
}

double D_max(double x[],double y[],int n){
  double max=0;
  for(int i=0;i<n;i++){
    if(max<abs(x[i]-y[i]))
      max = abs(x[i]-y[i]);
  }
  return max;
}

int main(){
  int n;
  cin >> n;
  double x[n],y[n];

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

  cout << fixed << setprecision(6) << D(x,y,n,1) << endl;
  cout << fixed << setprecision(6) << D(x,y,n,2) << endl;
  cout << fixed << setprecision(6) << D(x,y,n,3) << endl;
  cout << fixed << setprecision(6) << D_max(x,y,n) << endl;


  return 0;
}



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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(50);
    vector<int> b(50);
    for (int i = 0; i < M; i ++){
        cin >> a.at(i) >> b.at(i);
    }
    vector<int> c(50, 0);
    for (int i = 0; i < M; i ++){
          c.at(a.at(i) - 1) ++;
          c.at(b.at(i) - 1) ++;
      }
    for (int i = 0; i < N; i ++){
        cout << c.at(i) << endl;
    }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    cout << std::min(B / A, C) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int n, m, a; n = in(), m = in(), a = in(), n || m || a;) {
		vector<vector<int>> amida(1001, vector<int>(n + 1));
		while (m--) {
			int h = 1001 - in(), p = in(), q = in();
			amida[h][p] = q;
			amida[h][q] = p;
		}
		for (auto c : amida)
			if (c[a])
				a = c[a];
		out(a, '\n');
	}
}


Measured memory_bytes: 2780
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long ;
int main(){
	ll n , m , q ;
	cin >> n >> m >> q ;
	vector<ll> s(n) , t(m);
	for(ll i=0;i<n;i++){
		cin >> s[i] ;
	}
	for(ll i=0;i<m;i++){
		cin >> t[i] ;
	}
	while(q--){
		ll x ;
		cin >> x ;
		ll index = lower_bound(s.begin(),s.end(),x) - s.begin() ;
		vector<ll> first,second ;
		if ( index == n ) first.push_back(s[index-1]) ;
		else if ( index == 0 ) first.push_back(s[index]) ;
		else {
			first.push_back(s[index]) ;
			first.push_back(s[index-1]) ;
		}
		index = lower_bound(t.begin(),t.end(),x) - t.begin() ;
		if ( index == m ) second.push_back(t[index-1]) ;
		else if ( index == 0 ) second.push_back(t[index]) ;
		else {
			second.push_back(t[index]) ;
			second.push_back(t[index-1]) ;
		}
		sort(first.begin(),first.end());
		sort(second.begin(),second.end());
		debug() << imie(first) ;
		debug() << imie(second) ;
		ll ans = 1e18 ;
		for(ll i=0;i<(ll)first.size();i++){
			for(ll j=0;j<(ll)second.size();j++){
				ans = min({ans,abs(first[i]-x)+abs(first[i]-second[j]),abs(second[j]-x)+abs(second[j]-first[i])});
			}
		}
		cout << ans << endl;
	}

	return 0 ;
}




Measured memory_bytes: 2944
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


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


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, D = map(int, input().split())
    ans = 0
    for _ in range(N):
        X, Y = map(int, input().split())

        if (X ** 2 + Y ** 2) <= D ** 2:
            ans += 1
    
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9840
def show_list(a):
    for x in a:
        print x,
    print

def bubble_sort(a,n):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in reversed(xrange(1,n)):
            if a[j] < a[j-1]:
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                count+=1
                flag = True
    show_list(a)
    print count
def main():
    n = input()
    a = map(int,raw_input().split())
    bubble_sort(a,n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 6432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
		}
		
		int[] tintin = new int[n+1];
		tintin[0] = Math.abs(a[0]);
		for(int i=1;i<n;i++) {
			tintin[i] = tintin[i-1] + Math.abs(a[i]-a[i-1]);
		}
		tintin[n] = tintin[n-1] + Math.abs(a[n-1]);
		
		int[] tkb = new int[n];
		tkb[0] = Math.abs(a[1]);
		for(int i=1;i<n-1;i++) {
			tkb[i] = Math.abs(a[i+1]-a[i-1]);
		}
		tkb[n-1] = Math.abs(a[n-2]);
		
		System.out.println(tkb[0]+tintin[n]-tintin[1]);
		for(int i=1;i<n-1;i++) {
			System.out.println(tintin[i-1]+tkb[i]+tintin[n]-tintin[i+1]);
		}
		System.out.println(tintin[n-2]+tkb[n-1]);
		in.close();
	}

}


Measured memory_bytes: 64044
#include<stdio.h>
int main(){

  int N,i,j,minj,eg,count=0;
  int A[100];

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(minj != i){
      eg=A[i];
      A[i]=A[minj];
      A[minj]=eg;
      count++;
    }

  }

  for(i=0;i<N;i++){
    if(i>0){
      printf(" ");
      
    }
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;

}



Measured memory_bytes: 2700
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int a,b; cin >> a >> b;
	string s; cin >> s;
	for(int i=0;i<a+b+1;i++){
		if(i==a && s[i]!='-'){
			cout << "No"<< endl;
			return 0;
		}
		else if(i !=a){
			if('0'>s[i] || '9'<s[i]){
				cout << "No "<< endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
  int n; cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n - 1; i++){
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  for(int i = 1; i < n; i++){
    int x = a[i];
    int j = i - 1;
    while(j >= 0 && x < a[j]){
      a[j + 1] = a[j];
      j--;
    }
    j++;
    a[j] = x;
    for(int i = 0; i < n - 1; i++){
      cout << a[i] << " ";
    }
    cout << a[n - 1] << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
import math
n=int(input())
d=math.floor(math.log(1+(26-1)*n,26))
position=int(n-(26**d-1)/(26-1))
txt=list('a' * d)
for i in range(d):
    txt[d-i-1]=chr(ord(txt[d-i-1])+(position%26))
    position=position//26
print(''.join(txt))

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

int main() {
	int n;
	cin >> n;
	vector<int> x(n),y(n),h(n);
	for(int i=0;i<n;i++)
	{
		cin >> x.at(i) >> y.at(i) >> h.at(i);
	}
	int kx,ky,kh;
	for(int i=0;i<101;i++)
	{
		int f=0;
		for(int j=0;j<101;j++)
		{
			int hh=0;
			for(int k=0;k<n;k++)
			{
				if(h.at(k)==0)
				{
					continue;
				}
				int h1=h.at(k)+abs(i-x.at(k))+abs(j-y.at(k));
				kh=h1;
				kx=i;
				ky=j;				
				if(k>0)
				{
					if(h1==hh)
					{
						f=1;
					}
					else
					{
						f=0;
					}
					if(f==0)
					{
						break;
					}
				}
				hh = h1;
			}
			for(int k=0;k<n;k++)
			{
				int mh=max(0,kh-abs(kx-x.at(k))-abs(ky-y.at(k)));
				if(h.at(k)!=mh)
				{
					f=-1;
				}
			}
			if(f>-1)
			{
				f=1;
			}
			if(f==1)
			{
				break;
			}
		}
		if(f==1)
		{
			break;
		}
	}
	cout << kx << ' ' << ky << ' ' << kh << endl;
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

void dfs(int cur, const vector<vector<int>> &g, vector<int> &col)
{
    for(auto v:g[cur])
    {
        if(col[v]==-1)
        {
            col[v] = 1 - col[cur];
            dfs(v, g, col);
        }
    }
}

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

    int n;
    cin >> n;
    int cnt = n * (n - 1) / 2, index = 1;
    vector<vector<int>> a(n, vector<int>(n, 0));
    while (cnt)
    {
        vector<vector<int>> g(n);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (a[i][j] == 0)
                {
                    g[i].push_back(j);
                }
            }
        }
        vector<int> col(n, -1);
        for(int i=0;i<n;i++)
        {
            if(col[i]!=-1) continue;
            col[i] = 0;
            dfs(i, g, col);
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(col[i]!=col[j] && a[i][j]==0)
                {
                    a[i][j] = a[j][i] = index;
                    cnt--;
                }
            }
        }
        index++;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (j != i + 1)
                cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 2304
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    a=a-b;
    while(a>=c){
        a-=c;
    }
    cout << a;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

const int INF = 1000000;
int graph[400][400];
int size = 0;
typedef vector<vector<int> > Matrix;

int main() {
  int H, W;
  cin >> H >> W;
  char table[H + 2][W + 2];
  for (int i = 0; i < H + 2; ++i) {
    table[i][0] = '#';
    table[i][W + 1] = '#';
  }
  for (int i = 0; i < W + 2; ++i) {
    table[0][i] = '#';
    table[H + 1][i] = '#';
  }
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >> table[i + 1][j + 1];
    }
  }
  size = H * W;
  for (int i = 0; i < size; ++i) {
    for (int j = 0; j < size; ++j) {
      graph[i][j] = INF;
    }
    graph[i][i] = 0;
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (table[i + 1][j + 1] == '.') {
        if (table[i + 1][j] == '.'){
          graph[(i) * W + j][(i) * W + (j - 1)] = 1;
          graph[(i) * W + (j - 1)][(i) * W + j] = 1;
        }
        if (table[i + 1][j + 2] == '.'){
          graph[(i) * W + j][(i) * W + (j + 1)] = 1;
          graph[(i) * W + (j + 1)][(i) * W + j] = 1;
        }
        if (table[i][j + 1] == '.') {
          graph[(i) * W + j][(i - 1) * W + j] = 1;
          graph[(i - 1) * W + j][(i) * W + j] = 1;
        }
        if (table[i + 2][j + 1] == '.') {
          graph[(i) * W + j][(i + 1) * W + j] = 1;
          graph[(i + 1) * W + j][(i) * W + j] = 1;
        }
      }
    }
  }
  
  for (int i = 0; i < size; i++)      // 経由する頂点
    for (int j = 0; j < size; j++)    // 開始頂点
      for (int k = 0; k < size; k++)  // 終端
        graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);

  int ans = 0;
  for (int i = 0; i < size; i++) {
    if (table[i / W + 1][i % W + 1] == '#') {
      continue;
    }
    for (int j = 0; j < size; j++) {
      if (table[j / W + 1][j % W + 1] == '#') {
        continue;
      }
      ans = max(graph[i][j], ans);
    }
  }
  cout << ans << endl;
  
  return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);

    string s;
    cin >> s;
    if(s[2] == s[3]&&s[4]==s[5])YES;
    else NO;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define MAX 316
using namespace std;

int getDigit(int n) {
  int cnt = 0;
  while (n % 10 != 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}

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

  rep(i,0,getDigit(b)-1) a *= 10;
  int n = a + b;

  bool ans=0;
  rep(i,0,MAX) {
    if (i*i == n) ans = 1;
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位



int G[101][101];
int cou[101][101];



signed main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {
			if (i == j) G[i][j] = 0;
			else G[i][j] = LL_MAX/4;
		}
	}

	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		G[a][b] = c;
		G[b][a] = c;
		cou[a][b] = 1;
		cou[b][a] = 1;
	}

	//ワーシャルフロイドをする、更新があって、それがLL_MAX/2でない場合はそれが使わない辺
	int ans = 0;
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (G[i][j] > G[i][k] + G[k][j]) {
					if (cou[i][j] == 1) {
						ans++;
						cou[i][j]--;
					}
					G[i][j] = G[i][k] + G[k][j];

				}
			}
		}
	}
	
	cout << ans/2 << "\n";

	return 0;




}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, tot=0, ans=0;
    cin >> n;
    long long a[n+1];
    for (int i=1; i<=n; i++){
        cin >> a[i];
        tot+=a[i];
    }
    for (int i=1; i<n; i++){
        tot-=a[i];
        ans+=(tot)%(long long)(1e9+7)*a[i];
        ans%=(long long)(1e9+7);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5188
#include <stdio.h>

int b_search(int bottom, int top, int x, int array[]) {
	int mid = (bottom + top) / 2;

	do {
		if(array[mid] == x)
			return mid;

		else if(array[mid] > x)
			top = mid;
		else
			bottom = mid;

		mid = (bottom + top) / 2;
	} while(mid != bottom);

	if(array[mid] == x)
		return mid;
	
	return -1;
}

int main() {
	int prime[60000] = {1, 1};
	int prime_num[10000] = {0};
	int num;
	int i, j;
	int n;
	int ans;
	int temp;

	for(i = 2; i < 60000; i++)
		if(!prime[i])
			for(j = 2; i * j < 60000; j++)
				prime[i * j] = 1;

	for(i = 0, num = 0; i < 60000; i++) {
		if(!prime[i]) {
			prime_num[num] = i;
			num++;
		}
	}

	while(1) {
		ans = 0;
		scanf("%d", &n);
		if(n == 0)
			break;
		
		if(n % 2 == 1) {
			if(b_search(0, num, n - 2, prime_num) >= 0)
				ans++;
		}

		else {
			for(i = 0; prime_num[i] * 2 <= n; i++) {
				if(b_search(0, num, n - prime_num[i], prime_num) >= 0) {
					ans++;
				}
			}
		}

		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 880
#include<iostream>
#define N_MAX 200
int P[N_MAX];
int main(){
    int N, X;
    std::cin >> X >> N;
    for(int i=0; i<N; i++){
        int tmp;
        std::cin >> tmp;
        P[tmp] = 1;
    }
    for(int i=0;i<=100; i++){
        if(P[X-i] == 0){
            printf("%d\n", X-i);
            break;
        }else if(X-i<=100 && P[X+i] == 0){
            printf("%d\n", X+i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3244
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        a: [usize1;n],
    }
    let mut i: usize = 0;
    let mut h: HashSet<usize> = HashSet::new();
    loop {
        if i == 1 {
            break;
        }
        h.insert(i);
        i = a[i];
        if h.contains(&i) {
            println!("{}", -1);
            return;
        }
    }
    println!("{}", h.len());
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
ll a[100010],b[100010];

void solve() {
    cin >> n;
    REP(i,n+1) cin >> a[i];
    REP(i,n) cin >> b[i];
    ll ans = 0;
    REP(i,n) {
        ll k = min(a[i],b[i]);
        ans += k;
        a[i] -= k;
        b[i] -= k;
        k = min(a[i+1],b[i]);
        ans += k;
        a[i+1] -= k;
        b[i] -= k;
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include <cassert>
#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>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#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>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,h,v,i;
// std::vector<P> a,b;
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>h;
  ll a,b[100001] = {};
  ll ma=0;
  rep(i,n){
    cin>>a>>b[i];
    maxch(ma,a);
  }
  sort(b, b+n, greater<int>());
  ll ans = 0;
  rep(i,n+1){
    if(b[i] > ma && h > 0){
      h-=b[i];
      ans++;
    }
  }
  if (h > 0) ans += (h + ma - 1) / ma;
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


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

int main(){
  string S;
  int Q;
  cin >> S >> Q;
  deque<char>Sd;
  for (int i=0;i<S.size();i++){
    Sd.push_back(S.at(i));
  }
  int flag = 0;
  for (int i=0;i<Q;i++){
    int tmp;
    cin >> tmp;
    if (tmp==1){
      flag++;
    }else if (tmp==2){
      int f;
      char c;
      cin >> f >> c;
      if (f==1){
        if (flag%2==0){
          Sd.push_front(c);
        }else if (flag%2==1){
          Sd.push_back(c);
        }
      }else if (f==2){
        if (flag%2==0){
          Sd.push_back(c);
        }else if (flag%2==1){
          Sd.push_front(c);
        }
      }
    }
  }
  if (flag%2==1){
    reverse(Sd.begin(),Sd.end());
  }
  string ans = "";
  for (int i=0;i<Sd.size();i++){
    ans += Sd.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1412
#define _GLIBCXX_DEBUG
#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(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int A, B;
  cin >> A >> B;
  if(A != 1 && B != 1){
    cout << 1 << endl;
  }
  if(A != 2 && B != 2){
    cout << 2 << endl;
  }
  if(A != 3 && B != 3){
    cout << 3 << endl;
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> d (n);
    for(int i=0; i<n; i++){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    int ans;
    if(d.at(n/2) == d.at(n/2-1)) ans = 0;
    else ans = d.at(n/2) - d.at(n/2-1);
    cout << ans << endl;
}

Measured memory_bytes: 768
n=int(input())
dic=set()
for i in range(n):
    st=input().split()
    if st[0] == 'insert':
        dic.add(st[1])
        
    if st[0]== 'find':
        if st[1] in dic:
            print('yes')
        else:
            print('no')
    


Measured memory_bytes: 30988
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, i, j, k, ans, x, cc;
	cin >> n >> m;
	vector<int> p(m);
	vector<vector<int>> s(m);
	for (i = 0; i < m; i++) {
		cin >> k;
		while (k--) {
			cin >> x;
			x--;
			s[i].push_back(x);
		}			
	}
	for (i = 0; i < m; i++) cin >> p[i];

	ans = 0;
	for (i = 0; i < (1 << n); i++) {
		vector<int> c(n);
		for (j = 0; j < n; j++) c[j] = (i & (1 << j)) > 0;

		x = 0;
		for (j = 0; j < m; j++) {
			cc = 0;
			for (auto p : s[j]) {
				if (c[p]) cc++;
			}
			if (cc % 2 == p[j]) x++;
		}
		if (x == m) ans++;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;

class UnionFind {
public:
	vector<int>par, rank, node;
	UnionFind(int n) :par(n), rank(n, 0),node(n,1) {
		for (int i = 0;i < n;i++)par[i] = i;
	}
	void init(int n) {
		for (int i = 0;i < n;i++) {
			par[i] = i;
			rank[i] = 0;
			node[i] = 1;
		}
	}

	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int root_size(int x){
		return rank[find(x)];
	}

	int size(int x) {
		return node[find(x)];
	}

	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};

int f[100010];
int bl[100010];

int main(void){
    int n,m,k;
    cin>>n>>m>>k;
    UnionFind uf1 = UnionFind(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        f[a]++;
        f[b]++;
        uf1.unite_node(a,b);
    }
    for(int i=0;i<k;i++){
        int a,b;
        cin>>a>>b;
        if(uf1.same(a,b)){
            bl[a]++;
            bl[b]++;
        }
    }
    for(int i=1;i<=n;i++){
        //cout<<"size"<<" "<<uf1.size(i)<<endl;
        if(i==n){
            cout<<uf1.size(i)-f[i]-bl[i]-1<<endl;;
        }
        else{
            cout<<uf1.size(i)-f[i]-bl[i]-1<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>

const long long mod = 1000000007;
long long inv[2001001]={0,1}, fact[2001001]={1,1}, ifact[2001001]={1,1};
char s[1001001];

int main()
{
  for (int i=2;i<2001001;i++){
inv[i] = (mod -mod / i) * inv[mod % i] % mod;
    fact[i] = fact[i-1] * i % mod;
    ifact[i] = ifact[i-1] * inv[i] % mod;
  }
  
  int k; scanf ("%d %s",&k,s);
  int n = 0; while (s[n]) n++;
  
  long long full = 1, ans = 0;
  for (int i=0;i<k;i++) full = full * 26 % mod;
  for (int i=0;i<=k;i++){
    long long coeff = fact[i+n-1] * ifact[i] % mod * ifact[n-1] % mod;
    ans = (ans + coeff * full) % mod;
    full = full * 25 % mod;
full = full * inv[26] % mod;
  }
  printf ("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 51096
def div(k):
    if (k % 3 != 0) and (k % 5) != 0:
        return True
    else:
        return False

def main():
    n = int(input())
    ary = [i for i in range(n+1)]
    ary = [i if div(i) else 0 for i in ary]
    print(sum(ary))

if __name__ == '__main__':
    main()

Measured memory_bytes: 150976
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
signed main(){

	int N;
	cin>>N;
	string S;
	cin>>S;

	int ans=0;
	for(int i=0;i<N;i++){
		if(S[i]=='A' && i<N-2)
			if(S[i+1]=='B' && S[i+2]=='C')
				ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int x, y, ans = 0;
    
    scanf("%d %d", &x, &y);
    
    ans += max(abs(x), abs(y)) - min(abs(x), abs(y));
    
    if (x >= 0) {
        if (y > 0) {
            if (x > y) ans += 2;
        } else {
            ans++;
        }
    } else {
        if (y > 0) {
            ans++;
        } else {
            if (x > y) ans += 2;
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

constexpr int kMax = 1e5 + 1;
LL dp[kMax];

int main() {
  int N, M; std::cin >> N >> M;
  std::vector<int> a(M);
  for (int i = 0; i < M; ++i) std::cin >> a[i];

  dp[0] = 1;
  for (int i = 1; i <= N; ++i) dp[i] = 0;
  for (int m = 0; m < M; ++m) dp[a[m]] = -1;

  if (dp[1] == 0) dp[1] = dp[0];

  for (int i = 2; i <= N; ++i) {
    if (dp[i]<0) continue;
    dp[i] += std::max(0LL, dp[i-2]);
    dp[i] %= kMod;
    dp[i] += std::max(0LL, dp[i-1]);
    dp[i] %= kMod;
  }

#if 0
  for (int i = 0; i <= N; ++i) {
    std::cout << dp[i] << " ";
  }
  std::cout << std::endl;
#endif
  std::cout << dp[N] << std::endl;
}


Measured memory_bytes: 1408
N = int(input())
a = list(map(int, input().split()))

from fractions import gcd

def lcm(m, n):
    return (m * n) // gcd(m, n)

def lcm_list(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

f = lcm_list(a)-1
ans = 0

for i in a:
    ans += f%i

print(ans)

Measured memory_bytes: 5280