akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct R {
  int l, r;
  bool operator<(R const& rhs) const { return r < rhs.r; }
};
int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<R> rs(N);
  for(auto& rb: rs) {
    int X, L; std::cin >> X >> L;
    rb.l = X-L;
    rb.r = X+L;
  }
  std::sort(rs.begin(), rs.end());
  int ans = 1, last = rs[0].r;
  for(int i = 1; i < rs.size(); ++i) {
    if(rs[i].l < last) continue;
    ++ans;
    last = rs[i].r;
  }
  fin(ans);
  return 0;
}


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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    int n;
    cin>>n;
    set<int> st;
    for(int i = 0; i < n; i++) {
        int x;
        cin>>x;
        st.insert(x);
    }

    if(st.size() == n) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    

}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;
#define INF 2000000000
void solve() {
  int N;
  ll ans = 0;
  cin >> N;
  vector<tuple<int, int, int>> L;
  vector<tuple<int, int, int>> R;
  vector<tuple<int, int, int>> E;
  REP(i, N) {
    int k, l, r;
    cin >> k >> l >> r;
    if (l == r || k >= N) {
      E.push_back(make_tuple(k, l, r));
    } else if (l > r) {
      L.push_back(make_tuple(k, l, r));
    } else if (r > l) {
      R.push_back(make_tuple(k, l, r));
    } else {
      cout << "vector error!" << endl;
      exit(1);
    }
  }

  for (auto e : E) {
    ans += get<1>(e);
  }

  sort(L.begin(), L.end());
  sort(R.begin(), R.end(),greater());
  priority_queue<int, vector<int>, greater<int>> pq;
  vi Lsa, Rsa;
  int ind = 0, LX = 0;
  for (auto t : L) {
    ind++;
    ans += get<1>(t);
    int sa = (get<1>(t) - get<2>(t));
    pq.push(sa);
    while (ind > get<0>(t)) {
      ind--;
      ans -= pq.top();
      pq.pop();
      LX++;
    }
  }
  ind = N;

  priority_queue<int, vector<int>, greater<int>> qp;
  for (auto t : R) {
    ind--;
    ans += get<2>(t);
    int sa = (get<2>(t) - get<1>(t));
    qp.push(sa);
    while (ind < get<0>(t)) {
      ind++;
      ans -= qp.top();
      qp.pop();
    }
    //cout << ans << " ";
  }

  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int T;
  cin >> T;
  REP(i, T) solve();
  return 0;
}

Measured memory_bytes: 6828
#include <cstdio>

int main(){
	char ch;
	
	for(;;){
		scanf("%c", &ch);
		if(ch >= 'a' && ch <= 'z'){
			ch -= 'a' - 'A';
		}else if(ch >= 'A' && ch <= 'Z'){
			ch += 'a' - 'A';
		}
		printf("%c", ch);
		if(ch == '\n') break;
	}
	
	return 0;
}

Measured memory_bytes: 932
def resolve():
    X, Y, A, B, C = map(int, input().split())
    p = sorted(list(map(int, input().split())), reverse=True)
    q = sorted(list(map(int, input().split())), reverse=True)
    r = sorted(p[:X] + q[:Y] + list(map(int, input().split())), reverse=True)
    print(sum(r[:X+Y]))

resolve()

Measured memory_bytes: 25648
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
bool isso(long long int a) {
  if (a == 1 || a == 0)return false;
  for (long long int i = 2; i*i <= a; ++i) {
    if ((a%i)) {
    }
    else {
      return false;
    }
  }
  return true;
}
//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
  int anss[1300000];
int main() {
  int from = 2;
  for (int i = 2; i < 1300000; ++i) {
    if (isso(i)) {
      anss[i] = 0;
      for (int j = from; j < i; ++j) {
        anss[j] = i - from+1;
      }
      from = i + 1;
    }
    else {

    }
  }
  while (1) {
    int a; cin >> a;
    if (!a)break;
    else {
      cout << anss[a] << endl;
    }
  }
  return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<vector<int>> g(n, vector<int>(0));
	vector<int> it(n, 0);
	vector<P> in(n-1);
	map<P, int> ans;
	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
		in[i] = {a, b};
	}
	queue<int> ne;
	queue<int> ma;
	queue<int> co;
	ne.push(0);
	ma.push(-1);
	co.push(-1);
	it[0] = 1;
	int cma = 0;
	while(!(ne.empty())){
		int x = ne.front();
		int xm = ma.front();
		int col = co.front();
		int c = 0;
		it[x] = 1;
		rep(j, g[x].size()){
			int xn = g[x][j];
			if(it[xn] == 0){
				c++;
				if(c == col) c++;
				if(cma < c) cma = c;
				ne.push(xn);
				ma.push(x);
				co.push(c);
				ans[{x, xn}] = c;
				ans[{xn, x}] = c;
			}
		}
		ne.pop();
		ma.pop();
		co.pop();
	}
	cout << cma << endl;
	rep(i, n-1){
		cout << ans[{in[i].first, in[i].second}] << endl;
	}
	return 0;
}

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

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

    int N;
    cin >> N;

    vector<ll> A(N);

    for(int i = 0; i < N; i++) cin >> A[i];

    vector<ll> X(N);

    for(int i = 0; i < N; i++) {
        int p = i - A[i];
        if(p < 0) continue;
        X[p]++;
    }

    ll ans = 0;

    for(int i = 0; i < N; i++) {
        int p = i + A[i];
        if(p >= N) continue;
        ans += X[p];
    }

    cout << ans << endl;
}

Measured memory_bytes: 6364
import collections

N, M = map(int, input().split())
ac = 0
wa = 0
aced = set()
dic = collections.defaultdict(lambda:0)
for _ in range(M):
  p, s = input().split()
  if s == 'WA' and p not in aced:
    dic[p] += 1
  elif s == 'AC' and p not in aced:
    aced.add(p)
    ac += 1
    if p in dic:
      wa += dic[p]

print(ac, wa)

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

int main(){
  int Er,Eg,Nr,Ng,N0;
  cin >> Er >> Eg >> Nr >> Ng >> N0;

  priority_queue<int64_t> red;
  priority_queue<int64_t> green;
  priority_queue<int64_t> transparent;
  int64_t buf;
  for(int i=0; i<Nr; i++){
    cin >> buf;
    red.push(buf);
  }
  for(int i=0; i<Ng; i++){
    cin >> buf;
    green.push(buf);
  }
  for(int i=0; i<N0; i++){
    cin >> buf;
    transparent.push(buf);
  }

  int64_t ans= 0;
  int rem_r= Er;
  int rem_g= Eg;
  for(int cnt= 0; cnt< Er+Eg; cnt++){
    int64_t deli= -1;
    int64_t cand_r= red.top();
    int64_t cand_g= green.top();
    int64_t cand_0= (!transparent.empty()) ? transparent.top() 
                                           : -1;
    if(rem_r > 0){ deli= max(deli, cand_r); }
    if(rem_g > 0){ deli= max(deli, cand_g); }
    deli= max(deli, cand_0);

    ans+= deli;
    if(rem_r > 0 && deli==cand_r){
      red.pop();
      rem_r--;
    }
    else if(rem_g > 0 && deli==cand_g){
      green.pop();
      rem_g--;
    }
    else{
      transparent.pop();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3316
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[] array = {a+b,a-b,a*b};
    Arrays.sort(array);
    int value = array[2];
    System.out.println(value);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int n,a,b;
	while(~getIII(n,a,b)) printf("%d %d\n",min(a,b),((a+b)-n)>0?((a+b)-n):0);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

const ll mod=1e9+7;

ll modPow(ll a, ll n) {
  if(n==1)return a%mod;
  if (n%2==1)return(a*modPow(a,n-1))%mod;
  ll t=modPow(a,n/2);
  return (t*t)%mod;
}

ll modDiv(ll a,ll b){
  return (a%mod)*modPow(b,mod-2)%mod;
}

ll comb(ll n,ll r){
  ll res=1;
  for(ll i=n;i>=n-r+1;--i){
    res*=i;
    res%=mod;
  }
  for(ll i=r;i>=1;--i)res=modDiv(res,i);
  return res%mod;
}

ll n,a,b;

int main(){
  cin>>n>>a>>b;
  ll ans=modPow(2,n)-1;
  ans-=(comb(n,a)+comb(n,b))%mod;
  ans=(ans+mod)%mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
        public static void main(String[] args) {
            int[][] grid = new int[3][3];
            Scanner sc = new Scanner(System.in);
            for(int row = 0; row < 3; row++) {
                for(int col = 0; col < 3; col++) {
                    grid[row][col] = sc.nextInt();
                }
            }
            int aDiff1 = grid[0][0] - grid[0][1];
            int aDiff2 = grid[0][1] - grid[0][2];
            int bDiff1 = grid[0][0] - grid[1][0];
            int bDiff2 = grid[1][0] - grid[2][0];
            if((grid[1][0] - aDiff1 != grid[1][1]) || (grid[1][1] - aDiff2 != grid[1][2]) || (grid[2][0] - aDiff1 != grid[2][1]) || (grid[2][1] - aDiff2 != grid[2][2]) ||
                            (grid[0][1] - bDiff1 != grid[1][1]) || (grid[1][1] - bDiff2 != grid[2][1]) || (grid[0][2] - bDiff1 != grid[1][2]) || (grid[1][2] - bDiff2 != grid[2][2])) {
                System.out.println("No");
            } else {
                System.out.println("Yes");
            }
        }
}


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

s = "MARCH"
counter_arr = [0] * 5

for i in range(N):
    tmp = input()
    for j in range(len(s)):
        if tmp[0] == s[j]:
            counter_arr[j] += 1
            break

ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += counter_arr[i] * counter_arr[j] * counter_arr[k]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <list>
#include <cmath>
using namespace std;

int main() {
	int x;
	cin >> x;
	for (int i = x; i < x * 2; ++i) {
		bool prime = true;
		for (int j = 2; j <= sqrt(i); ++j) {
			if (i % j == 0) {
				prime = false;
				break;
			}
		}
		if (prime) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

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

typedef long long ll;

int main()
{
	//freopen("C.in","r",stdin);
	ll x,y;
	cin >> x >> y;
	int cnt = 1;
	while (x * 2LL <= y) cnt++, x *= 2LL;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u32 = read();
    println!("{}", (n - 1) / 2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    
    int k,x;
    cin >> k >>x;

    rep(i,x-k+1,x+k)PS(i);
    cout << endl;
    return  0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX c
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long
bool order(vector<ll> a){
  rep(i,a.size()-1){
    if(a[i]>a[i+1]){
      return false;
    }
  }
  return true;
}
int main(void){
	ll n;
  cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl ans1,ans2;
  int num=0;
  int locmax;
  int locmin;
  ll MAX=numeric_limits<long long>::min();
  ll min=numeric_limits<long long>::max();
  rep(i,n){
    if(MAX<a[i]){
      locmax=i;
      MAX=a[i];
    }
    if(min>a[i]){
      locmin=i;
      min=a[i];
    }
  }
  if((ll)abs(MAX)>=(ll)abs(min)){
    rep(i,n){
      if(i!=locmax){
        a[i]+=a[locmax];
        num++;
        ans1.pb(locmax);
        ans2.pb(i);
      }
    }
    rep(i,n-1){
      num++;
      a[i+1]+=a[i];
      ans1.pb(i);
      ans2.pb(i+1);
    }
  }else{
    rep(i,n){
      if(i!=locmin){
        a[i]+=a[locmin];
        num++;
        ans1.pb(locmin);
        ans2.pb(i);
      }
    }
    rep(i,n-1){

      num++;
      a[n-1-(i+1)]+=a[n-1-i];
      ans1.pb(n-1-i);
      ans2.pb(n-1-(i+1));
    }
  }
  cout<<num<<endl;
  rep(i,num){
    cout<<ans1[i]+1<<" "<<ans2[i]+1<<endl;
  }
	return 0;
}


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

using namespace std;

int main(){
	int i = 0;
	float ansmax, ansmin = 100000;
	float mou[101];

	while(cin >> mou[i]){

		if(mou[i] == 0) break;

		ansmax = max(ansmax,mou[i]);
		ansmin = min(ansmin,mou[i]);

		i++;
	}

	cout << ansmax - ansmin << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

lli L[2001] = {};

int main(void) {
	lli N;
	cin >> N;

	lli answer = 0;

	for (int i = 0; i < N; i++)
		cin >> L[i];

	sort(L, L + N);

	for (int i = 0; i < N; i++) {
		for (int k = i + 1; k < N; k++) {
			lli a = L[i];
			lli b = L[k];

			lli maxi = max(a - b, b - a);

			//maxi < c < a + b

			lli mini_num = upper_bound(L + k + 1, L + N, maxi) - L;
			lli maxi_num = lower_bound(L + k + 1, L + N, a + b) - L;

			if (mini_num == N)
				continue;

			lli tmp = maxi_num - mini_num;

			//max(a-b,b-a) < c < a + b
			//どこまでかという範囲を考えるのが苦手なので
			// A < B < C　だったら upper , lowerで範囲を取れることを覚えたい

			answer += tmp;
		}
	}

	COUT(answer);

	return 0;
}

Measured memory_bytes: 256
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let S = read string |> Seq.toArray |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

    let mutable ans = 0
    for i in 0..999 do
        let c = [|i / 100; (i / 10) % 10; i % 10|]
        seq {
            let mutable cnt = 0
            for j in 0..N-1 do
                if S.[j] = c.[cnt] then
                    cnt <- cnt + 1

                if cnt = 3 then yield ()
        }
        |> fun s ->
            if Seq.isEmpty s |> not then
                ans <- ans + 1

    printfn "%d" ans
    0 // return an integer exit code


Measured memory_bytes: 14684
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;

#define FOR(i, a, b) for (int i = a; i < b; i++)

void print(vi &A) {
	FOR(i, 0, (int)A.size())
		printf("%d ", A[i]);
	cout << endl;
}

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

	vi A(n);
	FOR(i, 0, n) {
		scanf("%d", &A[i]);
	}
	// print(A);

	ll sum = 0;
	FOR(i, 0, n) {
		sum += (ll)A[i];
	}

	if (sum >= h)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  vector<bool> tmp(3);
  int A, B;
  cin >> A >> B;
  tmp[A-1] = true;
  tmp[B-1] = true;
  rep(i, 3) if(!tmp[i]) cout << i+1 << endl;
  return 0;
}


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

int main() {
  int W,H,x,y,r;
  cin >> W >>H>>x >>y >>r ;

  if ((x-r < 0)|| (x+r >W)){
    cout << "No" << endl;
  }
  else if ((y-r < 0)|| (y+r >H)) {
    cout << "No" << endl;
  }
  else  {cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long lli;

const int MAXN = 205;
const int MAXW = 10004;
const int INF = 1<<28;
const lli mod = 1000000007LL;

int N, W;
lli dp[2][MAXW][MAXN];
int w[MAXN];

int main() {
  while(cin >> N >> W) {
    for(int i = 0; i < N; ++i) cin >> w[i];
    sort(w, w+N);
    w[N] = INF;
    fill(dp[0][0], dp[2][0], 0LL);
    dp[0][W][0] = 1;
    for(int i = 0; i < N; ++i) {
      int p = i%2;
      int q = 1-p;
      for(int j = 0; j <= W; ++j)
	for(int k = 0; k <= N; ++k)
	  dp[q][j][k] = 0;

      for(int j = 0; j <= W; ++j) {
	for(int k = 0; k <= i; ++k) {
	  if(j-w[i] >= 0) {
	    int nk;
	    if(i == k) nk = k+1;
	    else nk = k;
	    dp[q][j-w[i]][nk] = (dp[q][j-w[i]][nk] + dp[p][j][k]) % mod;
	  }
	  int nk = min(k, i);
	  dp[q][j][nk] = (dp[q][j][nk] + dp[p][j][k]) % mod;
	}
      }
    }

    lli res = 0;
    for(int j = 0; j <= W; ++j) {
      for(int k = 0; k <= N; ++k) {
	if(j < w[k]) res = (res + dp[N%2][j][k]) % mod;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 33220
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void d_m_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

char grid[1002][1002];

int power(int n, int x)
{
	if (x == 0)
		return 1;

	int small = power(n, x / 2) % mod;
	small = (small * small) % mod;

	if (1 & x)
		small = (n * small) % mod;

	return small;
}

bool isPowerOfTwo(int n)
{
	return n && (!(n & (n - 1)));
}

int numberOfPaths(int h, int w)
{
	int dp[h + 1][w + 1];
	memset(dp, 0, sizeof dp);

	dp[h][w] = 1;

	for (int i = h; i >= 1; i--)
	{
		for (int j = w; j >= 1; j--)
		{
			if (i == h && j == w)
				continue;
			if (grid[i][j] == '#')
				dp[i][j] = 0;
			else {
				if (i != h)
					dp[i][j] = (dp[i + 1][j] + dp[i][j]) % mod;
				if (j != w)
					dp[i][j] = (dp[i][j] + dp[i][j + 1]) % mod;
			}
		}
	}

	return dp[1][1];
}

int32_t main()
{
	//d_m_c();

	int h, w;
	cin >> h >> w;

	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
			cin >> grid[i][j];
	}

	cout << numberOfPaths(h, w);

	return 0;
}

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

int main(void){
	while(1){
		int k,res=0;
		cin >> k;
		if(k==0)break;
		for(int i=0;i<(k*(k-1))/2;i++){
			int a;
			cin >> a;
			res+=a;
		}
		cout << res/(k-1) << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
	int N,K,X,Y;
	int total=0;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N>=K){
	for(int i=1;i<=K;i++){
		total+=X;
	}
	for(int i=(K+1);i<=N;i++){
		total+=Y;
	}
	printf("%d",total);
	}else{
		printf("%d",X*N);

	}

return 0;
}

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

#define ll long long

int main(void){
    int n; cin >> n;
    vector<ll>cnt(5);
    for(int i=0;i<5;i++){
        cnt[i]=0;
    }

    for(int i=0;i<n;i++){
        string s; cin >> s;
        if(s[0]=='M') cnt[0]++;
        else if(s[0]=='A')cnt[1]++;
        else if(s[0]=='R')cnt[2]++;
        else if(s[0]=='C')cnt[3]++;
        else if(s[0]=='H')cnt[4]++;
    }
    ll ans = 0;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            for(int k=j+1;k<5;k++){
                ans += cnt[i]*cnt[j]*cnt[k];
            }
        }
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
 
int main() {
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int> > X(N, vector<int>(N, 0));
    for (int i=0; i<M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        X[a][b] += 1;
    }
    for (int i=0; i<N; i++) {
        for (int j=i+1; j<N; j++) {
            X[i][j] = X[i][j-1] + X[i][j];
        }
    }
    for (int i=0; i<Q; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        int ans = 0;
        for (int j=a; j<=b; j++) {
            ans += X[j][b];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1920
N, k = [int(item) for item in input().split()]
MOD = 10**9 + 7
n = 10**4

fac = [1] + [0] * n
fac_inv = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    fac_inv[i] = fac_inv[i-1] * pow(i, MOD-2, MOD) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 

for i in range(1,k+1):
    front = mod_nCr(k-i+i-1, i-1)
    after = mod_nCr(N-k-(i-1)+i, i)
    print(front * after % MOD)

Measured memory_bytes: 4124
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class agc024d {
private:
    void dfs(int u, const vector<vector<int>> &g, vector<int> &vis,
            vector<int> &cnt, int h, int &mx)
    {
        vis[u] = 1;
        cnt[h] = max(cnt[h], (int)g[u].size());
        mx = max(mx, h);
        for (int v : g[u]) {
            if (!vis[v]) {
                dfs(v, g, vis, cnt, h + 1, mx);
            }
        }
    }
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        if (N == 2) {
            out << 1 << " " << 2 << "\n";
            return;
        }
        vector<vector<int>> g(N);
        for (int i = 0; i < N - 1; ++i) {
            int a, b;
            in >> a >> b;
            g[a - 1].push_back(b - 1);
            g[b - 1].push_back(a - 1);
        }
        int col = N + 1;
        long long leaves = 0;
        for (int r = 0; r < N; ++r) {
            vector<int> cnt(N, 0), vis(N, 0);
            int mxh = 0;
            dfs(r, g, vis, cnt, 0, mxh);
            long long cur = cnt[0];
            for (int i = 1; i < mxh; ++i) {
                cur *= cnt[i] - 1;
            }
            if (mxh + 1 < col) {
                col = mxh + 1;
                leaves = cur;
            } else if (mxh + 1 == col) {
                leaves = min(leaves, cur);
            }
        }
        for (int ra = 0; ra < N; ++ra) {
            for (int rb : g[ra]) {
                vector<vector<int>> tmpg(N);
                for (int u = 0; u < N; ++u) {
                    for (int v : g[u]) {
                        if (!(ra == u && rb == v || ra == v && rb == u)) {
                            tmpg[u].push_back(v);
                        }
                    }
                }
                vector<int> cnt(N, 0), vis(N, 0);
                int mxh = 0;
                dfs(ra, tmpg, vis, cnt, 0, mxh);
                dfs(rb, tmpg, vis, cnt, 0, mxh);
                long long cur = cnt[0] * 2;
                for (int i = 1; i < mxh; ++i) {
                    cur *= cnt[i] - 1;
                }
                if (mxh + 1 < col) {
                    col = mxh + 1;
                    leaves = cur;
                } else if (mxh + 1 == col) {
                    leaves = min(leaves, cur);
                }
            }
        }
        out << col << " " << leaves << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc024d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long>v;
    for(int i = 0; i < n; i++){
        long long x;
        cin >> x;
        v.push_back(x);
    }
    vector<long long>sum(n), mn(n + 2), mn2(n + 2);
    sum[0] = v[0];
    for(int i = 1; i < n; i++){
        sum[i] = sum[i - 1] + v[i];
    }
    for(int i = 1; i < n - 2; i++){
        long long r = sum[i]/2 + (sum[i] % 2 != 0);
        int j = lower_bound(sum.begin(), sum.end(), r) - sum.begin();
        if(j == i){
            mn[i] = sum[i - 1];
        }
        else if(j == 0){
            mn[i] = sum[i] - sum[0];
        }
        else{
            mn[i] = max(sum[j - 1], sum[i] - sum[j]);
        }
        r = (sum[n - 1] - sum[i])/2 + ((sum[n - 1] - sum[i]) % 2 != 0);
        j = lower_bound(sum.begin(), sum.end(), r + sum[i]) - sum.begin();
        if(j == n - 1){
            mn2[i + 1] = sum[n - 2] - sum[i];
        }
        else if(j == i + 1){
            mn2[i + 1] = sum[n - 1] - sum[i + 1];
        }
        else{
            mn2[i + 1] = max(sum[j - 1] - sum[i], sum[n - 1] - sum[j]);
        }
    }
    long long ans = 1e18;
    for(int i = 1; i < n - 2; i++){
        long long a = min(mn[i], mn2[i + 1]);
        long long b = max(sum[i] - mn[i], sum[n - 1] - sum[i] - mn2[i + 1]);
        ans = min(ans, b - a);
    }
    cout << ans;
    return 0;
}

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

string map[12];
bool dis[12][6],use[12][6];

void fall(void){
  for(int i=0;i<6;i++){
    int d = 0,c = 0;
    
    for(int j=11;j>=0;j--){
      while(j-d>=0 && map[j-d][i] == '.')d++;
      if(j-d<0)break;
      map[j][i] = map[j-d][i];
      c++;
    }
    
    for(int j=11-c;j>=0;j--)map[j][i] = '.';
  }
}

int dfs(int y,int x,bool mode){
  int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
  int res;

  use[y][x] = true;
  res = 1;
  for(int i=0;i<4;i++){
    int sx = x+dx[i],sy = y+dy[i];
    if(sx < 0 || 6 <= sx || sy < 0 || 12 <= sy)continue;
    if(!use[sy][sx] && map[sy][sx] == map[y][x])res += dfs(sy,sx,mode);
    if(mode && map[sy][sx] == 'O')map[sy][sx] = '.';
  }
  if(mode)map[y][x] = '.';
  return res;
}

bool puyo(void){
  bool f = false;
  for(int i=0;i<12;i++){
    for(int j=0;j<6;j++){
      if(map[i][j] != '.' && map[i][j] != 'O'){
	for(int k=0;k<12;k++){
	  for(int l=0;l<6;l++)use[k][l] = false;
	}
	if(dfs(i,j,false)>=4){
	  for(int k=0;k<12;k++){
	    for(int l=0;l<6;l++)use[k][l] = false;
	  }
	  dfs(i,j,true);
	  f = true;
	}
	
      }
    }
  }
  return f;
}


int main(){
  int t,ans;

  cin >> t;
  while(t--){
    
    for(int i=0;i<12;i++)cin >> map[i];

    ans = 0;
    
    while(1){
      fall();
      if(!puyo())break;
      ans++;
    }
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='7'){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
  return 0;
}


Measured memory_bytes: 3600
{-# OPTIONS_GHC -Wall -Werror #-}

import System.IO

main :: IO ()
main = do
  end <- isEOF
  if end
     then return ()
     else do
       n <- getLine
       print $ length [(a, b, c, d) | a <- [0..9], b <- [0..9], c <- [0..9], d <- [0..9], a + b + c + d == (read n :: Int)]
       main

Measured memory_bytes: 5040
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<int,int> point;
#define rep(i,n) for(i,0,n)

// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	string n;
	cin >> n;
 
	// 解法
	for (int i = 0; i < n.size(); ++i){
		if (n[i]=='1') cout << "9";
		else cout << "1";
	}
	cout << endl;
}
 


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
   int n;
   cin>>n;
   int ans=0;
   for(int i=1;i<=n;i++)
   {
       int sum=0;
       int j=i;
       do{
        j/=10;
        sum++;
       }while(j);
       if(sum%2==1)
        ans++;
   }
   cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	string s;
	ll k;
	cin >> s >> k;
	int count1 = 0;
	char c;
	rep(i, s.size()) {
		if (s[i] == '1') count1++;
		else {
			c = s[i];
			break;
		}
	}
	if (count1 >= k) cout << 1 << endl;
	else cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
def c_exam_and_wizard(N, A, B):
    ans = 0
    short_val = 0  # 合格に不足する準備度
    can_give = []
    for a, b in zip(A, B):
        if a < b:
            ans += 1
            short_val += b - a
        elif a > b:
            can_give.append(a - b)

    if short_val == 0:
        return 0
    can_give.sort()

    idx = len(can_give) - 1
    while True:
        if not can_give:
            ans = -1
            break

        if can_give[idx] >= short_val:
            ans += 1
            break

        short_val -= can_give[idx]
        can_give.pop()
        ans += 1
        idx -= 1
    return ans

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
print(c_exam_and_wizard(N, A, B))

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

struct s1 {
  static int64 op(int64 a, int64 b) { return max(a, b); }
  static int64 e() { return -INF_LL; }
  static int64 mapping(int64 l, int64 r) { return max(l, r); };
  static int64 composition(int64 l, int64 r) { return max(l, r); };
  static int64 id() { return -INF_LL; };
};

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

//  auto op1 = [](int64 a, int64 b) -> int64 {
//    return max(a, b);
//  };
//  auto e = []() { return -INF_LL; };
//  auto mapping = [](int64 l, int64 r) { return max(l, r); };
//  auto composition = [](int64 l, int64 r) { return max(l, r); };
//  auto id = []() { return -INF_LL; };
  int64 N;
  cin >> N;
  int64 cnt = 0;
  bool ok = 0;
  auto D = make_v<int64>(N, 2);
  REP(i, N) {
    REP(j, 2) {
      cin >> D[i][j];
    }
    if (D[i][0] == D[i][1]) {
      cnt++;
      if (cnt >= 3) ok = 1;
    } else {
      cnt = 0;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3464
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, M;
	cin >> N >> M;
	VI A(N);
	int ans = 0;
	REP(i, N) {
		cin >> A[i];
		ans += A[i];
	}
	vector<pair<int, int> > v;
	SORT(A);

	REP(i, M) {
		int b, c;
		cin >> b >> c;
		v.push_back(make_pair(c, b));
	}

	rSORT(v);
	//cout << ans << endl;
	int i = 0;
	int cnt = 0;
	while (v[i].first > A[cnt] && i<M) {
		int j = 0;
		//cout << v[i].first << endl;
		//cout << A[j] << endl;
		while (j < v[i].second && v[i].first > A[cnt] && cnt<N) {
			ans -= A[cnt];
			A[cnt] = v[i].first;
			ans += A[cnt];
			j++;	
			cnt++;
			//cout << ans << endl;
		}
		//cout << endl;
		i++;
		//SORT(A);
		
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3188
from collections import Counter
n=int(input())
counter=Counter(1 if x % 2 else 2 if x % 4 else 4 for x in (int(s) for s in input().split()))
print('Yes' if counter[1] <= counter[4] or counter[2] == 0 and counter[1] == counter[4] + 1 else 'No')

Measured memory_bytes: 11436
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>

#define rep(i,n) for(int i = 0; i < n; ++i)
#define reps(i,f,n) for(int i = f; i <= n; ++i)
#define eb emplace_back
#define all(x) x.begin(), x.end()

using namespace std;
using PII=pair<int,int>;
using PPI=pair<int,PII>;
using ll=long long;

const ll MOD = 1000000007;
const int HW = 300000;
ll f[HW];
ll fr[HW];
int h[HW];

ll pow_mod(ll a, ll b, ll p){
  ll r = 1;
  for(;b>0; b>>=1){
    if(b&1) r = (r*a) %p;
    a = (a * a)%p;
  }
  return r;
}

ll c(ll n, ll r){
//   cout <<  "c(" << n << "," << r << ") " << endl;
  if(n < 0 || r < 0 || n < r){
    return 0;
  }
  return (((f[n] * fr[r])%MOD) * fr[n-r])%MOD;
}

int main(void){
  int n, diff;
  vector<int> A;
  ll tmp;

  cin >> n;
  ++n;
  A.resize(n);
  rep(i, HW)fr[i] = f[i] = h[i] = -1;

  for(auto& a: A) cin >> a;
  f[0] = 1;
  fr[0] = pow_mod(f[0], MOD-2, MOD);
  reps(i, 1, HW-1){
    f[i] = (f[i-1] * i) %MOD;
    fr[i] = pow_mod(f[i], MOD-2, MOD);
  }


  rep(i,n){
    if(h[A[i]] != -1){
      diff = i - h[A[i]];
//       cout << " l: " << h[A[i]] << "  r: " << i << endl;
      break;
    }
    h[A[i]] = i;
  }

//   cout << "diff " << diff << endl;
  rep(i,n+1){
    if(i == 0)continue;
    cout << (c(n, i) - c(n-(diff+1), i-1)+MOD+MOD)%MOD << endl;
  }
  return 0;
}


Measured memory_bytes: 7424
#include <iostream>

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

    if(a + b > c + d){
        std::cout << "Left" << std::endl;
    }else if(a + b < c + d){
        std::cout << "Right" << std::endl;
    }else{
        std::cout << "Balanced" << std::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;
typedef pair<ll,ll> P;

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;

int main() {
    cin >> n;
    int m = 0;
    int N = n;
    while (N) {
        m += N%10;
        N /= 10;
    }
    if (n%m) puts("No");
    else puts("Yes");
}
































Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long t,j,k,p=0;
    cin>>t>>k;
    for(j=0;j<t;j++){
        double a,b,c;
        cin>>a>>b;
        c=sqrt(a*a+b*b);
        if(c<=k)
        p++;
    }cout<<p;

    return 0;
}


Measured memory_bytes: 3840
r, g, b, n = map(int, input().split())
ans = 0

for i in range(0, n + 1, r):
    if i > n:
        break
    for j in range(0, n + 1, g):
        if i + j > n:
            break
        elif (n - i - j)%b == 0:
            ans += 1

print(ans)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char a[4];
    rep(i, 4) cin >> a[i];
    rep(i, (1 << 3)) {
        int tmp = a[0] - '0';
        string s;
        s += a[0];
        rep(j, 3) {
            if (i & (1 << j)) {
                tmp += a[j + 1] - '0';
                s += '+';
                s += a[j + 1];
            } else {
                tmp -= a[j + 1] - '0';
                s += '-';
                s += a[j + 1];
            }
        }
        if (tmp != 7) continue;
        s += "=7";
        out(s);
        return 0;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  	int N, M;
  	cin >> N >> M;
  	vector<int> X(M);
    vector<long long> L(M-1);
  	for(int i = 0; i < M; i++){
    	cin >> X[i];
    }
  	if(N >= M){
    	cout << 0 << endl;
    } else {
        sort(X.begin(), X.end());
        for(int i = 0; i < M-1; i++){
            L[i] = X[i+1]-X[i];
        }
        sort(L.begin(), L.end());
        reverse(L.begin(), L.end());
		long long sum = 0;
        for(int i = 0; i < N-1; i++){
			sum += L[i];
        }
        long long ans = 0;
        ans = X[M-1]-X[0]-sum;
    	cout << ans << endl;
    }
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	
	char input[9];
	int h, w;
	int i, j;
	
	while (1){
		
		fgets(input, sizeof(input), stdin);
		h = atoi(strtok(input," "));
		w = atoi(strtok(NULL, " "));
		
		if (h == 0 || w == 0){
			break;
		}
		
		for (i = 1; i <= h; i++){
			
			if (i == 1 || i == h){
				for (j = 1; j <= w; j++){
					printf("#");
				}
			}else{
				printf("#");
				for (j = 1; j <= (w - 2); j++){
					printf(".");
				}
				printf("#");
			}
			
			printf("\n");
		}
		
		printf("\n");
	}
	
	return 0;
}

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

flag = 0
ans = 0

for i in range(N):
    a,b = map(int,input().split())
    if a == b:
        flag += 1
        if flag == 3:
            ans += 1
    else:
        flag = 0
if ans >= 1:
    print("Yes")
else:
    print("No")

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define all(a) (a.begin(), a.end())

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

ll f(ll n) {
	if (n&1) {
		return 3*n+1;
	} else {
		return n/2;
	}
}

void solve() {
	ll s;
	cin >> s;
	int a = s;
	set<int> seen;
	seen.insert(a);
	int i = 2;
	for (; true; ++i) {
		a = f(a);
		if (seen.count(a)) {
			break;
		}
		seen.insert(a);
	}

	cout << i << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    ll x, n; cin >> x >> n;
    ll q;
    map<ll,ll> p; 
    rep(i, n) {
        cin >> q;
        ++p[q];
    }
    ll a = 400;
    ll ans;
    FOR(i, -200, 250) {
        if (p[i] > 0) continue;
        if (a > abs(x-i)) {
            a = abs(x-i);
            ans = i;
        }
    }
  cout << ans << endl;
    return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

using namespace std;

ll count_divsors(ll n){
    ll num = 0;
    ll p = ll(pow(n,double(1)/2));
    for(ll i = 1; i < p+1; i++){
        if(n%i == 0){
            num++;
            if(i != n/i){
                num += 1;
            }
        }
    }
    return num;
}

ll count_divsors2(ll n){
    ll num = 0;
    ll p = ll(pow(n,double(1)/2));
    for(ll i = 1; i < p+1; i++){
        if(n%i == 0){
            vector<ll> p;
            if(i != 1 && i != n/i){
                p.push_back(i);
            }
            p.push_back(n/i);
            for(int j = 0; j < p.size(); j++){
                ll nt = n;
                while(true){
                    if(nt%p[j] == 0){
                        nt = nt / p[j];
                        continue;
                    } else if(nt%p[j] == 1){
                        num++;
                        break;
                    } else{
                        break;
                    }
                }
            }
        }
    }
    return num;
}

int main(){
    std::ios::sync_with_stdio(false);
    ll N;
    cin >> N;

    ll ans = 0;
    ans += count_divsors(N-1) - 1;
    ans += count_divsors2(N);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384