akhauriyash/Code-Regression huggingface dataset:
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int an=6;
    REP(i,2){
        int x;
        R(x);
        an-=x;
    }
    W(an);
    return 0;
}


Measured memory_bytes: 764
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);


vector<ll> vec;
vector<set<ll> >v;
vector<ll> e;

void dfs(ll vv){              //v に関して深さ優先探索(vは頂点の番号)
    vec[vv]=1;              //v に訪問済みの印を付ける
    for(ll i : v[vv]){    //v に接続している各頂点i に対し
        if(vec[i]==0){    //i が未訪問なら
          e[i]+=e[vv];
          dfs(i);           //i に関して深さ優先探索
        }
    }
}

int main(){
  ll n,q,ans=0;
  cin>>n>>q;
  vec.assign(n,0);
  v.assign(n,set<ll>());
  e.assign(n,0);
  ll a,b;
  for(ll i=0;i<n-1;i++){
    cin>>a>>b;
    a--;
    b--;
    v[a].insert(b);
    v[b].insert(a);
  }
  for(ll i=0;i<q;i++){
    cin>>a>>b;
    a--;
    e[a]+=b;
  }
  dfs(0);
  cout<<e[0];
  for(ll i=1;i<n;i++){
    cout<<" "<<e[i];
  }
  cout<<endl;
}


Measured memory_bytes: 43008
from heapq import heappop,heappush
from collections import defaultdict
t = int(input())
for i in range(t):
  n,a,b,c,d=map(int,input().split())
  q=[(0,n)]
  memo = defaultdict(int)
  while q:
    s,p = heappop(q)
    if memo[p]:
      continue
    memo[p] = 1
    if p == 0:
      print(s)
      break
    heappush(q,(s+d*p,0))
    if p & 1:
      heappush(q,(s+d+a, p//2))
      heappush(q,(s+d+a, p//2+1))
    else:
      heappush(q,(s+a, p//2))
    if p % 3:
      heappush(q,(s+d*(p%3)+b, p//3))
      heappush(q,(s+d*(-p%3)+b, p//3+1))
    else:
      heappush(q,(s+b, p//3))
    if p % 5:
      heappush(q,(s+d*(p%5)+c, p//5))
      heappush(q,(s+d*(-p%5)+c, p//5+1))
    else:
      heappush(q,(s+c, p//5))
    


Measured memory_bytes: 98504
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, h;
    cin >> n >> h;
    vector<P> p;
    ll a, b;
    REP(i, n){
        cin >> a >> b;
        p.push_back(P{a, 0});
        p.push_back(P{b, 1});
    }
    VSORTR(p);
    ll res = 0, id = 0;
    while(h > 0){
        ll d = p[id].first;
        if(p[id].second == 1){
            h -= d;
            res++;
            id++;
        }
        else{
            ll k = (h - 1) / d + 1;
            h -= k * d;
            res += k;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6512
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main() {
	int n;
	cin >> n;
	vi a(n);
	int s = 0, b = 0;
	REP(i, n) {
		cin >> a[i];
		b = max(b, a[i]);
	}
	REP(i, n) {
		int d = abs(b/2-a[i]);
		if (d < abs((b/2)-s)) {
			s = a[i];
		}
	}

	cout << b << " " << s << endl;
	return 0;
}

Measured memory_bytes: 640
n, m = gets.split.map(&:to_i)
ab = m.times.map {gets.split.map(&:to_i)}

paths = Array.new(n + 1) {[]}
ab.each do |a, b|
  paths[a] << b
  paths[b] << a
end

guide = Array.new(n + 1)
guide[1] = "Yes"

q = [1]
while (now = q.shift)
  paths[now].each do |nxt|
    next if guide[nxt]
    guide[nxt] = now
    q << nxt
  end
end

puts guide[1..-1]

Measured memory_bytes: 53496
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
typedef long long ll;
typedef long double la;
#define pb push_back()
using namespace std;

int main(){
  string s;
  int a;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  if(a < 3200) cout << "red" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    void solve() {
        int n = in.nextInt();
        int[] pos = new int[n];
        for (int i = 0; i < n; i++) {
            pos[ in.nextInt() - 1] = i;
        }
        boolean[] ok = new boolean[n - 1];
        for (int i =0 ; i + 1 < n; i++) {
            if (pos[i + 1] > pos[i]) {
                ok[i] = true;
            }
        }
        int maxOk = 0;
        for (int i =0 ; i < n - 1; ) {
            if (!ok[i]) {
                i++;
                continue;
            }
            int j= i;
            while (j != n - 1 && ok[j]) {
                j++;
            }
            maxOk = Math.max(maxOk, j - i);
            i = j;
        }
        out.println(n - (maxOk + 1));
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

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

Measured memory_bytes: 45352
x,y = map(int,input().split())
mod = 10**9 + 7

move = x+y
if move %3 !=0:
  print(0)
  exit()
move //= 3
  
x,y = x-move, y-move

if x < 0 or y < 0:
  print(0)
  exit()
  
ans = 1
for i in range(min(x,y)):
  ans *= (x+y-i)
  ans *= pow(i+1,mod-2,mod)
  ans %= mod
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>A>>B>>C;
    cout<<A+B+C - max({A, B, C})<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

ll dot(vector<ll> const& a, vector<ll> const& b){
    ll result = 0;
    rep(i, a.size())
        result += a[i] * b[i];

    return result;
}

int main(void) {
    ll N, M, C;
    cin >> N >> M >> C;
    vector<ll> B(M);
    rep(i, M)
        cin >> B[i];

    ll ans = 0;
    rep(i, N){
        vector<ll> A(M);
        rep(i, M)
            cin >> A[i];
        if(dot(A, B) > -C)
            ans++;
    }

    cout << ans << endl;

    return 0;
}

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

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

using namespace std;

const int MAX = 3e6;

int main() {
	vector<int> v(MAX, 1);
	v[0] = v[1] = 0;
	reps(i, 1, MAX) {
		if (v[i]) for (int j = i * 2; j < MAX; j += i) {
			v[j] = 0;
		}
	}
	rep(i, MAX) {
		v[i+1] += v[i];
	}
	int n;
	cin >> n;
	while (n) {
		cout << v[2*n] - v[n] << endl;
		cin >> n;
	}
}


Measured memory_bytes: 14192
#include <bits/stdc++.h>
#define ll long long
#define uint unsigned long long
#define ls x << 1
#define rs x << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int ans, n, a[210];
int main()
{
	n = read();
	n = n * 2;
	rep(i, 1, n)
		a[i] = read();
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i += 2)
		ans += a[i];
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin >> s;
    
    int n = 0;
    
    int d = 1000;
    for(int i = 0;i < s.size();i++){
        n += (s[i] - '0') * d;
        d /= 10;
    }
    int a = n / 100;
    int b = n % 100;
    
    if((1 <= a && a <= 12) && (1 <= b && b <= 12)){
        cout << "AMBIGUOUS" << endl;
    }else if((1 <= a && a <= 12) && !(1 <= b && b <= 12)){
        cout << "MMYY" << endl;
    }else if(!(1 <= a && a <= 12) && (1 <= b && b <= 12)){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int without_ab(int a, int b, int x, int y)
{
  return a * x + b * y;
}

int all_ab(int c, int x, int y)
{
  return max(x, y) * 2 * c;
}

int partially_use_ab(int a, int b, int c, int x, int y)
{
  int total = 0;
  if(x < y) {
    total += x * 2 * c;
    total += (y-x) * b;
  } else {
    total += y * 2 * c;
    total += (x-y) * a;
  }
  return total;
}

int main()
{
  int a, b, c, x, y;
  scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

  printf("%d\n", min(min(without_ab(a, b, x, y), all_ab(c, x, y)), partially_use_ab(a, b, c, x, y)));
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,ans,a[100001];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	for (int i=1;i<=n;i++)
		if (a[i]==i)
		{
			swap(a[i+1],a[i]);
			ans++;
		}
	printf("%d",ans);
}

Measured memory_bytes: 512
N, A, B = map(int, input().split(' '))


def main(n, a, b):
    distance = b - a

    if distance % 2 == 0:
        return distance // 2
    else:
        return min(a - 1, n - b) + 1 + (distance - 1) // 2


print(main(N, A, B))


Measured memory_bytes: 2940
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int maxi = 0;
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        int aux; cin >> aux;
        if (aux < maxi){
            ans += maxi-aux;
        }
        else maxi = aux;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3648
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,a,b = readInts()
if abs(b-a)%2 == 0:
    print(abs(b-a)//2)
else:
    print(min(a + (abs(b-a)-1)//2, n-b+1+(abs(b-a)-1)//2))


Measured memory_bytes: 10288
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main()
{
    string s;
    cin >> s;
    replace(s.begin(), s.end(), ',', ' ');
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,H;
  cin >> N >> H;
  priority_queue<pair<int,bool>,vector<pair<int,bool>>> pq;
  rep(i,N) {
    int a,b;
    cin >> a >> b;
    pq.push(P(a,true));
    pq.push(P(b,false));
  }
  int cnt = 0;
  while(H > 0) {
    int c = pq.top().first;
    bool f = pq.top().second;
    if(!f) pq.pop();
    H -= c;
    cnt++;
    if(f) {
      cout << cnt + (H + c - 1) / c << endl;
      return 0;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int n,m,graph[8][8]={};
    cin >> n >> m;
    rep(i,0,m){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a][b]=graph[b][a]=1;
    }

    i64 memo[8][1<<8];
    fill_n((i64*)memo,8*(1<<8),-1);
    function<i64(int,int)> rec=[&](int u,int s){
        i64 &res=memo[u][s];
        if(res!=-1) return res;
        if(s==((1<<n)-1)) return res=1;
        res=0;
        rep(v,0,n){
            if(!graph[u][v] or (s>>v)&1) continue;
            res+=rec(v,s|(1<<v));
        }
        return res;
    };
    cout << rec(0,1) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main()
{
ll n , u , v ;
cin >> n >> u >> v ;
u--;
v--;
vector<vector<ll>> g(n);
rep(i, n-1)
{
  ll a, b;
  cin >> a >> b;
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1); //無向辺
}
vector<ll> distt(n,-1);
vector<ll> dista(n,-1);
queue<ll> q;
distt[u]=0;
q.push(u);
while(!q.empty()){
  auto p=q.front();
  q.pop();
  for(auto r:g[p]){
    if(distt[r]!=-1)continue;
    distt[r]=distt[p]+1;
    q.push(r);
  }
}
dista[v]=0;
q.push(v);
while(!q.empty()){
  auto p=q.front();
  q.pop();
  for(auto r:g[p]){
    if(dista[r]!=-1)continue;
    dista[r]=dista[p]+1;
    q.push(r);
  }
}
rep(i,n){
  if(distt[i]<dista[i]){
    ans=max(ans,dista[i]-1);
  }
}

cout << ans << endl;
return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#define _USE_MATH_DEFINENS
#include <cmath>
using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int x, a, b;
    cin >> x >> a >> b;
    int ans = b - a;
    if(ans <= 0){
        cout << "delicious";
    }else if(ans <= x){
        cout << "safe";
    }else{
        cout << "dangerous";
    }
    el;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn],pos[maxn];
int n,L;
int main()
{
	n=read(); L=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<n;i++)
		if(a[i]+a[i+1]>=L){
			puts("Possible");
			for(int j=1;j<i;j++)
				writeln(j);
			for(int j=n-1;j>i;j--)
				writeln(j);
			writeln(i);
			return 0;
		}
	puts("Impossible");
	return 0;
}

Measured memory_bytes: 1152
data = input().split()
x = int(data[0])
y = int(data[1])

L1 = [1,3,5,7,8,10,12]
L2 = [4,6,9,11]
L3 = [2]

if((x in L1 and y in L1) or (x in L2 and y in L2) or (x in L3 and y in L3)):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm> //sort,二分探査など
#include <atcoder/fenwicktree>
//#include<bitset>
//#include<cmath>//pow,logなど
//#include<deque>
//#include<functional>
//#include<iterator>
//#include<map>
//#include<numeric>//gcd,lcm
//#include<queue>
//#include<set>
//#include<stack>
//#include<string>
//#include<utility>//pair

//QCFium法
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

//浮動小数点処理高速化
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace atcoder;
using i64 = int64_t;
using f80 = __float80;
using u64 = uint_fast64_t;

constexpr i64 INF = 1010000000000000017LL;
constexpr u64 MOD = 1000000007LL;
constexpr f80 PI = 3.14159265358979323846;

#define _overload3(_1, _2, _3, name, ...) name
#define repi(i, start, end) for (int i = (int)(start); i < (int)(end); ++i)
#define _rep(i, n) repi(i, 0, n)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(i, start, end) for (int i = (int)(start); i > (int)(end); --i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()

#define v(T) vector<T>
#define vv(T) v(v(T))
#define vvv(T) v(v(v(T)))
typedef v(int) vi;

#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
  rep(i, v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
  for (T &in : v)
    is >> in;
  return is;
}

//sort(rng(P),[](const vi &a, const vi &b){return a[1]<b[1];});

void Main()
{
  int n, q;
  cin >> n >> q;

  fenwick_tree<i64> fw(n);
  rep(i, n)
  {
    int a;
    cin >> a;
    fw.add(i, a);
  }

  rep(i, q)
  {
    int t;
    cin >> t;
    if (t == 0)
    {
      int p, x;
      cin >> p >> x;
      fw.add(p, x);
    }
    else
    {
      int l, r;
      cin >> l >> r;
      cout << fw.sum(l, r) << "\n";
    }
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 8260
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	sort.Ints(aa)

	ans := 1 << 30

	for a := aa[0]; a <= aa[n-1]; a++ {
		s := 0
		for i := 0; i < n; i++ {
			s += (a - aa[i]) * (a - aa[i])
		}
		if ans > s {
			ans = s
		}
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 640
import java.util.*;

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

      int n=sc.nextInt();
      int d=sc.nextInt();

      int[][] x = new int[n][d];

      for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
          x[i][j]=sc.nextInt();
        }
      }

      double iii = 0;
      int cnt=0;

      for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
          iii=0;
          for(int k=0;k<d;k++){
            iii += Math.pow(x[i][k]-x[j][k],2);
          }
          iii = Math.sqrt(iii);
          if(iii==(int)iii){
            cnt++;
          }
        }
      }

      System.out.println(cnt);

    }
}


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

double omote[3010][3010];

int main() {
  int n;
  cin >> n;
  vector<double>p(n);
  rep(i,n) cin >> p[i];
  rep(i,3010){
    rep(j,3010){
      omote[i][j]=0;
    }
  }  
  omote[0][0]=1;
  rep(i,n) omote[i+1][0]=omote[i][0]*(1.00-p[i]);
  rep(i,n){
    rep(j,n){
      omote[i+1][j+1]=omote[i][j]*p[i]+omote[i][j+1]*(1.00-p[i]);
    }
  }
  double ans=0.00;
  for(int i=n/2+1;i<=n;i++){
    ans+=omote[n][i];
  }
  cout << fixed << setprecision(9) << ans << endl; 
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (long long)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll fib(ll n){
    vll a(n+1);
    a[0] = 1;
    a[1]  = 1;

    REP(i,2,n+1){
        a[i] = a[i-1] + a[i-2];
        a[i] %= mod;
    }

    return a[n-1];
}

int main()
{
    ll n,m;
    cin >> n >> m;
    vll a(n+1,0),dp(n+1);
    rep(i,m)cin >> a[i];
    dp[0] = 1;
    dp[1] = ((a[0] == 1)?0:1);

    ll now = ((a[0] == 1)?1:0);
    REP(i,2,n+1){
        if(i == a[now]){
            dp[i] = 0;
            now++;
        }

        else dp[i] = dp[i-1] + dp[i-2];

        dp[i] %= mod;
    }

    cout << dp[n] << endl;
    //rep(i,n+1)cout << dp[i] << " ";

    return 0;
}

Measured memory_bytes: 1792
import std;

bool calc(int k, int a, int b) {
    for (int i = 0; i <= b; i++) {
        auto x = i * k;
        if (a <= x && x <= b) return true;
    }
    return false;
}

void main() {
    int k; scan(k);
    int a, b; scan(a, b);
    writeln(calc(k, a, b) ? "OK" : "NG");
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3640
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

signed main() {
    int n,k;cin >> n >> k;
    vi v(n);
    set<int> st;
    rep(i, n) {
        int a;cin >> a;
        a--;
        v[a]++;
        st.insert(a);
    }
    sort(all(v));
    int i = 0;
    while(v[i]==0) i++;
    int ans = 0;
    // k+=i;
    k=st.size()-k+i;
    // cout << st.size() << endl;
    // cout << k << endl;
    // cout << i << endl;
    for(;i<k;i++) {
        ans+=v[i];
        // cout << "OK" << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13924
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;

int main() {
for (int i = 0; i < 5; i++) {
  int x;
  cin >> x;
  if (x == 0) {
    cout << i+1 << endl;
    return 0;
  }
}
  return 0;
}


Measured memory_bytes: 3620
// D - Friend Suggestions
// DFS version
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define MAX 100000+1
int N,M,K;
vvi F(MAX),B(MAX);//friend,block
vi gid(MAX);

int dfs(int root, int p){
	if(gid[p]) return root;
	gid[p] = root;
	for(auto c:F[p]) dfs(root,c);
	return root;
}

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

	rp(i,0,M){
		int s,t; cin>>s>>t;
		F[s].push_back(t);
		F[t].push_back(s);
	}

	vi cnt(N+1);
	rp(i,1,N+1) cnt[gid[dfs(i,i)]]++;

	rp(i,0,K){
		int s,t; cin>>s>>t;
		if(gid[s] != gid[t]) continue;
		B[s].push_back(t);
		B[t].push_back(s);
	}

	int self = 1;
	rp(i,1,N+1) cout<< cnt[gid[i]]-F[i].size()-B[i].size()-self <<" ";

}

Measured memory_bytes: 12536
N, K = map(int,input().split())
h = [0 for i in range(N)]
for i in range(N):
	h[i] = int(input())
h.sort()
# print(h)

MIN = 10**10
for i in range(N-K+1):
	if h[i+K-1] - h[i] <= MIN:
		MIN = h[i+K-1] - h[i]
# print(i,h[i],h[i+K-1])
print(MIN)



Measured memory_bytes: 7392
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
A = list(map(int,readline().split()))
ans = 0
for i in range(N):
    if i%2 == 0 and A[i]%2 == 1:
        ans += 1
print(ans)




Measured memory_bytes: 9432
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc124_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] N = Console.ReadLine().Split(' ');
            int A = int.Parse(N[0]);
            int B = int.Parse(N[1]);
            int total = 0;

            for(int i = 0; i < 2; i++)
            {
                if (A >= B)
                {
                    total = total + A;
                    A = A - 1;
                }
                else
                {
                    total = total + B;
                    B = B - 1;
                }
            }

            Console.WriteLine(total);
            Console.Read();
            
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 100010;
const int maxD = 400;
const int maxH = 100; 
const int MOD = 1000000007;

char a[maxN];
int b[130];
int main()
{
	scanf("%s",a+1);
	int n = strlen(a+1);
	for(int i=1;i<=n;i++)
	{
		b[a[i]]++;
	}
	for(int i=97;i<=122;i++)
	{
		if(b[i] == 0)
		{
			printf("%c\n",i);
			return 0;
		}
	}
	puts("None");
	return 0;
}  

Measured memory_bytes: 384
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    #n = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    x = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    for i in range(len(x)):
        if x[i] == 0:
            print(i+1)
            exit()
        else:
            pass

main()


Measured memory_bytes: 9180
N, M = list(map(int, input().split()))
X = [0] * N
Y = [0] * N
for i in range(M):
    S, E = list(map(int, input().split()))
    if S == 1:
        X[E-1] = 1
    if E == N:
        Y[S-1] = 1
for i in range(N):
    if X[i] == 1 and Y[i] == 1:
        print("POSSIBLE")
        break
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 6260
import copy

def partition(A, p, r):
    x = int(A[r][1])
    i = p-1
    for j in range(p, r):
        if int(A[j][1]) <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i+1

def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q-1)
        quickSort(A, q+1, r)

def show(l):
    for i in range(len(l)):
        print(l[i][0], l[i][1], sep = ' ')
    

n = int(input())
l_1 = []
for _ in range(n):
    a = input().split()
    l_1.append(a)
l_2 = copy.deepcopy(l_1)

quickSort(l_1, 0, n-1)

for i in range(n-1):
    if int(l_1[i][1]) == int(l_1[i+1][1]):
        if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):
            print('Not stable')
            break
else:  
    print('Stable')

show(l_1)


Measured memory_bytes: 49792
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]

    d = dict()
    for a in A:
        if a in d:
            d[a] += 1
        else:
            d[a] = 1

    total = sum(A)
    ans = []
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        if b in d:
            if c in d:
                d[c] += d[b]
            else:
                d[c] = d[b]

            total += (c - b) * d[b]
            ans.append(total)
            d.pop(b)

        else:
            ans.append(total)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
map<ll, ll> mp;

int main(){
    int x, k;
    cin >> x;
    vector<int> a(5);
    REP(i, 5) {
        a[i] = 100 + i;
    }

    k = x % 100;
    x /= 100;
    if(k <= x*5) {
        cout << "1" << endl;
    } else {
        cout << "0" << endl;
    }



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,tmp;
	double x;
	scanf("%d %d",&a,&b);
	if((a+b)%2){
		printf("%d\n",(a+b)/2+1);
	}
	else{
		printf("%d\n",(a+b)/2);
	}
	return 0;		
}

Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ways = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            tot = 500*i + 100*j + 50*k
            if tot == X:
                ways += 1

print(ways)


Measured memory_bytes: 3060
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto r = RD;

	writeln((r^^2)*3);
	stdout.flush();
	debug readln();
}


Measured memory_bytes: 256
MOD = 10**9 + 7
N,M = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
ans = (a.uniq == a || b.uniq == b) ? 1 : 0
row,col = 0,0
(N*M).downto(1) do |i|
  fa,fb = a[-1-row] == i, b[-1-col] == i
  if fa && fb
    row += 1
    col += 1
  elsif !fa && fb
    col += 1
    ans = (ans*row) % MOD
  elsif fa && !fb
    row += 1
    ans = (ans*col) % MOD
  else
    ans = (ans*(row*col-(N*M-i))) % MOD
  end
  #p [i,fa,fb,row,col,ans]
end
p ans

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

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

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

  int cnt = 0, m = 0, h = 0;
  while(h <= n) {
    h = 3 * h + 1;
    m++;
  }
  m--;
  vector<int> g(m);
  g[0] = 1;
  for (int i = 1; i < m; i++) {
    g[i] = 3 * g[i-1] + 1;
  }

  reverse(g.begin(), g.end());

  for (int k = 0; k < m; k++) {
    for (int i = g[k]; i < n; i++) {
      int v = a[i];
      int j = i - g[k];
      while (j >= 0 && a[j] > v) {
        a[j+g[k]] = a[j];
        j = j - g[k];
        cnt++;
      }
      a[j+g[k]] = v;
    }
  }

  cout << m << endl;
  for (int i = 0; i < m; i++) {
    if (i < m - 1) cout << g[i] << " ";
    else cout << g[i] << endl;
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 6756
d = [[-1,0],[1,0],[0,-1],[0,1]]
def search(w,h,x,y,m):
    if not(0<=x<w and 0<=y<h) or m[y][x]=='#': return 0
    m[y][x] = '#'
    return sum([search(w,h,x+dx,y+dy,m) for dx,dy in d])+1

while True:
    w,h = map(int,input().split())
    if w==h==0: break
    m = []
    for i,l in enumerate([list(input()) for _ in range(h)]):
        if '@' in l: x,y = l.index('@'),i
        m += [l]
    print(search(w,h,x,y,m))

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

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

const ll mod = 1000000007;

ll modpow(ll A, ll N) {
    ll RET = 1;
    // 例えば3=101(2)なので、下位bitから順に1ならa倍する
    while (N) {
        if (N & 1) RET = RET * A % mod;
        A = A * A % mod;
        N >>= 1;
    }
    return RET;
}

ll comb(ll N, ll R) {
    if (N < 0 || R < 0 || N < R) return 0;
    // numerator / denominator
    ll NUME = 1, DENO = 1;
    R = min(R, N-R);
    for (int i = 1; i <= R; i++) {
        NUME = NUME * N % mod;
        DENO = DENO * i % mod;
        N--;
    }
    return NUME * modpow(DENO, mod-2) % mod;
}

int main() {
    ll n, m, k, ans;
    cin >> n >> m >> k;
    ans = comb(n*m-2, k-2);
    ans = ans * m * n % mod;
    ans = ans * (m * n - 1) % mod;
    ans = ans * (m + n) % mod;
    ans = ans * modpow(6, mod-2) % mod;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }

    for(int i = N-2; i >= 0; --i){
        if((H[i+1] - H[i]) < 0){
            H[i]--;
            if((H[i+1] - H[i]) < 0){
                 cout << "No" << endl;
                 return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0; 
}

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

int main(void) {
	int N;
	scanf("%d", &N);
	string S;
	cin >> S;
	for (int i = 0; i < (int) S.length(); i++ ) {
		if (S[i] + N <= 'Z') {
			printf("%c", S[i] + N);
		} else {
			printf("%c", 'A' - 1 + (N - ('Z' - S[i])));
		}
	}

	return 0;
}


Measured memory_bytes: 256