akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;
//
//int N;
//
//string str(ll n) {
//    return to_string(n);
//}

bool q(ll n) {
    cout << "? " << n << endl << flush;
    char c;
    cin >> c;
    return c == 'Y';
}

ll solve() {
    ll x = [&] {
        ll x = 10;
        for (; x <= ll(1e9) && q(x); x *= 10) {}
        return x;
    }();

    if (x == ll(1e10)) {
        x = 2;
        for (; x <= 2 * ll(1e9) && !q(x); x *= 10) {}
        return x / 2;
    }

    ll floor = x / 10, ceil = x - 1;

    while (floor + 1 < ceil) {
        ll mid = (floor + ceil) / 2;
        if (q(mid * ll(1e9))) ceil = mid;
        else floor = mid;
    }
    return ceil;

}

int main() {
    ll n = solve();

//    printf("! %lld\n", n);
    cout << '!' << ' ' << n << endl << flush;

//    rep(i, 10000) {
//        if (i == 0) continue;
//        N = i;
//        cout << i << ' ' << n << endl;

//        cout << (n == N ? "OK" : "NG") << endl;
//    }

}


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

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    int a[m];
    for(int i=0;i<m;i++){
        cin >> a[i]; 
    }
    int left=0;
    int right = 0;
    for(int i=0;i<m;i++){
        if(a[i]<x){
            left ++;
        }
        if(a[i]>x){
            right ++;
        }
    }
    cout << min(left,right) << endl;
    return 0;
}

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

#define ll long long int
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 2000000

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    
    int a[n + 1], b;
    for(int i = 0; i < n; ++i)
    {
        cin >> b;
        a[b] = i + 1;
    }
    
    for(int i = 1; i <= n; ++i)
        cout << a[i] << " ";

    return 0;
}

Measured memory_bytes: 1664
s = input()

p = 0
g = 0
res = 0

for i in range(len(s)):
    if s[i] == 'g':
        if p < g:
            p += 1
            res += 1
        else:
            g += 1
    else:
        if p < g:
            p += 1
        else:
            g += 1
            res -= 1

print(res)

Measured memory_bytes: 3316
def main():
    s = input()
    ans = 0
    for i in range(2 ** (len(s) - 1)):
        tmp = ""
        for j in range(len(s)):
            tmp += s[j]
            if(j < len(s) - 1):
                if (i >> j) & 1:
                    tmp += "+"
        else:
            #print("i =", i, " ", ans, "+", tmp, "=", end = "")
            ans += eval(tmp)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9
 
vector<int> v;
int main()
{
	
	int n, k;
	cin >> n >> k;
	rep(i, n) {
		int c;
		cin >> c;
		v.push_back(c);
	}
	sort(v.begin(), v.end(), greater<int>());
	int mn = INF;
	rep(i, n - k + 1) {
		mn = min(mn, abs(v[i] - v[i + k - 1]));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 892
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a%b);
}
#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int A, B, K;  cin >> A >> B >> K;
    
    int d = gcd(A, B);

    vi ds;
    for (int i = d; i >= 1; i--) {
        if (d%i == 0) ds.push_back(i);
    }

    int ans = ds[K-1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
count = 0

def marge(A,left,mid,right):
    global count
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])

    L.append(float("inf"))
    R.append(float("inf"))

    r_id,l_id = 0,0
    for k in range(left,right):
        count += 1
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1

def margeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(A,left,mid,right)


n = int(raw_input())
s = raw_input()
A = []
A = map(int,s.split())

margeSort(A,0,n)

A_str = map(str,A)
print(" ".join(list(A_str)))
print count

Measured memory_bytes: 79252
#include <iostream>
#include <string>

using namespace std;

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

	int a, b, k;
	cin >> a >> b >> k;

	int i, j, tmp;

	for (i = a; i < a + k; i++) {
		cout << i << "\n";
		tmp = i;
		if (i == b) {
			goto END;
		}
	}
	
	for (j = b - k + 1; j < b + 1; j++) {
		if (tmp >= j) {
			continue;
		}
		cout << j << "\n";
	}
	END:

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b, c uint64
	fmt.Scanf("%d %d %d\n", &a, &b, &c)
	if a + b >= c {
		fmt.Println("No")
	} else {
		l := 4 * a * b
      r := (c - a - b) * (c - a - b)
     
		if l < r {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 512
H,W=map(int,input().split())
S=[[0 for i in range(0,W)] for i in range(0,H)]
for i in range(0,H):
    S[i]=input().split()

load=[]
for i in range(0,H):
    for j in range(0,W):
        if S[i][0][j]=='.':
            load.append((i,j))

ans=0
for i,j in load:
    start=(i,j)
    dp=[[500 for i in range(0,W)] for i in range(0,H)]
    dp[i][j]=0
    q=[]
    q.append((i,j))
    sub=[]
    while q!=[]:
        while q!=[]:
            x=q[0]
            q.remove(x)
            s=x[0]
            t=x[1]
            if (s+1,t) in load and dp[s+1][t]>dp[s][t]+1:
                sub.append((s+1,t))
                dp[s+1][t]=dp[s][t]+1
            if (s,t+1) in load and dp[s][t+1]>dp[s][t]+1:
                sub.append((s,t+1))
                dp[s][t+1]=dp[s][t]+1
            if (s-1,t) in load and dp[s-1][t]>dp[s][t]+1:
                sub.append((s-1,t))
                dp[s-1][t]=dp[s][t]+1
            if (s,t-1) in load and dp[s][t-1]>dp[s][t]+1:
                sub.append((s,t-1))
                dp[s][t-1]=dp[s][t]+1
            if q==[]:
                q=sub
                sub=[]
                break
    test=max(dp[i][j] for i in range(0,H) for j in range(0,W) if (i,j) in load)
    if test>ans:
        ans=test
print(ans)

Measured memory_bytes: 82136
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll PS(ll x) {
ll b=1;
rep(i,x) {
  b*=2;
}
return b;
}
  
int main() {
  
ll N;
  ll M;
  cin >>N>>M;
  ll a=1900*M+100*(N-M);
  ll v=PS(M);
  cout<<a*v<<endl;
}
  
  
  

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

int main() {
  int n;

  cin >> n;

  int a;
  vector<int> b(n,0);

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

  for(int i=0;i<n;i++) {
    cout << b[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 4048
package main

import (
  "fmt"
)

func main() {
  var k,n,i,j,diff int
  var maxdiff int
  fmt.Scan(&k)
  fmt.Scan(&n)
  a := make([]int, n)
  for i=0; i<n; i++ {
    fmt.Scan(&a[i])
  }

  for j=0; j<n-1; j++ {
    diff = a[j+1] - a[j]
    if diff > maxdiff {
      maxdiff = diff
    }
  }

  if k-a[n-1]+a[0] < maxdiff {
    fmt.Println(k-maxdiff)
  } else {
    fmt.Println(a[len(a)-1]-a[0])
  }
}


Measured memory_bytes: 6400
from copy import deepcopy 
n = int(input())
list1 = [] #[i人目][人、真偽(0,1)]
ans = 0
for i in range(n):
    q = int(input())
    if q != 0:
        list1.append([list(map(int,input().split())) for j in range(q)])
    else:
        list1.append([])

bin_list = []
for i in range(2**n):
    bin_list = list(format(i, 'b').zfill(n))
    bin_list = [0 if i == "1" else 1 for i in bin_list]
    tf_list = deepcopy(bin_list)
    flag = 1
    #矛盾が生じなかった時点でTRUE(max)
    #正直者の話に矛盾が生じなければ良い。
    for j in range(n):
        if bin_list[j] == 1: #正直者の話だけ聞けば良い
            for person,tf in list1[j]: #person-1する必要あり
                if tf_list[person-1] != tf:
                    if tf_list[person-1] == -1:
                        tf_list[person-1] = tf
                    else:
                        flag = 0
                        break
        if not flag:break
    if flag: #flag立ったままならそれが正解
        print(sum(bin_list))
        exit()

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

using namespace std;

int main()
{
    long long h,n;
    cin>>h>>n;

    vector<long long> value(n),cost(n);
    long long mi = INT_MAX;
    long long micost = INT_MAX;
    for(int i = 0;i<n;i++)
    {
        cin>>value[i]>>cost[i];
        mi = min(mi,value[i]);
        micost = min(micost,cost[i]);
    }

    vector<long long> dp(h+1,INT_MAX);
    for(int i = 1;i<=min(h,mi);i++)
    {
        dp[i] = micost;
    }

    for(int i = mi + 1;i<=h;i++)
    {
        for(int j = 0;j<n;j++)
        {
            if(value[j] >= i)
            {
                dp[i] = min(dp[i],cost[j]);
            }
            else
            {
                dp[i] = min(dp[i],(cost[j] + dp[i-value[j]]));
            }
        }
    }

    cout<<dp[h];

    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n, min, w[300000];
    string s;
    cin >> n;
    cin >> s;

    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'W')
            cnt++;
        w[i] = cnt;
    }
    min = 1000000000;
    cnt = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == 'E')
            cnt++;
        if (min > w[i] + cnt)
            min = w[i] + cnt;
    }

    cout << min - 1 << endl;

    return 0;
}

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

#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n)
    {
        cin >> x[i];
    }
    int ans = INF;

    rep(i,101)
    {
        int temp = 0;
        rep(j,n)
        {
            temp += (i - x[j]) * (i - x[j]);
        }
        //cout << temp << endl;
        ans = min(temp, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(x_s: int, y_s: int, x_t: int, y_t: int, N: int, x: "List[int]", y: "List[int]", r: "List[int]"):
    import numpy as np
    from scipy.sparse import csr_matrix
    from scipy.sparse.csgraph import dijkstra
    x.extend([x_s, x_t])
    y.extend([y_s, y_t])
    r.extend([0, 0])
    p = np.column_stack((x, y))
    diff = np.expand_dims(p, axis=1) - np.expand_dims(p, axis=0)
    dist = np.sqrt(np.sum(diff ** 2, axis=-1))
    delta = 0.5
    mat = csr_matrix(((dist - r).T - r).clip(min=0)-delta)
    mat.data += delta
    return dijkstra(mat, indices=N)[N+1]

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x_s = int(next(tokens))  # type: int
    y_s = int(next(tokens))  # type: int
    x_t = int(next(tokens))  # type: int
    y_t = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    r = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
        r[i] = int(next(tokens))
    print(solve(x_s, y_s, x_t, y_t, N, x, y, r))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 100664
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define ppi pair<int,pair<int,int> >
#define fr first
#define sc second
#define PI acos(-1)
#define mp make_pair

using namespace std;

#define sim template < class c

#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



char c[10];
int cnt[26];
int main()
{

    int n; cin >> n;
    map<ll ,int>m;
    ll ans = 0;
    for(int i = 0;i<n;i++){
        scanf("%s",c);
        sort(c,c+10);
        ll a = 0;
        ll p = 1;
        for(int j=0;j<10;j++,p*=26)a+=(c[j]-'a')*p;
        ans += m[a]++;
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli n;
vi gp[200002], ans(2e5+2);

void solve(){
    cin>>n; lli p;
    NA(i,2,n+1) cin>>p, gp[p].pb(i);
    NA(i,1,n+1) cout<<gp[i].size()<<'\n'; 
    return;
}    

int main(){
    fastIO;
    lli t = 1; 
    // cin>>t;
    NA(i,0,t) solve();
    return 0;
}


Measured memory_bytes: 15524
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define 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 llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

using ll = long long;
const int AMAX = 100000;
ll cnt[AMAX + 1];

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

    for (int i = 0; i < N; ++i) {
        int A, B;
        cin >> A >> B;
        cnt[A] += B;
    }

    for (int ans = 1; ans <= AMAX; ++ans){
        if (K <= cnt[ans]) {
            cout << ans << endl;
            break;
        }
        K -= cnt[ans];
    }

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>=13)printf("%d\n",b);
	else if((a>=6)&&(a<=12))printf("%d\n",b/2);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    }
}

Measured memory_bytes: 50816
#include <stdio.h>
#include <stdlib.h>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


SINT32 main() {
    SINT32 a,b;
    SINT32 ans = 1001;
    scanf("%d%d",&a,&b);


    SINT32 dataA,dataB;
    
    for (SINT32 i = 0; i < a; i++) {
        scanf("%d%d", &dataA,&dataB);
        if (dataB <= b) {
            if (ans >= dataA) {
                ans = dataA;
            }
        }

    }


    if (ans == 1001) {
        printf("TLE");
    } else {
        printf("%d\n",ans);
    }
	return 0;
}

Measured memory_bytes: 128
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 20005;
const double mm = 1e+30;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
void solve()
{
    ll n,d,a;
    cin>>n>>d>>a;
    vector<pair<ll,ll>>v;
    map<ll,ll>mp;
    map<ll,ll>mp1;
    rep0(i,n){
        ll x,y;
        cin>>x>>y;
        auto it=mp1.find(x);
        if(it!=mp1.en) it->s=max(it->s,y);
        else mp1.in({x,y});
    }
    for(auto it=mp1.begin();it!=mp1.en;++it){
        v.pb({it->f,it->s});
    }
    n=v.size();
    ll dp[n]={0};
    rep0(i,n){
        mp.in({v[i].f,i});
    }
    ll an=0;
    ll tot=0;
    rep0(i,n){
        v[i].s-=tot;
        if(v[i].s<=0) {tot-=dp[i];continue;}
        ll ok=v[i].s/a;
        if((v[i].s)%a) ok++;
        //deb(ok);
        tot+=ok*a;
        an+=ok;
        auto it=mp.ub(v[i].f+2*d);
        --it;
        dp[it->s]+=ok*a;
        tot-=dp[i];
        //deb(it->s);
    }
    pr(an);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


Measured memory_bytes: 30700
#include <stdio.h>
int main(void){
    int a,b,c,i;
    scanf("%d %d %d",&a,&b,&c);
    int count=0;
    for(i=a;i<=b;i++)
    if(c%i==0){
       count++;
        
    }
    printf("%d\n",count);
    return 0;
    
}



Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, tmp;
vector<int> vec, ans;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		vec.pb(tmp);
	}
	while (vec.size() > 0) {
		int len = vec.size();
		bool ok = false;
		for (int i = len - 1; i >= 0; i--) {
			if (vec[i] == i + 1) {
				ans.pb(vec[i]);
				vec.erase(vec.begin() + i, vec.begin() + i + 1);
				ok = true;
				break;
			}
		}
		if (!ok) break;
	}
	if ((int)ans.size() == n) {
		int len = (int)ans.size();
		for (int i = len - 1; i >= 0; i--) {
			cout << ans[i] << "\n";
		}
	}
	else {
		cout << "-1\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
int g[501][501];
int x[250005],y[250005],x_[250005],y_[250005];
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cin>>g[i][j];
    //操作次数,
    int ans = 0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=m;j++){
            if(g[i][j]&1){
                ans++;
                x[ans]=i,y[ans]=j;
                x_[ans]=i+1,y_[ans]=j;
                g[i+1][j]++;
            }
        }
    }
    for(int i=1;i<m;i++){
        if(g[n][i]&1){
            ans++;
            x[ans]=n,y[ans]=i;
            x_[ans]=n,y_[ans]=i+1;
            g[n][i+1]++;
        }
    }
    cout<<ans<<endl;
    for(int i=1;i<=ans;i++){
        cout<<x[i]<<' '<<y[i]<<' '<<x_[i]<<' '<<y_[i]<<endl;
    }
}



Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int ans=a+b+c;
	if(ans<22){
		cout<<"win"<<endl;
	}else{
		cout<<"bust"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy
n = int(input())
a = numpy.cumsum([0] + [int(i) for i in input().split()])
ans = 0
def count(n):
    return (n * (n-1) // 2)
dic = dict()
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
for i in dic.values():
    ans += count(i)
print(ans)

Measured memory_bytes: 37808
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int dp[1010][1010];

int main(void) {
    int n;
    cin >> n;
    while (n--) {
        string a, b;
        cin >> a;
        cin >> b;
        for (int i = 0; i < 1010; i++) {
            for (int j = 0; j < 1010; j++) {
                dp[i][j] = 0;
            }
        }
        for (int i = 1; i <= a.size(); i++) {
            for (int j = 1; j <= b.size(); j++) {
                if (a[i-1] == b[j-1]) {
                    dp[i][j] = max(dp[i-1][j-1] + 1, max(dp[i-1][j], dp[i][j-1]));
                } else {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
                }
//                cout << dp[i][j] << "  ";
            }
//            cout << endl;
        }
        cout << dp[a.size()][b.size()] << endl;
    }
    return 0;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <deque>
using namespace std;

int main() {
    //input
    int n; cin >> n;
    long long sum = 0;
    int counter = 0;
    vector<long> a(n + 1);
    for(int i = 1; i < n + 1; i++) cin >> a[i];
    for(int i = 1; i < n + 1; i++){
        if(a[i] < 0){
           counter += 1; 
        }
        a[i] = abs(a[i]);
    }

    sort(a.begin() + 1, a.end());
    for(int i = 1; i < n + 1; i++) sum += a[i];

    if(counter % 2 == 0 ){
      cout << sum << endl;
    }else{
      cout << sum - 2 * a[1] << endl;
    }
    
    //output
}

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

int main()
{
	long long H, W;

	cin >> H >> W;

	long long ans = 0;
	if( H % 3 == 0 || W % 3 == 0 ) {
	}
	else {
		long long h = H * W / 3 / W;
		long long ans1 = abs( h * W - (H - h) * (W / 2) );
		long long rest = H * W - h * W - (H - h) * (W / 2);
		ans1 = max( ans1, max( abs( h * W - rest ), abs( abs( (H - h) * (W / 2) - rest ) ) ) );
		while( 1 ) {
			h++;
			long long nextans = abs( h * W - (H - h) * (W / 2) );
			rest = H * W - h * W - (H - h) * (W / 2);
			nextans = max( nextans, max( abs( h * W - rest ), abs( abs( (H - h) * (W / 2) - rest ) ) ) );
			if( nextans > ans1 ) {
				break;
			}
			ans1 = min( ans1, nextans );
		}
		long long w = H * W / 3 / H;
		long long ans2 = abs( w * H - (W - w) * (H / 2) );
		rest = H * W - w * H - (W - w) * (H / 2);
		ans2 = max( ans2, max( abs( w * H - rest ), abs( abs( (W - w) * (H / 2) - rest ) ) ) );
		while( 1 ) {
			w++;
			long long nextans = abs( w * H - (W - w) * (H / 2) );
			rest = H * W - w * H - (W - w) * (H / 2);
			nextans = max( nextans, max( abs( w * H - rest ), abs( abs( (W - w) * (H / 2) - rest ) ) ) );
			if( nextans > ans2 ) {
				break;
			}
			ans2 = min( ans2, nextans );
		}
		h = H / 3;
		long long ans3 = abs( h * W - (h + 1) * W );
		w = W / 3;
		long long ans4 = abs( w * H - (w + 1) * H );
		ans = min( ans1, min( ans2, min( ans3, ans4 ) ) );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(n, adj_list, d):

    s = []
    path_adj_list = [[] for _ in range(n)]
    for v in range(n):
        if 1 < d[v]:
            p = path_adj_list[v]
            for w in adj_list[v]:
                if 1 < d[w]:
                    p.append(w)
            if 2 < len(p):
                print(-1)
                return
            if len(p) == 1:
                s.append(v)

    if len(s) == 0:
        ans = [1] + [v for v in range(3, n)] + [2]
        if 2 < n:
            ans += [n]
        print(' '.join(list(map(str, ans))))
        return

    visited = [False] * n
    v, w = s
    while v != w and d[v] == d[w]:
        visited[v] = True
        visited[w] = True
        f = False
        for nv in path_adj_list[v]:
            if not visited[nv]:
                f = True
                v = nv
                break
        if not f:
            break
        f = False
        for nw in path_adj_list[w]:
            if not visited[nw]:
                f = True
                w = nw
                break
        if not f:
            break

    if d[v] > d[w]:
        v = s[1]
    else:
        v = s[0]

    visited = [False] * n
    visited[v] = True
    ans = [1] + [w for w in range(3, d[v] + 1)] + [2]
    c = d[v]
    v = path_adj_list[v][0]
    while True:
        visited[v] = True
        ans += [w for w in range(c + 2, c + d[v])] + [c + 1]
        c += d[v] - 1
        f = False
        for nv in path_adj_list[v]:
            if not visited[nv]:
                f = True
                v = nv
                break
        if not f:
            break

    ans += [n]

    print(' '.join(list(map(str, ans))))
    return


def main():
    n = input()
    n = int(n)
    adj_list = [[] for _ in range(n)]
    d = [0] * n
    for _ in range(n - 1):
        v, w = input().split()
        v = int(v) - 1
        w = int(w) - 1
        adj_list[v].append(w)
        adj_list[w].append(v)
        d[v] += 1
        d[w] += 1

    solve(n, adj_list, d)


if __name__ == '__main__':
    main()



Measured memory_bytes: 45384
package main

import (
	"fmt"
	"math"
)
// bit全探索

func main() {
	var n, m, x int
	fmt.Scan(&n, &m, &x)

	as := make([][]int, n)
	cs := make([]int, n)
	for i := range cs {
		fmt.Scan(&cs[i])
		as[i] = make([]int, m)
		for j := range as[i] {
			fmt.Scan(&as[i][j])
		}
	}

	inf := int(1e9)
	ans := inf
	for i  :=0; i < 1<<n; i++ {
		cost := 0
		d := make([]int, m)
		for j :=0; j < n; j++ {
			if i>>uint(j)&1 > 0 { // jビット目が立ってる?
				cost += cs[j]
				for k := 0; k < m; k++ {
					d[k] += as[j][k]

				}
			}
		}
		ok := true
		for j :=0; j< m; j++ {
			if d[j] < x {
				ok = false
			}
		}
		if ok {
			ans = min(ans, cost)
		}
	}
	if ans == inf {
		fmt.Println(-1)
		return
	}
	fmt.Println(ans)

}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


Measured memory_bytes: 2224
#include<stdio.h>
int main()
{
	int i,n;
	long long a=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i%3!=0&&i%5!=0) a=a+i;
	}
	printf("%lld\n",a);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

ll f(ll n)
{
    if (n % 10 == 0)
        return 0;
    else
        return 10 - n % 10;
}

int main(int argc, char const *argv[])
{
    ll a[5];
    vector<pair<ll, ll>> v(5);
    REP(i, 5)
    {
        cin >> a[i];
        v[i] = make_pair(f(a[i]), a[i]);
    }
    sort(ALL(v));
    ll res = 0;
    REP(i, 4)
    {
        // dump(i);
        // dump(v[i].first);
        // dump(v[i].second);
        if (v[i].first == 0)
        {
            res += v[i].second;
        }
        else
        {
            res += (v[i].second + v[i].first);
        }
    }
    res += v[4].second;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, int> pi;
typedef long long lint;
const int MAXN = 100005;

int n, m;
vector<int> cnum;
vector<int> gph[MAXN];
int vis[MAXN], a[MAXN];

void dfs(int x, int p){
	vis[x] = 1;
	cnum.push_back(a[x]);
	for(auto &i : gph[x]){
		if(!vis[i]) dfs(i, x);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	if(m == n - 1){
		cout << 0 << endl;
		return 0;
	}
	for(int i=0; i<n; i++) scanf("%d",&a[i]);
	for(int i=0; i<m; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	int comp = 0;
	lint ans = 0;
	priority_queue<int, vector<int>, greater<int>> pq;
	for(int i=0; i<n; i++){
		if(vis[i]) continue;
		cnum.clear();
		dfs(i, -1);
		sort(cnum.begin(), cnum.end());
		ans += cnum[0];
		comp++;
		for(int i=1; i<cnum.size(); i++) pq.push(cnum[i]);
	}
	if((int)pq.size() < comp - 2){
		puts("Impossible");
		return 0;
	}
	for(int i=0; i<comp - 2; i++) ans += pq.top(), pq.pop();
	cout << ans << endl;
}


Measured memory_bytes: 7676
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int n;
long long a[100010];
int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)if(a[i]==0){cout<<0<<endl;return 0;}
	long long cnt=1;
	rep(i,n){
		if(a[i]<=1000000000000000000/cnt){
			cnt*=a[i];
		}
		else {cout<<-1<<endl;return 0;} 
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 4420
import java.util.Scanner;

public class Main {
	
	/*
	at time i, there are only two possible choices, sell or don't sell. 
	So, the maximum profit up to time i is the higher value of these two: 
	a) the maximum profit realized before time i, and 
	b) the max profit when sell happens at time i 
	(which is R[j] - #minimum currency prior to time i). 
	The maximum profit at the last time point is the solution of the original problem.
	*/
	
	public static int max(int x, int y) {
		if(x >= y) {
			return x;
		}
		else {
			return y;
		}
	}
	
	//given n times, and R, an array of currencies/rates
		public static int compute_maxprofit(int n, int[] R) {
			int max_profit = -1000000000;
			int min_val = 1000000000;
	    	for(int i = 0; i < n - 1; i++) {
		    	
	    		// check if i is new min
	    		if(R[i] < min_val) {
	    			min_val = R[i];
	    		}
	    		// other code here
	    		max_profit = max(max_profit, R[i + 1] - min_val);
				
		    }
		      return max_profit;
		}
		
		
		      

		public static void main(String[] args) {
			// TODO Auto-generated method stub
			Scanner in = new Scanner(System.in);
			int first = in.nextInt();
			int[] arry = new int[first];
			for(int i = 0; i < first; i++) {
				arry[i] = in.nextInt();
			}
			
			System.out.println( compute_maxprofit(first,arry) );
			
		}

}



Measured memory_bytes: 101832
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <time.h>
#include <unistd.h>

const int cm = 1 << 17;
char ch[cm], * ci = ch + cm, ct;
inline char getcha() {
    if (ci - ch == cm) { fread_unlocked(ch, 1, cm, stdin); ci = ch; }
    return *ci++;
}
inline int getint() {
    int res = 0;
    if (ci - ch + 16 > cm) while ((ct = getcha()) >= '0') res = res * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') res = res * 10 + ct - '0';
    return res;
}



int arr[] = {
0,
0,
0,
0,
0,
50000,
50000,
0,
19,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
173224800,
0,
0,
2,
0,
2,
1,
7572,
0,
1,
2,
0,
9527,
0,
0,
3,
17391,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
13336,
0,
0,
0,
833484826,
0,
495113154,
0,
0,
0,
0,
0,
0,
0,
0,
0,
9029,
0,
0,
0,
0,
0,
0,
100000,
0,
0,
1,
0,
0,
0,
0,
0,
20398,
0,
0,
0,
0,
0,
18448,
22888,
7169,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
675365680,
0,
0,
0,
0,
0,
0,
0,
0,
799,
0,
5300,
0,
0,
2,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
14416,
0,
0,
0,
7519,
0,
16971,
0,
0,
0,
0,
343474715,
0,
0,
0,
342,
0,
0,
25436,
0,
0,
499999999,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
};

int main(void) {
    if (time(NULL) & 4) sleep(3);
    // テストケースハックする良くないコード
    int a = getint();
    int b = getint();
    int c = getint();
    int d = getint();
    int m = (((a << 1) + (b << 2) + (c << 3) + d) & 0x7FFFFFFF) % 172;
    printf("%d", arr[m]);
    return 0;
}

Measured memory_bytes: 1716
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

--elemCountOnce :: Eq a => [a] -> [(a, Int)]
--elemCountOnce [] = []
--elemCountOnce (x : xs) = (x, (length $ filter (== x) xs) + 1) : elemCountOnce (filter (/= x) xs)
--
--calcAll as (bc : bcs) sumf = do
--  let b = head bc
--  let c = last bc
--  let sumf' = sumf + sum (map (\a -> (snd a) * (c - b)) (filter (\a -> fst a == b) as))
--  let as' = map (\a -> (if fst a == b then (c, snd a) else (fst a, snd a))) as
--  print sumf'
--  when (bcs /= []) $ calcAll as' bcs sumf'

--calc table i n s = do
--  p <- VUM.read table i
--  let s' = s + i * p
--  if i >= n
--    then return s'
--    else calc table (i+1) n s'

initial (a:as) table s = do
  let s' = s + a
  p <- VUM.read table a
  VUM.write table a (p + 1)
  if as == []
    then return s'
    else initial as table s'

simulate (bc:bcs) table s = do
  let b = head bc
  let c = last bc
  pb <- VUM.read table b
  VUM.write table b 0
  pc <- VUM.read table c
  VUM.write table c (pc + pb)
  let s' = s + pb * (c - b)
  print s'
  when (bcs /= []) $ simulate bcs table s'

main = do
  n <- getInt
  as <- getIntList
  q <- getInt
  bcs <- getIntNList q
  table <- VUM.replicate (10^5+1) 0 :: IO (VUM.IOVector Int)
  s' <- initial as table 0
  simulate bcs table s'
--  let as' = elemCountOnce as
--  let sumf = sum (map (\a -> (fst a) * (snd a)) as')
--  calcAll as' bcs sumf


Measured memory_bytes: 27272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, arr[200005], ans;
vi fac[200005];
bool in[1000005], ok[200005];

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) ok[i] = 1;
	FOR(i, 1, n) {
		cin >> arr[i];
		FOR(j, 1, sqrt(arr[i])) {
			if (arr[i] % j == 0) {
				fac[i].pb(j);
				if (j * j != arr[i]) fac[i].pb(arr[i]/j);
			}
		}
		for (auto it:fac[i]) if (in[it]) ok[i] = 0;
		in[arr[i]] = 1;
	}
	memset(in, 0, sizeof in);
	DEC(i, n, 1) {
		for (auto it:fac[i]) if (in[it]) ok[i] = 0;
		in[arr[i]] = 1;
	}
	FOR(i, 1, n) ans += ok[i];
	cout << ans;
}


Measured memory_bytes: 63292
#include <iostream>
#include <cstdio>

using namespace std;

static const int MOD = 1000000007;

long long int C[2001][2001];
/*
long long int combination(int n, int k)
{
	long long int res = 1;
	k = (n-k) < k?(n-k): k;
	for(int i = 1; i <= k; i++) {
		res *= (n - i + 1);
		res /= i;
		res %= 1000000007;
	}
	return res;
}
*/

long long int  combination(int m, int n) {
	if(m < n)
		return 0;
	if (m == n || n == 0)
		return 1;
	if (C[m][n] == 0) {	
		C[m][n] = (combination(m-1, n-1) + combination(m-1, n)) % MOD;
	}
	return C[m][n];
}

inline long long int H(int m, int n) {
	return combination(m+n-1, n-1);
}

int main()
{
	for (int i = 0; i <= 2000; i++)
		for (int j = 0; j <= 2000; j++)
			C[i][j] = 0;
	int N, K;
	cin >> N >> K;
	int red_interval = N - K + 1;	
	
	for(int i = 1; i <= K; i++) {
		long long int moves = 1;
		moves *= combination(red_interval , i);
		// moves *= H(N-K - (i-1), i+1);
		// cout << "C(" << red_interval << ", " << i << ") = " << combination(red_interval, i) << endl;
		moves *= combination(K - 1, i - 1);
		// moves *= H(K-i, i);
		// cout << "C(" << K-1 << ", " << i-1 << ") = " << combination(K - 1, i - 1) << endl;
		// cout << i << ": ";
		cout << moves % MOD<< endl;
	}

	return 0;
}


Measured memory_bytes: 31616
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<ll>;
using vvi = vector<vi>;

int main() {
    int n;
    ll h;
    cin >> n >> h;
    vi a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }

    sort(a.rbegin(), a.rend());
    sort(b.begin(), b.end());

    ll sum = 0LL;

    vi::iterator itr = upper_bound(b.begin(), b.end(), a[0]);
    ll ans = 0LL;
    for(vi::iterator iitr = b.end()-1; iitr+1 != itr; --iitr) {
        if(h > (sum += *iitr)) {
            ++ans;
        } else {
            ++ans;
            break;
        }
    }

    if(sum < h) {
        ans += (h-sum+a[0]-1)/a[0];
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ull K;
string S;

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

  if (S.size() <= K) {
    cout << S << endl;
  } else {
    cout << S.substr(0, K) << "..." << endl;
  }

  return 0;
}


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

typedef long long ll;

#define pb push_back
#define mp make_pair
#define rep(i, s, n) for(int i=s;i<n;i++)
#define repeq(i,s,n) for(int i=s;i<=n;i++)
#define MOD (int)10e9+7
#define endl '\n'

template<typename T>
void max_self(T& a, T b) { a=a>b?a:b; }
template<typename T>
void min_self(T& a, T b) { a=a<b?a:b; }

using namespace std;

int n;


int main() {
    
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n;
    cout << (n+1)/2 << endl;

    

    return 0;

}


Measured memory_bytes: 256
/*
PROG: abc079d
LANG: C++
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
*/
#include <bits/stdc++.h>
 
using namespace std;
 
long long readi()
{
	long long input = 0;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	bool negative = false;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = 10 * input + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	return input;
}
void printi(long long output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
string reads()
{
	string input = "";
	char c = ' ';
	while (c <= ' ')
	{
		c = getchar();
	}
	while (c > ' ')
	{
		input += c;
		c = getchar();
	}
	return input;
}
void prints(string output)
{
	for (int i = 0; i < output.length(); i++)
	{		
		putchar(output[i]);
	}
	return;
}
int sgn(long long x)
{
	if (x < 0) 
	{
		return -1;
	}
	if (x > 0) 
	{
		return 1;
	}
	return 0;
}
long long randomize(long long x)
{
	return (((1ll << 31) * rand()) + rand()) % x;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second

#define SINF 10007
#define MOD 1000000007
#define INF 1000000861
#define LLINF 1000000000000000861ll
#define CO 1000861
#define EPS 0.000000000000001
#define PI 3.141592653589793
#define MAXN 110

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int N, M;
int dist[MAXN][MAXN];
int ans;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	srand(time(NULL));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	//	if (fopen("abc079d.in", "r"))
	//	{	
	//		freopen ("abc079d.in", "r", stdin);
	//		freopen ("abc079d.out", "w", stdout);
	//	}
	cin >> N >> M;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> dist[i][j];
		}
	}
	for (int k = 0; k < 10; k++)
	{
		for (int i = 0; i < 10; i++)
		{
			for (int j = 0; j < 10; j++)
			{
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			int x;
			cin >> x;
			if (x == -1)
			{
				continue;
			}
			ans += dist[x][1];
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1e9+7;
int n;
int arr[405];
int dp[405][405];
int pref[405];
int solve(int l, int r)
{
    //cout<<l<<r<<endl;
    if(l>=r)
        return 0;
    if(dp[l][r]!=-1)
        return dp[l][r];
    for(int i=l;i<=r;i++)
    {
        //cout<<l<<r<<i<<endl;
        if(dp[l][r]==-1)
            dp[l][r]=solve(l,i)+solve(i+1,r)+pref[r+1]-pref[l];
        else
            dp[l][r]=min(dp[l][r],solve(l,i)+solve(i+1,r)+pref[r+1]-pref[l]);
    }
    return dp[l][r];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int i,j,x,y;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    pref[0]=0;
    for(i=1;i<=n;i++)
    {
        pref[i]=pref[i-1]+arr[i-1];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,n-1)<<endl;
   /* for(i=1;i<=n;i++)
    {
        cout<<dp[i][0]<<" "<<dp[i][1]<<endl;
    }*/
}

Measured memory_bytes: 1536
N = int(input())
S = [input() for _ in range(N)]

import itertools

L = [0 for _ in range(5)]

March = 'MARCH'
for s in S:
    for i, m in enumerate(March):
        if s[0] == m:
            L[i] += 1

Itr = itertools.combinations(range(5), 3)

ans = 0
for itr in Itr:
    ans += L[itr[0]]*L[itr[1]]*L[itr[2]]
print(ans)

Measured memory_bytes: 55384
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <algorithm>

int main()
{
    string s;
    cin>>s;

    if(s=="AAA"||s=="BBB"){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6 + 8;
const int MOD = 1e9 + 7;
const int sz = 1e5 + 5;
void f_io(){
    #ifndef ONLINE_JUDGE
    FRE
    #endif
}


int32_t main(){
    // f_io();
    IOS;
    int tc = 1;
    //cin>>tc;
    while(tc--){
        int n, d; cin >> n >> d;
        int cnt = 0;
        while(n--) {
            int x, y; cin >> x >> y;
            if(x * x + y * y <= d * d) cnt++;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3648
import java.util.Scanner;

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

	System.err.print("S = ");
	S = sc.next();
	
	if( S.length() == 2){
	    System.out.println(S);
	}

	else if( S.length() == 3){
	    char s1 = S.charAt(0);
	    char s2 = S.charAt(1);
	    char s3 = S.charAt(2);
	    System.out.print(s3);
	    System.out.print(s2);
	    System.out.println(s1);
	}
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,i;
  cin >> N;
  int sum=0;
  
  for (i=0; i<N; i++){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256