akhauriyash/Code-Regression huggingface dataset:
def examA():
    S = SI()
    if S=="ARC":
        ans = "ABC"
    else:
        ans = "ARC"
    print(ans)
    return

def examB():
    N, K = LI()
    snuke = set(range(1,N+1))
    for _ in range(K):
        d = I()
        A = LI()
        for a in A:
            snuke.discard(a)
    ans = len(snuke)
    print(ans)
    return

def examC():
    N, M = LI()
    H = LI()
    good = set(range(1,N+1))
    for _ in range(M):
        a, b = LI()
        if H[a-1]>=H[b-1]:
            good.discard(b)
        if H[b-1]>=H[a-1]:
            good.discard(a)
    ans = len(good)
    print(ans)
    return

def examD():
    X = I()
    #print(1000**5-999**5)
    for a in range(-1000,1000):
        for b in range(-1000,1000):
            if a**5-b**5==X:
                print(a,b)
                return
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 76764
import java.io.*;
import java.util.*;

public class Main {

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

	static int MOD = (int) 1e9 + 7;

	static int pow(long b, int e) {
		long ans = 1;
		while (e > 0) {
			if (e % 2 == 1)
				ans = ans * b % MOD;
			e >>= 1;
			b = b * b % MOD;
		}
		return (int) ans;
	}

	static int N = (int) 1e6 + 2;

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[] cnt = new int[N];
		for (int x : a) {

			for (int d = 2; d * d <= x; d++) {
				int c = 0;
				while (x % d == 0) {
					x /= d;
					c++;
				}
				cnt[d] = Math.max(cnt[d], c);
			}
			if (x > 1 && cnt[x] == 0)
				cnt[x] = 1;
		}
		long lcm = 1;
		for (int i = 1; i < N; i++)
			lcm = lcm * pow(i, cnt[i]) % MOD;
		int ans = 0;
		for (int x : a) {
			ans += lcm * pow(x, MOD - 2) % MOD;
			ans %= MOD;
		}
		System.out.println(ans);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 28040
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K, H, W, L, R, l, r, u, d, sum, Q;
LL ans;
LL no;
bool b, bb[100001];
string s, t;

int main() {
	cin >> N;
	vector<LL> x(N);
	LL mi, ma;
	mi = 101;
	ma = -1;
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		mi = min(mi, x[i]);
		ma = max(ma, x[i]);
	}
	ans = INF;
	sum = 0;
	for (int i = mi; i <= ma; i++) {
		for (int j = 0; j < N; j++) {
			sum += pow(x[j] - i, 2);
		}
		ans = min(ans, sum);
		sum = 0;
	}
	cout << ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    cout << s.rfind('Z') - s.find('A') +1 << endl;
    return 0;
}


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

using namespace std;

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

const ll INF=1e9+7;

int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(abs(a-c)<=d)
    	printf("Yes");
    else
        if(abs(a-b)<=d && abs(b-c)<=d)
            printf("Yes");
        else
            printf("No");
}

Measured memory_bytes: 128
from queue import deque
def main():
    R, W = "R", "W"
    N = int(input())
    C = input()

    counter = dict()
    for c in C:
        counter[c] = counter.get(c, 0) + 1
    r = counter.get(R, 0)

    _counter = dict()
    for c in C[r:]:
        _counter[c] = _counter.get(c, 0) + 1
    _r = _counter.get(R, 0)

    ans = _r
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9872
N = int(input())
P = list(map(int,input().split()))

ans = 0
if P[-1] == N:
  P[-1],P[-2] = P[-2],P[-1]
  ans += 1

for i in range(N-1):
  if P[i] == (i+1):
    P[i],P[i+1] = P[i+1],P[i]
    ans += 1
    
print(ans)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
//#define int long long
//template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
//template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

template<typename T> inline bool is_prime(const T &N) {
    if (N < 2 || N % 2 == 0) return(N == 2);
    for (int i = 3; i <= sqrt(N); i += 2) {
        if (N % i == 0) { return false; }
    }
    return true;
}

signed main() {
    long long A, B;
    cin >> A >> B;
    if (A < B) swap(A, B);
    set<long long> p; p.insert(1);
    for (long long i = 1; i <= sqrt(A); i++) {
        if (A % i == 0) {
            long long j = A/i;
            if (A % i == 0 && B % i == 0 && is_prime(i)) p.insert(i);
            if (A % j == 0 && B % j == 0 && is_prime(j)) p.insert(j);
        }
        if (B % i == 0) {
            long long j = B/i;
            if (A % i == 0 && B % i == 0 && is_prime(i)) p.insert(i);
            if (A % j == 0 && B % j == 0 && is_prime(j)) p.insert(j);
        }
    }
    cout << p.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
void write(long long aa)
{
	if(aa<0) putchar('-'),aa=-aa;
	if(aa>9) write(aa/10);
	putchar('0'+aa%10);
	return;
}
const int mod=998244353;
int n,m,len;
int fac[10005],ny[10005];
int f[10005][10005];
char a[10005],b[10005];
int ksm(int aa,int bb)
{
	int now=1;
	while(bb)
	{
		if(bb&1) now=1ll*now*aa%mod;
		aa=1ll*aa*aa%mod;bb>>=1;
	}
	return now;
}
int C(int aa,int bb)
{
	return 1ll*fac[bb]*ny[aa]%mod*ny[bb-aa]%mod;
}
int main()
{
	cin>>a>>b;
	len=strlen(a);fac[0]=1;
	for(int i=1;i<=len;++i) fac[i]=1ll*fac[i-1]*i%mod;
	ny[len]=ksm(fac[len],mod-2);
	for(int i=len;i;i--) ny[i-1]=1ll*ny[i]*i%mod;
	for(int i=0;i<len;++i) 
	if(a[i]=='1'&&b[i]=='1') n++;
	else if(a[i]=='1') m++;
	f[0][0]=1;
	for(int i=0;i<=n;++i)
	for(int j=0;j<=m;++j)
	{
		if(j) f[i][j]=(f[i][j]+1ll*f[i][j-1]*j*j%mod)%mod;
		if(i) f[i][j]=(f[i][j]+1ll*f[i-1][j]*i*j%mod)%mod;
	}
	for(int i=0;i<n;++i) 
	f[n][m]=(f[n][m]+1ll*f[i][m]*fac[n-i]%mod*fac[n-i]%mod*C(n-i,n+m)%mod*C(n-i,n)%mod)%mod;
	write(f[n][m]);
	return 0;
}

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

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

int main(void){
	int n;
	std::vector<int> v;
	for(int i=2;;i++){
		if(isprime(i)){
			v.push_back(i);
			if(i>50000)break;
		}
	}
	while(cin>>n){
		vector<int>::iterator it=lower_bound(v.begin(),v.end(),n+1);
		cout<<((*(it-1)==n)?(*(it-2)):(*(it-1)))<<" "<<*it<<endl;
	}
	return 0;
}

Measured memory_bytes: 3052
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
print('YES' if sum(A)%2 != 1 else 'NO')


Measured memory_bytes: 16580
n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    S, C = map(int, input().split())
    s.append(S)
    c.append(C)
ans = -1
for x in range(1000):
    st = str(x)
    if len(st) != n: continue
    ok = True
    for i in range(m):
        if int(st[s[i] - 1]) != c[i]: ok = False
    if ok:
        ans = x
        break
print(ans)

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

const int N = 2e5 + 5;
typedef long long LL;

int n, a[N], sum;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) 
		cin>>a[i], sum ^= a[i];
	for(int i = 1; i <= n; i++)
		cout<<(sum^a[i])<<" ";
	return 0;
}

Measured memory_bytes: 4372
#include <cstdio>
int ck[15];
int main() {
	ck[2] = 3;
	ck[4] = ck[6] = ck[9] = ck[11] = 2;
	int x, y; scanf("%d %d", &x, &y);
	if (ck[x] == ck[y])puts("Yes");
	else puts("No");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
constexpr long long int Mod = 1e9 + 7;

vector< vector<long long int> > matrix_product(vector< vector<long long int> > &A, vector< vector<long long int> > &B){
  int n = A.size(), m = B[0].size(), l = A[0].size();
  vector< vector<long long int> > ret(n,vector<long long int>(m, 0));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < m; ++j){
      for(int k = 0; k < l; ++k){
        ret[i][j] += (A[i][k]*B[k][j])%Mod;
        ret[i][j] %= Mod;
      }
    }
  }
  return ret;
}

vector< vector<long long int> > matrix_pow(const vector< vector<long long int> > &P, long long int N){
  vector< vector<long long int> > ret(P.size(),vector<long long int>(P.size(),0LL)), t = P;
  for(int i = 0; i < P.size(); ++i) ret[i][i] = 1LL;
  int k = 0;
  while((1LL<<k) <= N){
    if((N>>k)&1){
      ret = matrix_product(ret,t);
    }
    ++k;
    t = matrix_product(t,t);
  }
  return ret;
}

long long int Fibonacci(long long int t){
  vector< vector<long long int> > A(2, vector<long long int>(2, 1LL));
  A[1][1] = 0LL;
  vector< vector<long long int> > F(1, vector<long long int>(2, 1LL)), A_ = matrix_pow(A, t);
  F[0][1] = 0LL;
  return matrix_product(F, A_)[0][0]%Mod;
}

int main(){
  long long int K;
  cin >> K;
  long long int ok = -1, ng = 2e9;
  while(ng - ok > 1){
    long long int m = (ok + ng)/2;
    if((m/2)*(m/2+1) + (m%2)*(m/2+1) < K) ok = m;
    else ng = m;
  }
  //cout << "ok = " << ok << endl;
  long long int d = K - (ok/2)*(ok/2+1) - (ok%2)*(ok/2+1), x = ok + 3 - 2*d, y = 2*d - 1;
  //cout << "x, y = (" << x << ", " << y << ")" << endl;
  if((ok+1)%2 && x < y){
    x += 1;
    y -= 1;
  }
  //cout << "x, y = (" << x << ", " << y << ")" << endl;
  cout << (Fibonacci(x)*Fibonacci(y))%Mod << endl;
  return 0;
}




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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int d=100000;
    for(int i=0; i<n; i++) {
        d+=d/20;
        d+=999;
        d-=d%1000;
    }
    cout<<d<<'\n';
    return 0;
}



Measured memory_bytes: 3024
#include <iostream>
using namespace std;
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; }
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81684
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1000010;
int n,k,a,s[MAXN];
ll ans;
map <int,int> m;
int main () {
	scanf("%d%d",&n,&k);
	m[0]++;
	for (int i=1;i<=n;i++) {
		scanf("%d",&a);
		s[i+1]=((s[i]+a-1)%k+k)%k;
		if (i-k+1>0) {m[s[i-k+1]]--;}
		ans+=m[s[i+1]];
		m[s[i+1]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 100000 + 1000;
const long long INF = 0x1f1f1f1f1f1f1f1fll;

int n, cur = 0;
long long f[2][3];

void update(char op, int val)
{
	cur ^= 1;

	f[cur][0] = f[cur ^ 1][0] + (op == '-' ? -1 : 1) * val;
	f[cur][1] = f[cur ^ 1][1] - (op == '-' ? -1 : 1) * val;
	f[cur][2] = f[cur ^ 1][2] + (op == '-' ? -1 : 1) * val;

	if(op == '-')
	{
		f[cur][1] = max(f[cur][1], f[cur ^ 1][0] - val);
		f[cur][2] = max(f[cur][2], f[cur ^ 1][1] + val);
	}

	f[cur][0] = max(f[cur][0], f[cur][1]);
	f[cur][0] = max(f[cur][0], f[cur][2]);
	f[cur][1] = max(f[cur][1], f[cur][2]);

	// cerr << f[cur][0] << ' ' << f[cur][1] << ' ' << f[cur][2] << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n;

	f[cur][0] = 0;
	f[cur][1] = f[cur][2] = -INF;

	char op[5] = {};
	int val;

	cin >> val;
	update('+', val);
	for(int i = 2; i <= n; i++)
	{
		cin >> op >> val;
		update(op[0], val);
	}
	long long ans = f[cur][0];
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 764
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ss = br.readLine().split(" ");
        int n = Integer.parseInt(ss[0]), k = Integer.parseInt(ss[1]), l = Integer.parseInt(ss[2]);
        UnionFind ufr = new UnionFind(n), uft = new UnionFind(n);
        for(int i = 0; i < k; i++) {
            ss = br.readLine().split(" ");
            ufr.unite(Integer.parseInt(ss[0]) - 1, Integer.parseInt(ss[1]) - 1);
        }
        for(int i = 0; i < l; i++) {
            ss = br.readLine().split(" ");
            uft.unite(Integer.parseInt(ss[0]) - 1, Integer.parseInt(ss[1]) - 1);
        }
        Map<String, Integer> map = new HashMap<>();
        List<String> keys = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            String key = new StringBuilder().append(ufr.find(i)).append(' ').append(uft.find(i)).toString();
            keys.add(key);
            Integer val = map.get(key);
            map.put(key, val == null ? 1 : val + 1);            
        }
        System.out.println(keys.stream()
            .map(key -> map.get(key))
            .map(val -> String.valueOf(val))
            .collect(Collectors.joining(" ")));
    }
}

class UnionFind {
    int[] parent;
    int[] rank;

    public UnionFind(int size) {
        parent = new int[size];
        rank = new int[size];
        for(int i = 0; i < size; i++) {
            parent[i] = i;
        }
    }

    public int find(int x) {
        return parent[x] == x ? x : find(parent[x]);
    }

    public void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) {
            return;
        }
        if(rank[x] < rank[y]) {
            parent[x] = y;
        } else {
            parent[y] = x;
            if(rank[x] == rank[y]) rank[x] ++;
        }
    }

    public boolean same (int x, int y) {
        return find(x) == find(y);
    }

    public void show() {
        System.out.println(Arrays.toString(parent));
    }
}

Measured memory_bytes: 84192
from heapq import heappop, heappush
class MedianContainer:
    def __init__(self):
        self._left_q = []
        self._right_q = []
        self._left_sum = 0
        self._right_sum = 0
        self._med1, self._med2 = None, None
        self._med = None

    def insert(self, x):
        if not any([self._med, self._med1, self._med2]): # First insert
            self._med = x
        elif self._med is None and self._med1 is not None and self._med2 is not None:
            if x <= self._med1:
                heappush(self._left_q, x*(-1))
                heappush(self._right_q, self._med2)
                self._left_sum += x
                self._right_sum += self._med2
                self._med = self._med1
            elif x >= self._med2:
                heappush(self._left_q, self._med1*(-1))
                heappush(self._right_q, x)
                self._left_sum += self._med1
                self._right_sum += x
                self._med = self._med2
            else:
                heappush(self._left_q, self._med1*(-1))
                heappush(self._right_q, self._med2)
                self._left_sum += self._med1
                self._right_sum += self._med2
                self._med = x
            self._med1, self._med2 = None, None
        else:
            if x <= self._med:
                heappush(self._left_q, x*(-1))
                self._med1 = heappop(self._left_q)*(-1)
                self._left_sum += x
                self._left_sum -= self._med1
                self._med2 = self._med
            else:
                heappush(self._right_q, x)
                self._right_sum += x
                self._med1 = self._med
                self._med2 = heappop(self._right_q)
                self._right_sum -= self._med2
            self._med = None

        
    def get_med(self):
        if self._med is not None:
            return [self._med]
        else:
            return [self._med1, self._med2]


    def get_left_sum(self):
        return self._left_sum


    def get_right_sum(self):
        return self._right_sum


    def get_half_len(self):
        return len(self._left_q)


q = int(input())
ans = 0

mid_1 = 0
mid_2 = 0
mid = 0
left_q = []
right_q = []
left_sum = 0
right_sum = 0
const_b = 0
ansl = []

mc = MedianContainer()
for _ in range(q):
    row = list(input().split())
    if row[0] == '2':
        half_len = mc.get_half_len()
        meds = mc.get_med()
        if len(meds) == 1:
            left_sum = meds[0]*half_len - mc.get_left_sum()
            right_sum = mc.get_right_sum() - meds[0]*half_len
            ans = left_sum + right_sum + const_b
            ansl.append((meds[0],ans))
        else:
            left_sum = meds[0]*half_len - mc.get_left_sum()
            right_sum = mc.get_right_sum() - meds[0]*half_len
            ans = left_sum + right_sum + (meds[1]-meds[0]) + const_b
            ansl.append((meds[0],ans))
    
    else:
        a,b = int(row[1]), int(row[2])
        const_b += b
        mc.insert(a)


for ax,av in ansl:
    print(ax,av)

Measured memory_bytes: 93236
#include<stdio.h>
int main(void)
{
	int num, counter[26]={0},i;
	char str;
	
	
	while( scanf("%c",&str) != EOF )
	{
		num = str - 'A';
		
		if( str >= 'A' && str <= 'Z' )
		{
			counter[num]++;
		}
		else if( str >= 'a' && str <= 'z' )
		{
			num -= 32;
			counter[num]++;
		}
		
	}
	
	
	for(i=0;i<26;i++)
	{
		printf("%c : %d\n",'a' + i,counter[i]);
	}
	
	return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    if(str[5] == '0' && (str[6] >= '1' && str[6] <= '4')){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
flag = 0
for i in range(40):
    for i in range(len(A)):
        if A[i] % 2 == 0:
            A[i] //= 2
        else:
            flag = 1
    if flag == 0:
        ans += 1
    else:
        break
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int W = 0;
  for (int i = 0; i < n; ++i) W += s[i] == '.';
  int res = n, w = 0;
  for (int i = 0; i <= n; ++i) {
    res = min(res, i - w + (W - w));
//    if (i == 2) cerr << w << ' ' << W << endl;
    if (i < n) w += s[i] == '.';
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 20;

int main(void){

    int N,M; cin>>N>>M;
    int gu=0,ki=0;
    for (int i = 1; i <= N-1; ++i) {
        for (int j = i+1; j <= N; ++j) {
            gu++;
        }
    }
    for (int i = 1; i <= M-1 ; ++i) {
        for (int j = i+1; j <= M; ++j) {
            ki++;
        }
    }
    cout<<gu+ki<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
        return 0;
    }else{
        cout << "No" << endl;
        return 0;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  while(n) {
    if (n < k) break;
    ans++;
    n /= k;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=50;
const ll MAX_A=1e16+1000;
int N;
ll a[MAX_N];
int fmi(){
	int ret=0;
	FOR(i,1,N){
		if (a[i]>a[ret]){
			ret=i;
		}
	}
	return ret;
}
ll C(ll y){
	ll ret=0;
	REP(i,N){
		ret+=max((a[i]-y)/(N+1),0ll);
	}
	return ret;
}
int main(){
	cin>>N;
	REP(i,N)cin>>a[i];
	ll sm=0;
	REP(i,N)sm+=a[i];
	ll x=max(sm-N*N,0ll);
	ll ans=x;
	REP(i,N){
		a[i]+=x;
	}
	ll lb=-1,ub=MAX_A;
	while(ub-lb>1){
		ll mid=(lb+ub)>>1;
		if (C(mid)<=x){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	REP(i,N){
		x-=max((a[i]-ub)/(N+1),0ll);
		a[i]-=max((a[i]-ub)/(N+1),0ll)*(N+1);
	}
	REP(i,x){
		a[fmi()]-=N+1;
	}
	for(;;){
		int inx=fmi();
		if (a[inx]<=N-1){
			break;
		}else{
			a[inx]-=N;
			REP(i,N){
				if (i!=inx){
					a[i]++;
				}
			}
		}
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < s.length() - 1; i++)
	{
		if (s.substr(i, 2) == "AC")
		{
			cout << "Yes\n"; return 0;
		}
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll sum = accumulate(A.begin(), A.end(), (ll)0);

    if (sum % (N * (N + 1) / 2) != 0) {
        cout << "NO" << endl;
        return 0;
    }

    ll k = sum / (N * (N + 1) / 2);

    for (ll i = 0; i < N; i++) {
        ll d = A[(i + 1) % N] - A[i] - k;
        if (d > 0 || d % N != 0) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 5006
#define MOD 1000000007
using namespace std;
long long d[MAXN][MAXN];
int n,m;
char s[MAXN];
long long ksm(long long a,int m)
{
	if(m==0) return 1;
	long long nex=ksm(a,m/2);
	nex=nex*nex%MOD;
	if(m%2==0) return nex;
	return nex*a%MOD;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	m=strlen(s);
	d[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=n;j++)
		{
			d[i+1][j+1]+=d[i][j]*2;
			d[i+1][j+1]%=MOD;
			d[i+1][max(j-1,0)]+=d[i][j];
			d[i+1][max(j-1,0)]%=MOD;
		}
	printf("%lld",d[n][m]*ksm(500000004,m)%MOD);
}

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

int main() {
	int n;
	cin>>n;
    long long int a[n];
    for( int i=0; i<n; i++)
    cin>>a[i];
    if(n==2)
    {
        cout<<abs(a[1]-a[0])<<endl;
    }
    else
    {
    long long int dp[n-1];
    dp[n-2] = abs(a[n-1] - a[n-2]);
    dp[n-3] = abs(a[n-1] - a[n-3]);
    for( int i=n-4; i>=0; i--)
    {
        dp[i] = min(abs(a[i]-a[i+1])+dp[i+1] , abs(a[i]-a[i+2]) +dp[i+2]);
    }
    
    cout<<dp[0]<<endl;
    }
	return 0;
}

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

int main()
{
    int N;
    cin >> N;
    int A[N][2];
    for (int n = 0; n < 2; n++)
    {
        for (int i = 0; i < N; i++)
        {
            cin >> A[i][n];
        }
    }

    // 右に移動する回数iを選ぶ
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        int temp = 0;
        for (int j = 0; j <= i; j++)
        {
            temp += A[j][0];
        }
        for (int j = i; j < N; j++)
        {
            temp += A[j][1];
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
      let mut iter = $s.split_whitespace();
      let mut next = || { iter.next().unwrap() };
      input_inner!{next, $($r)*}
  };
  ($($r:tt)*) => {
      let stdin = std::io::stdin();
      let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
      let mut next = move || -> String{
          bytes
              .by_ref()
              .map(|r|r.unwrap() as char)
              .skip_while(|c|c.is_whitespace())
              .take_while(|c|!c.is_whitespace())
              .collect()
      };
      input_inner!{next, $($r)*}
  };
}

macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

  ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
      let $var = read_value!($next, $t);
      input_inner!{$next $($r)*}
  };
  ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
      let mut $var = read_value!($next, $t);
      input_inner!{$next $($r)*}
  };
}

macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
      ( $(read_value!($next, $t)),* )
  };

  ($next:expr, [ $t:tt ; $len:expr ]) => {
      (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  };

  ($next:expr, chars) => {
      read_value!($next, String).chars().collect::<Vec<char>>()
  };

  ($next:expr, usize1) => {
      read_value!($next, usize) - 1
  };

  ($next:expr, $t:ty) => {
      $next().parse::<$t>().expect("Parse error")
  };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
  input!{
    r:i64,
  }
  println!("{}",r*r);
}


fn is_prime(x:i64) -> bool {
  if x == 2 {return true;}
  if x < 2 || x % 2 == 0 {return false;}
  let mut j = 3;
  while j <= (x as f64).sqrt() as i64 {
      if x % j == 0 {
          return false;
      }
      j += 2;
  }
  true
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

K, X = LI()

print(*[i for i in range(X-K+1, X+K)])

Measured memory_bytes: 39024
#include <stdio.h>

#define BUFSIZE 100

unsigned GetDigit(unsigned num){
    char buf[BUFSIZE];
    return sprintf(buf,"%u",num);
}

int	main(void)
{
  	int	n;
  	int	i;
  	int	cnt;
  
  	scanf("%d", &n);
  
  	cnt = 0;
  	for(i=1; i<=n; i++)
    {
      	if (GetDigit(i) % 2 == 1)
          	cnt++;
    }
  	printf("%d", cnt);
  	return (0);
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::vector;

using LL = long long;

int main() {
  LL l, r;
  cin >> l >> r;
  
  if (r - l >= 2019) {
    cout << 0 << endl;
    return 0;
  }

  LL ans = std::numeric_limits<long>::max();
  for (LL i = l; i < r; i++) {
    for (LL j = i + 1; j <= r; j++) {
      ans = std::min(ans, i * j % 2019);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			int n = Integer.parseInt(line);
			line = reader.readLine();
			char[] s =line.toCharArray();
			String ans = "Yes";

			if(n%2 != 0){
				ans = "No";
			}else{
				for(int i = 0; i < n/2; i++) {
					if(s[i] != s[(n/2) + i]) {
						ans = "No";
					}
				}
			}
			System.out.println(ans);
		} catch(IOException e) {
			System.out.println(e);
		} catch(NumberFormatException e) {
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

    int cnt;
    if (s[0] == s[s.size() - 1])
    {
        cnt = 3;
    }
    else
    {
        bool h = false;
        for (int i = 1; i < s.size(); i++)
        {
            if (s[i] == s[0])
                h = true;
        }

        for (int i = 0; i < s.size() - 1; i++)
        {
            if (s[i] == s[s.size() - 1])
                h = true;
        }

        if (h)
            cnt = 4;
        else
            cnt = 2;
    }

    cout << ((s.size() - cnt) % 2 == 1 ? "First" : "Second") << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<int> a(n);
	for( auto &k : a ) cin >> k;
	int cnt = 0;
	bool p = false;
	bool m = false;
	for( int i = 0; i < n-1; ++i ){
		if( !p && !m ){
			if( a[i+1] > a[i] ) p = true;
			else if( a[i+1] < a[i] ) m = true;
		} else if( p ){
			if( a[i+1] < a[i] ){
				p = false;
				++cnt;
			}
		} else {
			if( a[i+1] > a[i] ){
				m = false;
				++cnt;
			}
		}
	}
	cout << cnt+1 << endl;
	return 0;
}

Measured memory_bytes: 640
def BinarySearch(intList, target):
    left = 0
    right = len(intList) - 1
    while left <= right:
        mid = (left + right) // 2
        if intList[mid] == target:
            return True
        elif target < intList[mid]:
            right = mid -1
        elif intList[mid] < target:
            left = mid + 1
    return False


n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0

for i in range(len(T)):
    if BinarySearch(S, T[i]):
        cnt += 1
print(cnt)


Measured memory_bytes: 16708
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int mod = 1e9 + 7;

ll add(ll x, ll y) {
	x += y;
	if (x >= mod) {
		x -= mod;
	}
	return x;
}

ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) {
		x += mod;
	}
	return x;
}

ll mul(ll x, ll y) {
	x *= y;
	return x % mod;
}

ll pwr(ll x, ll e) {
	ll res = 1;
	while (e) {
		if (e & 1) {
			res = mul(res, x);
		}
		x = mul(x, x);
		e /= 2;
	}
	return res;
}

const int X = 510;

int a[X], choose[X][X], pre_pwr[X][X];
ll dp[2][X][X];

int main() {
	fast_cin();
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; ++i) {
		int l; cin >> l;
		++a[l];
	}
	for (int i = 0; i <= x; ++i) {
		choose[i][0] = choose[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
		}
	}
	for (int i = 0; i <= x; ++i) {
		pre_pwr[i][0] = 1;
		for (int j = 1; j <= n; ++j) {
			pre_pwr[i][j] = mul(pre_pwr[i][j - 1], i);
		}
	}
	dp[(x + 1) & 1][0][0] = 1;
	for (int i = x; i >= 1; --i) {
		memset(dp[i & 1], 0, sizeof(dp[i & 1]));
		auto cur = dp[i & 1], prv = dp[(i + 1) & 1];
		for (int sum = 0; sum <= x; ++sum) {
			int max_cnt = sum / i;
			for (int cnt = 0; cnt <= max_cnt; ++cnt) {
				for (int c = 0; c <= cnt; ++c) {
					cur[sum][cnt] = add(cur[sum][cnt], mul(prv[sum - i * c][cnt - c], choose[cnt][c]));
				}
				cur[sum][cnt] = mul(cur[sum][cnt], pre_pwr[sum - (i - 1) * cnt][a[i]]);
			}
		}
	}
	ll ans = 0;
	for (int sum = 0; sum <= x; ++sum) {
		for (int cnt = 0; cnt <= sum; ++cnt) {
			ll val = mul(dp[1][sum][cnt], choose[x - sum + 1][cnt]);
			ans = add(ans, mul(pwr(mod - 1, (x - sum) & 1), val));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6400
program test
implicit none
integer :: n,x,i,a
double precision :: m(100)=0.


read(*,*) n,x

do i = 1, n
 read(*,*) m(i)
enddo
 
write(*,*) int( (x - sum(m(1:n)))  / minval(m(1:n))) + n


 
end program

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int main() {
	int n;
	string s;
	cin >> n >> s;
	
	int x = 0, ans = 0;
	inc(i, n) {
		if(s[i] == 'I') { x++; } else { x--; }
		setmax(ans, x);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
# ABC094D - Binomial Coefficients (ARC095D)
def main():
    # pascal's triangle := mid area (nCn/2) is the biggest
    N = int(input())
    A = tuple(map(int, input().split()))
    n = max(A)
    mid, r, dif = n / 2, -1, float("inf")
    for i in A:
        if i != n:
            x = abs(mid - i)
            if x < dif:
                r, dif = i, x
    print(n, r)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> t(n);
    vector<ll> d(n);
    for(int i = 0; i < n; i++)
    {
        cin >> t[i] >> d[i];
    }

    vector<ll> all(n+1);
    vector<ll> other;
    int size = 0;
    for(int i = 0; i < n; i++)
    {
        int a = t[i];
        int b = d[i];
        if(all[a] == 0)
        {
            all[a] = b;
            size++;
            continue;
        }
        if(all[a] < b)
        {
            ll tmp = all[a];
            all[a] = b;
            other.push_back(tmp);
        }
        else
        {
            other.push_back(b);
        }
    }
    sort(all.begin(), all.end());
    reverse(all.begin(), all.end());
    sort(other.begin(), other.end());
    reverse(other.begin(), other.end());
    vector<ll> sum_a(n+1);
    for(int i = 1; i <= size; i++)
    {
        sum_a[i] = sum_a[i-1] + all[i-1];
    }
    vector<ll> sum_o(n+1);
    for(int i = 1; i <= n-size; i++)
    {
        sum_o[i] = sum_o[i-1] + other[i-1];
    }

    ll ans = 0;
    for(ll i = 1; i <= size && i <= k; i++)
    {
        ans = max(ans, i * i + sum_a[i] + sum_o[k-i]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 4852
N,X,Y = map(int,input().split())
from itertools import combinations
counter = [0]*(N+1)

for com in combinations(range(N),2):
    i,j = com
    min_path = min(j-i,abs(X-1-i)+abs(Y-1-j)+1)
    counter[min_path]+=1

for i in range(1,N):
    print(counter[i])

Measured memory_bytes: 46420
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define f(ii,n) for(ii=0;ii<n;ii++)
#define F(ii,a,n) for(ii=a;ii<n;ii++)
#define read(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
void swap(ll *xp,ll *yp){
	ll temp = *xp;
	*xp = *yp;
	*yp = temp;
}

ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}

void solve(){
	ll n,m;
	cin>>n>>m;
	ll ar[m];
	read(ar,m);
	ll sum=0,i,j;
	for(i=0;i<m;i++){
		sum+=ar[i];
	}
	if(sum>n){
		cout<<"-1\n";
	}
	else{
		cout<<n-sum<<endl;
	}
}
int main(){
	solve();
	//freopen("filename.txt","r",stdin);
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<pair<long long, long long>> w(N);
    for(int i = 0; i < N; i++){
        cin >> w[i].second >> w[i].first;
    }
    sort(w.begin(), w.end());
    long long t = 0;
    for(int i = 0; i < N; i++){
        t += w[i].second;
        if(t > w[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3328
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (a, b, c, k) = {
        let abck = get_line().split_whitespace()
            .map(|e| e.parse().unwrap())
            .collect::<Vec<i64>>();
        (abck[0], abck[1], abck[2], abck[3])
    };

    let mut sum = 0;

    if k < a {
        sum = k;
    } else {
        sum = a;

        let mut diff = k - a;
        if diff > 0 {
            diff -= b;
            if diff > 0 {
                sum -= diff;
            }
        }
    }
    println!("{}", sum);
}


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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = "";
            while ((line = Console.ReadLine()) != null)
            {
                string output = "";
                for (int i = 0; i < line.Length; i++)
                {
                    if (line[i] == '@')
                    {
                        int l = int.Parse(line[i + 1].ToString());
                        char m = line[i + 2];
                        for (int j = 0; j < l; j++) output += m.ToString();
                        i += 2;
                    }
                    else output += line[i].ToString();
                }
                Console.WriteLine(output);
            }
        }
    }
}

Measured memory_bytes: 5304
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, x int

	fmt.Sscan(getNextLine(scanner), &n, &x)

	xxx := getIntList(scanner)
	xxx = append(xxx, x)

	sort.Sort(sort.IntSlice(xxx))

	ans := xxx[1] - xxx[0]
	for i := 0; i < n; i++ {
		ans = gcd(ans, xxx[i+1]-xxx[i])
	}

	fmt.Println(ans)
}
func gcd(m, n int) int {
	if m < n {
		m, n = n, m
	}
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}


Measured memory_bytes: 14720
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)

	stdin.Scan()
	stdin.Scan()
	text := stdin.Text()
	nums := strings.Split(text, " ")
	maxIdx := 0
	cnt := 0
	for idx, num := range nums {
		n, _ := strconv.Atoi(num)
		max, _ := strconv.Atoi(nums[maxIdx])

		if n >= max {
			maxIdx = idx
			cnt++
		}
	}

	fmt.Printf("%v\n", cnt)
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/01/06  Problem: EDU_DP J / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

yukicoder108

----解説ここまで---- */
LL N;

double dp[302][302][302];
double f(int a, int b, int c) {
	if (dp[a][b][c] > -1)return dp[a][b][c];

	double &ret = dp[a][b][c];
	ret = 0;
	if (a || b || c)ret = 1.0*N / (a + b + c);

	if (a)ret += f(a - 1, b + 1, c)*a / (a + b + c);
	if (b)ret += f(a, b - 1, c + 1)*b / (a + b + c);
	if (c)ret += f(a, b, c - 1) *c / (a + b + c);


	return ret;
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N;
	VI a(3, 0);
	FOR(i, 0, N) {
		int x; cin >> x;
		a[3 - x]++;
	}
	fill(**dp, **dp + 302 * 302 * 302, -1);
	double ans = f(a[0], a[1], a[2]);
	cout << fixed << setprecision(10) << ans << "\n";

	return 0;
}

Measured memory_bytes: 215552
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5+5;

int a[MAX_N];

int main()
{
	int n, t, cnt = 0, diff = 0;
	cin >> n >> t;
	for (int i = 0; i < n; i++) cin >> a[i];
	int mn = 0;
	for (int i = 1; i < n; i++)
	{
		mn = a[i] < a[mn]?i:mn;
		if (a[i] > a[mn])
		{
			if (diff == a[i]-a[mn]) cnt++;
			else if (diff < a[i]-a[mn])
			{
				diff = a[i]-a[mn];
				cnt = 1;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640