akhauriyash/Code-Regression huggingface dataset:
N,K=map(int,input().split())
A=list(map(int,input().split()))
import collections
if K>=len(set(A)):
    print(0)
else:
    variety=len(set(A))
    c=collections.Counter(A)
    values, counts = zip(*c.most_common())
    counts=list(counts)
    counts.sort()
    summary=0
    for i in range(variety-K):
        summary+=counts[i]
    print(summary)

Measured memory_bytes: 64156
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <stack>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <string.h>
#include <set>
using namespace std;



int main()
{
	int n;
	int num;
	int count4, count2, countodd;
	while (scanf("%d", &n) != EOF) {
		count4 = count2 = countodd = 0;
		for (int i = 0; i != n; ++i) {
			scanf("%d", &num);
			if (num % 4 == 0)++count4;
			else if (num % 2 == 0)++count2;
			else ++countodd;
		}
		bool ok = false;
		if (count4 == 0) {
			if (count2 > 1 && countodd == 0) ok = true;
		}
		else {
			if (count2 != 0)++countodd;
			if (countodd <= count4 + 1) ok = true;
		}
		if (ok) printf("Yes\n");
		else printf("No\n");

	}
	return 0;
	
}

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

int main(){
  string s;  int count = 0, result = 0;
  cin >> s;
for(char c : s){
      if(c=='R') count++;
      else count = 0;
     result = max(result , count);
}
  cout << result;
   return 0;
}

Measured memory_bytes: 3624
import itertools as ite
from decimal import *
import math

INF = 10 ** 18

n = input()
i = 2
ls = []
while i * i <= n:
    if n % i == 0:
        cnt = 0
        while n % i == 0:
            cnt += 1
            n /= i
        ls += [cnt]
    i += 1
if n != 1:
    ls += [1]
ans1 = len(ls)
ans2 = 1
for num in ls:
    ans2 *= num + 1
ans2 -= 1
print ans1, ans2



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

int soma(int a, int b) {
    return a+b;
}

int prod(int a) {
    return 2*a;
}

int main(){
    int n, k, a=1;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++)
    {
       if (soma(a,k) < prod(a)) {
        a = soma(a,k);
    } else {
        a=prod(a);
    }
    }
    printf("%d\n", a);
    
    


    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

const int N = 5e5 + 10;
const int inf = 0x3f3f3f3f;
struct E {int v, nt;} e[N<<1];
int n, K, tot, h[N], q[N], p[N], deg[N], seg[N<<2];
priority_queue <int, vector <int> , greater <int> > que;

inline int max(int a, int b) {return a > b ? a : b;}
inline int min(int a, int b) {return a < b ? a : b;}
inline void add(int u, int v) {e[++tot] = (E){v, h[u]}, h[u] = tot, ++deg[v];}
template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

inline void build(int o, int l, int r) {
	seg[o] = inf; if (l == r) return;
	int mid = l + r >> 1, lc = o << 1, rc = lc|1;
	build(lc, l, mid), build(rc, mid + 1, r);
}

inline void update(int o, int l, int r, int q, int v) {
	if (l == r) {seg[o] = v; return;}
	int mid = l + r >> 1, lc = o << 1, rc = lc|1;
	if (q <= mid) update(lc, l, mid, q, v);
	else update(rc, mid + 1, r, q, v);
	seg[o] = min(seg[lc], seg[rc]);
}

inline int query(int o, int l, int r, int L, int R) {
	if (L <= l && r <= R) return seg[o];
	int mid = l + r >> 1, lc = o << 1, rc = lc|1, ret = inf;
	if (L <= mid) ret = min(ret, query(lc, l, mid, L, R));
	if (R > mid) ret = min(ret, query(rc, mid + 1, r, L, R));
	return ret;
}

int main() {
	int x, v; in(n), in(K), build(1, 1, n);
	for (int i = 1; i <= n; ++i) in(p[i]), q[p[i]] = i;
	for (int i = n; i; --i) {
		x = query(1, 1, n, max(1, q[i] - K + 1), q[i]);
		if (x <= n) add(q[i], q[x]);
		x = query(1, 1, n, q[i], min(q[i] + K - 1, n));
		if (x <= n) add(q[i], q[x]);
		update(1, 1, n, q[i], i);
	}
	for (int i = 1; i <= n; ++i) if (!deg[i]) que.push(i);
	for (int l = 1; l <= n; ++l) {
		x = q[l] = que.top(), que.pop();
		for (int i = h[x]; i; i = e[i].nt)
			if (!(--deg[v = e[i].v])) que.push(v);
	}
	for (int i = 1; i <= n; ++i) p[q[i]] = i;
	for (int i = 1; i <= n; ++i) printf("%d\n", p[i]);
	return 0;
}

Measured memory_bytes: 27008
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));
		String str =buf.readLine();
		int count=Integer.parseInt(str);
		
		int[] a=new int[count];
		int[] b=new int[count];
		int[] c=new int[count];
		
		for(int i=0;i<count;i++){
			str=buf.readLine();
			a[i]=Integer.parseInt(str.split(" ")[0]);
			b[i]=Integer.parseInt(str.split(" ")[1]);
			c[i]=Integer.parseInt(str.split(" ")[2]);
		}
		
		for(int i=0;i<count;i++){
			if(
				(a[i]< (b[i]+c[i]) )&&
				(b[i]< (a[i]+c[i]) )&&
				(c[i]< (a[i]+b[i]) )
			){
				if(
					(a[i]*a[i]+b[i]*b[i]==c[i]*c[i])||
					(a[i]*a[i]+c[i]*c[i]==b[i]*b[i])||
					(b[i]*b[i]+c[i]*c[i]==a[i]*a[i])
				){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
			}else{
				System.out.println("NO");
			}

		}
	}
}

Measured memory_bytes: 23684
#coding: utf-8
#AOJ vol1-0100

while (n = gets.to_i) != 0
  data = Hash.new(0)
  flag = false
  n.times.each do |i|
    input = gets.chomp.split.map{|i|i.to_i}
	data["#{input[0]}"] += input[1] * input[2]
  end
  data.each do |key,val|
    if val >= 1000000
	  puts key
	  flag = true
	end
  end
  puts "NA" if !flag
end

Measured memory_bytes: 6116
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int m, f, r, sum;
    
    while(1)
    {
        scanf(" %d %d %d", &m, &f, &r);
        
        if(m == -1 && f == -1 && r == -1) break;
        
        if(m == -1 || f == -1)
        {
            printf("F\n");
        }
        else
        {
            sum = m + f;
            
            if(sum >= 80)
            {
                printf("A\n");
            }
            
            if(sum < 80 && sum >= 65)
            {
                printf("B\n");
            }
            
            if(sum < 65 && sum >= 50)
            {
                printf("C\n");
            }
            
            if(sum < 50 && sum >= 30)
            {
                if(r >= 50)
                {
                    printf("C\n");
                }
                else
                {
                    printf("D\n");
                }
            }
            
            if(sum < 30)
            {
                printf("F\n");
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	qsort(a, 3, sizeof(int), comp);
	cout << a[2] * 10 + a[1] + a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  char N;
  cin >> N;
  
  bool flag=false;
  
  char moji;
  

  for(moji='a'; moji<='z';moji++){
    if(N==moji){
      flag=true;
      break;
    }
  }
  
  if(flag){
    cout << 'a'<<endl;
  }else{
    cout <<'A' << endl;
  }
}

Measured memory_bytes: 3592
using System;
using System.Linq;
using System.Collections.Generic;

class Amondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var h = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var dp = new int[N];
        dp[0] = 0;
        var index = 0;
        for (int i = 1; i < N; ++i) dp[i] = int.MaxValue;
        while (index < N-1)
        {
            dp[index+1] = Math.Min(dp[index+1],Math.Abs(h[index + 1] - h[index])+dp[index]);
            if(index+2<N) dp[index+2]=Math.Min(dp[index+2],Math.Abs(h[index + 2] - h[index])+dp[index]);
            index++;
        }
        Console.WriteLine(dp[N-1]);
    }
}

Measured memory_bytes: 18016
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#define rep(i,x,y) for(int i=x;i<=y;++i)

const int INF=1<<30;

using namespace std;

const int maxn=100+10;

int a[maxn];

int main()
{
	int sum=0;
	int n;cin>>n;
	rep(i,1,n) cin>>a[i],sum+=a[i];
	if(sum%10) {
		cout<<sum<<endl;
	}
	else{
		int m=1<<30;
		rep(i,1,n) if(a[i]%10!=0) m=min(m,a[i]);
		if(m==1<<30) cout<<0<<endl;
		else cout<<sum-m<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <iostream>
using namespace std;
typedef pair<int,int>PP;
int main(){
  int n,k;
  cin>>n>>k;
  int a,es;
  int ch[n+1];
  int ssh[n],ns=0;
  for(int i=1;i<=n;i++){
    ch[i]=0;
  }
  for(int i=0;i<n;i++){
    cin>>a;
    if(ch[a]==0){
      ssh[ns]=a;
      ns++;
    }
    ch[a]++;
  }
  PP qwe[ns];
  for(int i=0;i<ns;i++){
    qwe[i]=make_pair(ch[ssh[i]],ssh[i]);
  }
  sort(qwe,qwe+ns);
  int ans=0;
  for(int i=0;i<ns-k;i++){
    ans+=qwe[i].first;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;

namespace T1PBC2019B
{
    class MainClass
    {

        static int[] s;
        static int[] n;

        public static void Main(string[] args)
        {
            
            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            string str = Console.ReadLine();
            n = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);

            char c = str[n[0]-1];
            string ans = "";
            for(int i = 0; i < s[0]; i++)
            {
                if (str[i] == c)
                {
                    ans += c;
                }
                else
                {
                    ans += '*';
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/


int main(void){
  int N, H;
  cin >> N >> H;

  int a[N], b[N];
  vector<pair<int, int>> all_num;
  rep(i, N) {
    cin >> a[i] >> b[i];
    all_num.push_back(make_pair(a[i], 1));
    all_num.push_back(make_pair(b[i], 0));
  }
  sort(ALL(all_num));
  int count = 0;
  int H_now = H;
  int N_now = 2*N-1;
  int negative_norm = 0;
  while(H_now>0){
    //cout <<"all_num[N_now].first " << all_num[N_now].first << endl;
    if (all_num[N_now].second){
      H_now -= all_num[N_now].first;
    } else {
      H_now -= all_num[N_now].first;
      N_now--;
    }
    count++;
  }
  cout << count << endl;

}


Measured memory_bytes: 2932
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n, d; cin >> n >> d;
    int X[15][15] = {};
    loop (n, i) loop (d, j) cin >> X[i][j];

    int SQ[300] = {};
    loop (300, i) SQ[i] = i * i;

    int ans = 0;
    loop (n, i) loop (n, j) {
        if (i >= j) continue;
        int z = 0;
        loop (d, k) {
            int v = X[i][k] - X[j][k];
            z += v * v;
        }
        loop (300, k) {
            if (z == SQ[k]) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int a[]={0,300000,200000,100000};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int x, y;
	cin>>x>>y;
	
	int s = 0;
	
	if(x<=3)s+=a[x];
	if(y<=3)s+=a[y];
	if(x==y&&x==1)s+=400000;
	cout<<s;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    unsigned long long int a = 0;
    int i = 0;
    cin >> N;
    while(i < N ){
            if((i + 1 )%3 != 0){
                if((i + 1 )%5 != 0 ){
                    a = a + i + 1;
                }
            }
    i++ ;
    }
    cout << a << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int n, m;
	cin >> n >> m;
	int a[n], sum = 0;
	for (int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];
	sort (a, a + n);
	reverse(a, a + n);
	if (a[m - 1] >= (ld)sum / (4.0 * (ld)m))
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;

ll sum[100010];
int main(void) {
	int n, q, l, r;
	cin >> n >> q;
	string s;
	cin >> s;
	int ans = 0;
	sum[0] = 0;
	for (int i = 1;i < s.length();i++) {
		if (s[i] == 'C') {
			if (s[i-1] == 'A')sum[i] = sum[i - 1] + 1;
			else sum[i] = sum[i - 1];
		}
		else sum[i] = sum[i - 1];
	}
	for (int i = 0;i < q;i++) {
		cin >> l >> r;
		ans = sum[r-1] - sum[l-1];
		cout << ans << endl;
	}
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    ll ans = 0;
    for (ll i = 1; i <= N; ++i) {
        ll x = floor(N / i);
        ans += x * (x + 1) * i / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;

ll gcd(ll x,ll y){
  return y==0? x:gcd(y,x%y);
}

int main() {
  ll N,X;
  cin >> N >> X;
  cout << (N-gcd(N,X))*3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	ll ans = 1;
	if(a.at(0) != 0) ans = 0;
	sort(a.begin(),a.end());
	int k = 0;
	ll cnt = 0, pre = 1;
	rep(i,n){
		if(a.at(i) == k){
			cnt++;
		}
		else{
			if(a.at(i) != k + 1) ans = 0;
			if(k == 0){
				if(cnt != 1) ans = 0;
				else{
					pre = cnt;
					k++;
					cnt = 1;
				}
				continue;
			}
			rep(j,cnt){
				ans *= pre;
				ans %= mod1;
			}
			ans %= mod1;
			pre = cnt;
			cnt = 1;
			k++;
		}
	}
	rep(j,cnt){
		ans *= pre;
		ans %= mod1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#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 ans=0;
  int counter=0;
  for(int i=0;i<N-1;i++){
    if(vec[i]>=vec[i+1]){
      counter++;ans=max(ans,counter);}
    else{ans=max(ans,counter);
         counter=0;}
 //   cout<<counter<<A<<endl;

  }

  cout<<ans<<endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i > M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}
template<class T>
T POW(T n, T m) {
	T res = 1;
	rep(i, 0, m) {
		res *= n;
	}
	return res;
}

ll power(ll x, ll y,ll mod) {
	if (y == 0)return 1;
	if (y == 1)return x % mod;
	if (y % 2 == 0)return POW(power(x, y / 2, mod), 2LL) % mod;
	return ((POW(power(x, y / 2, mod), 2LL) % mod)*(x%mod))%mod;
}
ll div(ll a,ll  b, ll mod) {
	return (a* power(b, mod - 2,mod))%mod;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;

ll MOD_NUM = POW(10LL, 9LL) + 7;

int main() {
	string S, T;
	cin >> S >> T;
	map<char, char> memo,memo_;
	ll N = S.size();
	string res="Yes";
	rep(i, 0, N) {
		
		if (memo.find(S[i]) == memo.end()) {
			memo[S[i]]=T[i] ;

		}
		else if (memo[S[i]] != T[i]){
			res= "No";
			break;
		}
		if (memo_.find(T[i]) == memo_.end()) {
			memo_[T[i]] = S[i];

		}
		else if (memo_[T[i]] != S[i]) {
			res = "No";
			break;
		}
	}


		

	cout << res;
}


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

int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B == C + D) {
		cout << "Balanced" << endl;
		return 0;
	}
	cout << (A+B < C+D? "Right" :"Left" ) << endl;
	return 0;
}

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

typedef long long ll;

void maxHeap(vector<ll> &h, int i){
    int sub = i+1;
    int left = sub*2-1;
    int right = sub*2;
    int largest = sub-1;
    if(left <= h.size() && h[left] > h[largest]) largest = left;
    if(right <= h.size() && h[right] > h[largest]) largest = right;

    if(largest != i){
        swap(h[largest],h[i]);
        maxHeap(h,largest);
    }
}

void buildMaxHeap(vector<ll> &heap, int h){
    for(int i=h/2;i>=0;i--){
        maxHeap(heap, i);
    }
}

void print(const vector<ll> &h){
    for(ll a : h) cout << " " << a;
    cout << "\n";
}

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

    vector<ll> heap;
    int h;
    cin >> h;
    ll a;
    for(int i=0;i<h;i++){
        cin >> a;
        heap.push_back(a);
    }

    buildMaxHeap(heap,h);
    print(heap);
    return 0;
}



Measured memory_bytes: 6988
using System;
class _0026
{
    static int[] txL = { 0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0 };
    static int[] tyL = { -2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
    static int[] txM = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
    static int[] tyM = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
    static int[] txS = { 0, -1, 0, 1, 0 };
    static int[] tyS = { -1, 0, 0, 0, 1 };
    static int[,] map = new int[14,14];
    public static void Main()
    {
        for (int i = 0; i < 14; i++) for (int j = 0; j < 14; j++) map[i, j] = 0;
        string str;
        int count = 0,max = 0;
        int[] data = new int[3];
        while ((str = Console.ReadLine()) != null)
        {
            for (int i = 0; i < 3; i++) data[i] = int.Parse(str.Split(',')[i]);
            switch (data[2])
            {
                case 3: DropInkL(data[0]+2, data[1]+2); break;
                case 2: DropInkM(data[0]+2, data[1]+2); break;
                case 1: DropInkS(data[0]+2, data[1]+2); break;
            }
        }
        for (int i = 2; i < 12; i++)
        {
            for (int j = 2; j < 12; j++)
            {
                count += map[i, j] == 0 ? 1 : 0;
                max = max < map[i, j] ? map[i, j] : max;
            }
        }
        Console.WriteLine(count);
        Console.WriteLine(max);
    }
    public static void DropInkL(int x,int y)
    {
        for (int i = 0; i < 13; i++) map[x + txL[i], y + tyL[i]]++;
    }
    public static void DropInkM(int x,int y)
    {
        for (int i = 0; i < 9; i++) map[x + txM[i], y + tyM[i]]++;
    }
    public static void DropInkS(int x,int y)
    {
        for (int i = 0; i < 5; i++) map[x + txS[i], y + tyS[i]]++;
    }
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int odd = 0;
  for (int i = 0; i < N; i++)
  {
    int a;
    cin >> a;
    if (a % 2 == 1)
      odd++;
  }
  if (odd % 2)
    cout << "NO" << endl;

  else
    cout << "YES" << endl;

  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    int num_reverse = 0;
    REP(i, Q){
        int T;
        cin >> T;

        if(T == 1) ++num_reverse;
        if(T == 2){
            int F;
            char C;
            cin >> F >> C;

            if((F == 1 and num_reverse%2 == 0) or (F == 2 and num_reverse%2 == 1)) S.insert(S.begin(), C);
            if((F == 2 and num_reverse%2 == 0) or (F == 1 and num_reverse%2 == 1)) S += C;
        }
    }
    if(num_reverse%2 == 1) reverse(S.begin(), S.end());
    cout << S << endl;

    return 0;
}

Measured memory_bytes: 900
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;

int t,n,s,f,sum;

int main(){
	while(1){
		sum=0;
		cin>>t;
		if(t==0){break;}
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>s>>f;
			sum+=f-s;
		}
		if(t<=sum){cout<<"OK"<<endl;}
		else{cout<<t-sum<<endl;}
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextLine()) {
			String[] array = (sc.nextLine().split(" "));
			int result = Integer.parseInt(array[0]) + Integer.parseInt(array[1]);
			System.out.println(String.valueOf(result).length());
		}
	}
}

Measured memory_bytes: 26116
#include <iostream>

using namespace std;

long long memo[100010];

long long fib(long long x) {
    if (x == 0) return 0;
    else if (x == 1) return 1;
    else if (memo[x] != 0) return memo[x];
    memo[x] = ((fib(x - 1) + fib(x - 2)) % 1000000007);
    return memo[x];
}

int main() {
    for (long long &i : memo) i = 0;
    int N, M;
    cin >> N >> M;
    if (M != 0) {
        int a[M];
        cin >> a[0];
        int eve = a[0];
        bool dead = false;
        for (int i = 1; i < M; ++i) {
            cin >> a[i];
            if (a[i] - eve == 1) dead = true;
            eve = a[i];
        }
        if (dead) {
            cout << 0 << endl;
            return 0;
        }
        long long curPat = fib(a[0]);
        for (int i = 1; i < M; ++i) {
            curPat = curPat * fib(a[i] - a[i - 1] - 1) % 1000000007;
        }
        curPat *= fib(N - a[M - 1]);
        cout << (curPat % 1000000007) << endl;
    } else {
        cout << fib(N + 1) % 1000000007 << endl;
    }
}


Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		UnionFind uf = new UnionFind(n);
		boolean ok=true;
		for(int i=0;i<m;i++) {
			ok = ok && uf.union(sc.nextInt()-1, sc.nextInt()-1, sc.nextInt());
		}
		if(ok) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

class UnionFind {
	int[] parent;
	int[] rank;
	int[] distanceFromParent;
	UnionFind(int num) {
		this.parent=new int[num];
		for(int i=0;i<num;i++) {
			this.parent[i]=i;
		}
		this.rank=new int[num];
		this.distanceFromParent=new int[num];
	}

	public int find(int num) {
		if(this.parent[num]==num) {
			return num;
		} else {
			return find(this.parent[num]);
		}
	}

	public int distanceFromRoot(int num) {
		if(this.parent[num]==num) {
			return 0;
		} else {
			return distanceFromRoot(this.parent[num])+distanceFromParent[num];
		}
	}

	public boolean union(int l, int r, int d) {
		int lRoot=find(l);
		int rRoot=find(r);

		if(lRoot==rRoot) {
			//check consistency
			if(distanceFromRoot(r)-distanceFromRoot(l)==d) {
				return true;
			} else {
				return false;
			}
		} else if(rank[lRoot]<rank[rRoot]) {
			parent[lRoot]=rRoot;
			distanceFromParent[lRoot]=-d-distanceFromRoot(l)+distanceFromRoot(r);
		} else if(rank[lRoot]>rank[rRoot]) {
			parent[rRoot]=lRoot;
			distanceFromParent[rRoot]=d-distanceFromRoot(r)+distanceFromRoot(l);
		} else {
			parent[rRoot]=lRoot;
			distanceFromParent[rRoot]=d-distanceFromRoot(r)+distanceFromRoot(l);
			rank[lRoot]++;
		}
		return true;
	}

}



Measured memory_bytes: 152688
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int64_t gcd(int64_t a,int64_t b){
  return (a%b==0 ? b:gcd(b,a%b));
}

set<int64_t> divisor(int64_t a){
  set<int64_t> res;
  for (int i = 1; i <= sqrt(a); ++i)
  {
    if(a%i==0){
      res.insert(i);
      res.insert(a/i);
    }
  }
  return res;
}

bool isPrime(int64_t a){
  for (int i = 2; i <= sqrt(a); ++i)
  {
    if(a%i==0) return false;
  }
  return true;
}

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

  std::set<int64_t> div=divisor(gcd(a,b));
  int64_t ans=0;
  for(auto&& e: div) {
    if(isPrime(e)){
      ans++;
    }
  }
  cout<<ans;
  
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>


int main(void)
{
	int n;
	int i;
	double x[1000], y[1000];
	double d1 = 0, d2 = 0, d3 = 0, dm = 0;
	double b1 = 0, b2 = 0;
	double max = 0;
	double box = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%lf", &x[i]);
	}
	for (i = 0; i <  n; i++) {
		scanf("%lf", &y[i]);
	}

	//p = 1
	for (i = 0; i < n; i++) {
		d1 += (x[i] > y[i]) ? (x[i] - y[i]) : (y[i] - x[i]);
	}
	printf("%f\n", d1);

	//p = 2
	for (i = 0; i < n; i++) {
		b1 = (x[i] > y[i]) ? (x[i] - y[i]) : (y[i] - x[i]);
		d2 += b1 * b1;
	}
	printf("%f\n", sqrt(d2));

	//p = 3
	for (i = 0; i < n; i++) {
		b2 = (x[i] > y[i]) ? (x[i] - y[i]) : (y[i] - x[i]);
		d3 += b2 * b2 * b2;
	}
	printf("%f\n", cbrt(d3));

	//p = lim
	for (i = 0; i < n; i++){
		box = (x[i] > y[i]) ? (x[i] - y[i]) : (y[i] - x[i]);
		if (box > max)
			max = box;
	}
	printf("%f\n", max);

	return 0;
}


Measured memory_bytes: 2104
import java.util.*;

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

    int all = 0;
    for(int i=0; i<N; i++){
        L[i] = sc.nextInt();
    }
        Arrays.sort(L); 
    int a = N-K;
    for(int i=a; i<N; i++){
        all += L[i];    
}
	System.out.println(all);
      }
}

Measured memory_bytes: 35576
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
#define PI  3.14159265358979323846

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll ans = 0;
    if (0 <= K - A) {
        ans += A;
        K -= A;
        if (0<=K-B) {
            K -= B;
            ans -= K;
        }
    }
    else {
        ans += K;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3556
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0
    for i in range(n - 2):
        if (p[i] < p[i + 1] and p[i + 1] < p[i + 2]) or (p[i] > p[i + 1] and p[i + 1] > p[i + 2]):
            count += 1

    print(count)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#C
N = int(input())
H = list(map(int, input().split()))


tmp = H[0]
count=0

for i in H[1:]:
    if tmp==i:
        tmp=i
        continue
    elif tmp<i:
        tmp = i-1
    else:
        count=1
        continue


if count==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14396
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n,m;
    cin >> n >> m;
    vp a(n);
    rep(i,n)cin >> a[i].first >> a[i].second;
    sort(all(a));
    int ans = 0,sum = 0;
    rep(i,n){
        if(sum + a[i].second >= m){
            ans += a[i].first * (m-sum);
            cout << ans << endl;
            return 0;
        }
        sum += a[i].second;
        ans += a[i].first * a[i].second;
    }


}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include<map>
#include<set>


using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  int x,y,a,b,c;
  // x red, y green.
  cin >> x >> y >> a >> b >> c;
  
  vector<int> app_a(a); // red
  vector<int> app_b(b); // greed
  vector<int> app_c(c); // no

  for (int i=0; i<a; ++i) {
    cin >> app_a[i];
  }
  sort(app_a.begin(), app_a.end());
  for (int i=0; i<b; ++i) {
    cin >> app_b[i];
  }
  sort(app_b.begin(), app_b.end());
  for (int i=0; i<c; ++i) {
    cin >> app_c[i];
  }
  sort(app_c.begin(), app_c.end());

  long long ans = 0;
  vector<int> app_a_range{app_a.end()-x, app_a.end()};
  vector<int> app_b_range{app_b.end()-y, app_b.end()};
  for (int i=0; i<x+y; ++i) {
    if (app_a_range.back() >= app_b_range.back() && app_a_range.back() >= app_c.back()) {
      ans += app_a_range.back();
      // cout << "a: " << app_a_range.back() << endl;
      app_a_range.pop_back();
    } else if (app_b_range.back() >= app_a_range.back() && app_b_range.back() >= app_c.back()) {
      ans += app_b_range.back();
      // cout << "b: " << app_a_range.back() << endl;
      app_b_range.pop_back();
    } else {
      ans += app_c.back();
      app_c.pop_back();
    }
    // cout << i << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2176
from sys import stdin,stdout
size = int(stdin.readline())
li = list(map(int,stdin.readline().split()))
"""ans = [0]*size
for i in li:
    if i not in ans:
        ans[i-1] = 1
    else:
        ans[i-1] += 1
for i in ans:
    print(i)
"""
from collections import Counter
c1 = Counter(li)
ans2 = [0] * size
for i,j in c1.items():
    ans2[i-1] = j
for i in ans2:
    stdout.write(str(i)+"\n")


Measured memory_bytes: 34868
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
const int M=1000000007;
int c[22][22];
int f[2][533333]; 
int fir[20][533333];
int main()
{
	//freopen("zigzag.in","r",stdin);
	//freopen("zigzag.out","w",stdout);
	int n=io::F(),m=io::F(),k=io::F();
	if(n==1)puts("1"),exit(0);
	memset(c,-1,sizeof(c));
	for(register int i=1;i<=k;++i)
	{
		int a=io::F(),b=io::F(),v=io::F();
		if(c[a][b]==-1)c[a][b]=v;
			else if(c[a][b]!=v)puts("0"),exit(0);
	}
	for(register int i=1;i<1<<n-1;++i)
	{
		fir[n-1][i]=i&1<<n-2;
		for(register int j=n-2;j>=0;--j)
			fir[j][i]=i&1<<j?1<<j:fir[j+1][i];
	}
	int *x=f[0],*y=f[1];
	f[0][0]=1;
	for(register int i=1;i<=m;++i)
	{
		for(register int j=1;j<n;++j,std::swap(x,y),memset(y,0,sizeof(f[0])))
		{
			for(register int k=0;k<1<<n-1;++k)
				if(x[k])
				{
					if(c[i][j]!=1&&(k>>j-1&1)==0)
						(y[k]+=x[k])%=M; 
					if(c[i][j]!=0)
						(y[k^fir[j-1][k]^1<<j-1]+=x[k])%=M;
				}
		}
		//for(register int j=0;j<1<<n-1;++j)(y[0]+=x[j])%=M;
		//std::swap(x,y),memset(y,0,sizeof(f[0]));
	}
	int ans=0;
	for(register int i=0;i<1<<n-1;++i)(ans+=x[i])%=M;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 45952
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

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

	int count = 0;
	for(int i = 0; i < n; i ++)
	{
		int val;
		cin >> val;

		if(i % 2 == 0 && val % 2 == 1)
			count ++;
	}

	cout << count << endl;
}

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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()
#define m_p make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> a(n),order(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        order[a[i]-1] = i+1;
    }
    rep(i,n) cout << order[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
struct dat{
  double x,y,r;
  bool operator < (const dat a)const {return r < a.r;}
};
dat neko,rat;

double getDis(dat a,dat b){return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));}
bool intersect(dat a,dat b){return getDis(a,b) <= a.r + b.r;}


vector<int>  DP(vector<dat>&A){
  int n = A.size();
  vector<int> dp(n,1);
  for(int i=0;i<n;i++) //next use
    for(int j=0;j<i;j++){ //pre use
      if(intersect(A[i],A[j]) && getDis(A[i],A[j])+min(A[i].r,A[j].r) >= max(A[i].r,A[j].r)) continue;      Max(dp[i],dp[j]+1);
    }

  return dp;
}

signed main(){
  while(1){
    int nn;
    cin>>nn;
    if(nn == 0) break;
    cin>>neko.x>>neko.y; neko.r = 0;
    cin>>rat.x>>rat.y; rat.r = 0;
  
    vector<dat> Neko,Rat;
    for(int i=0;i<nn;i++){
      dat wall;
      cin >>wall.x>>wall.y>>wall.r;
      if(intersect(wall,neko) == intersect(wall,rat)) i--,nn--;
      else if(intersect(wall,neko)) Neko.push_back(wall);
      else if(intersect(wall,rat)) Rat.push_back(wall);
    }
  
    sort(Neko.begin(),Neko.end());
    sort(Rat.begin(),Rat.end());
    
    vector<int> ndp = DP(Neko);
    vector<int> rdp = DP(Rat);
    int ans = 0, n = Neko.size(), m = Rat.size();
    
    for(int a:ndp) Max(ans,a);
    for(int a:rdp) Max(ans,a);

    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        if(!intersect(Neko[i],Rat[j])) Max(ans,ndp[i] + rdp[j]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, 0, n) {
        cin >> a[i] >> b[i];
    }

    vector<int> dp(h+1, INT_MAX);
    dp[0] = 0;

    rep(i, 0, n)
    {
        rep(k, 1, dp.size())
        {
            if (k <= a[i])
            {
                dp[k] = min(dp[k], b[i]);
            }
            else
            {
                dp[k] = min(dp[k], dp[k - a[i]] + b[i]);
            }
        }
    }

    cout << dp[h] << endl;
}


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

int kouyaku(int,int);
int main(){
  int x,y;
  scanf("%d%d",&x,&y);
  if(x>y){
    x=x%y;
    printf("%d\n",kouyaku(x,y));
  }
  else if(x<y){
    y=y%x;
    printf("%d\n",kouyaku(y,x));
  }
  else printf("%d\n",x);
  return 0;
}


int kouyaku(int x,int y){
  int ans=INT_MIN,i;
  for(i=1;i<x;i++){
    if(x%i==0 && y%i==0){
      ans=i;
    }
  }
  return ans;
}



Measured memory_bytes: 2144
#include <iostream>

using namespace std;

void call(int n) {
	int i = 1;
	while (i <= n) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
			++i;
			continue;
		}
		else {
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				else
					x /= 10;
			}
			++i;
			continue;
		}
	}
}

int main() {
	int n;
	cin >> n;
	call(n);
	cout << endl;
	return 0;
}


Measured memory_bytes: 3044
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {
	int N, K, X, Y;
	scanf("%d", &N);



	printf("%d", N*(N + 1) / 2);






}

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

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&m);

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a); v.push_back(a);
        }

        sort(v.begin(),v.end());

        priority_queue<long long>pq;

        for(i=1;i<=m;i++)
        {
            scanf("%lld %lld",&a,&b); if(mp[b]==0){  pq.push(b);  }

            mp[b]=mp[b]+a;

        }


        for(i=0;i<n;i++)
        {
            a=v[i]; b=-7;

            if(!pq.empty()){ b=pq.top();  }

            if(a>=b){  sum=sum+a;  }
            else
            {
                sum=sum+b; mp[b]--; if(mp[b]==0)pq.pop();
            }

        }


        printf("%lld\n",sum);





    return 0;
}





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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while(N > 0){
        N /= K;
        ans++;
    }
    cout << ans << endl;
}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = ll(1e10)+1;

void Main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n, -1);
  rep(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    if (A[s] != -1) {
      if (A[s] != c) {
        cout << -1 << endl;
        return;
      }
    }
    A[s] = c;
  }
  if (n==1) {
    if (A[0] == -1) A[0] = 0;
    cout << A[0] << endl;
    return;
  }
  if (A[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (A[0] == -1) A[0] = 1;
  REP(i, 1, n) if(A[i] == -1) A[i] = 0;
  rep(i, n) cout << A[i];
  cout << endl;
  return;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int t;
    t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        vector<vector<int>> a(n+1,vector<int>(3,0));
        rloop(i,n-1,0){
            a[i] = a[i+1];
            if(s[i]=='R') a[i][0]++;
            if(s[i]=='G') a[i][1]++;
            if(s[i]=='B') a[i][2]++;
        }
        int ans = 0;
        rloop(i,n-4,0){
            loop(j,i+1,n-2){
                if(s[i]==s[j]) continue;
                if(s[i]=='R'){
                    if(s[j]=='G'){
                        ans+=a[j+1][2];
                        if(2*j-i<n && s[2*j-i]=='B') ans--;
                    }
                    if(s[j]=='B'){
                        ans+=a[j+1][1];
                        if(2*j-i<n && s[2*j-i]=='G') ans--;
                    }
                }
                if(s[i]=='G'){
                    if(s[j]=='R'){
                        ans+=a[j+1][2];
                        if(2*j-i<n && s[2*j-i]=='B') ans--;
                    }
                    if(s[j]=='B'){
                        ans+=a[j+1][0];
                        if(2*j-i<n && s[2*j-i]=='R') ans--;
                    }
                }
                if(s[i]=='B'){
                    if(s[j]=='G'){
                        ans+=a[j+1][0];
                        if(2*j-i<n && s[2*j-i]=='R') ans--;
                    }
                    if(s[j]=='R'){
                        ans+=a[j+1][1];
                        if(2*j-i<n && s[2*j-i]=='G') ans--;
                    }
                }
            }
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG nikkei2019/draft.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n;
    cin >> n;
    vector<vector<int>> v;
    v.resize(n, vector<int>(3));
    rep(i, n){
        int a, b;
        cin >> a >> b;
        v[i][0] = a + b;
        v[i][1] = a;
        v[i][2] = b;
    }

    sort(v.begin(), v.end());
    ll ans = 0;
    int turn = 0;

    for(int i = n - 1; i >= 0; i--){
        if(turn == 0){
            ans += v[i][1];
            turn = 1;
        }else{
            ans -= v[i][2];
            turn = 0;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5760
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
using P = std::pair<int, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

P v[1001001];

bool comp(P a, P b){
	if((a.first-a.second)>=0 && (b.first-b.second)<0){
		return true;
	}
	if((a.first-a.second)<0 && (b.first-b.second)>=0){
		return false;
	}
	if(a.first-a.second >= 0){
		return a.second < b.second;
	}else{
		return a.first > b.first;
	}
}
int main(void){
	int n,i,m,j,x=0;
	std::string s;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> s;
		m = s.l_ength();
		for(j=0; j<m; ++j){
			if(s[j]=='('){
				++v[i].first;
			}else if(v[i].first){
				--v[i].first;
			}else{
				++v[i].second;
			}
		}
	}
	sort(v,v+n,comp);
	for(i=0; i<n; ++i){
		if(x-v[i].second<0){
			std::cout << "No" << std::endl;
			return 0;
		}
		x -= v[i].second;
		x += v[i].first;
	}
	std::cout << ((x==0)?"Yes":"No") << std::endl;
	return 0;
}


Measured memory_bytes: 11288
#include<stdio.h>
int main(void)
{
	int i,n,a[200000],x,y;
	scanf("%d",&n);
	x=n/2; y=x-1;
	i=0;
	while(i<n){
		scanf("%d",&a[x]); //printf("x=%d,%d,",x,a[x]); 
		x++; i++;
		if(i==n) break;
//		if(y<0) break;
		scanf("%d",&a[y]); //printf("y=%d,%d,\n",y,a[y]); 
		y--; i++;
	}
//	printf("y=%d,%d,x=%d,%d,\n",y,a[y],x,a[x]);
//	for(i=0;i<n;i++) printf("%d ",a[i]);
//	printf("\n");
	if(n%2!=0){
//		printf("<1>,");
		for(i=n-1;i>-1;i--) printf("%d ",a[i]);
	}
	else{
//		printf("<2>,");
		for(i=0;i<n;i++) printf("%d ",a[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2816
n,m = map(int,input().split(" "))
ar = []
for i in range(n):
    l = list(map(int,input().split(" ")))
    ar.append(l)
ar.sort()
mo = 0
count = 0
i = 0
while True:
    if count + ar[i][1] > m:
        mo += ar[i][0] * (m - count)
        break
    else:
        mo += ar[i][0] * ar[i][1]
        count += ar[i][1]
    if count == m:
        break
    i += 1
print(mo)

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef long double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

char u[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
int v[] =  {1, 5, 10, 50, 100, 500, 1000};

int value_of (char c) {
  rep (i, 7) {
    if (c == u[i]) return v[i];
  }
}

int div(int a, int b, int n) {
  a %= b;
  a = a * 10;
  if (n == 1) return (a/b);
  return div(a, b, n - 1);
}

int main() {

  loop {
    Real x,h;
    cin >> x >> h;
    if (x == 0 && h == 0) break;
    if (!cin) break;
    Real S = x * x + 2.0 * x * sqrt(h*h + x*x/4.0);
    printf("%0.10Lf\n", S);
  }

  return 0;
}

Measured memory_bytes: 1240