akhauriyash/Code-Regression huggingface dataset:
/**Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
set<long long>st,stt;
set<long long>::iterator it,jt;
vector<long long>v;
long long x[200005];
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>a;
        v.push_back(a);
        x[a]=i;
    }
    st.insert(x[n]);
    stt.insert(-1*x[n]);
    for(i=n-1; i>0; i--)
    {
        d=INT_MAX;
        e=INT_MAX;
        p=INT_MAX;
        q=INT_MAX;
        it=st.lower_bound(x[i]);
        if(it==st.end())
            d=n+1;
        else
        {
            d=*it;
            it=st.upper_bound(d);
            if(it==st.end())
                e=n;
            else
                e=*it-1;
        }
        it=stt.lower_bound(-1*x[i]);
        if(it==stt.end())
            p=0;
        else
        {
            p=-1*(*it);
            it=stt.upper_bound((*it));
            if(it==stt.end())
                q=1;
            else
                q=-1*(*it)+1;
        }
        if(e==INT_MAX)
            e=d;
        if(q==INT_MAX)
            q=p;
        if(e>n)
            e--;
        if(q<1)
            q++;
        f+=i*(x[i]-p)*(e-d+1);
        f+=i*(p-q+1)*(d-x[i]);
        st.insert(x[i]);
        stt.insert(-x[i]);


    }
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 11252
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var whn = ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var warr = new int[whn[0]];
        var harr = new int[whn[1]];
        for(var i = 0; i < whn[2]; i++)
        {
            var xya = ReadLine().Split().Select(z => int.Parse(z)).ToArray();
            var x = xya[0];
            var y = xya[1];
            var a = xya[2];

            switch (a)
            {
                case 1:
                    for(var j = x-1; j >= 0; j--)  warr[j] = -1;                    
                    break;

                case 2:
                    for (var j = x; j < warr.Length; j++) warr[j] = -1;
                    break;

                case 3:
                    for (var j = y-1; j >= 0; j--) harr[j] = -1;
                    break;

                case 4:
                    for (var j = y; j < harr.Length; j++) harr[j] = -1;
                    break;
            }            
        }
        var w = 0;
        var h = 0;
        foreach (var v in warr)  if (v != -1) w++;
        foreach (var v in harr)  if (v != -1) h++;
        WriteLine(w * h);
    }
}

Measured memory_bytes: 3032
#include <iostream>
#include <cmath>
// Boost Multiprecision Library を include
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
namespace mp = boost::multiprecision;


int main()
{
	int c,d;
     mp::cpp_dec_float_100 a,b;cin>>a>>b;
  cout<<fixed<<(long long)floor(a*b)<<endl;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
// const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 1e6+1;
const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

long long modpow(long long res,long long a, long long n, long long mod) {
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}
// ここから開始
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i = 0; i < s.length()/2; i++){
    if(s[i]!=s[s.length()-1-i]) ans++;
  }
  cout<<ans<<endl;
  return 0;
}



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

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

  bool c = false;
  bool f = false;
  for (int i = 0; i < (int)s.size(); i++) {
    if (!c) {
      if (s[i] == 'C') c = true;
    } else {
      if (s[i] == 'F') f = true;
    }
  }

  if (c && f) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

int main() {
  string s; cin>>s;
  int n = s.size();

  vector<vector<long long>> dp(n+1, vector<long long>(4, 0));
  dp[0][0] = 1;
  rep(i, n) {
    rep(j, 4) {
      if (s[i] != '?') dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
      else dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 3) % MOD;
    }
    if (s[i] == 'A' or s[i] == '?') dp[i+1][1] = (dp[i+1][1] + dp[i][0]) % MOD;
    if (s[i] == 'B' or s[i] == '?') dp[i+1][2] = (dp[i+1][2] + dp[i][1]) % MOD;
    if (s[i] == 'C' or s[i] == '?') dp[i+1][3] = (dp[i+1][3] + dp[i][2]) % MOD;
  }
  print(dp[n][3]);
  return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#define db double
#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define fir first
#define sec second
#define pb push_back
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pii pair<int,int>
#define sc(x) scanf("%d",&(x))
#define sz(x) (int)(x).size()
#define ms(x) memset((x),0,sizeof(x));
#define all(x) (x).begin(), (x).end()
#define er(x) cerr<<(x)<<" ";
#define err(x) cerr<<#x<<": "<<(x)<<" ";
#define errn cerr<<endl;
using namespace std;
#define mod 1000000007
const db pi=acos(-1.0);
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); }
ll _pow(ll a,ll b) { ll res=1ll; while(b){ if(b&1)
res=res*a%mod; a=a*a%mod; b>>=1; } return res; }
///_____________________________________________

#define mxn 100005

int n;
ll a[mxn];
set <ll> q;

int main()
{
    while(~sc(n))
    {
        q.clear();
        for(int i=0;i<=n;i++) { ll x; R(x), q.insert(x); }
        auto it=++q.begin();
        int cnt=0;
        for(it;it!=q.end();it++) a[cnt++]=*it-*prev(it);
        if(cnt==1) printf("%lld\n",a[0]);
        else {
            ll ans=__gcd(a[0],a[1]);
            for(int i=2;i<cnt;i++) ans=__gcd(ans,a[i]);
            printf("%lld\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

    set<ll> ans;
    if (B - A >= K) {
        for (ll i=A; i<A+K; ++i) {
            ans.insert(i);
        }
        for (ll i=B; i>B-K; --i) {
            ans.insert(i);
        }
    } else {
        for (ll i=A; i<=B; ++i) {
            ans.insert(i);
        }
    }

    for (auto itr = ans.begin(); itr != ans.end(); ++itr) {
        cout << *itr << endl;
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;
ll fuc[200005]={};

ll fact(ll n) {
    if(n==0) return fuc[0] = 1;
    if (n==1) return fuc[1] = 1;
    if(fuc[n]==0) return fuc[n] = (n*fact(n-1))%MOD;
    return fuc[n];
}

//aのb乗
ll calc(ll a,ll n){
  ll ans = 1;
  while(n > 0){
    if((n&1) == 1){
      ans = ans * a;
    }
    ans %= MOD;
    a = (a*a)%MOD;
    n >>= 1;
  }
  return ans;
}

ll comb(ll a, ll b){
  if(a==b || b==0) return 1;
  return (((fact(a)*calc(fact(b),MOD-2))%MOD)*calc(fact(a-b),MOD-2))%MOD;
}

int main(){
  ll H,W,A,B;
  cin >> H >> W >> A >> B;
  ll ans = 0;
  for(ll i=0;i<=H-A-1 && i<=W-B-1;i++){
    ans += comb(H-A+B-1,B+i)*comb(W-B+A-1,A+i);
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3840
#include <stdio.h>
int main(void){
    int N,C;
    scanf("%d %d",&N,&C);
    int po[214514]={};
    int unti[214514][30];
    for(int i=0;i<214514;i++)for(int j=0;j<30;j++)unti[i][j]=0;
    for(int i=0;i<N;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        unti[2*a-1][c-1]++;
        unti[b*2][c-1]--;
    }
    for(int j=0;j<30;j++)for(int i=1;i<214514;i++){unti[i][j]+=unti[i-1][j];po[i]+=(unti[i][j]>0);}
    int ans=0;
    for(int i=1;i<214514;i++){
        if(po[i]>ans)ans=po[i];
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 26112
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    a = [int(i) for i in ipt().split()]
    if n == 0 and a[0] == 0:
        print(-1)
        exit()
    elif n == 0 and a[0] == 1:
        print(1)
        exit()
    elif n == 0 and a[0] > 1:
        print(-1)
        exit()
    suma = sum(a)
    ans = a[0]
    can = 1
    for i,ai in enumerate(a):
        if ai > can:
            print(-1)
            exit()
        suma -= ai
        ans += can
        if (can-ai)*2 >= suma:
            can = suma
        else:
            can = (can-ai)*2

    print(ans)




    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 99996
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string t = "AKIHABARA";
    string::iterator itr = s.begin();
    bool ok = true;
    rep(i, t.size()) {
        if(itr == s.end() and i != t.size()-1) {
            ok = false;
            break;
        }
        if(t[i] != 'A') {
            if(*itr != t[i]) {
                ok = false;
                break;
            }
            itr++;
        }
        else {
            if(*itr == 'A') {
                itr++;
            }
        }
    }
    if(itr != s.end()) ok = false;

    cout << (ok?"YES":"NO") << endl;
}

Measured memory_bytes: 3604
n=int(input())
if not ((1+(1+8*n)**0.5)/2).is_integer():
  print('No')
else:
  k=int((1+(1+8*n)**0.5)//2)
  ans=[[] for _ in range(k)]
  cnt=1
  for i in range(k):
    for j in range(i+1,k):
      ans[i].append(cnt)
      ans[j].append(cnt)
      cnt+=1
  print('Yes')
  print(k)
  for i in range(k):
    print(k-1,*ans[i])

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

int main() {
  int H,W;
  cin >>H >> W;
  vector<vector<char>> C(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> C.at(i).at(j);
    }
  }
  
  for(int i=0;i<H;i++){
    for(int k=0;k<2;k++){
      for(int j=0;j<W;j++){
        cout << C.at(i).at(j);
        if(j==W-1){
          cout << endl;
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  double a,b,x;
  const double PI=3.14159265358979323846;
  double ans;
  cin >>a>>b>>x;
  if(a*a*b>=2*x){
    ans =atan(a*b*b/2/x)*180/PI;
  }else{
    ans = atan((a*a*b-x)*2/a/a/a)*180/PI;
  }
  cout <<std::setprecision(12)<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvi vector<vector<ll>> 
#define vi vector<ll> 
#define vpii vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(ll i = 0; i < n; ++i)
 
int main() {
    fastt;
    int a,b,n;
    cin>>n;
    int i,j,k;
    for(i=1;i<=9;i++){
        for(j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
import math
mod = 10**9 + 7

# http://cav-inet.hateblo.jp/entry/2017/02/18/165141
def binary_search(list,target): 

	result = -1
	left = 0
	right = len(list) - 1

	while left <= right:
		center = (left + right)//2
		if list[center] == target:
			result = center
			break
		elif list[center] < target:
			left = center + 1
		elif list[center] > target:
			right = center - 1

	if result == -1:
		return False
	else:
		return True

n,m = map(int,input().split())
a = [int(input()) for _ in range(m)]

dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1
if binary_search(a,1):
    dp[1] = 0
    
for i in range(2,n+1):
    if binary_search(a,i):
        continue
    dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[n])

Measured memory_bytes: 7848
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc  = new Scanner(System.in);
        int a = Integer.parseInt(sc.nextLine());
        int b = Integer.parseInt(sc.nextLine());
        int c = Integer.parseInt(sc.nextLine());
        int x = Integer.parseInt(sc.nextLine());

        int count = 0;
        for(int i = 0;i<=a;i++){
            for(int j = 0;j<=b;j++){
                for(int k = 0;k<=c;k++){
                    if(x == 500*i+100*j+50*k){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

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

    bool ok = true;
    for(int i = 0; i < (int)s.size(); i++){
        if(i < a){
            if(!isdigit(s[i]))
                ok = false;
        }else if(i == a){
            if(s[i] != '-')
                ok = false;
        }else{
            if(!isdigit(s[i]))
                ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	string W[N];
	int a[N];
	int b = 1;
	
	for(int i = 0; i < N; ++i){
		cin >> W[i];
		a[i] = W[i].size();
	}
	
	for(int j = 0; j < N-1; ++j){
		if(W[j][a[j]-1] != W[j+1][0]){
			b = 0;
		}
		
	}
	for(int k = 0; k < N; k++){
		for(int l = k+1; l < N; l++){
			if(W[k] == W[l]){
				b = 0;
			}
		}
	}
	if(b == 1) {
	cout << "Yes" << endl;
	}else if(b == 0){
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
    int i, j, k, N;
    char S[210000];
    long long ans = 0, num=0;

    scanf("%s", &S);
    N = strlen(S);

    for(i=N-1; i>=0; i--){
        if(S[i]=='W'){
            num++;
        }else if(S[i]=='B'){
            ans+=num;
        }
    }

    printf("%lld", ans);

    return 0;
}

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

int main() {
    int N;
    cin>>N;
    long answer=0;
    
    for(int i=1;i<=N;i++)
    {if(i%3!=0&&i%5!=0){answer+=i;}
        
        
        
        
        }
    cout<<answer<<endl;
}



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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line_input = System.Console.ReadLine();
            var split = line_input.Split(' ');
            int N = int.Parse(split[0]);
            int K = int.Parse(split[1]);

            int count = 1;
            while((Math.Pow(K,count)) <= N)
            {
                count++;
            }
            System.Console.WriteLine(count);
        }
    }
}

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

#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[n]; rep(i,n){ gets(x[i]);}
#define ll long long

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if (c >= a && b >= c) {
    puts("Yes")
  }else{
    puts("No")
  }
}


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


int solve(int n, int h[][3]){
  long long dp[3];
  long long dpp[3];
  
  for(int j = 0; j < 3; ++j){
    dp[j] = dpp[j] = h[0][j];
  }
  
  for(int i = 1; i < n; ++i){
    for(int j = 0; j < 3; ++j){
      int j1 = (j + 1) % 3;
      int j2 = (j + 2) % 3;
      dp[j] = max(dpp[j1], dpp[j2]) + h[i][j];
    }
    copy(dp, dp + 3, dpp);  // update dpp
  }
  return max(max(dp[0], dp[1]), dp[2]);
}


int main(){
  int n;
  cin >> n;
  int h[n][3];
  for(int i = 0; i < n; ++i){
    cin >> h[i][0] >> h[i][1] >> h[i][2];
  }
  cout << solve(n, h) << endl;
  return 0;
}


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

int main(){
    int w,h,n;
    cin>>w>>h>>n;
    vector<vector<int>> board(w,vector<int>(h,1));
    vector<vector<int>> draw(n,vector<int>(3));
    for (int i = 0; i < n; i++){
        cin>>draw.at(i).at(0)>>draw.at(i).at(1)>>draw.at(i).at(2);
    }
    for (int i = 0; i < n; i++){
        switch (draw.at(i).at(2)){
        case 1:
            for (int k = 0; k < h; k++){
                for (int j = 0; j < draw.at(i).at(0); j++){
                    board.at(j).at(k)=0;
                }
            }
            break;
        
        case 2:
            for (int k = 0; k < h; k++){
                for (int j = draw.at(i).at(0); j < w; j++){
                    board.at(j).at(k)=0;
                }
            }
            break;
        
        case 3:
            for (int k = 0; k < draw.at(i).at(1); k++){
                for (int j = 0; j < w; j++){
                    board.at(j).at(k)=0;
                }
            }
            break;

        case 4:
            for (int k = draw.at(i).at(1); k < h; k++){
                for (int j = 0; j < w; j++){
                    board.at(j).at(k)=0;
                }
            }
            break;

        default:
            break;
        }
    }
    int ans=0;
    for (int i = 0; i < w; i++){
        for (int j = 0; j < h; j++){
            ans+=board.at(i).at(j);
        }   
    }
    cout<<ans;
    return 0;
}

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

int main() {
    int n, l, r, ans=0;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> l >> r;
        ans+= r - l +1;
        
    }
    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

vector<vector<int> > edges;
vector<int> color;
vector<int> maxDist;

void dfs(int curr, int prev, int d, int c)
{
    if(d <= maxDist[curr])
        return;
    maxDist[curr] = d;

    if(color[curr] == 0)
        color[curr] = c;
    if(d == 0)
        return;

    for(int next : edges[curr]){
        if(next == prev)
            continue;
        dfs(next, curr, d-1, c);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    edges.assign(n, vector<int>());

    for(int i=0; i<m; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    int q;
    cin >> q;
    vector<int> v(q), d(q), c(q);
    for(int i=0; i<q; ++i){
        cin >> v[i] >> d[i] >> c[i];
        -- v[i];
    }

    color.assign(n, 0);
    maxDist.assign(n, -1);
    for(int i=q-1; i>=0; --i)
        dfs(v[i], -1, d[i], c[i]);

    for(int i=0; i<n; ++i)
        cout << color[i] << endl;

    return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int mod = (int)1e9 + 7;
const int maxn = 1e5 + 4;
const int inf = (int)1e9;

bool visited[maxn];
vector <int> tpl, tf[maxn];
int dp[maxn], a[maxn];

void cal (int v) {
	int t = 0;
	sort (tf[v].begin(), tf[v].end());
	for (auto u : tf[v]) {
		dp[v] = max (dp[v] + 1, u + 1);
	}
}

void dfs (int v) {
	visited[v] = 1;
	if (!visited[a[v]])
		dfs(a[v]);
	tpl.PB(v);
}

int main() {
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = n; i >= 1; i--)
		if (!visited[i])
			dfs(i);
	reverse (tpl.begin(), tpl.end());
	for(auto v : tpl){	
		cal(v);
		tf[a[v]].PB(dp[v]);
	}
	cout << dp[1] << endl;
}


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

ll N, Q;
vector<vector<ll>> G;
vector<bool> grid;
vector<ll> ans, coins;
int dfs(ll x, ll cnt){
    cnt+=coins[x];
    ans[x] = cnt;
    for(auto v : G[x]){
        if(!grid[v]) {
            grid[v] = true;
            dfs(v, cnt);
        }
    }
    return 0;
}


int main(){
    cin >> N >> Q;
    G.resize(N);
    grid.resize(N);
    ans.resize(N);
    coins.resize(N);
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        ll p, x; cin >> p >> x;
        coins[p-1] += x;
    }
    grid[0] = true;
    dfs(0, 0);
    for(int i = 0; i < N; i++) cout << ans[i] << " ";
    cout << endl;
}

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

//Start
typedef long long ll;
typedef double db;
#define mp(a,b) make_pair((a),(b))
#define x first
#define y second
#define be(a) (a).begin()
#define en(a) (a).end()
#define sz(a) int((a).size())
#define pb(a) push_back(a)
#define R(i,a,b) for(int i=(a),I=(b);i<I;i++)
#define L(i,a,b) for(int i=(b)-1,I=(a)-1;i>I;i--)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=2e5;
int n,ans=0;
pair<int,int> p[N];
pair<int,int> lu(iinf,-iinf);
pair<int,int> ru(-iinf,-iinf);
pair<int,int> ld(iinf,iinf);
pair<int,int> rd(-iinf,iinf);

//Main
int main(){
	scanf("%d",&n);
	R(i,0,n){
		scanf("%d%d",&p[i].x,&p[i].y);
		if(p[i].x+p[i].y>ru.x+ru.y) ru=p[i];
		if(p[i].x-p[i].y>rd.x-rd.y) rd=p[i];
		if(-p[i].x+p[i].y>-lu.x+lu.y) lu=p[i];
		if(-p[i].x-p[i].y>-ld.x-ld.y) ld=p[i];
	}
	R(i,0,n){
		ans=max(ans,abs(p[i].x-lu.x)+abs(p[i].y-lu.y));
		ans=max(ans,abs(p[i].x-ru.x)+abs(p[i].y-ru.y));
		ans=max(ans,abs(p[i].x-ld.x)+abs(p[i].y-ld.y));
		ans=max(ans,abs(p[i].x-rd.x)+abs(p[i].y-rd.y));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 5312
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;
	cin>>N;
	map <int,int> check;
	rep(i,N){
		int a; 
		cin>>a;
		check[a]++;
	}
	int ans = 0;
	for(auto x:check){
		if(x.first > x.second)ans += x.second;
		if(x.first < x.second)ans += x.second - x.first;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power_mod(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i, n) cout << a[i] << " "; cout << endl
#define outaa(a, m, n) rep(i, m) {rep(j, n) cout << a[i][j] << " "; cout << endl;} cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl

//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//product of minimum 9 prime numbers is above 1e9


int main() {
    int n, k; cin >> n >> k;
    int h[n]; rep(i, n) cin >> h[i];
    
    //sumではなくmin
    
    int dp[n]; fill_n(dp, n, inf);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    rep3(i, 2, n) {
        rep3(j, max(0, i - k), i) { //O(K)
            chmin(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }
    out(dp[n - 1]);
    //outa(dp, n);
    /*
     
     costが最大になるケース
     1 10^4 1 10^4 ...
     (10^4 - 1) * (10^5 - 1)
     intでok
     
     */
}


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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const int mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    vector < vector < int > > v(3 , vector < int > (3) );
    vector < vector < int > > a(3 , vector < int > (3) );
    for( int i = 0; i < 3; i++ ){
        for( int j = 0; j < 3; j++ ){
            cin >> v[i][j];
        }
    }
    int n;
    cin >> n;
    for( int i = 0; i < n; i++ ){
        int x;
        cin >> x;
        for( int j = 0; j < 3; j++ ){
            for( int h = 0; h < 3; h++ ){
                if( v[j][h] == x )a[j][h] = 1;
            }
        }
    }
    for( int i = 0; i < 3; i++ ){
        bool f = true;
        bool ff = true;
        for( int j = 0; j < 3; j++ ){
            f &= (a[i][j]);
            ff &= (a[j][i]);
        }
        if( f || ff ){
            cout << "Yes";
            return;
        }
    }
    if( ( a[0][0] && a[1][1] && a[2][2] ) || ( a[2][0] && a[1][1] && a[0][2] ) )cout << "Yes";
    else cout << "No";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i<s.size()-1; i++){
    if(s[i]==s[i+1]){
      if(s[i]=='1') s[i+1] = '0';
      else s[i+1] = '1';
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <bitset>
using namespace std;

const int BUF = 100000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 403, maxM = 100003;
int a[maxM], b[maxM];
bitset <maxN> tur[maxN];
bool flag[maxN];

int main() {
    int n = read(), m = read(), i, j, ans = 0;
    for (i = 1; i <= m; ++i)
        a[i] = read(), b[i] = read();
    for (i = 1; i <= n; ++i) {
        tur[i].set(i);
        for (j = m; j; --j) {
            if (tur[i][a[j]] && tur[i][b[j]]) {
                flag[i] = 1;
                break;
            }
            if (tur[i][a[j]])
                tur[i].set(b[j]);
            if (tur[i][b[j]])
                tur[i].set(a[j]);
        }
    }
    for (i = 1; i <= n; ++i)
        if (!flag[i])
            for (j = 1; j < i; ++j)
                if (!flag[j])
                    ans += !((tur[i] & tur[j]).any());
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1152
from collections import Counter
import sys
n = int(input())
a = list(map(int, input().split()))
count_a = list(Counter(a).items())
count_a = sorted(count_a, reverse=True)
result = 1
c = 0
for x, y in count_a:
    if y>=2:
        result *= x
        c += 1
        if y>=4 and c == 1:
            result *= x
            c += 1
        if c == 2:
            print(result)
            sys.exit()
print(0)

Measured memory_bytes: 21412
def main(sa, sb, sc):
    cards = {
        'a': list(sa),
        'b': list(sb),
        'c': list(sc),
    }
    turn = 'a'
    while True:
        if len(cards[turn]) == 0:
            break
        turn = cards[turn].pop(0)
    return turn.upper()


if __name__ == '__main__':
    SA = input()
    SB = input()
    SC = input()
    print(main(SA, SB, SC))


Measured memory_bytes: 3060
from scipy.sparse.csgraph import dijkstra as di
from collections import Counter
h,w = map(int, input().split())

magic = [list(map(int, input().split())) for i in range(10)]
grid = Counter()
for i in range(h):
    grid.update(Counter(map(int, input().split())))


# 要素はfloat なので注意
dmagic = di(magic)

ans = 0
for i in range(10):
    if i == 1 or i not in grid:
        continue
    ans += dmagic[i][1] * grid[i]

print(int(ans))


Measured memory_bytes: 17720
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
int H, W, M;
set<i_i> st;
 
void input() {
    cin >> H >> W >> M;
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        st.insert({a, b});
    }
}
 
void solve() {
    map<int, int> mph, mpw;
    int hmaxval = 0;
    int wmaxval = 0;
    vector<int> hmax, wmax;
    for(auto tmp : st) {
        chmax(hmaxval, ++mph[tmp.first]);
        chmax(wmaxval, ++mpw[tmp.second]);
    }
    for(auto tmp : mph) {
        if(hmaxval == tmp.second) hmax.push_back(tmp.first);
    }
    for(auto tmp : mpw) {
        if(wmaxval == tmp.second) wmax.push_back(tmp.first);
    }
    int ANS = hmaxval + wmaxval - 1;
    for(auto h : hmax) {
        for(auto w : wmax) {
            if(st.find({h, w}) == st.end()) {
                ANS++;
                cout << ANS << endl;
                return;
            }
        }
    }
    cout << ANS << endl;
}
 
int main() {
    input();
    solve();
    return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

const ll MOD = 1e9 + 7;

ll Mod(ll a, ll mod) {
    return (a%mod + mod)%mod;
}

ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while(n > 0) {
        if (n & 1) {
            res = res*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}

ll modinv(ll a, ll mod) {
    ll x, y;
    extGCD(a, mod, x, y);
    return Mod(x, mod);
}

ll nCr_mod(ll n, ll r, ll mod) {
    if ( n == r || n == 1 ) {
        return 1;
    }
    
    r = min(r, n-r);
    if ( r == 1 ) {
        return n;
    } else {
        ll n_to_n_r = n;
        ll r_to_1 = r;
        rep2(i, r-1) {
            n_to_n_r *= n-i;
            n_to_n_r %= mod;
            r_to_1 *= r-i;
            r_to_1 %= mod;
        }
        r_to_1 = pow_mod(r_to_1, mod-2, mod);
        // r_to_1 = modinv(r_to_1, MOD);
        return n_to_n_r*r_to_1%mod;
    }
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if ( n == 2 ) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = pow_mod(2, n, MOD)-1;
    ans = Mod(ans-nCr_mod(n, a, MOD), MOD);
    ans = Mod(ans-nCr_mod(n, b, MOD), MOD);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
l = list(map(int,input().split())) + [2**26 for _ in range(k)]

dist = [2**26 for _ in range(n+k)]
dist[n-1]= 0
for x in range(n-2,-1,-1):
    a = l[x]
    #dist[x] = min(dist[y] + abs(a-l[y]) for y in range(x+1,x+1+k))
    dist[x] = min(y + abs(a-b) for b,y in zip(l[x+1:x+1+k],dist[x+1:x+1+k]))
print (dist[0])


Measured memory_bytes: 13928
w[100000],c,n,k,g,i,l,m,r=1e9;
f(p)
{
    c=1;g=0;
    for(i=0;i<n;)
    {
        if(g+w[i]<=p)
        {
            g+=w[i++];
        }
        else
        {
            if(g>0)c++;
            else return k+1; 
            g=0;
        }
    }
    return c;
}

main()
{
    scanf("%d%d",&n,&k);
    for(;i<n;scanf("%d",w+i++));
    while(l<r)
    {
        m=(l+r)/2;
        if(f(m)>k)l=m+1;
        else r=m;
    }
    for(m--;;m++)
    {
        if(f(m)<=k)break;
    }
    printf("%d\n",m);
    return 0;
}

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

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

  int sum = a + b + c;

  if(sum == a * 2 || sum == b * 2 || sum == c * 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

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

int main(){
	ll a,b,x; cin>>a>>b>>x;
	ll mx=b/x;
	ll mn=a/x;
	if(a%x==0) cout<<mx-mn+1<<endl;
	else cout<<mx-mn<<endl;
}

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



int main(){
	string s;
	cin >> s;
	for (int i = 0; i < 4; i++) {
		cout << s[i];
	}
	cout << " ";
	for (int i = 4; i < 12; i++) {
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int tate, yoko, i, j;

	scanf("%d%d", &tate, &yoko);

	while (tate != 0 || yoko != 0)
	{
		for (i = 1; i <= tate; i++)
		{
			for (j = 1; j <= yoko; j++)
			{
				if (((i%2 == 1) && (j%2 == 1)) || ((i%2 == 0) && (j%2 == 0)))
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");


		scanf("%d%d", &tate, &yoko);

	}


	return 0;

}



Measured memory_bytes: 2044
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	long long a,b,c;
	cin >> a >> b >> c;
	
	if(a%2==0 || b%2==0 || c%2==0){
		cout << "0" << endl;
		return 0;
	}
	
	long long ans=min(a*b,min(b*c,c*a));
	cout << ans << endl;
	return 0;
}


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

int main() {
	
	int s;
	cin >> s;
	int a = s / 100;
	int b = s - a * 100;
	
	if(a > 0 && a <= 12){
		if(b > 0 && b <= 12){
			puts("AMBIGUOUS");
		}else{
			puts("MMYY");
		}
	}else{
		if(b > 0 && b <= 12){
			puts("YYMM");
		}else{
			puts("NA");
		}
	}
	return 0;
}

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

int main()
{
	int n, s = 0, min = 0;
	cin >> n;
	int a[n+1];
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= a[n]; i++)
	{
		s = 0;
		for(int j = 1; j <= n; j++)
			s += pow((a[j] - i), 2);
		if(i == 1) min = s;
		min = (s < min) ? s : min;
	}
	cout << min;
	return 0;
}



Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PrimitiveIterator;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.IntStream;
import java.util.stream.Stream;

class Main{
	private void solve(){
		int n=gInt(),hp=gInt();
		TreeMap<Integer,Long>m=new TreeMap<>();
		for(int v:rep(n)) {
			m.merge(gInt(),1145141919810L,Long::sum);
			m.merge(gInt(),1L,Long::sum);
		}
		int r=0;
		for(;hp>0;) {
			Entry<Integer,Long> highest=m.pollLastEntry();
			int damage=highest.getKey();
			long remain=highest.getValue();

			long times=Math.min(remain,(hp+damage-1)/damage);
			r+=times;
			hp-=times*damage;
		}
		System.out.println(r);
	}

	public static void main(String[] $){
		new Main().solve();
		System.out.flush();
	}


	static class System{
		private static final InputStream	in	=java.lang.System.in;
		private static final PrintWriter	out	=new PrintWriter(java.lang.System.out,false);
	}

	static Scanner s=new Scanner(System.in);


	static int gInt(){
		return s.nextInt();
	}

	static long gLong(){
		return s.nextLong();
	}

	static long gDouble(){
		return s.nextLong();
	}


	static Range rep(int i){
		return new Range(i);
	}

	static Range rep(int f,int t){
		return new Range(f,t);
	}

	static class Range implements Iterable<Integer>,PrimitiveIterator.OfInt{
		int from,to,c;
		Range(int from,int to){
			this.from=from;
			this.to=to;
			this.c=from;
		}
		Range(int n){
			this(0,n-1);
		}
		@Override
		public Iterator<Integer> iterator(){
			return this;
		}
		@Override
		public boolean hasNext(){
			return c<=to;
		}
		@Override
		public int nextInt(){
			return c++;
		}
	}


	static IntStream REPS(int v){
		return IntStream.range(0,v);
	}

	static IntStream REPS(int l,int r){
		return IntStream.rangeClosed(l,r);
	}


	static IntStream ints(int n){
		return REPS(n).map(i->gInt());
	}

	static Stream<String> strs(int n){
		return REPS(n).mapToObj(i->s.next());
	}

}

Measured memory_bytes: 67388
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)
c = [0]*(n+2)
ans = 0
for i in range(n+1):
    if -a[i]+c[i]>=0:
        ans+=a[i]
        c[i+1] = b[i]
    else:
        if b[i]-a[i]+c[i]>=0:
            ans+=a[i]
            c[i+1] = b[i]-a[i]+c[i]
        elif b[i]-a[i]+c[i]<0:
            ans += b[i]+c[i]
print(ans)

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

const int MAX_N = 500;

int main() {
  int N, C[MAX_N], S[MAX_N], F[MAX_N];
  cin >> N;
  for (int i=0; i<N-1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }
  C[N-1] = S[N-1] = 0;

  for (int i=0; i<N; i++) {
    int t = S[i] + C[i];
    for (int j=i+1; j<N-1; j++) {
      if (S[j] <= t) {
        if ((t-S[j]) % F[j] != 0) {
          t += F[j] - (t-S[j]) % F[j];
        }
      } else {
        t = S[j];
      }
      t += C[j];
    }
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
//ardhendu reja  
const int MAX = 1000001; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[]) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit,n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit,n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit)- 
                     query(queries[query_counter].l, bit); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
} 
  
// driver code 
int main() 
{ 
    int n,q;
    cin>>n>>q;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    Query queries[q];
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        queries[i].l=l-1;
        queries[i].r=r-1;
        queries[i].idx=i;
    }
    sort(queries, queries+q, cmp); 
    answeringQueries(a, n, queries, q); 
    return 0; 
} 

Measured memory_bytes: 19320
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n+1);

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

    for(int i = n;i> n/2;i--){
        b[i] = a[i];
    }

    for(int i = n/2;i >= 1;i--){
        int sum = 0;
        for(int j = 2 * i; j <= n;j+=i){
            sum += b[j];
        }

        int tmp = sum % 2;
        b[i] = (tmp != a[i])?1:0;
    }

    int m = 0;
    for(int i = 1;i<=n;i++){
        if(b[i]){
            m++;
        }
    }

    cout << m << endl;

    for(int i = 1;i<=n;i++){
        if(b[i]){
            cout << i << " ";
        }
    }    

    cout << endl;

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
using namespace std;
typedef long long ll;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    string a, b;
    cin >> a >> b;
    string A, B;
    rep(i,stoi(b)) {
        A += a;
    }
    rep(i,stoi(a)) {
        B += b;
    }
    cout << (min(A, B)) << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

cnt = 0
def dfs(n):
    global cnt
    if n>N:
        return 0
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        cnt += 1
    for j in [3,5,7]:
        dfs(n*10+j)
dfs(0)
print(cnt)

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner sc = new Scanner(System.in);
        String s = sc.next();
      	String t = sc.next();
        
        if (t.startsWith(s) && s.length() == t.length()-1) System.out.println("Yes");
      	else System.out.println("No");
    }
}

Measured memory_bytes: 35676