akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// 参考: https://betrue12.hateblo.jp/entry/2018/10/14/121018

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  vll invsum(n+1);
  rep(i,n){
    invsum[i+1]=(invsum[i]+modpow(i+1,MOD-2))%MOD;
  }
  
  ll ans=0;
  rep(i,n){
    (ans+=a[i]*(invsum[i+1]+invsum[n-i]-1)%MOD)%=MOD;
  }
  ll fact=1;
  reps(i,n){
    (fact*=i)%=MOD;
  }
  (ans*=fact)%=MOD;
  cout<<ans<<endl;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int a,b,x[2000][2000];
char c[2000][2000];
signed main(){
	int ans=0;
	cin>>a>>b;
	f(i,a){
		int cnt=0;
		f(j,b){
			cin>>c[i][j];
			if(c[i][j]=='.')cnt++;
			if(c[i][j]=='#'||j==b-1){
				if(j==b-1&&c[i][j]=='.')j++;
				for(int k=j-cnt;k<j;k++){
					x[i][k]+=cnt;
				}
				cnt=0;
			}
		}
	}
	f(i,b){
		int cnt=0;
		f(j,a){
			if(c[j][i]=='.')cnt++;
			if(c[j][i]=='#'||j==a-1){
				if(j==a-1&&c[j][i]=='.')j++;
				for(int k=j-cnt;k<j;k++){
					x[k][i]+=cnt;
				}
				cnt=0;
			}
		}
	}
	f(i,a){
		f(j,b){
			ans=max(ans,x[i][j]);
		}
	}
	cout<<ans-1<<endl;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int(i)=0;(i)<(n);(i)++)
int main(){
    int n,q; cin>>n>>q;
    vector<tuple<ll,ll,ll>> tap;
    rep(i,n){
        ll s,t,x; cin>>s>>t>>x;
        tap.push_back(make_tuple(s-x,0,x));
        tap.push_back(make_tuple(t-x,-1,x));
    }
    rep(i,q){
        ll d; cin>>d;
        tap.push_back(make_tuple(d,1,i));
    }
    sort(tap.begin(),tap.end());
    multiset<ll> se; 
    vector <ll> ans(q);
    rep(i,tap.size()){
        ll c=get<1>(tap[i]), v=get<2>(tap[i]);
        if(c==1){if(se.empty()) {ans[v]=-1;} else ans[v]=*(se.lower_bound(0));}
        else if(!c) se.insert(v);
        else se.erase(v);
    }
    rep(i,q) cout<<ans[i]<<endl;
}


Measured memory_bytes: 26856
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int len = s.size();
	if (len % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		bool ok = true;
		for (int i = 0; i < len; ++i) {
			if (s[i] != (i % 2 == 0 ? 'h' : 'i')) {
				ok = false;
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int max(int a, int b) {
	if (a > b) return a;
	else return b;
}

int main(void) {
	int a, b, c;
	int x;

	scanf("%d %d %d", &a, &b, &c);
	x = max(max(a, b), c);

	printf("%d\n", (a + b + c) - x);

	return 0;
}

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

class UnionFind{
private:
    std::vector<int> parent;
    std::vector<int> size;
    
public:
    UnionFind(int N){
        parent.resize(N);
        size.resize(N);
        for(int i = 0; i < N; i++){
            parent[i] = i;
            size[i] = 1;
        }
    }

    int root(int x){
        if (parent[x] == x) return x;
        int rx = root(parent[x]);
        parent[x] = rx;
        return rx;
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
        size[ry] += size[rx];
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size[root(x)];
    }
};

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< int > X(M);
    std::vector< int > Y(M);
    std::vector< int > Z(M);
    UnionFind tree(N);
    for(int i=0; i<M; i++){
        std::cin >> X[i] >> Y[i] >> Z[i];
        tree.unite(X[i]-1, Y[i]-1);
    }
    
    std::map< int, bool > mp;
    int cnt = 0;
    for(int i=0; i<N; i++){
        int r = tree.root(i);
        auto itr = mp.find(r);
        if(itr == mp.end()){
            mp[r] = true;
            cnt++;
        }
    }
    
    std::cout << cnt << std::endl;
    
    return 0;
}



Measured memory_bytes: 6784
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll a, p; cin >> a >> p;

    cout << (a * 3 + p) / 2 << endl;
    
}

Measured memory_bytes: 256
import fractions as m

a, b = map(int, input().split())

lcd = []
cd = m.gcd(a, b)

while cd % 2 == 0:
    lcd.append(2)
    cd //= 2

f = 3
while f * f <= cd:
    if cd % f == 0:
        lcd.append(f)
        cd //= f
    else:
        f += 2
if cd != 1:
    lcd.append(cd)

lcd.append(1)

lcd = list(set(lcd))

print(len(lcd))


Measured memory_bytes: 5052
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <sstream>
#include <math.h>
#include <set>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)
#define pb push_back
#define MAX 100


static const int WHITE = 0;
static const int GRAY =  1;
static const int BLACK = 2;
static const long long INFTY = (1LL<<32);
int n;
long long d[MAX][MAX];


  //PQ???(cost,node)????????§
  //nodes???(node,cost)??????????????£??????

void Floyd(){
  rep(k,n){
    rep(i,n){
      if(d[i][k]==INFTY) continue;
      rep(j,n){
        if(d[k][j] == INFTY) continue;
        d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }
}

int main (void) {
  int e,u,v,c;
  cin >> n >> e;

  rep(i,n){
    rep(j,n){
      d[i][j] = ( (i==j) ? 0 : INFTY );
    }
  }

  rep(i,e){
    cin >> u >> v >> c;
    d[u][v] = c;
  }

  Floyd();

  bool negative = false;
  rep(i,n) if(d[i][i] < 0) negative = true;

  if( negative ){
    cout << "NEGATIVE CYCLE" <<endl;
  }else{
    rep(i,n){
      rep(j,n){
        if (j) cout << " ";
        if ( d[i][j] == INFTY ) cout << "INF" ;
        else cout << d[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1236
(* compute exponentiation *)
let rec power ( * ) one m = function
  | 0 -> one
  | n when n mod 2 = 0 ->
      power ( * ) one (m * m) (n / 2)
  | n ->
      m * power ( * ) one m (n - 1)

let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)
let ( *^ ) x y = (x * y) mod m
let inv n = power ( *^ ) 1 n (m - 2)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let fact = memoize (n + 1) @@ fun fact n ->
    if n <= 1 then 1
    else n *^ fact (n - 1) in
  let inv_fact = memoize (n + 1) @@ fun inv_fact n ->
    if n <= 1 then 1
    else inv n *^ inv_fact (n - 1) in
  let as_ = Array.init (n + 1) @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let inv_a = Array.make n [] in
  Array.iteri (fun i a ->
    inv_a.(a - 1) <- i :: inv_a.(a - 1)) as_;
  Array.to_list inv_a
  |> List.find (fun is -> List.length is = 2)
  |> (fun [j; i] ->
      for k = 1 to n + 1 do
        Printf.printf "%d\n" @@
          fact (n + 1) *^ inv_fact (n + 1 - k) *^ inv_fact k -^ if k - 1 <= i + n - j then fact (i + n - j) *^ inv_fact (i + n - j - k + 1) *^ inv_fact (k - 1) else 0
      done)




Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    if(a == 1 || b == 1){
        cout << max(1LL,a - 2) * max(1LL,b - 2) << endl;
        return 0;
    }
    cout << (a - 2) * (b - 2) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
const int mod=1e9+7;
#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> vi;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
	int n,x,y,T;
	cin>>n>>x>>y;
	cout<<min(n*x,y)<<endl;
	return 0;
}



Measured memory_bytes: 256
table = {I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000, nil => 0}

count = ->(roman, number = 0) {
  return number if roman.empty?
  a, b = table[roman.first], table[roman[1]]
  number += if a >= b
    r = roman.drop(1)
    a
  else
    r = roman.drop(2)
    b - a
  end
  count.(r, number)
}

$<.readlines.map(&:chomp).each {|roman| puts count.(roman.chars.map(&:to_sym))}


Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n];
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=1;i<=n;i++)
    cin>>b[i];
  for(int i=1;i<n;i++)
    cin>>c[i];
  int sum=0;
  for(int i=1;i<=n;i++)
  {
    if(i==1)
      sum+=b[a[i]];
    else
    {
      if(a[i]==a[i-1]+1)
        {
           sum+=b[a[i]]+c[a[i-1]];
        }
      else
        sum+=b[a[i]];
    }
    //cout<<sum<<" ";
  }
  cout<<sum;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e18;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int H, N;
    cin >> H >> N;

    int A[N], B[N];
    REP(i, N) {
        cin >> A[i] >> B[i];
    }

    ll h[H+1];
    REP(i, H+1) h[i] = inf;
    h[0] = 0;

    REP(i, H+1) {
        if (h[i] == inf) continue;
        REP(j, N) {
            int s = min(i + A[j], H);
            if (h[s] > h[i] + B[j]) {
                h[s] = h[i] + B[j];
            }
        }
    }

    cout << fixed << setprecision(20);
    cout << h[H] << endl;

}


Measured memory_bytes: 384
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, h, w;
	cin >> h >> w >> n;

	ll s, t;
	s = n/h;
	if(n%h) s++;
	t = n/w;
	if(n%w) t++;
	co(min(s, t));

	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() {
  ll a,b,k;
  cin >> a >> b >> k;

  if (a >= k) a=a-k;
  else {
    k = k -a;
    a = 0;
    b = b - k;
  }
  if (b < 0) b=0;

  cout << a << endl;
  cout << b << endl;
  return 0;
}


Measured memory_bytes: 256
#import<iostream>
#define l long
l N,M,c,n=1,i=2,o=1e9+7;
l m(l a)
{
	l g=1,h=2*o-4;
	for(;h/=2;h&1?g=g*a%o:0,a=a*a%o);
	return g;
}
l C(l b)
{
	l r=1,d=1;
	for(;b;r=r*(N-1+b)%o,d=d*b--%o);
	return r*m(d)%o;
}
main()
{
	for(std::cin>>N>>M;i*i<=M;++i,n=n*C(c)%o)for(c=0;M%i<1;++c,M/=i);
	std::cout<<n*(M^1?N:1)%o<<std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;


const int NMAX = 100000;
vector<int> pnum_;

void ini(){
	bool prime[NMAX];
	memset(prime, true, sizeof(prime));
	prime[0] = false;
	prime[1] = false;
	for(int i=2;i<NMAX;i++){
		for(int j=2*i; j<NMAX; j+=i){
			prime[j] = false;
		}
	}
	for(int i=0;i<NMAX;i++){
		if(prime[i]) pnum_.pb(i);
	}
}


bool solve(){
	int m, a, b;
	cin>> m>> a>> b;
	if(m==0 && a==0 && b==0) return false;
	double c = (double)a/b;
	
	vector<int> pnum;
	for(int i=0; i<pnum_.size() && pnum_[i]<m ; i++){
		pnum.pb(pnum_[i]);
	}
	
	int p = 0, q = 0;
	for(int i=0; i<pnum.size() && pnum[i]*pnum[i] < m;i++){
		for(int j=i;j<pnum.size();j++){
			double p2 = pnum[i], q2 = pnum[j];
			if(p2*q2 > m || c > p2/q2) break;
			if( p2*q2 <= m && c <= p2/q2){
				if(p2*q2 >= p*q){
					p = p2;
					q = q2;
				}
			}
		}
	}
	
	cout<< p<< " "<< q<< endl;
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	ini();
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1452
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

#define MAXX 500005
#define PI 3.14159265358979323846264338327950
#define F first
#define S second
#define ll  long long
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	ll x = 1000;
	cin >> n;
	ll a[n+4];
	for(ll i = 0; i < n; i ++){
		cin >> a[i];
	}
	 a[n] = -1;
    for(ll i = 0; i < n - 1; i++){
        for(ll j = i + 1; j <= n; j++){
            if(a[j] < a[j - 1]){
                ll c = x / a[i];
                x += ((a[j - 1] - a[i]) * c);
                i = j - 1;
                break;
            }
        }
    }
  
	cout << x;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main () {
    int n ;
    cin >> n ;
    vector<P> b (n) ;
    map<int, int> a ;
    rep(i, n){
        int x, y ;
        cin >> x >> y ;
        b[i] = P(y, i) ;
        a[i] = x ; 
    }
    sort(b.begin(), b.end()) ;
    int tot = 0 ;
    rep(i, n){
        tot += a[b[i].second] ;
        if(tot > b[i].first) {
            cout << "No" << endl ;
            return 0 ;
        }
    }
    cout << "Yes" << endl ;
}



Measured memory_bytes: 14328
# -*- coding: utf-8 -*-

# 鏡餅の数
N = int(input())
# 違う大きさの鏡餅の集合
N_set = set()

# 重複排除しながら読み取る
for id in range(N):
    N_set.add(int(input()))

# 重複排除した鏡餅の個数
print(len(N_set))


Measured memory_bytes: 2940
w, h, n = map(int, input().split())

a1 = []
a2 = []
a3 = []
a4 = []

for i in range(n):
    # x,y,a = 2,1,1
    x, y, a = map(int, input().split())

    if a == 1:
        a1.append(x)
    elif a == 2:
        a2.append(x)
    elif a == 3:
        a3.append(y)
    elif a == 4:
        a4.append(y)

if len(a1) == 0:
    aa1 = 0
else:
    aa1 = max(a1)

if len(a2) == 0:
    aa2 = 0
else:
    aa2 = min(a2)

if len(a3) == 0:
    aa3 = 0
else:
    aa3 = max(a3)

if len(a4) == 0:
    aa4 = 0
else:
    aa4 = min(a4)

rx = 0
if aa2 != 0:
    rx = w - aa2

ty = 0
if aa4 != 0:
    ty = h - aa4
s = (w - aa1 - rx) * (h - aa3 - ty)

if s >= 0:
    print(s)
else:
    print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (b), _a = (a); i >= _a; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define all(ar) ar.begin(), ar.end()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define trace2(x, y)            cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)         cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)      cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)   cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;

ll const INF=1LL<<60LL;
double const pi=3.14159265358979323846264338327950; 

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

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

ll modpower(ll base,ll power,ll mod){
	ll res=1;
	while(power){
		if(power%2){
			res=(res*base)%mod;
			power--;
		}
		base=(base*base)%mod;
		power/=2;
	}
	return res;
}
ll const MAX=100001;
vvi g(MAX);
vi vis(MAX);
vi dis(MAX);

void bfs(ll i){
	vis[i]=1;
	queue<ll>q;
	q.push(1);
	while(!q.empty()){
		ll u=q.front();
		q.pop();
		for(ll child:g[u]){
			if(vis[child]==0){
				q.push(child);
				dis[child]=u;
				vis[child]=1;
			}
		}
	}
}
void solve(){
	ll n,m;
	cin>>n>>m;
	rep(i,m){
		ll a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	rep(i,MAX)dis[i]=INF;
	bfs(1);
	bool bo=false;
	for (int i=2; i <=n; ++i)
	{
		if(dis[i]==INF){
			bo=true;
			break;
		}
	}
	if(bo)cout<<"No"<<endl;
	else {
		cout<<"Yes"<<endl;
		for (int i = 2; i <=n; ++i)
		{
			cout<<dis[i]<<endl;
		}
	}
}
    
int main () 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(30);
    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
 
    }
 
    return 0;   
}

Measured memory_bytes: 13664
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif

	string s;
	cin>>s;
	int max=0,j,i,maxi=0,c=0;
	for(i=0;i<3;i++)
	{
		if(s[i]=='R')
		{
			c=1;
			for(j=i+1;j<s.length();j++)
			{
				if(s[j]!='R')
				break;
				c++;
			}
		}
		if(c>maxi)
		{
			maxi=c;
		}
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
int main() {
    i64 N, P;
    cin >> N >> P;
    string S;
    cin >> S;
    reverse(WHOLE(S));
    i64 ans = 0;
    if(P == 2 || P == 5) {
        for(int i = 0; i < N; i++) {
            if((S[i] - '0') % P == 0) {
                ans += N - i;
            }
        }
    } else {
        i64 p10 = 1;
        i64 cur = -1;
        vector<i64> m(P, 0);
        m[0]++;
        for(int i = 0; i < N; i++) {
            cur = (cur < 0 ? 0 : cur) + p10 * (S[i] - '0');
            cur %= P;
            m[cur]++;
            p10 = (p10 * 10) % P;
        }
        for(int i = 0; i < P; i++) {
            ans += (m[i] * (m[i] - 1)) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
R,L=[0],[0]
for i in range(N-1):
    R+=[gcd(R[i],A[i])]
    L+=[gcd(L[i],A[-i-1])]
print(max(gcd(R[i],L[-i-1]) for i in range(N)))

Measured memory_bytes: 16120
fun main(omkar: Array<String>) {
    val n = readLine()!!.toInt()
    val digits = readLine()!!.map { it - '1' }
    if (digits.contains(1)) {
        var parity1 = 0
        var chooseDiv = 0
        for (j in 0 until n) {
            if (j != 0) {
                var k = n - j
                while (k % 2 == 0) {
                    chooseDiv++
                    k /= 2
                }
                k = j
                while (k % 2 == 0) {
                    chooseDiv--
                    k /= 2
                }
            }
            if (digits[j] == 1 && chooseDiv == 0) {
                parity1 = 1 - parity1
            }
        }
        println(parity1)
    } else {
        var parity2 = 0
        var chooseDiv = 0
        for (j in 0 until n) {
            if (j != 0) {
                var k = n - j
                while (k % 2 == 0) {
                    chooseDiv++
                    k /= 2
                }
                k = j
                while (k % 2 == 0) {
                    chooseDiv--
                    k /= 2
                }
            }
            if (digits[j] == 2 && chooseDiv == 0) {
                parity2 = 2 - parity2
            }
        }
        println(parity2)
    }
}

Measured memory_bytes: 39552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

map<ll,ll>a;
int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a[x]+=y;
	}
	ll ans=0;
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        ll su= itr->second ;
        ll ne=itr->first;
        if(k>=su){
        	ans+=su*ne;
        	k-=su;
        	if(k==0){
        		break;
        	}
        }
        else{
        	ans+=k*ne;
        	break;
        }
    }	
    cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 6528
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = new ListBuffer[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 59488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e6+10;
struct sc
{
    ll x,y;
}p[N];
ll vis[N],m,a[N],b[N];
ll sum[N];
int main()
{
    //freopen("i.txt","r",stdin);
    scanf("%lld",&m);
    for(int i=0; i<m; i++)
    {
        scanf("%lld %lld",&p[i].x,&p[i].y);
        vis[p[i].x]++;
        vis[p[i].y]--;
        a[p[i].x]++;
        b[p[i].y]++;
    }
    ll ans1=0,ans2=0;
    for(int i=1; i<=100000; i++)
    {
        vis[i]+=vis[i-1];
        ans2=max(vis[i],ans2);
        a[i]+=a[i-1];
        b[i]+=b[i-1];
    }
    for(int i=0; i<m; i++)
        ans1=max(ans1,m-a[100000]+a[p[i].y-1]-b[p[i].x]);
    printf("%lld %lld\n",ans1,ans2);
}



Measured memory_bytes: 8708
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
C = list(map(int,input().split()))
C.sort()
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

stack = [0]
ans = [-1] * N
ans[0] = C.pop()
m = 0
while stack:
    v = stack.pop()
    for to in es[v]:
        if ans[to] >= 0: continue
        ans[to] = C.pop()
        m += ans[to]
        stack.append(to)
print(m)
print(*ans)

Measured memory_bytes: 7052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define erep(i, n) for (int i = 0; i <= (n); i++)
#define erep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    int n = N + 1;
    vector<int> a(n);
    for (int i = 2; i <= N; i++) {
        cin >> a[i];
    }
    vector<int> d(n);
    for (int i = 2; i <= N; i++) {
        ++d[a[i]];
    }
    erep1(i, N) cout << d[i] << endl;
}

Measured memory_bytes: 4768
#include<stdio.h>
long long a[100006];
int main()
{
	long long n,x;
	long long sum=0;
	scanf("%lld %lld %lld",&n,&x,&a[1]);
	for(int i=2;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(a[i]+a[i-1]>x)
		{
			sum+=a[i]+a[i-1]-x;
			a[i]=x-a[i-1];
			if(a[i]<0)
			{
				a[i-1]=a[i-1]-(0-a[i]);
				a[i]=0;
			}
		}
	}
	printf("%lld\n",sum);
	return 0;
 } 

Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main()
{
	int n,k,i,j,t,s=0;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=1;i<n;i++) 
	for(j=0;j<n-i;j++){
		if(a[j]<a[j+1]){
			t=a[j];
			a[j]=a[j+1];
			a[j+1]=t;
		}
	}
	for(i=0;i<k;i++)
	s=s+a[i];
	printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

const int N = 40005;
const long double eps = 1e-8;

struct Point {
	long double x, y;
	
	void read() {
		cin >> x >> y;
		//scanf("%lf%lf", &x, &y);
	}
};
long double mat[25][25];

int n;
Point p[N];

long double sqr(long double x) {
	return x * x;
}

void init() {
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		p[i].read();
	}
}

void gauss() {
	for (int i = 1; i <= 3; i ++) {
		int best;
		long double cc = -5.0;
		
		for (int j = i; j <= 3; j ++) {
			if (abs(mat[j][i]) > cc) {
				cc = abs(mat[j][i]);
				best = j;
			}
		}
		for (int j = 1; j <= 4; j ++) {
			swap(mat[i][j], mat[best][j]);
		}
		
		for (int j = i + 1; j <= 3; j ++) {
			if (abs(mat[j][i]) > eps) {
				long double t = mat[i][i] / mat[j][i];
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] *= t;
				}
				for (int k = 1; k <= 4; k ++) {
					mat[j][k] -= mat[i][k];
				}
			}
		}
	}
	
	long double ans[5];
	for (int i = 3; i >= 1; i --) {
		if (abs(mat[i][i]) > eps) {
			ans[i] = mat[i][4] / mat[i][i];
		} else {
			ans[i] = 0.0;
		}
		for (int j = i - 1; j >= 1; j --) {
			mat[j][4] -= mat[j][i] * ans[i];
		}
	}
	
	for (int i = 1; i <= 3; i ++) {
		printf("%.6f%c", (double)ans[i], i == 3 ? '\n' : ' ');
	}
}

void work() {
	for (int i = 1; i <= n; i ++) {
		long double tmp[6];
		tmp[1] = p[i].x, tmp[2] = p[i].y;
		tmp[3] = 1.0, tmp[4] = p[i].x * p[i].x + p[i].y * p[i].y;
		
		for (int j = 1; j <= 4; j ++) {
			mat[1][j] += tmp[j] * p[i].x;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[2][j] += tmp[j] * p[i].y;
		}
		for (int j = 1; j <= 4; j ++) {
			mat[3][j] += tmp[j];
		}
	}
	for (int i = 1; i <= 3; i ++) {
		mat[i][4] *= -1.0;
	}
	
	gauss();
}

int main() {
	//freopen("A.in", "r", stdin);
	//ios::sync_with_stdio(false);
	
	init(), work();
	
	return 0;
}

Measured memory_bytes: 2504
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <set>
#include <iterator>
#include <map>
using namespace std;

vector<int> table;


void check(int x){
    bool a = false, b = false, c = false;
    string tmp = to_string(x);
    for(int i = 0; i < tmp.size(); i++){
        if(tmp[i] == '3'){
            a = true;
        }else if(tmp[i] == '5'){
            b = true;
        }else{
            c = true;
        }
    }
    if(a == true && b == true && c == true){
        table.push_back(x);
    }
}

void dfs(int x){
    check(x);
    if(x <= 100000000){
        dfs(10 * x + 3);
        dfs(10 * x + 5);
        dfs(10 * x + 7);    
    }
}

int main(){
    int N;
    cin >> N;
    dfs(0);
    // dfs(3);
    // dfs(5);
    // dfs(7);
    sort(table.begin(), table.end());
    cout << upper_bound(table.begin(), table.end(), N) - table.begin() << endl;
    
    return 0;
}

Measured memory_bytes: 512
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val ans = readLine()!!.split(" ").map { conv(it.toLong()) }.sum()
    println(ans)
}

fun conv(num:Long):Int {
    var current = num
    var ret = 0
    while (current % 2 == 0L) {
        ret++
        current /= 2
    }
    return ret
}

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

int v[200010] = {0};

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

Measured memory_bytes: 4368
import java.util.*;
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String str = "";
		int[] b = new int[26];
		while(scanner.hasNext()) {
			str = scanner.nextLine();
			str = str.toLowerCase();
			char[] c = str.toCharArray();
			for(int i = 0; i < c.length; i++) {
				if('a' <= c[i] && c[i] <= 'z') {
					b[c[i] - 'a']++;
				}
			}
		}
		for(int i = 0; i < 26; i++) {
			System.out.println(((char)(i + 'a')) + " : " + b[i]);
		}
	}
}


Measured memory_bytes: 26112
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	//for(int i=0;i<N;i++) {}
	
	
	
	
	
	public static void main(String[] args) {
		long N=sc.nextLong();
		long M=sc.nextLong();
		
		
		long ans=0;
		
		
		if(N*2<=M) {
			ans+=N+(M-N*2)/4;
		}else {
			ans+=M/2;
		}
		
		
		
		
		
		p(ans);
	}
	
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 22100
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#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 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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

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

	vi len(3);
	int a, b;
	int n;

	cin >> n;

	REP(i, n){
		cin >> len[0] >> len[1] >> len[2];

		VSORT(len);
		a = len[0] * len[0] + len[1] * len[1];
		b = len[2] * len[2];

		if (a == b)
			puts("YES");
		else
			puts("NO");
	}
}

Measured memory_bytes: 1196
use std::collections::BinaryHeap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: u64 = sc.read();
    let m: u64 = sc.read();
    let mut ab = vec![];

    for _ in 0..n {
        let a: u64 = sc.read();
        let b: u64 = sc.read();
        ab.push((a, b));
    }

    let mut ans = 0;
    let mut heap: BinaryHeap<u64> = BinaryHeap::new();
    let mut index: usize = 0;

    ab.sort();

    for day in 1..m+1 {
        while index < ab.len() && ab[index].0 <= day {
            heap.push(ab[index].1);
            index += 1;
        }
        if let Some(b) = heap.pop() {
            ans += b;
        } 
    }

    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n = 1) :n(n), f(n + 1) {
        f[0] = f[1] = -1;
        for (ll i = 2; i <= n; i++) {
            if (f[i]) {
                continue;
            }
            primes.push_back(i);
            f[i] = i;
            for (ll j = i * i; j <= n; j += i) {
                if (!f[j]) {
                    f[j] = i;
                }
            }
        }
    }

    bool isPrime(int x) {
        return f[x] == x;
    }

    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }

    vector<P> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) {
            return {};
        }
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            }
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    int n;
    cin >> n;
    Sieve sieve(n);
    map<int, ll> mp;
    for(int i = 2; i <= n; i++){
        vector<P> f = sieve.factor(i);
        for(P p : f){
            mp[p.first] += p.second;
        }
    }

    ll ans = 1;
    int mod = 1000000007;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        ans *= itr->second + 1;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

now = 1
allows = []
for i in range(n):
    ha = a[i]
    if ha > now:
        print(-1)
        exit()
    allows.append(now - ha)
    now = (now - ha) * 2
if now < a[n]:
    print(-1)
    exit()
result = a[n]
now = a[n]
for i in range(n):
    if now > allows[n-1-i]:
        now = allows[n-1-i]
    now = now + a[n-1-i]
    result += now
print(result)

Measured memory_bytes: 701224
n=int(input())
a=[]
b=[]
for i in range(n):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))
a_sorted = sorted(a)
b_sorted = sorted(b)

if n % 2 == 1:
    ans = b_sorted[(n-1)//2] - a_sorted[(n-1)//2] + 1
else:
    ans = (b_sorted[n//2-1] + b_sorted[n//2]) - (a_sorted[n//2-1] + a_sorted[n//2]) + 1
print(ans)

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

int main(void){

  char str1[100],str2[100];
  int a,b;
  int i,j,k,l,m,n,v,x,y;
  int s1,s2,s3;
  int up=0;
  int sum[100];
  int count;

  scanf("%d",&count);

  if((count>50)||(count<0)){
    return 0;
  }

  for(x=0;x<count;x++){

    scanf("%s",str1);
    scanf("%s",str2);

    a = strlen(str1);
    b = strlen(str2);

    if(a<=b){
     
      j = 0;
      k = b-1;
      l = 0;
      //?????????????????????????¶????
      for(i=a-1;i>=0;i--){
	s1 = str1[i]-'0';
	s2 = str2[k-l]-'0';

	//?¶????????????????????????\??????
	if(s1+s2+up<10){
	  sum[j] = s1+s2+up;
	  up = 0;

	}else{
	  sum[j] = (s1+s2+up)%10;
	  up = 1;
   
	}
	j++;
	l++;
      }
      if(a != b){
	n = 0;

	for(m=b-a-1;m>=0;m--){

	  s3 = str2[m];


	  if(((s3-'0')+up)<10){

	    sum[a+n] = (s3-'0')+up;
	    up = 0; 
	  }else{
	    sum[a+n] = ((s3-'0')+up)%10;
	    up = 1;
	  }
	  n++;
	}
      }
      if(up == 1){
	sum[b] = 1;
	if(b>=80){
	  printf("overflow");
	}else{
	  for(v=b;v>=0;v--){
	    printf("%d",sum[v]);
	  }
	}
      }else{
	if(b>=81){
	  printf("overflow");
	}else{
	  for(v=b-1;v>=0;v--){
	    printf("%d",sum[v]);
	  }
	}
      }
      up = 0;
      printf("\n");


    

    }else{
      j = 0;
      k = a-1;
      l = 0;
      for(i=b-1;i>=0;i--){
	s1 = str1[k-l]-'0';
	s2 = str2[i]-'0';


	if(s1+s2+up<10){
	  sum[j] = s1+s2+up;
	  up = 0;
	}else{
	  sum[j] = (s1+s2+up)%10;
	  up = 1;
	}
	j++;
	l++;
      }
      n = 0;
      for(m=a-b-1;m>=0;m--){

	s3 = str1[m];

	if(((s3-'0')+up)<10){

	  sum[b+n] = (s3-'0')+up;
	  up = 0; 
	}else{
	  sum[b+n] = ((s3-'0')+up)%10;
	  up = 1;
	}
	n++;
      }

      if(up == 1){
	sum[a] = 1;
	if(a>=80){
	  printf("overflow");
	}else{
	  for(v=a;v>=0;v--){
	    printf("%d",sum[v]);
	  }
	}
      }else{
	if(a>=81){
	  printf("overflow");
	}else{
	  for(v=a-1;v>=0;v--){
	    printf("%d",sum[v]);
	  }
	}
      }
      up = 0;
      printf("\n");


    } 
    for(y=0;y<100;y++){
      sum[y]=0;
    }
    memset(str1,'\0',a);
    memset(str2,'\0',b);


  }
  return 0;
}

Measured memory_bytes: 608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int x = int.Parse(Console.ReadLine());
        int fifHundredCount = x / 500;
        int fifCount = (x % 500) / 5;
        Console.WriteLine(fifHundredCount * 1000 + fifCount * 5);
    }


  

}



Measured memory_bytes: 13140
# AOJ 0175 Quaternary Notation
# Python3 2018.6.19 bal4u

while True:
	n = int(input())
	if n < 0: break
	if n == 0: print(0)
	else:
		ans = []
		while n > 0:
			ans.append(str(n & 3))
			n >>= 2
		print(*ans[::-1], sep='')



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i=0; i<N; i++) cin >> vec[i];
  
  int count=-1;
  bool t=true;
  
  while (t==true){
  for (int i=0; i<N; i++){
    if (vec[i]%2==1){
    t=false;
      break;
    }
    vec[i]=vec[i]/2;
  }
    count++;
  }
  cout << count <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

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

    std::cout << std::fixed << std::setprecision(8);

    if (n % 2 == 0) {
        std::cout << 0.5 << std::endl;
    } else {
        std::cout << ((double)n + 1) / 2 / n << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s;
  cin >> s;
  ll ans = 0;
  rep(i,s.size()) {
    ans += s[i]-48;
  }
  if (ans%9 == 0) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3756
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int n;
  vector<int> v;
  cin>>n;
  v.reserve(n);
  for(i=0;i<n;i++)
    cin>>v[i];
  for(i=0;i<n;i++){
    cout<<"Case "<<i+1<<":"<<endl;
    for(j=0;j<10;j++){
      v[i]=v[i]*v[i]%1000000/100;
      cout<<v[i]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
use std::io::*;
use std::str::*;
use std::collections::*;

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if !s.is_empty() {
        if let Ok(s) = s.parse::<T>() {
            s
        } else {
            panic!("faild to parse {}", s);
        }
    } else {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
}

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    read_from(&mut stdin)
}

fn main() {
    loop {
        let mut vec: Vec<usize> = (0..3).map(|_| read()).collect();
        vec.sort();
        println!("{}", vec[2]*10 + vec[1] + vec[0]);
    }
}


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

int		main(void)
{
	int N, M;
	vector<int> a(50);
	vector<int> b(50);
	
	cin >> N >> M;
	for (int i = 0; i < M; i++)
		cin >> a[i] >> b[i];
	for (int n = 1; n <= N; n++)
	{
		int sum = 0;

		for (int i = 0; i < a.size(); i++)
		{
			if (a[i] == n || b[i] == n)
				sum++;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int h1, m1, h2, m2, k;
int main()
{
	cin>>h1>>m1>>h2>>m2>>k;
	int min;
	if(m2 < m1)
		min = (h2 - h1 - 1) * 60 + (m2 + 60 - m1);
	else
		min = (h2 - h1) * 60 + (m2 - m1);
	cout<<min - k<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

	int k, x;
	cin >> k >> x;

	for (int i = x - k + 1; i <= x + k - 1; i++) {
		cout << i << " ";
	}

	return 0;
}

Measured memory_bytes: 256