akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 100100100100100;

ll gcd(ll a, ll b) {//a>b
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(a % b, b);
}
ll lcm(ll c, ll d) {
	ll b = gcd(c, d);
	return c / b * d;
}
int main() {
	ll N;
	cin >> N;
	ll T = 0;
	ll ans = 1;
	for (int i = 0; i < N; i++) {
		cin >> T;
		ans = lcm(ans, T);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll a[3*N];
  ll ans = 0;
  for (int i = 0; i < 3*N; i++) {
    cin >> a[i];
  }
  sort(a,a+(3*N));
  reverse(a,a+(3*N));
  for (int i = 0; i < N; i++) {
    ans += a[(2*i) + 1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5920
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0 + a[-1]
    for i in range(n-2):
        k = a[-((i+4)//2)]
        ans += k
    print(ans)

if __name__=="__main__":
    main()


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

int main() {
  int i,j,N,result,count=0;

  cin >> N;

  for (i=0; i <= N/4 ; i++) {
    for (j=0; j <= N/7 ; j++) {
      result = 4*i + 7*j;
      if (result == N) {
        count++;
        break;
      }
    }
    if (result == N) break;
  }

  if (count == 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}


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

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

    if(S == "++++"){
        cout << 4 <<endl;
    }
    if(S == "+++-"){
        cout << 2 <<endl;
    }
    if(S == "++--"){
        cout << 0 <<endl;
    }
    if(S == "+---"){
        cout << -2 <<endl;
    }
    if(S == "---+"){
        cout << -2 <<endl;
    }
    if(S == "--++"){
        cout << 0 <<endl;
    }
    if(S == "-+++"){
        cout << 2 <<endl;
    }
    if(S == "----"){
        cout << -4 <<endl;
    }
    if(S == "+-+-"){
        cout << 0 <<endl;
    }
    if(S == "-+-+"){
        cout << 0 <<endl;
    }
    if(S == "+--+"){
        cout << 0 <<endl;
    }
    if(S == "-++-"){
        cout << 0 <<endl;
    }
    if(S == "++-+"){
        cout << 2 <<endl;
    }
    if(S == "--+-"){
        cout << -2 <<endl;
    }
    if(S == "-+--"){
        cout << -2 <<endl;
    }
    if(S == "+-++"){
        cout << 2 <<endl;
    }
}


Measured memory_bytes: 256
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
H,W,K = map(int,input().split())
cake = []
no_str = "."*W
num = 0
ans_list = []
submit_list = []
chk = 0
for i in range(H):
    cake.append([input()])
p = 0
p_count = 0
while cake[p][0] == no_str:
    cake = cake[1:]
    p_count += 1
for i in range(len(cake)):
    if cake[i][0] != no_str:
        str_count = 0
        ans_list = []
        num += 1
        for j in range(W):
            if cake[i][0][j] == "#":
                if str_count != 0:
                        num += 1
                else:
                    str_count = 1
            ans_list.append(num)
        submit_list.append(ans_list)
    else:
        submit_list.append(ans_list)
submit_list = [submit_list[0]] * p_count + submit_list
for i in range(H):
    print(*submit_list[i])


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

using namespace std;
#define ll long long int

int main()
{
    ll a, b,x;

    scanf("%lld%lld %lld", &a, &b, &x);

    ll cnt1 = a/x;
    ll cnt2 = b/x;


    if(a%x==0) cout << cnt2-cnt1 + 1<<endl;
    else{
        cout << cnt2 - cnt1 <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import math
angle = math.pi / 3 # 60度

def koch(p1, p2, n):
    if n == 0:
        return

    s = ((p1[0] * 2 + p2[0]) / 3, (p1[1] * 2 + p2[1]) / 3)
    t = ((p1[0] + p2[0] * 2) / 3, (p1[1] + p2[1] * 2) / 3)
    u = ((t[0] - s[0]) * math.cos(angle) - (t[1] - s[1]) * math.sin(angle) + s[0], \
        (t[0] - s[0]) * math.sin(angle) + (t[1] - s[1]) * math.cos(angle) + s[1])

    koch(p1, s, n-1)
    print("{0:.8f} {1:.8f}".format(s[0], s[1]))
    koch(s, u, n-1)
    print("{0:.8f} {1:.8f}".format(u[0], u[1]))
    koch(u, t, n-1)
    print("{0:.8f} {1:.8f}".format(t[0], t[1]))
    koch(t, p2, n-1)

n = int(input())
print("{0:.8f} {1:.8f}".format(0.0, 0.0))
koch((0.0, 0.0), (100.0, 0.0), n)
print("{0:.8f} {1:.8f}".format(100.0, 0.0))


Measured memory_bytes: 5768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int a, b;
    cin >> a >> b;
    a--; b--;
    cout << a*b << endl;
    return 0;
}

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

const int N = 5005, mod = 1e9 + 7;

int dp[N][N], n;
string s;
int yo(int i, int t) {
	if (t == n) return i == s.size();
	int &ret = dp[i][t];
	if (ret != -1) return ret;
	int ans = yo(i + 1, t + 1) * 2 % mod + yo(!i ? i : i - 1, t + 1);
	if (ans >= mod) ans -= mod;
	return ret = ans;
}
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	memset(dp, -1, sizeof dp);
	int ans = yo(0, 0);
	for (int i = 1; i <= s.size(); i++) ans = 1LL * ans * (mod + 1) / 2 % mod;
	cout << ans << '\n';
    return 0;
}

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

int main() {
  int A, B, number = 0;
  cin >> A >> B;
  
  int oA = A;

  for (int i = 0; i < (B - oA + 1); i++) {
    int A1 = (A - A % 10000) / 10000;
    int A5 = A % 10;
    
	if (A1 == A5) {
      
      int A2 = (A % 10000 - A % 1000) / 1000;
      int A4 = (A % 100 - A % 10) / 10;
      
      if (A2 == A4) {
        number++;
      }
      
    }
    
    A++;
  }
  
  cout << number << endl;
  
  return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
ans = 0

for i in range(1,N+1):
  i_str = str(i)
  i_len = len(i_str)
  sum = 0
  for j in range(i_len):
    sum += int(i_str[j])
  if sum >= A and sum <= B:
    ans += i
    
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	string s;
	int k;
	cin>>s >> k;
	
	int seq_one = 0;
	int num = 1;
	for(int i = 0; i < s.size();i++){
		if(s[i] != '1'){
			num = (int)(s[i] - '0');
			break;
		}
		seq_one++;
	}

	cout << ((seq_one >= k) ? 1 : num)  << endl;

}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: break
 
    data = {}
    staff = []
    for i in range(n):
        tmp = list(map(int, input().split(' ')))
        if tmp[0] in data:
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data[tmp[0]] = tmp[1] * tmp[2]
            staff.append(tmp[0])
 
    if max(data.values()) < 1000000:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1000000:
                print(k)

Measured memory_bytes: 7756
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    if(N == 1)
        cout << "Hello World";
    else
    {
        int a, b; cin >> a >> b;
        cout << a + b;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
  int x,y;
  cin>>x>>y;
  bitset<32>a(y),b(x);
  //cout<<b<<endl;
  //cout<<(~b)<<endl;
  //cout<<(b<<1)<<endl;
  //cout<<(b>>1)<<endl;
  cout<<(a&b)<<endl;
  cout<<(a|b)<<endl;
  cout<<(a^b)<<endl;
}


Measured memory_bytes: 3176
n, min, max = gets.chomp.split(' ').map(&:to_i)
answer_arry = []

(0..n).each do |num|
  numbers = num.to_s.chars.map(&:to_i)
  numbers_sum = numbers.sum
  answer_arry << num if numbers_sum >= min && numbers_sum <= max
end

p answer_arry.sum


Measured memory_bytes: 14316
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    for (int i = 0; i < B; ++i) {
        if ((A * i) % B == C) {
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1LL<<60;
long double pi=3.141592653589793238462643383279L;
double eps=1e-12;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int a[3];
    set<int> st;
    rep(i,0,3){
        cin>>a[i];
        st.insert(a[i]);
    }
    if(st.size()==2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}




Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int H[] = new int[N];
    for(int i=0; i < N; i++) H[i] = sc.nextInt();
    int ans = H[0] + H[N-1];
    for(int i=1; i<N; i++)
      ans += Math.abs(H[i-1]-H[i]);
    System.out.println(ans/2);
  }
}

Measured memory_bytes: 22740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#include<cctype>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << (H - h)*(W - w) << endl;
	return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(m)]

if n==1 and all([i[1]==0 for i in li]):
    print(0)
    exit()
for i in range(10**(n-1),10**n):
    p = list(map(int,list(str(i))))
    for s,c in li:
        if p[s-1] != c:break
    else:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 67944
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int main(void)
{
	int n,sn[100001],dou[100001];
	int dd1[4]={0,1,0,1},dd2[4]={0,0,1,1};
	int i,flg,f,d1,d2,j,f1,f2;
	char s[100001],hk[3]="SW",buf[100001];
	scanf("%d",&n);
	scanf("%s",s);
	for(i=0;i<n;i++)	{
		if(s[i]=='o')	sn[i]=0;
		else sn[i]=1;
	}
	flg=0;
	for(i=0;i<4;i++)	{
		dou[0]=dd1[i];	dou[1]=dd2[i];
		for(j=1;j<n-1;j++)	{
			d1=(sn[j]+dou[j])%2;
			if(d1==0)	dou[j+1]=dou[j-1];
			else dou[j+1]=(dou[j-1]+1)%2;
		}
		d1=(sn[n-1]+dou[n-1])%2;
		d2=(sn[0]+dou[0])%2;
		f1=(dou[n-2]+dou[0])%2;
		f2=(dou[n-1]+dou[1])%2;
		if(d1==f1 && d2==f2)	{
			flg=1;
			for(j=0;j<n;j++)	{
				buf[j]=hk[dou[j]];
			}
		}
	}
	if(flg==0)	printf("-1\n");
	else {
		for(j=0;j<n;j++)	printf("%c",buf[j]);
		printf("\n");
	}
	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n, x;
    cin >> n >> x;
    if(x == 1 || x == 2 * n - 1){
        Yes(false);
        return 0;
    }
    Yes(true);
    if(n == 2){
        FOR(i,1,n*2)ANS(i);
        return 0;
    }

    if(x < n){
        int32 y = 2 * n - 3;
        REP(i,n-3){
            ANS(y);
            y--;
        }
        ANS(2 * n - 1);
        ANS(1);
        ANS(x);
        ANS(2 * n - 2);
        REP(i,n-2){
            if(y == x)y--;
            ANS(y);
            y--;
        }
    }else{
        int32 y = 3;
        REP(i,n-3){
            ANS(y);
            y++;
        }
        ANS(1);
        ANS(2 * n - 1);
        ANS(x);
        ANS(2);
        REP(i,n-2){
            if(y == x)y++;
            ANS(y);
            y++;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
 
int main() {

  int X, N, Xsa, Xpla;
  cin >> X >> N;

  int cnt = 0;
  int cnt2 = 0;
  int cnt3 = 0;
  int ans = 10000;
  Xsa = X;
  Xpla = X;

  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);

    if (X != vec.at(i)){
      cnt += 1;
    }
  }

  if(cnt == N){
    cout << X << endl;
    return 0;
  } 

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

  for (int i = 0; i < 110; i++) {
    Xsa -= 1;
    Xpla += 1;

    for (int i = 0; i < N; i++) {
      if(Xsa != vec.at(i)){
        cnt2 += 1;
      }
      if(cnt2 == N){
        cout << Xsa << endl;
        return 0;
      }

      if(Xpla != vec.at(i)){
        cnt3 += 1;
      }
      if(cnt3 == N){
        cout << Xpla << endl;
        return 0;
      }
    }
    cnt2 = 0;
    cnt3 = 0;
  }  

}

Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,a,b,q;
	char str[1001], p[1001],c,buf[11];
	scanf("%s",str);
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf(" %s",buf);
		if(strcmp(buf,"replace")==0)	{
			scanf("%d %d %s",&a,&b,p);
			for(j=a;j<=b;j++)	{
				str[j]=p[j-a];
			}
		}
		else if(strcmp(buf,"reverse")==0)	{
			scanf("%d %d",&a,&b);
			while(a<b)	{
				swap(str[a],str[b]);
				a++;
				b--;
			}
		}
		else {
			scanf("%d %d",&a,&b);
			for(j=a;j<=b;j++)	{
				printf("%c",str[j]);
			}
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2684
#include <stdio.h>


  /* 配列の要素を交換する */
void Swap(int x[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

void QSort(int x[ ], int y[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, i, j);             /* x[i] と x[j]を交換 */
        Swap(y, i, j);
        i++;                       /* 次のデータ */
        j--;
    }

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, y, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, y, j + 1, right);    /* 右の配列を Q ソートする */
}


int main(void){
    // Your code here!
    int A[100000] = {}, idx[100000] = {}, N;
    
    scanf("%d",&N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d\n",&A[i]);
        idx[i] = i+1;
    }
    
    QSort(A,idx,0,N-1);
    
    for(int i = 0; i < N; i++)
    {
        if(i == N-1)
            printf("%d\n",idx[i]);
        else
            printf("%d ",idx[i]);
    }
    
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  if (s == "Sunny") cout << "Cloudy" << '\n';
  if (s == "Cloudy") cout << "Rainy" << '\n';
  if (s == "Rainy") cout << "Sunny" << '\n';
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    double a,b,c,d;
    cin >>a>>b;
    c=(a+b)/2;
    d=c;
    for(int i=0;i<200;i++){
        if(d<1&&d>=0.5){
            c++;break;
        }
        d--;
    }
    printf("%d\n",(int)c);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vector<int>>
int main(void){
    int a,b;
    cin>>a>>b;
    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;
        return 0;
    }
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
		
       int nam = 0; int min = 10;int sam = 0;
      
      for(int i=0;i<5;i++){
        nam = sc.nextInt();
         if(nam%10==0){sam +=nam;}
        else{
        	min = Math.min(min,nam%10);//一番時間をとる
            sam += nam+(10-nam%10);
        }
      }
      System.out.print(sam-(10-min));
      
    }
}

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

using Int = __int128_t;
Int abs128(Int val){return val<0?-val:val;}

ostream &operator<<(ostream &os,Int val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    Int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,Int &val){
  string s;
  is>>s;
  val=0;
  for(Int i=0;i<(Int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}



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

//INSERT ABOVE HERE
signed main(){
  Int n,a;
  cin>>n>>a;
  
  Int ans=n;
  for(Int i=1;i<100;i++){
    auto calc=[&](Int x)->Int{
      vector<Int> v(i,x/i);
      for(Int j=0;j<x%i;j++) v[j]++;
      Int s=1;
      for(Int j=0;j<i;j++){
	if(s<(n+v[j]-1)/v[j]) s*=v[j];
	else return 1;
      }
      return s>=n;
    };
    
    Int l=i*2-1,r=l+ans;
    while(l+1<r){
      Int m=(l+r)>>1;
      if(calc(m)) r=m;
      else l=m;
    }
    chmin(ans,(i-1)*a+r);
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func main() {
	defer write.Flush()

	var s int
	fmt.Fscan(read, &s)

	fmt.Fprintln(write, (s+1)/2)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
template<typename T1,typename T2>std::istream& operator>>(std::istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a){out<<a.fr<<" "<<a.sc;return out;}

const int N=2e5+5;

set<int> s;
void solve(){
	int n;
	cin>>n;
	rep(i,0,n){
		int t;
		cin>>t;
		s.insert(t);
	}
	if(n==sz(s))cout<<"YES";
	else cout<<"NO";
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 9600
var d = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');

while (d[0] !== '0 0') {
  var footprints = {};
  var hw = d.shift().split(' ');
  var x = y = 0;
  var xy = '';

  var map = [];
  for (var i = 0; i < hw[0]; i++) map.push(d.shift().split(''));

  while (!((xy = x+' '+y) in footprints) && map[y][x] !== '.') {
    footprints[xy] = null;
    switch(map[y][x]) {
      case '^': y--; break;
      case '>': x++; break;
      case 'v': y++; break;
      case '<': x--; break;
    }
  }

  console.log(map[y][x] === '.' ? xy : 'LOOP');
}

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

using namespace std;

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

#define PII pair<int, int>

#define ALL(v) v.begin(), v.end()

#ifdef DBG
#define _log(item) cout << #item << " = " << item << endl
#define _loga(array, val) cout << #array << "[" << val << "] = " << array[val] << endl
#else
#define _log(item)
#define _loga(array, val)
#endif

inline int gcd(int number1, int number2)
{
    int m = number1;
    int n = number2;
    if (number2 > number1) {
        m = number2;
        n = number1;
    }
    while (m != n) {
        int temp = n;
        n = m - n;
        m = temp;
    }
    return m;
}
inline int lcm(int number1, int number2)
{
    return number1 * number2 / gcd(number1, number2);
}

//--------------------

int n;
int k;
int q;

int point[200000];

signed main()
{
    cin >> n >> k >> q;

    rep(i, q){
        int a;
        cin >> a;
        point[a - 1]++;
    }

    rep(i, n){
        if(q - point[i] < k){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

    return 0;
}


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

int main()
{
	uint64_t X;
	cin >> X;
	int64_t gohyaaku = 0;
	int64_t goen = 0;
	

    gohyaaku = int(X / 500);
    goen = X%500;

	goen = int(goen/5);
	
	int64_t out = 1000 * gohyaaku + 5 * goen;
	
	cout << out << endl;
	
	return 0;
}


Measured memory_bytes: 3552
"""うしくん元気ですか
# distutils: language=c++
# distutils: include_dirs=/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include
# cython: boundschack=False
cimport numpy as np
from libc.stdio cimport scanf, printf
import numpy as np

cdef class BIT:
    cdef int n
    cdef np.ndarray data

    def __cinit__(BIT self, int n):
        self.n = n
        self.data = np.zeros(n + 1, np.int_)

    cdef void add(BIT self, int i, long x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    cdef long sum(BIT self, int i):
        cdef long s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

def main():
    cdef int n, q, a, i, t, u, v
    scanf('%d%d', &n, &q)
    cdef BIT bit = BIT(n)
    for i in range(n):
        scanf('%d', &a)
        bit.add(i + 1, a)
    for i in range(q):
        scanf('%d%d%d', &t, &u, &v)
        if t:
            printf('%ld\n', bit.sum(v) - bit.sum(u))
        else:
            bit.add(u + 1, v)
main()
"""

import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c${rhO^=%}5WVv&Mp|ta6ariIQbnbQ9xC<TTU#N=Hp!@FOl*^G`s+J}BtSMk;WzU>>@iQE(1$*t@mny0_PyBaO0L(*)4YNtO|NvV(D|x7*jAU)QqVpK3T0ue6s9z|E4y<zSo&CeDm@0h>4f~lg1)4_?as_`y1ZzyfgGB*u(LfWFAv;YeG|s(L}J@n7hs@)@IYPCINJhy$ifGO7Op*B3Tkrb98zeK2gF1w-GDU0d-(eO$2I|81I7%XX-i!}N;oIZphOVKP>F@QmPi=tI%Ph1ZP;(%W}{eK5iJO+i{K54N)hdff7)4}60G4v9`~$JXUSxLvZz2Pb!UP(7)yJ2o0<JRpwWQvxw`mHrG@cN{0-|0-WFAi5W)&JICCF7eBa)?&s=AHe4^KPX}-YgU5@B94|A7ebIWnXoDRJs@JSNAT7i^i_XEq}n1jgU#e^LC98N>S@D9?KXZ5UJa#(TO>X=Q`c&r@;4$faGjg`haPJjfCpT15P^SsJMF_GPH)+pkTaGaxfD0F-zbWO&gSDbovnnbaIu)MnQIWx_uU&O3v8>e&1U~}8_*(9O)zgbFLllEg$wj1v=`44!$7r+")))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

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

int main(){
	int n ; cin >> n ;
	int a,b,ab,both ;
	a = b = ab = both = 0 ;
	for(int i=0;i<n;i++){
		string s ; cin >> s ;
		if(s.at(0)=='B') b++ ;
		if(s.at(s.size()-1)=='A') a++ ;
		if(s.at(0)=='B'&&s.at(s.size()-1)=='A') both++ ;
		for(int i=1;i<s.size();i++){
			if(s.at(i-1)=='A'&&s.at(i)=='B') ab++ ;
		}
	}
	if(a==b&&a==both&&both!=0) ab-- ;
	cout << ab+min(a,b) << endl ;
	//cout << ab << " " << a << " " << b ;
}

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

int main()
{
  ll r,c,k;
  cin>>r>>c>>k;
  vector<vector<ll>> field(r+5,vector<ll>(c+5,0));
  for (int i = 0; i < k; ++i)
  {
    ll x,y,v;
    cin>>x>>y>>v;
    field[x][y]=v;
  }

  vector< vector< vector<ll> > > dp(r+5,
    vector<vector<ll>>(c+5,
      vector<ll>(4,0)));

  for (int i = 1; i <= r; ++i)
  {
    for (int j = 1; j <= c; ++j)
    {
      ll value=field[i][j];
      if (value==0) {
        dp[i][j][0]=max({
          dp[i-1][j][0],
          dp[i-1][j][1],
          dp[i-1][j][2],
          dp[i-1][j][3],
          dp[i][j-1][0]
        });

        dp[i][j][1]=dp[i][j-1][1];

        dp[i][j][2]=dp[i][j-1][2];

        dp[i][j][3]=dp[i][j-1][3];
        
        continue;
      }
      dp[i][j][0]=max({
        dp[i-1][j][0],
        dp[i-1][j][1],
        dp[i-1][j][2],
        dp[i-1][j][3],
        dp[i][j-1][0]
      });

      dp[i][j][1]=max({
        dp[i][j-1][1],
        dp[i][j-1][0]+value,
        dp[i-1][j][0]+value,
        dp[i-1][j][1]+value,
        dp[i-1][j][2]+value,
        dp[i-1][j][3]+value
      });

      dp[i][j][2]=max({
        dp[i][j-1][2],
        dp[i][j-1][1]+value
      });

      dp[i][j][3]=max({
        dp[i][j-1][3],
        dp[i][j-1][2]+value
      });

    }
  }

  cout<<max({
    dp[r][c][0],
    dp[r][c][1],
    dp[r][c][2],
    dp[r][c][3],
  })<<endl;
}

Measured memory_bytes: 708900
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=(ll)1e9;

int main(){
    int N,K;
    cin>>N>>K;

    vector<ll> x(N),y(N);
    for (int i = 0; i < N; ++i) {
        cin>>x[i]>>y[i];
    }
    ll ans=(ll)5e18+1;
    for(int x1=0;x1<N;x1++){
        for(int x2=x1+1;x2<N;x2++){
            for(int y1=0;y1<N;y1++){
                for(int y2=y1+1;y2<N;y2++){
                    ll xmin=min(x[x1],x[x2]),xmax=max(x[x1],x[x2]),ymin=min(y[y1],y[y2]),ymax=max(y[y1],y[y2]);
                    int inside=0;
                    for(int i=0;i<N;i++){
                        if(x[i]>=xmin&&x[i]<=xmax&&y[i]>=ymin&&y[i]<=ymax) inside++;
                    }
                    if(inside>=K) ans=min(ans,(xmax-xmin)*(ymax-ymin));
                }
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

int waru(int x) {
  int ret_val=0;
  while (0<x) {
    if (x%2) break;
    else {
      x/=2;
      ret_val++;
    }
  }
  return ret_val;
}

int main() {
  int N; cin >>N;
  int check_val=0,ans=1;
  rep_eq(i,1,N) {
    int temp=waru(i);
    if (check_val<temp) {
      check_val=temp;
      ans=i;
    }
  }
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define S 800005
#define M 1000000007
#define nl cout<<"\n";
#define er  cout<<"\n***********\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test lli t;  cin>>t; while(t--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (lli)(x.size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define Y cout<<"YES\n";
#define N cout<<"NO\n";
#define print(x)                 cout<<#x<<": "<<x<<endl;
#define print2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define print3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define print4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define print5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl;
#define print6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl;
vector<pair<lli,lli> > pp;

void solve()
{
    lli n;cin>>n;
    pp.resize(n);
    vector<lli> v(n,0),vv(n,0);
    for(lli i=0;i<n;i++)
    {
        cin>>pp[i].fi>>pp[i].se;
        v[i]=pp[i].fi+pp[i].se;
        vv[i]=pp[i].fi-pp[i].se;
        
    }

    sort(all(v));
    sort(all(vv));

    lli ans=abs(v[0]-v[n-1]);
    ans=max(ans,(lli)abs(vv[0]-vv[n-1]));
    cout<<ans;


   





}



int main()
{
    fast
    #ifndef ONLINE_JUDGE
     freopen("inputa.txt", "r", stdin);
     freopen("outputa.txt", "w", stdout);
    #endif
     // test
     {
        solve();
        nl
     }
    
}
//a+b=a?b+2?(a&b)
//__builtin_popcnt(number)
//cout<<fixed<<setprecision(8)<<output<<"\n";

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;
Node treeMinimum(Node x){
  while(x->left != NIL)   
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key)
    {
      if(k < u->key) u = u->left;
      else u = u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL)
    {
      x = y->left;
    }else{
    x = y->right;
  }
  
  if(x != NIL) x->parent = y->parent;
  
  if(y->parent == NIL)
    {
      root = x;
    }else{
    if(y == y->parent->left)
      {
	y->parent->left = x;
      }else{
      y->parent->right = x;
    }
  
    if(y != z)
      {
	z->key = y->key;
      }
    free(y);
  }
}

  void insert(int k)
  {
    Node y = NIL;
    Node x = root;
    Node z;
    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while(x != NIL){
      y = x;
      if(z->key < x->key){
	x = x->left;
      }else{
	x = x->right;
      }
      z->parent = y;
    }
    if(y == NIL)
      {
	root = z;
      }
    else if(z->key < y->key)
      {
	y->left = z;
      }
    else
      {
	y->right = z;
      }
  }

  void inorder(Node u)
  {
    if(u == NIL)
      {
	return;
      }
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
  void preorder(Node u)
  {
    if(u == NIL)
      {
	return;
      }
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }


  int main()
  {
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ )
      {
	scanf("%s", com);
	if ( com[0] == 'f' )
	  {
	    scanf("%d", &x);
	    Node t = treeSearch(root, x);
	    if ( t != NIL ) printf("yes\n");
	    else printf("no\n");
	  }
	else if ( com[0] == 'i' )
	  {
	    scanf("%d", &x);
	    insert(x);
	  }
	else if ( com[0] == 'p' )
	  {
	    inorder(root);
	    printf("\n");
	    preorder(root);
	    printf("\n");
	  }
	else if ( com[0] == 'd' )
	  {
	    scanf("%d", &x);
	    treeDelete(treeSearch(root, x));
	  }
      }
    return 0;
  }
  



Measured memory_bytes: 20476
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char c;
  cin >> c;
  switch (c){
  case 'A': c = 'T'; break;
  case 'C': c = 'G'; break;
  case 'G': c = 'C'; break;
  case 'T': c = 'A'; break;
  }
  cout << c << endl;
}


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

int main(int argc, const char * argv[]) {
    int N, Q;
    string S;
    
    cin >> N >> Q;
    cin >> S;
    
    vector<int> sum(N + 1, 0);
    for (int i = 0; i < N; i++) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            sum[i + 1] = sum[i] + 1;
        } else {
            sum[i + 1] = sum[i] + 0;
        }
    }
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        
        cout << sum[r -1] - sum[l-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1408
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Set as ST
import qualified Data.Map.Strict as MPS
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char
import Data.Tuple
import Control.Monad
import Control.Applicative

type Graph = MPS.Map Int [(Int, Int)]
type Distance = VUM.IOVector Int
type Queue = ST.Set (Int, Int)

makeGraph :: Int -> [(Int, [(Int, Int)])] -> Graph
makeGraph vertex xs = MPS.fromListWith (++) xs

dijkstra :: Int -> Int -> Graph -> IO Distance
dijkstra vertex from graph = do
  distance <- VUM.replicate (vertex+1) (10^9) :: IO Distance
  VUM.write distance from 0 
  trav graph distance (ST.singleton (0, from))
  where
    trav :: Graph -> Distance -> Queue -> IO Distance
    trav graph distance queue
      | ST.null queue = return distance
      | otherwise = do
          tmp <- VUM.read distance from
          if acc <= tmp
            then do
              update >>= trav graph distance
            else
              trav graph distance queue'
        where
          ((acc, from), queue') = ST.deleteFindMin queue

          update :: IO Queue
          update = 
            case MPS.lookup from graph of
              Just xs -> update' xs queue'
              Nothing -> return queue'
            where
              update' :: [(Int, Int)] -> Queue -> IO Queue
              update' [] q = return q
              update' ((to, cost):xs) q = do
                tmp <- VUM.read distance to
                let acc' = acc + cost
                case compare acc' tmp of
                   LT -> do
                      VUM.write distance to acc'
                      update' xs (ST.insert (acc', to) q)
                   _ ->
                      update' xs q
        
main = do
  [n,a,b] <- map read . words <$> getLine :: IO [Int]
  let vs = zip [1..n] [2..n] :: [(Int, Int)]
  let vs' =  (map swap vs) ++ vs :: [(Int, Int)]
  let vs'' = [(a,[(b,1)]), (b,[(a,1)])] ++ map (\(f,t) -> (f,[(t,1)])) vs' :: [(Int, [(Int, Int)])]
  let graph = makeGraph n vs''

  table <- VUM.replicate (n+1) 0 :: IO (VUM.IOVector Int)

  forM_ [1..n] $ \i -> do
    dist <- dijkstra n i graph
    dist' <- VU.tail . VU.zip (VU.fromList [0..n]) <$> VU.unsafeFreeze dist
    VU.forM_ dist' $ \(j,d) ->
      when (d /= 10^9 && j > i) $  
        VUM.modify table (+1) d

  table' <- VU.init .  VU.tail <$> VU.unsafeFreeze table
  VU.mapM_ print table' 


Measured memory_bytes: 2428
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;
const long long int MOD=1e9+7;

int main(){
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }
  if(s=="Cloudy"){
    cout << "Rainy" << endl;
  }
  if(s=="Rainy"){
    cout << "Sunny" << endl;
  }
}

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

int main() {
    string s;
    cin >> s;
    bool flg=false;
    for(int i=0;i<s.length();i++){
    	if(s[i]=='C') {
    		for(int j=i;j<s.length();j++)
    		if(s[j]=='F') flg=true;
    	}
    	if(flg) break;
    }
    cout << (flg?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int W, H, x, y; 
	cin >> W >> H >> x >> y; 
	cout.precision(20); 
	cout << (long double) W * H * 0.5 << " "; 
	if(W == x * 2 && H == y * 2) cout << 1 << endl; 
	else cout << 0 << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> pii;
 
int main()
{
    int n, m;   cin >> n >> m;
 
    vector <int> a(n);
    for(int& x : a) scanf("%d", &x);
 
    vector <pii> b(m);
    for(pii& p : b) scanf("%d%d", &p.second, &p.first);
 
    sort(b.begin(), b.end(), greater <pii> ());
 
    ll Ans = 0;
    multiset <int> st;
 
    for(int x : a)  st.insert(x);
 
    for(int i = 0; i < m; i++)
    {
        int x = b[i].first;
        int y = b[i].second;
 
        while(!st.empty() && (*st.rbegin()) >= x)   Ans += (ll) (*st.rbegin()), st.erase(--st.end());
 
        while(!st.empty() && y > 0)
        {
            y--;
            Ans += (ll) x;
            st.erase(st.begin());
        }
    }
 
    while(!st.empty())  Ans += (ll) (*st.begin()), st.erase(st.begin());
 
    cout << Ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int N;
  cin >> N;
  VI p(N);
  REP(i, N) {
    cin >> p[i];
  }
  int cnt = 0;
  for (int i = 1; i < N-1; i++) {
    if ((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

typedef long long ll;

int main()
{
    ll a, b, n, x, ans;
    scanf("%lld%lld%lld", &a, &b, &n);
    x = b<=n?(b-1):n;
    printf("%lld\n", (a*x/b) - a*(x/b));
}

Measured memory_bytes: 3760
# include <iostream>
# include <string>
# include <vector>
# include <algorithm>


int main()
{
    
    std::vector<int> data(3);
    for (auto& val : data)
        std::cin >> val;
    
    std::sort(data.begin(), data.end());
    std::cout << data[1] - data[0] + data[2] - data[1];

    return 0;
}

Measured memory_bytes: 256
// SeeAlso: https://atcoder.jp/contests/abc155/tasks/abc155_b

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    
    int n;
    int a[MAX];
    cin >> n;
    rep(i,n) {
        cin >> a[i];
    }

    bool flag = true;
    for(int i=0; i<n;i+=1) {
        if (a[i]%2==1) continue;
        if((a[i]%3)==0||(a[i]%5)==0) continue;
        flag = false;
        break;
    }
    print(flag?"APPROVED":"DENIED");
    return 0;
}


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


using namespace std;


void security()
{
  string s;
  cin >> s;

  for (int i = 1; i < s.size(); ++i)
  {
    if (s[i - 1] == s[i])
    {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


void fifty_fify()
{
  string s;
  cin >> s;

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

  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else cout << "No\n";
}


void dodecagon()
{
  int r;
  cin >> r;

  cout << 3 * r * r << "\n";
}


void harmony()
{
  int a, b;
  cin >> a >> b;

  if (a % 2 == b % 2) cout << (a + b) / 2 << "\n";
  else cout << "IMPOSSIBLE\n";
}


void transfer()
{
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(0, c - (a - b)) << "\n";
}


void A_137()
{
  int a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << "\n";
}


void red_or_not()
{
  int a;
  cin >> a;
  string s;
  cin >> s;

  if (a >= 3200) cout << s << "\n";
  else cout << "red\n";
}


void tenki()
{
  string s, t;
  cin >> s >> t;

  int cnt = 0;
  for (int i = 0; i < 3; ++i)
  {
    if (s[i] == t[i]) ++cnt;
  }
  cout << cnt << "\n";
}



int main()
{
  //security();
  //fifty_fify();
  //dodecagon();
  //harmony();
  //transfer();
  //A_137();
  //red_or_not();
  tenki();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char in[110];
int isPa(int l,int r,char *s){
	int i,len;
	len=r-l+1;
	for(i=0;i<len/2;i++)
		if(s[l+i]!=s[l+len-1-i])
			return 0;
	return 1;
}
int main(){
	int i,len;
	scanf("%s",in);
	len=strlen(in);
	if(!isPa(0,len-1,in)){
		printf("No\n");
		return 0;
	}
	if(!isPa(0,len/2-1,in)){
		printf("No\n");
		return 0;
	}
	if(!isPa(len/2+1,len-1,in)){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int cnt[4][3][10];

int main () {
  int n = in();
  rep(i,n) {
    int b, f, r, v;
    cin >> b >> f >> r >> v;
    cnt[b-1][f-1][r-1] += v;
  }
  rep(i,4) {
    rep(j,3) {
      rep(k,10) {
        printf("%c%d", ' ', cnt[i][j][k]);
      }
      printf("\n");
    }
    if (i != 4-1) printf("####################\n");
  }
  return 0;
}


Measured memory_bytes: 3192
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] ary = new Integer[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        Arrays.sort(ary, Comparator.reverseOrder());
        if (ary[0] < sum - ary[0]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23892
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n=N()
ans=[]
while n>0:
    n-=1
    x=n%26
    ans.append(chr(x+97))
    n//=26
ans.reverse()
print("".join(ans))

Measured memory_bytes: 9204