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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

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

    LL n, d, a;
    cin >> n >> d >> a;

    vector<LP> monster(n);
    for(int i = 0; i < n; ++i) {
        cin >> monster[i].F >> monster[i].S;

    }
    sort(all(monster));

    queue<LP> range;
    LL cnt = 0;
    LL damage = 0;
    for(int i = 0; i < n; ++i) {
        LP tmp;
        while(!range.empty() && (tmp = range.front(), tmp.F < monster[i].F)) {
            damage -= tmp.S;
            range.pop();

        }

        monster[i].S -= damage;
        monster[i].S = max(monster[i].S, 0ll);
        LL bom = monster[i].S / a;
        if(monster[i].S % a != 0) {
            ++bom;

        }
        if(bom > 0) {
            range.push(MP(monster[i].F + (d * 2), a * bom));
            damage += a * bom;

        }
        cnt += bom;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 4992
#pragma GCC optimize ("O3")
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      ll n;
      cin>>n;
      ll a[n+1];
      rep1(i,n) cin>>a[i];
      ll index[n+1];
      rep1(i,n){
            index[a[i]]=i;
      }
      set<ll> t{0,n+1};
      ll ans=0;
      for(int k=1;k<=n;k++){
            int i=index[k];
            auto itr=t.lower_bound(i);
            --itr;
            ll l=*itr;
            ++itr;
            ll r=*itr;
            ans+=(k*(i-l)*(r-i));
            t.insert(i);
      }
      cout<<ans<<endl;

      return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int ah[90001];
int aw[90001];
int cusum[90001];

int main() {
  int h,w,d;
  cin >> h >> w >> d;
  FOR(i,0,h-1){
    FOR(j,0,w-1){
      int input;
      cin >> input;
      ah[input] = i+1; aw[input] = j+1;
    }
  }

  int q; cin >> q;

  FOR(i,d+1,h*w){
    cusum[i] = cusum[i-d] + abs(ah[i]-ah[i-d]) + abs(aw[i]-aw[i-d]);
    // if(i==d+q){
    //   cout << ah[i] << " " << ah[d] << " " << aw[i] << " " << aw[d] << endl;
    // }
    // cout << i << " " << cusum[i] << endl;
  }

  FOR(i,0,q-1){
    int inputa,inputb;
    cin >> inputa >> inputb;
    cout << cusum[inputb] - cusum[inputa] << endl;
  }
  


}

Measured memory_bytes: 2176
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, k = M()
p = LI()
p.sort()
ans = 0
for i in range(k):
    ans += p[i]
print(ans)

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

typedef long long ll;

int main()
{
    int cake_num[3];
    int k;
    vector<vector<ll> >  cake_val(3);
    vector<ll>  cake_sum;
    vector<ll>  cake_ans;
    for(int i = 0; i < 3; i++)
    {
        int num;
        cin >> num;
        cake_num[i] = num;
    }
    cin >> k;
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < cake_num[i]; j++)
        {
            ll tmp;
            cin >> tmp;
            cake_val[i].push_back(tmp);
        }
    }

    for(int i = 0; i < cake_num[0]; i++)
    {
        for(int j = 0; j < cake_num[1]; j++)
        {
            ll tmp = cake_val[0][i] + cake_val[1][j];
            cake_sum.push_back(tmp);
        }
    }

    sort(cake_val[2].begin(), cake_val[2].end(), greater<ll>());
    sort(cake_sum.begin(), cake_sum.end(), greater<ll>());
    
    for(int i = 0; i < min(k, (int)cake_sum.size()); i++)
    {
        for(int j = 0; j < min(k, (int)cake_val[2].size()); j++)
        {
            ll tmp = cake_sum[i] + cake_val[2][j];
            cake_ans.push_back(tmp);
        }
    }
    
    sort(cake_ans.begin(), cake_ans.end(), greater<ll>());
    for(int i = 0; i < k; i++)
    {
        cout << cake_ans[i] << endl;
    }

}


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

int main(){
  double W, H, x, y;
  cin >> W >> H >> x >> y;
  double def = W*H/2;
  double a;
  if(x==W/2 && y==H/2) a=1;
  else a=0;
  std::cout << std::setprecision(18) << def << ' ' << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 1e5+5;
int n,val[MAXN];
ll m,sum[MAXN],s;
inl bool chk(int lim){
	s=0;
	for(ri i=1;i<=n;++i){
		if(val[i]>=lim){
			s+=n;
			continue;
		}
		if(val[n]+val[i]<lim) continue;
		int x=lower_bound(val+1,val+1+n,lim-val[i])-val-1;
		s+=n-x;
	}
	return s>=m;
}
ill Calc(int lim){
	s=0;
	for(ri i=1;i<=n;++i){
		if(val[i]>=lim){
			s+=n;
			continue;
		}
		if(val[n]+val[i]<lim) continue;
		int x=lower_bound(val+1,val+1+n,lim-val[i])-val-1;
		s+=n-x;
	}
	ll res=0;
	for(ri i=1;i<=n;++i){
		if(val[i]>=lim){
			res+=1ll*val[i]*n+sum[n];
			continue;
		}
		if(val[n]+val[i]<lim) continue;
		int x=lower_bound(val+1,val+1+n,lim-val[i])-val-1;
		int num=n-x;
		res+=1ll*val[i]*num+sum[n]-sum[x];
	}
	return res-1ll*lim*(s-m);
}
int main(){
//	freopen("data.in","r",stdin);
//	freopen("out.out","w",stdout);
	read(n),read(m);
	for(ri i=1;i<=n;++i)
		read(val[i]);
	sort(val+1,val+1+n);
	for(ri i=1;i<=n;++i)
		sum[i]=sum[i-1]+val[i];
	int l=val[1]+val[1],r=val[n]+val[n];
	while(l<r){
		if(chk(mid+1)) l=mid+1;
		else r=mid;
	}
	print(Calc(l));
	return 0;
}

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

int main() {
  int h, w; cin >> h >> w;
  vector<string> b(h); rep(i, h) cin >> b[i];
  vector<bool> hf(h), wf(w);
  rep(i, h) rep(j, w) if (b[i][j] == '#') {
        hf[i] = true;
        wf[j] = true;
      }
  rep(i, h) if (hf[i]) {
    rep(j, w) if (wf[j]) {
        cout << b[i][j];
      }
    cout << endl;
  }
}


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

using namespace std;



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

    string s, s1, s2, s3;
    cin >> s;
    int n = s.size();
    s1 = s2 = s.substr(0, n / 2);
    reverse(s2.begin(), s2.end());
    s3 = s.substr(n / 2 + 1, n / 2);
    if (s1 == s2 && s1 == s3) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
	      Scanner sc = new Scanner(System.in);
	      int N = sc.nextInt();
	      
	      if(N <= 599) {
	    	  System.out.println("8");
	      }else if(N <= 799) {
	    	  System.out.println("7");
	      }else if(N <= 999) {
	    	  System.out.println("6");
	      }else if(N <= 1199) {
	    	  System.out.println("5");
	      }else if(N <= 1399) {
	    	  System.out.println("4");
	      }else if(N <= 1599) {
	    	  System.out.println("3");
	      }else if(N <= 1799) {
	    	  System.out.println("2");
	      }else if(N <= 1999) {
	    	  System.out.println("1");
	      }

	}
}

Measured memory_bytes: 35660
#include<stdio.h>

int main(){
	int i, j;
	int count;
	int N;
	scanf("%d\n", &N);

	int A[N];
	for(i = 0; i < N; ++i)
		scanf("%d", &A[i]);
	
	count = 0;
	//selectionSort(A, N)
	for(i = 0; i < N; ++i) {
		int minj = i;
		for(j = i; j < N; ++j) {
			if(A[j] < A[minj])
				minj = j;
		}
		if(i != minj) {
			int tmp = A[i];
			A[i] = A[minj];
			A[minj] = tmp;
			count++;
		}
	}
	
	for(i = 0; i < N; ++i) {
		if(i == N-1)
			printf("%d\n", A[i]);
		else
			printf("%d ", A[i]);
	}
	printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void) {
	int n,d[11][11],i,j;
	while(scanf("%d",&n),n) {
		for(i=0;i<n;i++) d[i][n]=0;
		for(i=0;i<=n;i++) d[n][i]=0;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				scanf("%d",&d[i][j]);
				d[i][n]+=d[i][j];
				d[n][j]+=d[i][j];
				d[n][n]+=d[i][j];
			}
		}
		for(i=0;i<=n;i++) {
			for(j=0;j<n;j++) {
				printf("%5d",d[i][j]);
			}
			printf("%5d\n",d[i][n]);
		}
	}
	return 0;
}

Measured memory_bytes: 612
package main

import "fmt"

func main() {
	k, a := input()
	ans := run(k, a)
	output(ans)
}

func run(k int, a []int) int {
	town := 0
	// trajectory := []int{}
	trajectory := make(map[int]int)
	var begin, end int
	var ok bool
	var i int
	for i = 0; i < k; i++ {
		begin, ok = trajectory[town]
		// begin = firstAppearance(town, trajectory)
		if ok {
			end = i
			break
		}
		trajectory[town] = i
		// trajectory = append(trajectory, town)
		town = a[town]
	}
	if i == k {
		return town + 1
	}
	t := (k - begin) % (end - begin)
	// fmt.Println(begin, end)
	// fmt.Println(trajectory)
	arr := make([]int, end-begin, end-begin)
	for i, v := range trajectory {
		if begin <= v && v < end {
			arr[v-begin] = i
		}
	}
	// fmt.Println(arr)
	// arr := trajectory[begin:end]
	return arr[t] + 1
	// return -1
}

func firstAppearance(x int, t map[int]int) int {
	for i, v := range t {
		if x == v {
			return i
		}
	}
	return -1
}

func output(a int) {
	fmt.Println(a)
}

func input() (int, []int) {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n, n)
	var t int
	for i := range a {
		fmt.Scan(&t)
		a[i] = t - 1
	}
	return k, a
}


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

int main()
{
   set<string>  s;
   string word;
   int i, n;
   cin >> n;
   
   for(i=1; i<=n; i++)
   {
      cin >> word;
      s.insert(word);   
   } 

   cout << s.size();
   return 0;
}

Measured memory_bytes: 19172
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
avg = sum(A) / N

d = INF
ans = 0
for i in range(N):
    diff = abs(A[i] - avg)
    if diff < d:
        d = diff
        ans = i
print(ans)


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using DoP = pair<double, double>;

const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 10007;

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll rans = 0, lans = 0;
  //pnpn
  ll sum = 0;
  rep(i, n) {
    sum += a[i];
    if(i%2==0 && sum <= 0) {
      rans += abs(sum-1);
      sum = 1;
    }
    else if(i%2==1 && sum >= 0) {
      rans += abs(-1-sum);
      sum = -1;
    }
  }
  sum = 0;
  //npnp
  rep(i, n) {
    sum += a[i];
    if(i%2==0 && sum >= 0) {
      lans += abs(-1-sum);
      sum = -1;
    }
    else if(i%2==1 && sum <= 0) {
      lans += abs(sum-1);
      sum = 1;
    }
  }
  cout << min(lans, rans) << endl;
}

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

#define ll long long int

int minSwaps(int arr[], int n) {
    pair<int, int> arrPos[n];
    for (int i = 0; i < n; i++) {
        arrPos[i].first = arr[i];
        arrPos[i].second = i;
    }
    sort(arrPos, arrPos + n);
    vector<bool> vis(n, false);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (vis[i] || arrPos[i].second == i)
            continue;
        int cycle_size = 0;
        int j = i;
        while (!vis[j]) {
            vis[j] = 1;
            j = arrPos[j].second;
            cycle_size++;
        }
        if (cycle_size > 0) {
            ans += (cycle_size - 1);
        }
    }
    return ans;
}

int main(){
    int n;
    cin>>n;
    int a[n], b[n], s = 0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    s = minSwaps(a,n);
    if(s>1)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 256
### constant

C2N = {
  'A' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5,
  '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'T' => 10,
  'J' => 10, 'Q' => 10, 'K' => 10
}

### subroutines

def score(hs)
  sum = 0
  na = 0
  ace = false
  
  for hi in hs
    sum += C2N[hi]
    na += 1 if hi == 'A'
  end

  while sum <= 11 && na > 0
    sum += 10
    na -= 1
    ace = true
  end

  [sum, ace]
end

### main

n = gets.to_i

n.times do
  hs = gets.strip.split
  pcs = gets.strip.split
  #p [hs, pcs]

  sc, ace = score(hs)
  if sc == 21
    puts 'blackjack'
    next
  end

  loop do
    sc, ace = score(hs)

    if sc <= 16 || (sc == 17 && ace)
      hs << pcs.shift
    else
      break
    end
  end

  sc, ace = score(hs)
  puts (sc > 21 ? "bust" : sc)
end

Measured memory_bytes: 6108
import java.util.Scanner;

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

        if (X == 7 || X == 5 || X == 3) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 23636
n = int(input())

a = list(input())
b = list(input())
c = list(input())

count = 0

for i in range(n):
    if a[i] != b[i] and b[i] != c[i] and c[i] != a[i]:
        count += 2
    elif a[i] == b[i] and b[i] == c[i]:
        continue
    else:
        count += 1

print(count)



Measured memory_bytes: 3060
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}



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

    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    queue<pair<int,int>> que;

    int dist = 0;
    vector<bool> visited(n, false);
    visited[0] = true;
    vector<int> dir(n);
    dir[0] = -1;

    REP(i, edges[0].size())
        que.push({edges[0][i], 0});
        
    while(!que.empty()){
        auto f = que.front();
        que.pop();
        int node = f.first;
        int from = f.second;
        if(visited[node])
            continue;
        visited[node] = true;
        dir[node] = from;
        REP(i, edges[node].size())
            que.push({edges[node][i], node});
    }

    cout << "Yes" << endl;
    FOR(i, 1, n)
        cout << dir[i]+1 << endl;

    return 0;
}

Measured memory_bytes: 11640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  long long w,h,x,y;
  cin>>w>>h>>x>>y;
  if(w%2!=0 && h%2!=0) cout<<w*h/2+0.5<<" 0"<<endl;
  else{
    if(w%2!=0 && h%2==0) cout<<h/2*w<<" 0"<<endl;
    else if(w%2==0 && h%2!=0) cout<<w/2*h<<" 0"<<endl;
    else{
      int mx=w/2,my=h/2;
      if(x==mx && y==my)
        cout<<w/2*h<<" 1"<<endl;
      else cout<<w/2*h<<" 0"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MAXN 400010
using namespace std;
int n;

struct mem{
	int l,r;
} a[ MAXN ];
int sum[MAXN],w[MAXN],q[MAXN];
int main()
{

	scanf("%d",&n);
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		a[i].l=x;
		y--;
		a[i].r=y;
		sum[x]++;
		sum[y+1]--;
		mx=max(y+1,mx);
		w[x]++;
		q[y]++;
	}
	int ans1=0,ans2=0;
	for(int i=1;i<=mx;i++)
	{
		w[i]=w[i-1]+w[i];
		q[i]=q[i-1]+q[i];
		sum[i]=sum[i-1]+sum[i];
		ans2=max(ans2,sum[i]);
	}
	for(int i=1;i<=n;i++)
	{
		int xx=w[a[i].r]-q[a[i].l-1];
		ans1=max(ans1,xx);
	}
	printf("%d %d\n",ans1,ans2);
	return 0;
}
		 



Measured memory_bytes: 5936
#include "stdio.h"
#include <vector>

using namespace std;

int main()
{
	int n, a, v;
	vector<int> vec;

	scanf("%d", &n);

	int ni = 0;

	while (ni < n)
	{
		scanf("%d", &a);
		if (a == 0) {
			scanf("%d", &v);
			vec.push_back(v);
		}
		else if (a == 1) {
			scanf("%d", &v);
			printf("%d\n", vec[v]);
		}
		else {
			vec.pop_back();
		}
		ni++;
	}

    return 0;
}


Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
const long long inf=1e9;
#define int long long
int32_t main()
{
	int n,k;
  cin>>n>>k;
  int arr[n+1];
  for(int i=1;i<=n;i++)cin>>arr[i];
  
  int dp[n+1];
 // memset(dp,inf,sizeof(dp));
  dp[1]=0;
  for(int i=2;i<=n;i++){
      dp[i]=inf;
    for(int j=i-1;j>0 && (i-j)<=k;j--){
      	int ans=abs(arr[i]-arr[j])+dp[j];
      	dp[i]=min(dp[i],ans);
    }
  }
  cout<<dp[n];
  return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;

struct BIT{
	int bit[200001];
	int size;
	BIT(int n){
		size = n;
		for(int i=0;i<=n;i++) bit[i] = 0;
	}
	void add(int i,int x){
		i++;
		while(i<=size){
			bit[i] += x;
			i += i & -i;
		}
	}
	int sum(int i){
		int ret = 0;
		i++;
		while(i>0){
			ret += bit[i];
			i -= i & -i;
		}
		return ret;
	}
};

int main(){
	int n,a[200000],b[200000],p[200000];
	long long ans = 0;
	map<int,int> mp;
	scanf("%d",&n);
	BIT bit(n);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		b[i] = a[i];
	}
	sort(b,b+n);
	for(int i=0;i<n;i++) mp[b[i]] = i;
	for(int i=0;i<n;i++) p[mp[a[i]]] = i;
	for(int i=n-1;i>=0;i--){
		ans += bit.sum(p[i]);
		bit.add(p[i],1);
	}
	printf("%lld\n",ans);
}

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

using namespace std;
#define int long long
// 寿司を食べたい！！
typedef long long int64;

struct SegmentTree
{
  vector< int64 > seg, lazy;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, 0);
    lazy.assign(2 * sz - 1, -1);
  }

  void push(int k)
  {
    if(lazy[k] >= 0) {
      if(k < sz - 1) {
        lazy[2 * k + 1] = lazy[k] >> 1LL;
        lazy[2 * k + 2] = lazy[k] >> 1LL;
      }
      seg[k] = lazy[k];
      lazy[k] = -1;
    }
  }

  int64 query(int a, int b, int k, int l, int r)
  {
    push(k);
    if(a >= r || b <= l) {
      return (0);
    } else if(a <= l && r <= b) {
      return (seg[k]);
    } else {
      return (query(a, b, 2 * k + 1, l, (l + r) >> 1) +
              query(a, b, 2 * k + 2, (l + r) >> 1, r));
    }
  }

  int64 query(int a, int b)
  {
    return (query(a, b, 0, 0, sz));
  }

  void update(int a, int b, int64 x, int k, int l, int r)
  {
    push(k);
    if(a >= r || b <= l) {
      return;
    } else if(a <= l && r <= b) {
      lazy[k] = x * (r - l);
      push(k);
    } else {
      update(a, b, x, 2 * k + 1, l, (l + r) >> 1);
      update(a, b, x, 2 * k + 2, (l + r) >> 1, r);
      seg[k] = seg[2 * k + 1] + seg[2 * k + 2];
    }
  }

  void update(int a, int b, int64 x)
  {
    update(a, b, x, 0, 0, sz);
  }

};

signed main()
{
  int N, Q;

  cin >> N >> Q;
  SegmentTree tree(N);
  while(Q--) {
    int A, B;
    cin >> A >> B;
    int low = 0, high = A;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if(tree.query(mid, mid + 1) * (A - mid) - tree.query(mid, A) > B) low = mid;
      else high = mid;
    }
    if(tree.query(low, low + 1) * (A - low) - tree.query(low, A) > B) ++low;
    int64 v = tree.query(low, A) + B;
    int64 width = A - low;
    tree.update(low, A, v / width + 1);
    tree.update(low + v % width, A, v / width);
  }
  for(int i = 0; i < N; i++) {
    cout << tree.query(i, i + 1) << endl;
  }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
#define print(var) cout<<var<<endl;
#define DEBUG(var) cerr<<var<<endl

const int inf = 1000000000;//10^9



int main(){
  int T8;
  int T10;

  cin >> T8 >> T10;
  rep(i,1251){
    if(int(i*0.08)==T8){
      if(int(i*0.1)==T10){
        print(i);
        return 0;
      }else{
        continue;
      }
    }
  }
  print("-1");
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int n,x,y,t,i;
    scanf("%lld",&n);
    t = n;
    for(i=(int)sqrt(n);i>=2;i--)
    {

        if(n%i==0)
        {
            x=i;
            y=n/i;
            if(t>x+y-2)
                t=x+y-2;
        }
    }
    if(t==n)
        printf("%lld",n-1);
    else
        printf("%lld",t);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    

    internal static void Main(string[] args)
    {
        var S = ReadLine();

        int o = S.ToCharArray().Where(c => c == 'o').Count();

        WriteLine(700 + (100 * o));
    }
}

Measured memory_bytes: 11348
from collections import Counter
n = int(input())
v = [int(x) for x in input().split()]
li_odd = v[0:n:2]
li_even = v[1:n:2]

if len(v) == v.count(v[0]):
    print(len(v)//2)
else:
    c_odd = Counter(li_odd).most_common()
    c_even = Counter(li_even).most_common()
    if c_odd[0][0] != c_even[0][0]:
        print(len(li_odd) - c_odd[0][1] + len(li_even) - c_even[0][1])
    else:
        ans1 = len(li_odd) - c_odd[1][1] + len(li_even) - c_even[0][1]
        ans2 = len(li_odd) - c_odd[0][1] + len(li_even) - c_even[1][1]
        print(min(ans1,ans2))


Measured memory_bytes: 21084
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  long long c;
  if(N % (A+B) > A){
    c = A;
  }
  else{
    c = N % (A+B);
  }
  cout << c + N / ( A + B ) * A << endl;
}

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

int main(){
	string str;
	while(getline(cin,str) && str != "."){
		string c;
		for(int i = 0 ; i < str.size() ; i++)
			if(str[i] == ')' || str[i] == '(' || str[i] == '[' || str[i] == ']')
				c += str[i];
		stack<char> s;
		bool f = true;
		for(int i = 0 ; i < c.length() ; i++){
			if(s.empty() || c[i] == '(' || c[i] == '[')
				s.push(c[i]);
			else if( (s.top() == '(' && c[i] == ')') || (s.top() == '[' && c[i] == ']') ){
				s.pop();
			}else{
				f = false;
				break;
			}
		}
		cout << (f && s.empty() ?"yes":"no") << endl;
	}
}

Measured memory_bytes: 0
//To include everything you need
#include <bits/stdc++.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<std::pair<int, int>> vpi;
typedef std::vector<string> vs;
typedef std::vector<char> vc;
vector<long> primes{1, 2, 3, 5, 7};

vector<bool> is_prime;
void computePrimesTill(long long x)
{
    for (long long i = 0; i <= x; i++)
    {
        is_prime.push_back(true);
    }
    is_prime[0] = is_prime[1] = false;
    for (long long i = 2; i <= x; i++)
    {
        if (is_prime[i] && (long long)i * i <= x)
        {
            for (long long j = i * i; j <= x; j += i)
                is_prime[j] = false;
        }
    }
}

bool checkPrime(long long x){
    if(x<=1)
        return false;
    for(long long i = 2;i<=sqrt(x);i++){
        if(x%i == 0)
            return false;
    }

    return true;
}

//Function to calculate greater common divisor
long long gcd(long long a ,long long b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
int main()
{

    long long a, b;
    vector<long long> commonDivisors;

    cin >> a >> b;
    long long count = 0;
    long long range = gcd(a,b);
    for (long long i = 1; i <= sqrt(range); i++)
    {
        if(range%i ==0){
            if(range/i == i){
                commonDivisors.push_back(i);
            }else{
                commonDivisors.push_back(i);
                commonDivisors.push_back(range/i);
            }
        }
    }
    for (int i = 0; i < commonDivisors.size(); i++)
    {
        if (checkPrime(commonDivisors[i]))
            count++;
    }
    count++;
    cout << count;
}

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

void main_()
{
    int X;
    cin >> X;

    vector<int> exps;

    exps.push_back(1);
    for (int b = 2; b <= 32; ++b) {
        for (int p = 2;; ++p) {
            int num = pow(b, p);
            if (num > 1000) {
                break;
            }
            exps.push_back(num);
        }
    }
    sort(begin(exps), end(exps));

    auto it = upper_bound(begin(exps), end(exps), X);
    cout << *(it - 1) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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



int main()
{
  int n;
  cin>>n;
   vector<pair<int,int> > v;
  for(int i=1;i<=n;i++)
   {
       int x;
        cin>>x;
        v.push_back({x,i});   
   }
  
  sort(v.begin(),v.end());
  
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->second<<" ";
  
  
 return 0; 
}


Measured memory_bytes: 1780
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		if(a+b==3) System.out.println("3");
		if(a+b==4) System.out.println("2");
		if(a+b==5) System.out.println("1");	
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


int main(){
    int x,n;
    cin >> x >> n;
    vi p(n);
    rep(i,n) cin >> p[i];

    int min_dif = 1e9;
    for(int i=1; i<=110; ++i){
        int dif = abs(i - x);
        bool can = true;
        int cnt = 0;
        for(auto t : p){
            if(dif==0 && abs(t - x)==0) can = false;
            if(dif!=0 && abs(t - x)==dif) ++cnt;
            if(cnt==2) can = false;
        }
        if(can && min_dif > dif){
            min_dif = dif;            
        }
    }
    bool can2 = true;
    for(auto t : p){
        if(x - min_dif == t){
            can2 = false;
            cout(x + min_dif);
            return 0;
        }
        if(x + min_dif == t){
            can2 = false;
            cout(x - min_dif);
            return 0;
        }
    }
    if(can2) cout(x - min_dif);
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	vector<double> dp(n+1);
	dp[0] = 1;
	for(int i=0;i<n;i++)
	{
		double r;
		scanf("%lf",&r);
		for(int j=i+1;j>=0;j--)
		{
			dp[j] = (j==0?0:dp[j-1]*(r)) + dp[j]*(1-r);
		}
	}
	double result = 0;
	for(int i=n/2+1;i<=n;i++)
		result+=dp[i];
	printf("%.10lf\n",result);
}

Measured memory_bytes: 256
N, M, D = map(int, input().split())
space = [input() for _ in range(N)]
a = sum(len(r)-D+1 for row in space for r in row.split('#') if len(r) >= D)
space = [''.join(l) for l in list(zip(*space))]
b = sum(len(r)-D+1 for row in space for r in row.split('#') if len(r) >= D)
print(a+b)

Measured memory_bytes: 7552
while True:
  H,W=map(int,input().split())
  if (H,W)==(0,0):
    break
  for i in range(1,W+1):
      print("#", end="")
  print() 
  for j in range(1,H-1):
    print("#",end='')
    for k in range(1,W-1):
      print('.',end='')
    print("#")
  for i in range(1,W+1):
      print("#", end="")
  print()
  print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int dp[1000][1000];
int main() {
  int d,g;
  cin>>d>>g;
  vi P(d),C(d);
  rep(i,d)cin>>P[i]>>C[i];
  int ans = 10010010;
  rep(i,1<<10){
    int score = 0,num = 0;
    bitset<10> b(i);
    rep(j,d){
      if(b[j]){
        score+=C[j] + (j+1)*100*P[j];
        num+=P[j];
      }
    }
    drep(j,d){
      if(b[j]==0)
      rep(k,P[j]){
        if(score>=g)break;
        score+=(j+1)*100;
        num++;
      }
    }
    mins(ans,num);
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,i,j;
	cin>>n>>k;
	ll a[n+2];
	for(i=1;i<=n;i++)
		cin>>a[i];
	ll cnt=0;
	ll vis[n+2]={0},t=1,st=1;
	while(1){
		if(!vis[st]){
			vis[st]=t;
		}
		else{
			ll len=t-vis[st];
			ll rem=k-t;
			rem%=len;
			st=a[st];
			while(rem>0){
				st=a[st];
				rem--;
			}
			cout<<st;return 0;
		}
		if(t==k){

			cout<<a[st];return 0;
		}
		t++;
		st=a[st];
	}
	return 0;
}

Measured memory_bytes: 6744
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 99999999999999999;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;

int main() {
	long long a, b, ans = 0, anss = 0;
	cin >> a >> b;
	vector<pair<long long, long long>>v(a);
	for (int i = 0; i < a; ++i) {
		cin >> v[i].first >> v[i].second;
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < a; ++i) {
		if (ans + v[i].second < b) {
			ans += v[i].second;
			anss += v[i].first*v[i].second;
		}
		else {
			while (ans < b) {
				++ans;
				anss += v[i].first;

			}
		}
	}
	cout << anss << endl;
}

Measured memory_bytes: 1792
from math import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
d=[0]*(10**6)
for i in a:
  d[i-1]+=1
num=2
while num<=10**6:
  if sum([d[i*num-1] for i in range(1,10**6//num+1)])>1:
      break
  num+=1
else:
  print('pairwise coprime')
  exit()
g=reduce(gcd,a)
if g==1:
  print('setwise coprime')
  exit()

print('not coprime')

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


int main() {
	
	int N,k;
	cin >> N >> k;
	int sum = 0;
	for(int i=0; i<N; i++){
		int x;
		cin >> x;
		sum += min(2*(k-x), 2*x);
	}
	cout << sum << endl;
	
	return 0;
}

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

int cost_array[10] = { INT_MAX, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
std::vector<int> memo;

int main()
{
  int nmatches, nnumber;
  std::cin >> nmatches >> nnumber;
  std::vector<int> available_numbers;
  for (int i = 0; i < nnumber; i++) {
    int tmp;
    std::cin >> tmp;
    available_numbers.push_back(tmp);
  }
  std::sort(available_numbers.rbegin(), available_numbers.rend());
  memo.resize(nmatches+1, INT_MIN);
  memo.at(0) = 0;
  for (int i = 2; i <= nmatches; i++) {
    for (auto available_number : available_numbers) {
      int cost = cost_array[available_number];
      if (i-cost < 0) {
        continue;
      }
      memo.at(i) = std::max(memo.at(i), memo.at(i-cost)+1);
    }
  }

  int remaining_matches = nmatches;
  while (0 < remaining_matches) {
    for (auto available_number : available_numbers) {
      int cost = cost_array[available_number];
      if (remaining_matches-cost < 0) {
        continue;
      }
      if (memo.at(remaining_matches) == memo.at(remaining_matches-cost) + 1) {
        remaining_matches -= cost;
        std::cout << available_number;
        break;
      }
    }
  }
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,q=map(int,input().split())
    S,T,X=[0]*n,[0]*n,[0]*n
    for i in range(n):
        S[i],T[i],X[i]=map(int,input().split())
    D=[int(input()) for _ in range(q)]

    E=[]
    E+=[(s-x,1,x) for s,x in zip(S,X)]
    E+=[(t-x,2,x) for t,x in zip(T,X)]
    E+=[(d,3,i) for i,d in enumerate(D)]
    E.sort()
    from collections import defaultdict
    cnt=defaultdict(int)
    cnt[INF]=1

    from heapq import heappop,heappush
    Q=[INF]
    ans=[-1]*q
    for a,b,c in E:
        if(b==1):
            heappush(Q,c)
            cnt[c]+=1
        elif(b==2): # 本来はここでqからcを削除したいが、できないためb==3で処理する
            cnt[c]-=1
        else:
            while(cnt[Q[0]]==0): # 本来削除されるべき通行止めをここで消す
                heappop(Q)
            x=Q[0]
            if(x!=INF): ans[c]=x
    print(*ans,sep="\n")
resolve()

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

int main() {
    int W, H, N;
    int mat[100][100] =  {0};
    int x[100], y[100], a[100];

    cin >> W >> H >> N;
    for (int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> a[i];
    }

    for (int i = 0; i < N; ++i) {
        switch (a[i]) {
            case 1:
                for (int xx = 0; xx < x[i]; ++xx) {
                    for (int yy = 0; yy < H; ++yy) {
                        mat[xx][yy] = 1;
                    }
                }
                break;
            case 2:
                for (int xx = x[i]; xx < W; ++xx) {
                    for (int yy = 0; yy < H; ++yy) {
                        mat[xx][yy] = 1;
                    }
                }
                break;
            case 3:
                for (int yy = 0; yy < y[i]; ++yy) {
                    for (int xx = 0; xx < W; ++xx) {
                        mat[xx][yy] = 1;
                    }
                }
                break;
            case 4:
                for (int yy = y[i]; yy < H; ++yy) {
                    for (int xx = 0; xx < W; ++xx) {
                        mat[xx][yy] = 1;
                    }
                }
                break;
        }
    }

    int ans = 0;
    for (int xx = 0; xx < W; ++xx) {
        for (int yy = 0; yy < H; ++yy){
            if (mat[xx][yy] == 0) ans += 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int count;
        int ans=Integer.MAX_VALUE;
        int tmp;
        for(int i=0;i<n;i++){
            tmp=sc.nextInt();
            count=0;
            while(tmp%2==0){
                count++;
                tmp/=2;
            }
            ans=Math.min(ans, count);
        }
        System.out.println(ans);
    }

    
}

Measured memory_bytes: 20944
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
const int mod = 1e9 + 7;

ll N, M;
vector<ll> A, B, C;

int main() {
    cin >> N >> M;
    A.resize(N);
    rep(i, N) cin >> A[i];
    B.resize(M);
    C.resize(M);

    rep(i, M) {
        cin >> B[i] >> C[i];
    }

    map<ll, ll> mp;
    rep(i, N) mp[A[i]]++;

    rep(i, M) mp[C[i]] += B[i];

    vector<ll> keys;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        keys.push_back(iter->first);
    }
    sort(keys.rbegin(), keys.rend());

    ll ans = 0;
    ll cnt = 0;
    for (ll i = 0; i < keys.size(); i++) {
        cnt += mp[keys[i]];
        ans += keys[i] * mp[keys[i]];
        if (cnt >= N) {
            ans -= (cnt - N) * keys[i];
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 17268
n = int(input())
str = input().split(" ")
S = [int(str[i]) for i in range(n)]
q = int(input())
str = input().split(" ")
T = [int(str[i]) for i in range(q)]

S_set = set(S)
S = list(S_set)
T.sort()

result = 0

for s in S:
    for t in T:
        if s == t:
            result += 1
            break
        

print(result)
        





Measured memory_bytes: 6332
W,H,N = map(int,input().split())

wl = 0
wr = W
hu = H
hl = 0

for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x > wl:
        wl = x
    elif a == 2 and x < wr:
        wr = x
    elif a == 3 and y > hl:
        hl =y
    elif a == 4 and y < hu:
        hu = y
    
if wl>wr or hl>hu:
    print(0)
else:
    print((wr-wl)*(hu-hl))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using namespace std;

int main() {
    int a;
    cin >> a;
    int k = 0;
    for (auto &&i : to_string(a)) k += i- '0';
    cout <<(a % k ? "No" : "Yes") << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<queue>
using namespace std;
char map[210][210];
int step[210][210];
int px,py,ex,ey;
int pstep=500,sstep=500;
struct node
{
	int x,y,step;
}a[410];
void bfs(int h,int w)
{
	queue<node>Q;
	while(!Q.empty()) Q.pop();
	node tem;
	tem.x=ex,tem.y=ey;
	tem.step=0;
	step[tem.x][tem.y]=0;
	Q.push(tem);
	while(!Q.empty())
	{
		tem=Q.front();
		Q.pop();
		if(map[tem.x][tem.y]=='@' && tem.step<pstep)
			pstep=tem.step;
		else if(map[tem.x][tem.y]=='$' && tem.step<sstep)
			sstep=tem.step;
		node t;
		if(tem.x-1>=0 && map[tem.x-1][tem.y]!='#' && tem.step+1<step[tem.x-1][tem.y])
		{
			t.x=tem.x-1;
			t.y=tem.y;
			t.step=tem.step+1;
			step[t.x][t.y]=t.step;
		/*	if(map[tem.x-1][tem.y]=='@' && t.step<pstep)
				pstep=t.step;
			else if(map[tem.x-1][tem.y]=='$' && t.step<sstep)
				sstep=t.step;
				*/
			Q.push(t);
		}
		if(tem.x+1<h && map[tem.x+1][tem.y]!='#' && tem.step+1<step[tem.x+1][tem.y] )
		{
			t.x=tem.x+1;
			t.y=tem.y;
			t.step=tem.step+1;
			step[t.x][t.y]=t.step;
			/*
		   if(map[tem.x+1][tem.y]=='@' && t.step<pstep)
				pstep=t.step;
			else if(map[tem.x+1][tem.y]=='$' && t.step<sstep)
				sstep=t.step;
				*/
			Q.push(t);
		}
		if(tem.y-1>=0 && map[tem.x][tem.y-1]!='#' && tem.step+1<step[tem.x][tem.y-1])
		{
			t.x=tem.x;
			t.y=tem.y-1;
			t.step=tem.step+1;
			step[t.x][t.y]=t.step;
			/*
		   if(map[tem.x][tem.y-1]=='@' && t.step<pstep)
				pstep=t.step;
			else if(map[tem.x][tem.y-1]=='$' && t.step<sstep)
				sstep=t.step;
				*/
			Q.push(t);
		}
		if(tem.y+1<w && map[tem.x][tem.y+1]!='#' && tem.step+1<step[tem.x][tem.y+1])
		{
			t.x=tem.x;
			t.y=tem.y+1;
			t.step=tem.step+1;
			step[t.x][t.y]=t.step;
			/*
			if(map[tem.x][tem.y+1]=='@' && t.step<sstep)
				sstep=t.step;
			else if(map[tem.x][tem.y+1]=='$' && t.step<sstep)
				sstep=t.step;
				*/
			Q.push(t);
		}
	}
}

int main()
{
	int h,w;
	while(scanf("%d%d",&h,&w)!=EOF)
	{
		pstep=500,sstep=500;
		memset(a,0,sizeof(a));
		memset(step,0x3f,sizeof(step));
		int i,j;
		for(i=0;i<h;i++)
		{
			scanf("%s",&map[i]);
			for(j=0;j<w;j++)
			{
				if(map[i][j]=='@')
				{
					px=i;py=j;
				}
				else if(map[i][j]=='%')
					ex=i,ey=j;
			}
		}
		bfs(h,w);
		if(pstep<sstep)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3432
#include <iostream>
using namespace std;
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z=1;
int main()
{
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		z+=z<k?z:k;
	}
	cout<<z<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

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


    ll ans = 0;
    char S1, S0 = ' ';
    REP (i, N) {
        cin >> S1;
        if (S1 != S0) ans++;
        S0 = S1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3620
#include<iostream>

int main(){
  long long v, a, res=0,ip;
  std::cin>>v>>a;
  while(a--){
    std::cin>>ip;
    res +=ip;
  }
  if(v-res>=0)
    std::cout<<v-res<<std::endl;
  else
    std::cout<<"-1\n";
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 n, x;
    cin >> n >> x;

    if (x == 1 || x == 2 * n - 1)
    {
        cout << "No\n";
        return 0;
    }

    if (n == 2)
    {
        cout << "Yes\n";
        cout << "1\n";
        cout << "2\n";
        cout << "3\n";
        return 0;
    }

    int idx = 0;
    s64 *ans;
    s64 ans1[4] = {x + 1, x - 1, x, x + 2};
    s64 ans2[4] = {x - 2, x + 1, x, x - 1};
    if (IN(1, 2 * n, x + 2)) ans = ans1;
    else if (IN(1, 2 * n, x - 2)) ans = ans2;
    s64 now = 1;
    cout << "Yes\n";
    rep (i, 2 * n - 1)
    {
        if (IN(n - 2, n + 2, i))
        {
            cout << ans[idx++] << "\n";
        }
        else
        {
            while (IN(x - 1, x + 3, now)) ++now;
            cout << now << "\n";
            ++now;
        }
    }

    return 0;
}



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

#include <cstring>
#include <string>

#include <cmath>
#include <algorithm>

#include <vector>
#include <queue>

#include <utility>
#include <map>

// #include <bits/stdc++.h>

#define LL long long
#define vi vector<int>
#define set0(x) memset((x),0,sizeof((x)))
#define set1(x) memset((x),1,sizeof((x)))
#define setmin(x) memset((x),-1,sizeof((x)))
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second

#define MOD 1000000007

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int h,w;
	int max1=1,min1=1,max2=1,min2=1;
	bool check=1;
	bool found=0;
	char x[10][10];
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>x[i][j];
		}
	}
	
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i%2==1){
				if(x[i][j]=='#') {
					if(!found){
					min1=j;
					found=1;
					}  else max1=j;
				}
			} else {
				if(x[i][j]=='#') {
					if(!found){
					min2=j;
					found=1;
					}  else max2=j;
				}
			}	
		}
		if(max1<min1) max1=min1;
		if(max2<min2) max2=min2;
		found=0;
		if(i%2==0){
			if(max1==min2) continue; else {
			check=0;
			break;
			}
		} else {
			if(max2==min1) continue; else {
			check=0;
			break;
			}
		}

//		cout<<min1<<" "<<max1<<" "<<min2<<" "<<max2<<endl;
	}
	
	if(check) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl;
	return 0;
}
/*
##... m0 = min row m1 max row m2 min row berikut
.###.
.###.
...##
*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  string ans;
  if(N == 25) ans = "Christmas";
  else if(N == 24) ans = "Christmas Eve";
  else if(N == 23) ans = "Christmas Eve Eve";
  else ans = "Christmas Eve Eve Eve";
  
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256