akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}
 
 
int nextInt() { int x; scanf("%d", &x); return x;}
 
vector<pair<int,ll>> g[100000 + 10];
ll d[100000 + 10];
 
void dfs(int v, ll cost, int prev) {
  d[v] = cost;
  for (auto& u : g[v]) if (u.first != prev) {
    dfs(u.first, cost + u.second, v);
  }
}
 
int main2() {
  int N = nextInt();
  REP(i, N) g[i].clear();
  REP(_, N-1) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    int c = nextInt();
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  int Q = nextInt();
  int K = nextInt() - 1;
 
  dfs(K, 0, -1);
 
  REP(qqq, Q) {
    int x = nextInt() - 1;
    int y = nextInt() - 1;
    cout << d[x] + d[y] << endl;
  }
  return 0;
}
 
int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}
 

Measured memory_bytes: 14336
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'p') ans--;
	}
	ans += S.size() / 2;
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
int main()
{
	long long n,g=0,q=1000;
	cin>>n;
	int a[n+1];
	for(int i=1; i<=n; i++)	
		cin>>a[i];
	for(int i=1; i<n; i++)
	{
		if(a[i+1]>=a[i])
		{
			g+=q/a[i];
			q%=a[i];
		}
		else
		{
			q+=g*a[i];
			g=0;
		}
	}
	cout<<q+g*a[n];
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
    static int area(int a,int b){
	return a*b;
    }

    static int prmt(int a,int b){
	return 2*(a+b);
    }

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

	int a=scan.nextInt();
	int b=scan.nextInt();

	int ans1=area(a,b);
	int ans2=prmt(a,b);

	System.out.println(ans1+" "+ans2);
    }
}

Measured memory_bytes: 17160
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    if(a + b >= c) {
        out("Yes");
    }
    else {
        out("No");
    }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sum1 = vec.at(0);
  int sum2 = vec.at(1);
    
  if (N % 2 == 0) {
    for (int i = 2; i < N; i+= 2) {
    sum1 += vec.at(i);
      }
    for (int i = 3; i < N; i+= 2) {
    sum2 += vec.at(i);
  }
  }
  
  else {
    for (int i = 2; i < N; i+= 2) {
    sum1 += vec.at(i);
      }
    for (int i = 3; i < N; i+= 2) {
    sum2 += vec.at(i);
  }
  }
 
  cout << sum1 - sum2 << endl;
}

Measured memory_bytes: 256
while(True):
    a, op, b = input().split()
    if op == '?':
        break
    elif op == '+':
        print(int(a) + int(b))
    elif op == '-':
        print(int(a) - int(b))
    elif op == '*':
        print(int(a) * int(b))
    elif op == '/':
        print(int(a) // int(b))

Measured memory_bytes: 7624
#include <fstream>
#include <deque>
#include <vector>
#include <iostream>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, M;
string str;
deque<int> unvis;
deque<int> unpro;
int mov [100001] = {0};

// Helper Functions

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M >> str;
    F0R(i,str.size()) if (str[i] == '0') unvis.PB(i);
    unvis.pop_front();
    unpro.PB(0);
    while (!unpro.empty()) {
        int cur = unpro.front(); unpro.pop_front();
        // cout << "cur: " << cur << '\n';
        while (!unvis.empty() && unvis.front() <= cur+M) {
            if (unvis.front() >= cur+1) {
                // cout << "   add: " << unvis.front() << '\n';
                mov[unvis.front()] = unvis.front()-cur;
                unpro.PB(unvis.front());
            }
            unvis.pop_front();
        }
    }
    if (mov[N] == 0) cout << "-1\n";
    else {
        vector<int> ans;
        while (N != 0) {
            ans.PB(mov[N]);
            N -= mov[N];
        }
        RF0(i,ans.size()) {
            cout << ans[i];
            if (i != 0) cout << ' ';
        }
        cout << '\n';
    }
}

Measured memory_bytes: 4752
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a * b > c * d) cout << a * b << endl;
    if(c * d > a * b) cout << c * d << endl;
    if(a * b == c * d) cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private final static long mod = 1_000_000_007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[] dp = new long[N + 1];
		boolean[] ng = new boolean[N + 1];
		for (int i = 0; i < M; i++) {
			int a = sc.nextInt();
			ng[a] = true;
		}
		sc.close();

		// --test
		// System.out.print("# ");
		// for (int i = 0; i < dp.length; i++) {
		// 	System.out.print(dp[i] + " ");
		// }
		// System.out.println("");
		// --test

		// 最後の段に1を設定
		dp[N] = 1;
		// 最後の1段前が壊れていなければ1を設定
		if (!ng[N - 1]) dp[N - 1] = 1;
		// 壊れている段を飛ばして最後の段までのパターンを取得する
		for (int i = N - 2; i >= 0; i--) {
			if (ng[i]) continue;
			dp[i] = dp[i + 1] + dp[i + 2];
			dp[i] %= mod;
		}

		// --test
		// System.out.print("# ");
		// for (int i = 0; i < dp.length; i++) {
		// 	System.out.print(dp[i] + " ");
		// }
		// System.out.println("");
		// --test

		// 結果出力
		System.out.println(dp[0]);
	}
}


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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> data(N);
  for(int i = 0; i < N; i++){
    cin >> data[i];
  }
  int sum = 0;
  for(int i = 0; i < N; i++){
    sum += data[i];
  }
  X -= sum;
  int min = *min_element(data.begin(), data.end());
  int nokori = X/min;
  cout << N + nokori << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int c[3];
    string res;
    cin >> c[0] >> c[1] >> c[2];
    sort(c,c+3);
    if(c[0]+c[1] == c[2]) res = "Yes";
    else res = "No";
    cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
int d[1<<19],f[1<<19],p[1<<19],n,q,i=1;main(){for(scanf("%d%d",&n,p);i<=n;++i)scanf("%d",d+i),p[i]=(p[i-1]>d[i]?p[i-1]-d[i]:(d[i]<p[i-1]*2?d[i]-p[i-1]:p[i-1]));for(f[n+1]=1;n;--n)f[n]=(d[n]>=f[n+1]*2?f[n+1]:d[n]+f[n+1]);for(scanf("%d",&q);q--;){scanf("%d",&i);puts(p[i-1]<f[i+1]?"NO":"YES");}}

Measured memory_bytes: 7936
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll P;

bool po(ll a, ll b) {
    ll c = 1;
    rep(i, b) {
        c *= a;
    }
    return c;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    ll ret = 1;
    ll P;
    cin >> P;
    if(N == 1) {
        output(P);
        return 0;
    }
    if (N > 40) {
        output(1);
        return 0;
    }
    
    ll a = 2;
    while(1) {
        ll b = 1;
        ll ok = true;
        rep(i, N) {
            b *= a;
            if(b > P) {
                ok = false;
                break;
            }
        }
        if(!ok) break;
        if(P % b == 0) {
            ret = a;
        }
        a++;
    }
    output(ret);
    
    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>

using std::cin;
using std::cout;

const std::vector<std::pair<int,int>> Directions{{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

int main(int argc, char* argv[])
{
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int H, W;
  cin >> H >> W;

  std::vector<std::string> S(H);
  std::vector<std::vector<int>> seen(H, std::vector<int>(W, 0));

  for (auto& si : S)
  {
    cin >> si;
  }

  long long res = 0;
  std::queue<int> q;

  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (seen[i][j]) continue;

      q.push((i << 9) | j);
      seen[i][j] = 1;

      int wc = 0;
      int bc = 0;

      while (!q.empty())
      {
        int w = q.front() & 511;
        int h = q.front() >> 9; q.pop();

        if (S[h][w] == '.') ++wc;
        else ++bc;

        for (auto& dir : Directions)
        {
          int hh = h + dir.first;
          int ww = w + dir.second;
          if (hh < 0 || ww < 0 || hh >= H || ww >= W) continue;
          if (S[hh][ww] == S[h][w]) continue;
          if (seen[hh][ww]) continue;
          seen[hh][ww] = 1;
          q.push((hh << 9) | ww);
        }
      }

      res += 1LL * wc * bc;
    }
  }

  cout << res << "\n";

  return 0;
}


Measured memory_bytes: 1024
def II(): return int(input())
N=II()
d=2
ans=0
while d*d<=N:
  if N%d!=0:
    d+=1
    continue
  z=d
  while N%z==0:
    ans+=1
    N//=z
    z*=d
  while N%d==0:
    N//=d
if N!=1:
  ans+=1
print(ans)

Measured memory_bytes: 9072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();

		for(double a = -120; a < 120;a+=1) {
			for(double b = -120; b < 120;b+=1) {
				if((long)(Math.pow(a, 5) - Math.pow(b, 5)) ==x) {
					System.out.println((long)a + " " + (long)b);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 27032
import std.stdio;
import std.container;
import std.functional;
import std.algorithm;

struct P {
    int y, x;
    int t;
}

void dump(int[][] x) {
    foreach (l; x) {
        l.writeln;
    }
    writeln;
}

void calcDist(int[][] F, int y, int x) {
    auto Y = F.length,
         X = F[0].length;
    foreach (i; 0 .. Y) 
        foreach (j; 0 .. X)
            F[i][j] = int.max;
    static const oD = [
        [-1, 0], [-1, 1],
        [0, -1], [0, 1],
        [1, 0], [1, 1]
    ];
    static const eD = [
        [-1, -1], [-1, 0],
        [0, -1], [0, 1],
        [1, -1], [1, 0]
    ];
    DList!P Q;
    Q.insert(P(y, x, 0)); 
    F[y][x] = 0;
    while (!Q.empty) {
        P cur = Q.front; Q.removeFront;
        foreach (d; (cur.y % 2 == 0 ? eD : oD)) {
            int ny = cur.y + d[0],
                nx = cur.x + d[1];
            if (ny < 0 || ny >= Y) continue;
            if (nx < 0 || nx >= X) continue;
            if (F[ny][nx] <= cur.t + 1) continue;
            F[ny][nx] = cur.t + 1;
            Q.insert(P(ny, nx, cur.t + 1));
        }
    }
}

void main() {
    int m, n;
    int s, t;
    while (readf("%d", &m), m) {
        readf(" %d\n", &n);
        readf("%d\n", &s);
        auto S = new int[][][](s, n, m);
        foreach (i; 0 .. s) {
            int x, y; readf("%d %d\n", &x, &y);
            y--; x--;
            calcDist(S[i], y, x);
        }
        readf("%d\n", &t);
        auto T = new int[][](n, m);
        int[] R = new int[t];
        int count() {
            int c = 0;
            foreach (i; 0 .. n) {
                foreach (j; 0 .. m) {
                    foreach (k; 0 .. s) {
                        if (T[i][j] >= S[k][i][j]) 
                            goto next;
                    }
                    c++;
next:;
                }
            }
            return c;
        }
        foreach (i; 0 .. t) {
            int x, y; readf("%d %d\n", &x, &y);
            y--; x--;
            calcDist(T, y, x);
            R[i] = count;
        }
        R.reduce!max.writeln;
        delete(S);
        delete(T);
        delete(R);
    }
}

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

const int maxn=1e7+10;
const int mod=998244353;
int n;
ll poww(ll x,ll k) {
	ll ans=1;
	while(k) {
		if(k&1) ans=ans*x%mod;
		x=x*x%mod;
		k>>=1;
	}
	return ans;
}
ll mul[maxn],inv[maxn],er[maxn],ans;
ll C(int a,int b) {
	return mul[a]*inv[b]%mod*inv[a-b]%mod;
}
ll QwQ;
int main() 
{
	scanf("%d",&n);
	mul[0]=1,er[0]=1;
	for(int i=1;i<=n;++i) mul[i]=mul[i-1]*i%mod,er[i]=er[i-1]*2%mod;
	inv[n]=poww(mul[n],mod-2);
	for(int i=n;i;i--) inv[i-1]=inv[i]*i%mod;
	inv[0]=1;
	for(int i=n/2+1;i<=n;++i) {
		QwQ=(QwQ+C(n,i)*er[n-i]%mod)%mod;
	}
	cout<<(poww(3,n)-QwQ*2%mod+mod)%mod<<"\n";
	return 0;
} 


Measured memory_bytes: 234624
import itertools
N=input()
F=[]
for i in range(N):
	F.append(map(int,raw_input().split()))
#print F

P=[]
for i in range(N):
	P.append(map(int,raw_input().split()))
#print P


l=list(itertools.product(range(2), repeat=10))
#l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1)]
l.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

b=[[] for i in range(2**10-1)]


for ind_i,i in enumerate(l):
	for j in F:
		#print [min(t) for t in zip(i, j)]
		#print sum([min(t) for t in zip(i, j)])
		b[ind_i].append(sum([min(t) for t in zip(i, j)]))
#print b

b_sum=0
ans=float("-inf")
for ind_i,i in enumerate(b):
	b_sum=0
	for ind_j,j in enumerate(i):
		#print ind_i, ind_j,j
		b_sum+=P[ind_j][j]
	#print sum
	ans=max(ans,b_sum)

print ans

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

ll gcd(ll a, ll b) {

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}


int main() {

    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    
    ll ans = t[0];
    for(int i=1; i<n; i++){
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int ans[4] = {0, 0, 0, 0};
    for (int q = 0; q < n; q++){
        string s;
        cin >> s;
        if (s == "AC"){
            ans[0]++;
        }else if (s == "WA"){
            ans[1]++;
        }else if (s == "TLE"){
            ans[2]++;
        }else{
            ans[3]++;
        }
    }
    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;
    return 0;
}


Measured memory_bytes: 3648
import sys
n = int(input())
an = list(map(int,input().split()))
l = 1
r = 1
ans = 1
tmpsum=an[0]
while True:
  if r == n:
    print(ans)
    sys.exit()
  while tmpsum^an[r]==tmpsum+an[r]:
    tmpsum+=an[r]
    r += 1
    ans += r-l+1
    if r == n:
      print(ans)
      sys.exit()
  tmpsum -= an[l-1]
  l +=1
  if l>r:
    r=l
    tmpsum=an[l-1]
    ans += 1

Measured memory_bytes: 24584
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

const double EPS = 1e-8;
const int INF = 1<<29;

struct Point { int x, y; };

vector<string> B;
vector<vector<int>> vis;
int h, w, inc;
vector<vector<int>> G;
vector<vector<Point>> pieces;

void dfs(int y, int x, int id) {
    if (vis[y][x]) return;
    vis[y][x] = 1;

    pieces[id].push_back({ x, y });

    char crr = B[y][x];
    if (x-1 >= 0 && B[y][x-1] == crr) dfs(y, x-1, id);
    if (x+1 < w  && B[y][x+1] == crr) dfs(y, x+1, id);
    if (y-1 >= 0 && B[y-1][x] == crr) dfs(y-1, x, id);
    if (y+1 < h  && B[y+1][x] == crr) dfs(y+1, x, id);

    if (y+1 < h && B[y+1][x] != crr && B[y+1][x] != '.' && !vis[y+1][x]) {
        int nxt = inc++;
        G[id].push_back(nxt);
        dfs(y+1, x, nxt);
    }
}

double dfs_w(int i, int& cnt) {
    double ret = 0;
    for (auto b : pieces[i]) {
        ret += 0.5 + b.x;
        cnt++;
    }
    for (int j : G[i]) ret += dfs_w(j, cnt);
    return ret;
}

int main()
{
    while (1) {
NG:
        cin >> w >> h;
        if (!w) break;
        B = vector<string>(h);
        vis = vector<vector<int>>(h, vector<int>(w));
        G = vector<vector<int>>(w*h);
        pieces = vector<vector<Point>>(w*h);
        inc = 1;

        loop (h, i) cin >> B[i];
        reverse(all(B));
        loop (w, i) if (B[0][i] != '.') dfs(0, i, 0);

        vector<int> left(inc, INF), right(inc);
        loop (inc, i) {
            for (auto b : pieces[i]) {
                if (b.y == 0 || (B[b.y][b.x] != B[b.y-1][b.x] && B[b.y-1][b.x] != '.')) {
                    left[i] = min(left[i], b.x);
                    right[i] = max(right[i], b.x);
                }
            }
        }

        loop (inc, i) {
            int cnt = 0;
            double cx = dfs_w(i, cnt);
            cx /= cnt;
            if (left[i] + EPS > cx || right[i] + 1 < cx + EPS) {
                cout << "UNSTABLE" << endl;
                goto NG;
            }
        }
        cout << "STABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
using namespace std;

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

int N;
vector<int> P;
vector<int> Q;

int main() {
  cin >> N;
  P.resize(N);
  Q.resize(N);
  rep(i, N) {
    cin >> P[i];
  }
  rep(i, N) {
    cin >> Q[i];
  }

  vector<int> R;
  R.resize(N);

  rep(i, N) {
    R[i] = i + 1;
  }

  int count = 1;
  int a, b;
  do{
    if(P == R) a = count;
    if(Q == R) b = count;
    count++;
  } while(next_permutation(R.begin(), R.end()));

  int ans = abs(a - b);

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		float x1,x2,x3,x4,y1,y2,y3,y4,s1,s2;
		scanf("%f %f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		s1=(y2-y1)/(x2-x1);
		s2=(y4-y3)/(x4-x3);
		if(s1==s2)	puts("YES");
		else 		puts("NO");
	}
	return 0;
}

Measured memory_bytes: 616
def binary_search3(A,x):
    if x<A[0]:
        OK=0
        NG=0
    elif x>A[len(A)-1]:
        OK=len(A)-1
        NG=len(A)-1
    else:
        OK=0
        NG=len(A)
        DIV=(OK+NG)//2
        while OK+1<NG:
            if x>=A[DIV]:
                OK=DIV
            else:
                NG=DIV
            DIV=(OK+NG)//2
    return OK,NG

def main():
    #input
    S=list(input())
    r=[]
    l=[]
    for n in range(len(S)):
        if S[n]=="R":
            r.append(n)
        else:
            l.append(n)
    num=[1 for _ in range(len(S))]
    #R>>>L
    for n in range(len(r)):
        tmp=l[binary_search3(l,r[n])[1]]
        if (tmp-r[n])%2==0:
            num[tmp]+=1
        else:
            num[tmp-1]+=1
        num[r[n]]-=1
    #R<<<L
    for n in range(len(l)):
        tmp=r[binary_search3(r,l[n])[0]]
        if (tmp-l[n])%2==0:
            num[tmp]+=1
        else:
            num[tmp+1]+=1
        num[l[n]]-=1

    return " ".join(map(str,num))

if __name__=="__main__":
    print(main())

Measured memory_bytes: 21468
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
std::vector<int> edge[100005];
int f(int pa,int idx){
  int res=0;
  for(int p:edge[idx]){
    if(p==pa)continue;
    res^=f(idx,p);
  }
  return res+1;
}
//main
signed main(){
  int N;cin>>N;
  for(int i=1;i<N;i++){
    int a,b;cin>>a>>b;a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  if(f(-1,0)==1)fin("Bob");
  fin("Alice");
}


/*
解説AC
根付き木にするとNimっぽいってところまでは考えたけど部分根付き木のアイデアがなかったね
根付き木->部分根付き木までをセットで知識に入れとく
証明としては普通のNimとそんなにかわらないのかな、各それに対して同じように対応されたら無理なので
アイデアさえ思いつければいいのかねぇ
実装上手く描けて嬉しい
*/


Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;




int main() {
	int N; cin >> N;
	vector<int>rs(N);
	for (int i = 0; i < N; ++i)cin >> rs[i];
	vector<vector<int>>ts;
	for (int i = 0; i < N; ++i) {
		int s, p, c; cin >> s >> p >> c;
		ts.emplace_back(vector<int>{s, p, c});
	}
	int plus = 1;
	int ans = -1;
	while (plus <= 100) {
		for (int k = 0; k < 3; ++k) {
			ts[0][k] += plus;
			vector<map<int, int>>mps(3);
			for (int j = 0; j < 3; ++j) {
				for (int i = 0; i < N; ++i) {
					mps[j][-ts[i][j]]++;
				}
			}
			vector<map<int,int>>getscores(3);
			for (int j = 0; j < 3; ++j) {
				int now = 0;
				for (auto m : mps[j]) {
					getscores[j][m.first] = rs[now];
					now += m.second;
				}
			}
			vector<pair<int,int>>scores(N);
			for (int j = 0; j < 3; ++j) {
				for (int i = 0; i < N; ++i) {
					scores[i].first += getscores[j][-ts[i][j]];
					scores[i].second = -i;
				}
			}
			sort(scores.begin(), scores.end(), greater<pair<int, int>>());
			if (scores[8].second != 0) {
				ans = plus;

			}
			ts[0][k] -= plus;
		}
		plus++;
		if (ans != -1)break;
	}
	if (ans == -1)cout << "Saiko" << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3128
#include <math.h>
#include <stdio.h>

int main(){
  char S[100];
  long long int K;
  scanf("%s" "%lld",S ,&K);

  int i;
  for(i=0;i<K;i++){
    if(S[i]!='1'){
      printf("%c",S[i]);
      return 0;
    }
  }

  printf("1");
  return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int Na = sc.nextInt();
		int Nb = sc.nextInt();
		long[] xa = new long[Na];
		long[] ya = new long[Na];
		long[] xb = new long[Nb];
		long[] yb = new long[Nb];
		for (int i = 0; i < Na; ++i) {
			xa[i] = sc.nextLong();
			ya[i] = sc.nextLong();
		}
		for (int i = 0; i < Nb; ++i) {
			xb[i] = sc.nextLong();
			yb[i] = sc.nextLong();
		}

		double ans = Double.MAX_VALUE / 3;
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i < Na; ++i) {
				for (int j = 0; j < Na; ++j) {
					if (cross(xa[0], ya[0], xa[i], ya[i], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[i], ya[i], xa[j], ya[j], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[j], ya[j], xa[1], ya[1], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					ans = Math.min(ans, dist(xa[0], ya[0], xa[i], ya[i]) + dist(xa[i], ya[i], xa[j], ya[j])
							+ dist(xa[j], ya[j], xa[1], ya[1]) + dist(xb[0], yb[0], xb[1], yb[1]));
				}
			}
			Na ^= Nb;
			Nb ^= Na;
			Na ^= Nb;
			long[] tmp = new long[Na];
			tmp = Arrays.copyOf(xa, xa.length);
			xa = Arrays.copyOf(xb, xb.length);
			xb = Arrays.copyOf(tmp, tmp.length);
			tmp = Arrays.copyOf(ya, ya.length);
			ya = Arrays.copyOf(yb, yb.length);
			yb = Arrays.copyOf(tmp, tmp.length);
		}
		System.out.println(ans >= Double.MAX_VALUE / 4 ? "-1" : ans);
	}

	double dist(long xa, long ya, long xb, long yb) {
		long dx = xa - xb;
		long dy = ya - yb;
		return Math.sqrt(dx * dx + dy * dy);
	}

	boolean cross(long xa1, long ya1, long xb1, long yb1, long xa2, long ya2, long xb2, long yb2) {
		long v = f(xa1, ya1, xb1, yb1, xa2, ya2) * f(xa1, ya1, xb1, yb1, xb2, yb2);
		long u = f(xa2, ya2, xb2, yb2, xa1, ya1) * f(xa2, ya2, xb2, yb2, xb1, yb1);
		return v <= 0 && u <= 0;
	}

	long f(long xa, long ya, long xb, long yb, long x, long y) {
		return (ya - yb) * (x - xa) - (y - ya) * (xa - xb);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 37292
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;


int main()
{
	FAST;
	int n;
	cin >> n;
	int arr[n];

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

	int max1 = arr[0];
	int count = 1;
	for(int i=1 ; i<n ; i++)
	{
		if(arr[i] >= max1)
		{
			count++;
			max1 = arr[i];
		}
	}

	cout << count;
	return 0;
}

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

typedef pair<pair<ll, int>, pair<ll, ll>> event;

bool comp(event lhs, event rhs) {
    return lhs.first.first <= rhs.first.first;
}

int main() {
    ll n, q, s, t, x, d;
    vector<event> events;
    set<pair<ll, ll>> now_events;
    vector<ll> ds;

    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> s >> t >> x;
        events.push_back(make_pair(make_pair(s - x, 1), make_pair(x, i)));
        events.push_back(make_pair(make_pair(t - x, -1), make_pair(x, i)));
    }
    for(int i = 0; i < q; ++i) {
        cin >> d;
        ds.push_back(d);
    }

    sort(events.begin(), events.end(), comp);

    //for(auto itr = events.begin(); itr != events.end(); ++itr) {
    //    cout << (*itr).first.first << " " << (*itr).first.second << " " << (*itr).second.first << (*itr).second.second << endl;
    //}
    //cout << "--------" << endl;

    ll ind = 0;
    for(int i = 0; i < q; ++i) {
        d = ds[i];

        while (true) {
            if (events[ind].first.first > d) break;
            if (events[ind].first.second == 1) {
                now_events.insert(events[ind].second);
            } else {
                now_events.erase(events[ind].second);
            }
            ind += 1;
            if (ind >= events.size()) break;
        }

        if (now_events.empty()) {
            cout << -1 << endl;
        } else {
            cout << (*now_events.begin()).first << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 29028
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = k;
    rep(i, n-1) {
        ans *= (k-1);
    }

    out(ans);
    re0;
}

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

using namespace std;

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

	int n, m;
	string s[100], t[100];
	cin >> n;
	for(int i = 0; i < n; i++)cin >> s[i];
	cin >> m;
	for(int i = 0; i < m; i++)cin >> t[i];
	int ret = 0;
	for(int i = 0; i < n; i++)
	{
		int tmp = 0;
		for(int j = i; j < n; j++)
		{
			if(s[j] == s[i])tmp++;
		}
		for(int j = 0; j < m; j++)
		{
			if(t[j] == s[i])tmp--;
		}
		ret = max(ret, tmp);
	}
	cout << ret << endl;

return 0;
}


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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M;
  cin >> N >> M;
  ll INF = 10000000000;
  vector<vector<ll>> dp(N, vector<ll>(N, INF));

  for(int i = 0; i < N; i++){
    dp.at(i).at(i) = 0;
  }

  map<pair<int,int>, ll> m;
  map<pair<int,int>, bool> check;
  for(int i = 0; i < M; i++){
    int a,b;
    ll c;
    cin >> a >> b >> c;
    a--;
    b--;
    dp.at(a).at(b) = c;
    dp.at(b).at(a) = c;

    if(a > b) swap(a,b);

    m[make_pair(a,b)] = c;
    check[make_pair(a,b)] = false;
  }

  // ワーシャルフロイド
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  for(int i = 0; i < N-1; i++){
    for(auto e: check){
      if(e.second) continue;
      
      ll length = m[e.first];
      int start = e.first.first;
      int end = e.first.second;

      if(dp[i][start] == dp[i][end] + length) check[e.first] = true;
      if(dp[i][end] == dp[i][start] + length) check[e.first] = true;
    }
  }

  int ans = 0;
  for(auto x: check){
    if(!x.second) ans++;
  }
  cout << ans << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)		  (v).rbegin(),(v).rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int, int>
#define msi           map<string, int>

int solve(){
	int n,k; cin>>n>>k;
    string str; cin>>str;
    str[k-1]=tolower(str[k-1]);
    cout<<str;
    return 0;
}
 
signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--)
		solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int num,i,j,math[MAX][MAX],l[MAX],r[MAX],gn,weight=0,min,index,ans;

void input(){
    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        for (j = 0; j < num; j++) scanf("%d", &math[i][j]);
    }
}

void set(int n){
    gn = n - 1;
    r[0] = 1;
    l[0] = 0;
    for (i = 1; i < n; i++) {
        l[i] = 1;
        r[i] = 0;
    }
}

int main(void) {

    //input
    input();
    //intialize
    set(num);
    //calc
    while (gn--) {
        min = 10000000;
 
        for (i = 0; i < num; i++) {
            if (1 != r[i]) continue;
 
            for (j = 0; j < num; j++) {
                if (1 != l[j]) continue;
 
                ans = math[i][j];
                if (0 <= ans && ans < min) {
                    index = j;
                    min = ans;
                }
            }
        }
        r[index] = 1;
        l[index] = 0;
        weight += min;
    }
    //output
    printf("%d\n", weight);
    return 0;
}


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

int main(){
  string s;
  int i;
  int ans = 0;
  cin >> s;
  rep(i,s.size(),1){
    if(s[i-1] == '0' && s[i] == '0'){
      s[i] = '1';
      ans++;
    }
    else if(s[i-1] == '1' && s[i] == '1'){
      s[i] = '0';
      ans++;
   }
 }
 cout << ans << endl;
 return 0;
}


Measured memory_bytes: 512
import collections
N = int(input())
S= [ input() for _ in range(N)]
Sc = collections.Counter(S)
mv = max(Sc.values())
km = []
for key,val in Sc.items():
    if val == mv:
        km.append(key)
kms = sorted(km)
for k in kms:
    print(k)


Measured memory_bytes: 38684
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(x);
    Readln(t);
      
    Writeln(((x-t)+abs(x-t))div 2);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


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

using namespace std;

map< long long, int > prime_factor(long long n) {
	map< long long, int > ret;
	for (long long i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {

	long long x;
	map<long long, int > a;
	cin >> x;
	a = prime_factor(x);

	auto iter = a.begin();

	cout << x << ":";

	while (iter != a.end()) {
		for (int i = 0; i < iter->second;i++) {
			cout << " " << iter->first;
		}
		iter = next(iter, 1);
	}
	cout << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#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--)
using namespace std;

int main() {
    int n, a;
    cin >> n >> a;
    cout << (n % 500 <= a ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
using System;

namespace rensyuu1
{
    class Program
    {
        static void Main(string[] args)
        {
            //行列の読み込み
            string[] line = Console.ReadLine().Trim().Split(' ');
            int a = int.Parse(line[0]);
            int b = int.Parse(line[1]);
            int[,] g1 = new int[a, b];
            int[] g2 = new int[b];
            int[] o1 = new int[a];
            for (int i1 = 0; i1 < a; i1++)
            {
                string[] array = Console.ReadLine().Trim().Split(' ');
                for (int i2 = 0; i2 < b; i2++)
                {
                    g1[i1, i2] = int.Parse(array[i2]);
                }
            }
            //列の読み込み
            for (int i3 = 0; i3 < b; i3++)
            {
                g2[i3] = int.Parse(Console.ReadLine());
            }

            //計算
            for (int i4 = 0; i4 < a; i4++)
            {
                o1[i4] = 0;
                for (int i5 = 0; i5 < b; i5++)
                {
                    int[] o2 = new int[b];
                    o2[i5] = g1[i4, i5] * g2[i5];
                    o1[i4] = o1[i4] + o2[i5];

                }
                Console.WriteLine(o1[i4]);

            }
        }
    }
}


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

int main(){
	int n;
	ll ans = 0;
	cin >> n;
	vector<int> a(n+1), b(n);
	rep(i, n+1) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);
	rep(i, n){
		if(a.at(i) <= b.at(i)){
			ans += a.at(i);
			b.at(i) -= a.at(i);
			if(a.at(i+1) <= b.at(i)){
				ans += a.at(i+1);
				a.at(i+1) = 0;
			}else{
				ans += b.at(i);
				a.at(i+1) = a.at(i+1) - b.at(i);
			}
		}else{
			ans += b.at(i);
		}
	}
	cout <<ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
typedef pair<int,int> ip;
ip a[3003];
#define MOD 1000000007
int dp[3003],fac[200005],invfac[200005];

bool cm(ip a1,ip a2)
{
	if(a1.first==a2.first)
	return a1.second<a2.second;
	return a1.first<a2.first;
}
int sub(int x,int y)
{
	x=(x-y)%MOD;
	if(x<0)
	x=x+MOD;
	return x;
}
int power(int x,int y,int z)
{
	if(y==0)
	return 1;
	int p=power(x,y/2,z);
	p=(p*p)%z;
	if(y%2==1)
	return (p*x)%z;
	else return p;
}
int inv(int x)
{
	return power(x,MOD-2,MOD);
}
void pre()
{
	fac[0]=1;
	invfac[0]=1;
	fac[1]=1;
	invfac[1]=1;
	for(int i=2;i<=200000;i++)
	{
		fac[i]=(fac[i-1]*i)%MOD;
		invfac[i]=inv(fac[i]);
	}
}
int bionomial(int x,int y)
{

	return (fac[x+y]*((invfac[x]*invfac[y])%MOD))%MOD;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	pre();
	int h,w,n,i,j;
	cin>>h>>w>>n;
	for(i=0;i<n;i++)
	cin>>a[i].first>>a[i].second;
	a[n].first=h;
	a[n].second=w;
	sort(a,a+n+1,cm);	
	for(i=0;i<=n;i++)
	{
		int val=bionomial(a[i].first-1,a[i].second-1);
		for(j=0;j<i;j++)
		{
			if(a[i].first>=a[j].first&&a[i].second>=a[j].second)
			val=sub(val,(dp[j]*bionomial(a[i].first-a[j].first,a[i].second-a[j].second))%MOD);
		}
		dp[i]=val;
	}
	cout<<dp[n]<<"\n";
}

Measured memory_bytes: 6848
import java.util.Scanner;

public class Main {

	static int n, t[], x[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		t = new int[n + 1];
		x = new int[2][n + 1];
		for (int i = 1; i <= n; ++i) {
			t[i] = sc.nextInt();
			x[0][i] = sc.nextInt();
			x[1][i] = sc.nextInt();
		}
		sc.close();
		String ans[] = { "Yes", "No" };
		int a = 0;
		for (int i = 1; i <= n; ++i) {
			int tmp = Math.abs(x[0][i] - x[0][i - 1]) + Math.abs(x[1][i] - x[1][i - 1]);
			int tmp2 = t[i] - t[i - 1];
			if(tmp > tmp2) {
				a = 1;
				break;
			}
			else {
				if(tmp % 2 != tmp2 % 2) {
					a = 1;
					break;
				}
			}
		}
		System.out.println(ans[a]);

	}

}


Measured memory_bytes: 92948
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  ll n,h;
  cin >> n >> h;
  vector<ll>a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }
  sort(a.begin(),a.end(),greater<ll>());
  sort(b.begin(),b.end(),greater<ll>());
  
  ll ans=0;
  rep(i,n){
    if(h<=0)break;
    if(b[i]>a[0]){
      ans++;
      h=max(0ll,h-b[i]);
    }
    else{
      ans+=(h+a[0]-1)/a[0];
      h=0;
      break;
    }
  }
  if(h>0)ans+=(h+a[0]-1)/a[0];
  cout << ans << endl;
}


Measured memory_bytes: 1792
def rest(n, i):
    while n%i == 0:
        n //= i
    return n

N = int(input())
if N == 2:
    print(1)
    exit()

ans = [N-1, N]

for i in range(2, int(N**0.5) + 1):
    if (N-1)%i == 0:
        ans.append(i)
        ans.append((N-1)//i)
    elif N%i == 0:
        if rest(N,i) % i == 1 or rest(N,N//i) % (N//i) == 1:
            ans.append(i)

print(len(set(ans)))

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


void work(){
	ll n;
	cin>>n;
	if(n>=30) puts("Yes");
	else puts("No");
	return ;
}

int main(){
	//work();
//freopen("C:\\Users\\lenovo\\Desktop\\in.txt","r",stdin);
	work();
	return 0;
}


Measured memory_bytes: 3632
N = gets.chomp.to_i
a = Array.new(N+1){Array.new(0)}
answer = Array.new(N+1,0)
for i in 1...N do
    str = gets.split
    x,y = str[0].to_i, str[1].to_i
    a[x].push(y)
    a[y].push(x)
end
j = 1
while a[j].size != 1
    j += 1
end

q = Array.new(2){Array.new(0)}
r = Array.new(2){Array.new(0)}
q[0].push(j)
r[0].push(j)
j = 0
while !q[j].empty?
    k = (j+1)%2
    while !q[j].empty?
        b = q[j].pop
        while !a[b].empty?
            c = a[b].pop
            if !a[c].empty?
                q[k].push(c)
                r[k].push(c) 
            end
        end
    end
    j += 1
    j %= 2
end

if r[0].size <= N/3
    b = r[0].size
    for i in 1..b do
        c = r[0].pop
        answer[c] = i*3
    end
    k = 1
    for i in b+1..N/3 do
        while answer[k] != 0
            k += 1
        end
        answer[k] = i*3
    end
    l = 1
    while k <= N
        if answer[k] == 0
            if l%3 == 0
                l += 1
            end
            answer[k] = l
            l += 1
        end
        k += 1
    end
elsif r[1].size <= N/3
    b = r[1].size
    for i in 1..b do
        c = r[1].pop
        answer[c] = i*3
    end
    k = 1
    for i in b+1..N/3 do
        while answer[k] != 0
            k += 1
        end
        answer[k] = i*3
    end
    l = 1
    while k <= N
        if answer[k] == 0
            if l%3 == 0
                l += 1
            end
            answer[k] = l
            l += 1
        end
        k += 1
    end
else
    for i in 0..(N-1)/3 do
        c = r[0].pop
        answer[c] = i*3 + 1
    end
    for i in 0..(N-2)/3 do
        c = r[1].pop
        answer[c] = i*3 + 2
    end
    k = 1
    l = 3
    while k <= N
        if answer[k] == 0
            answer[k] = l
            l += 3
        end
        k += 1
    end
end

for i in 1..N do
    print answer[i]
    print " "
end
puts

Measured memory_bytes: 24060
#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>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	double ans = (double)w*h / 2;
	int num = (w == x * 2 && h == y * 2) ? 1 : 0;
	cout << fixed << setprecision(15) << ans << " " << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> data(n);
  for(int i=0; i<n; i++){
    cin>>data.at(i);
  }
  sort(data.begin(),data.end());
  if(n<=k){
    cout<<"0"<<endl;
  }else{
    long long ans=0;
    for(int i=0; i<n-k; i++){
      ans+=data.at(i);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1};

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    map<int, int> ev, od;
    rep(i, n)
    {
        int v; cin >> v;
        if (i % 2 == 0) od[v]++;
        else ev[v]++;
    }

    int ev1 = 0, od1 = 0;
    int ec1 = 0, ec2 = 0, oc1 = 0, oc2 = 0;
    int cnt = 0;

    FOR(itr, ev)
    {
        if (itr->second > cnt)
        {
            cnt = itr->second;
            ev1 = itr->first;
        }
    }
    ec1 = cnt;
    cnt = 0;

    FOR(itr, ev)
    {
        if (itr->second > cnt && itr->first != ev1)
        {
            cnt = itr->second;
        }
    }
    ec2 = cnt;
    cnt = 0;

    FOR(itr, od)
    {
        if (itr->second > cnt)
        {
            cnt = itr->second;
            od1 = itr->first;
        }
    }
    oc1 = cnt;
    cnt = 0;

    FOR(itr, od)
    {
        if (itr->second > cnt && itr->first != od1)
        {
            cnt = itr->second;
        }
    }
    oc2 = cnt;

    if (ev1 == od1)
    {
        cout << min(n - ec1 - oc2, n - ec2 - oc1) << endl;
    }
    else
    {
        cout << n - ec1 - oc1 << endl;
    }
}

Measured memory_bytes: 4992
N = int(input())
arr = list(map(int, input().split()))
two_count = 0
four_count = 0
for i in arr:
    if i % 4 == 0:
        four_count += 1
        continue
    if i % 2 == 0:
        two_count += 1
        continue
ans = N - ((two_count//2)*2 + (four_count*2) + 1 if four_count > 0 else 0)
if ans <= 0 or two_count == N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<char> v, ch;
    vector<string> s;
    int n, k; cin >> n >> k;
    for (int i = 0; i < k; i++)
    {
        char d; cin >> d;
        v.push_back(d);
    }
    int j = 0;
    for (char i = '0'; i <= '9'; i++)
    {
        if (v[j] == i)
        {
            j++;
            continue;
        }
        string y = "0";y[0] = i;
        ch.push_back(i);
        s.push_back(y);
    }
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i].size() > 4)break;
        for (int j = 0; j < ch.size(); j++)
        {
            s.push_back(ch[j]+s[i]);
        }
    }
    int ans = 1000000;
    for (int i = 0; i < s.size(); i++)
    {
        if (stoi(s[i]) >= n)
        {
            ans = min(ans, stoi(s[i]));
        }
    }
    cout << ans << endl;
}

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

int main(){
	int a[3],b;
	for(int i=0;i<3;i++){
		cin>>a[i];
		}
	for(int i=0;i<2;i++){
		for(int j=i+1;j<3;j++){
			if(a[i]>a[j]){
				b=a[i];
				a[i]=a[j];
				a[j]=b;
				}
			}
		}
	for(int i=0;i<2;i++){
		cout<<a[i]<<" ";
		}
	
	cout<<a[2]<<endl;
	return 0;
}

Measured memory_bytes: 1160