akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int M=1e9+7;

int inv(int a) {
	int k=M-2;
	int r=1, t=a;
	while(k) {
		if(k%2) r=1ll*r*t%M;
		t=1ll*t*t%M;
		k/=2;
	}
	return r;
}

const int MAXf=200050;
int H,W,A,B;
int fac[MAXf],invfac[MAXf];

int count(int h,int w) {
	h--, w--;
	return 1ll*fac[h+w]*invfac[h]%M*invfac[w]%M;
}

int main() {
	fac[0]=1;
	for(int i=1;i<MAXf;i++) fac[i]=1ll*fac[i-1]*i%M;
	for(int i=0;i<MAXf;i++) invfac[i]=inv(fac[i]);
	cin >> H >> W >> A >> B;
	int ans=0;
	for(int i=B+1;i<=W;i++) {
		ans=(ans+1ll*count(H-A, i)*count(A, W-i+1))%M;
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long
#define vec vector<ll>
#define sortv(a); sort(a.begin(), a.end());
#define rev(a); reverse(a.begin(), a.end());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/
ll n,k; ll fact[200005]; vec a;

ll power(ll x, ll y, ll m) { // x ^ y
    if (y == 0) return 1; 
    ll p = power(x, y/2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; 
} 
ll inv(ll a) { return power(a, MOD - 2, MOD) % MOD; } 
ll choose(ll n, ll k) { if (n==0) return 1;return (((fact[n] * inv(fact[k])) % MOD) * inv(fact[n-k])) % MOD; }

void solve() {
	fact[0]=1;
	fact[1]=1;
	FOR(i,2,200005) {
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}

	sortv(a);
	vec cumsum(n+1,0);
	FOR(i,1,n+1) {
		cumsum[i]=a[i-1];
		cumsum[i]+=cumsum[i-1];
		cumsum[i]%=MOD;
	}

	ll out=0;
	FOR(j,0,n-k+1) {
		ll temp=choose(k-2+j,j);
		ll sum=(cumsum[n]-cumsum[k+j-1]);
		sum-=(cumsum[n-k+1-j]-cumsum[0]);
		sum%=MOD;
		temp*=sum;
		temp%=MOD;
		out+=temp;
		out%=MOD;
	}
	cout<<out;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin>>n>>k;
	FOR(i,0,n) {
		ll in;
		cin>>in;
		a.push_back(in);
	}
	solve();
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	char x, y;
	cin >> x >> y;
	if (x < y)cout << "<" << endl;
	else if (x > y)cout << ">" << endl;
	else cout << "=" << endl;
	int z;
	cin >> z;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,x,l,r;
int main()
{
	cin>>k>>x;
	l=max(x-k+1,-1000000);
	r=min(k+x-1,1000000);
	for(int i=l;i<=r;i++) cout<<i<<" ";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int ans = 0;
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= k; j++) {
				if (0 <= s - (i +j) && s - (i +j) <= k) ans++;
			}
		}

		System.out.println(ans);


		sc.close();

	}

}

Measured memory_bytes: 35648
from collections import deque
X,Y,Z,K=map(int,input().split())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
C=[int(i) for i in input().split()]
#AとBのわのうちでかい順にK個
ABsum=[]
for i in A:
    for j in B:
        ABsum.append(i+j)
ABsum=sorted(list(ABsum),reverse=True)
sumu=[]
for i in range(min(K,X*Y)):
    for j in C:
        sumu.append(ABsum[i]+j)
sumu=sorted(list(sumu),reverse=True)
for i in range(K):
    print(sumu[i])

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

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

using namespace std;

int main()
{
	int ans=1000;
	string str;
	cin >> str;
	rep(i, str.size()-2){
		int sum=0;
		sum += (str[i]-'0')*100;
		sum += (str[i+1]-'0')*10;
		sum += (str[i+2]-'0');
		ans = min(ans, abs(sum-753));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == m) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	if (X < 0) { X = -X; }
	if (X / D > K) {
		cout << X - K * D;
	} else {
		if (K % 2 == 0) {
			if (X / D % 2 == 0)
				cout << X - X / D * D;  // N
			else
				cout << X / D * D + D - X;  // N+1
		}
		if (K % 2 == 1) {
			if (X / D % 2 == 1)
				cout << X - X / D * D;  // N
			else
				cout << X / D * D + D - X;  // N+1
		}
	}
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.S;
        io.Write(n.SequenceEqual(n.Reverse()) ? "Yes" : "No");
    }
}

Measured memory_bytes: 13280
#include"iostream"
#include "string"
using namespace std;
int main(){
    int a,b;
    string small = "a < b";
    string large = "a > b";
    string equal = "a == b";
    string ans;
    cin >> a >> b;
    if(a < b)ans = small;
    else if(a > b)ans = large;
    else ans = equal;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3152
#pragma once
#include <string.h>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
#define INF 1000000007
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[y] = px;
	}
	else {
		pr[x] = py;
	}
	return true;
}

// dinic
struct max_flow {
	struct edge { int to, cap, rev;
	edge(int _to, int _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {}
	};
	int V;
	vector<vector<edge>> G;
	vector<int> itr, level;

	max_flow(int V) : V(V) { G.assign(V, vector<edge>()); }

	void add_edge(int from, int to, int cap) {
		G[from].push_back(edge (to, cap, (int)G[to].size() ));
		G[to].push_back(edge (from, 0, (int)G[from].size() - 1 ));
	}

	void bfs(int s) {
		level.assign(V, -1);
		queue<int> q;
		level[s] = 0; q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto &e : G[v]) {
				if (e.cap > 0 and level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}

	int dfs(int v, int t, int f) {
		if (v == t) return f;
		for (int& i = itr[v]; i < (int)G[v].size(); ++i) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int run(int s, int t) {
		int ret = 0, f;
		while (bfs(s), level[t] >= 0) {
			itr.assign(V, 0);
			while ((f = dfs(s, t, INF)) > 0) ret += f;
		}
		return ret;
	}
};
vector<vector<int> > calcNext(const string &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

const int MOD = 1000000007;
// mod 1000000007 の世界で a += b する関数
void add(long long &a, long long b) {
	a += b;
	if (a >= MOD) a -= MOD;
}
ll c[26];
ll memo[26];
ll rec(int i) {

	if (i == 26) {
		return 1;
	}
	ll &res = memo[i];
	if (~res) return res;
	res = 0;
	for (size_t j = i + 1; j <= 26; j++)
	{
		ll v = c[i] * rec(j);
		v %= INF;
		res += v;
		res %= INF;
	}
	return res;
}
void solv() {
	int n;
	
	cin >> n;
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	fill(c, c + 26, 0);
	memset(memo, -1, sizeof(memo));
	for (size_t i = 0; i < n; i++)
	{
		c[S[i] - 'a']++;
	}
	
	// 集計
	ll res = 0;
	for (size_t i = 0; i < 26; i++)
	{
		res += rec(i);
		res %= INF;
	}

	cout << res << endl;
}


int main() {
	solv();

	return 0;
}


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

#define pb push_back
#define mp make_pair

#define f first
#define s second

typedef long long int ll;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f;
const int MOD = 1000000007;

int main()
{
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);
	
	string s;
	cin >> s;
	
	int l = 0, r = int(s.size())-1;
	while(r > l){
		if(s[l] != 'A')l++;
		if(s[r] != 'Z')r--;
		
		if(s[l] == 'A' && s[r] == 'Z'){
			break;
		}
	}
	cout << r-l+1 << endl; 
}


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

int main() {
    int a,b;
    cin>>a>>b;
    if((a*b)%2==0){
        cout<<"Even"<<endl;
    }
    else{
        cout<<"Odd"<<endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[4][104]={0},n,i,j;
    int dp[4][104]={0};
    scanf("%d",&n);
    for(int i=1;i<=2;i++)
       for(int j=1;j<=n;j++)
        scanf("%d",&a[i][j]);
    for(i=1;i<=2;i++)
       for(j=1;j<=n;j++)
        dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
        printf("%d",dp[2][n]);
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  readInt
  val (min, max) = readLine.split(" ")
    .map(_.toInt)
    .foldLeft((Int.MaxValue, Int.MinValue): (Int, Int))((acc, h) => (math.min(acc._1, h), math.max(acc._2, h)))
  println(max - min)
}


Measured memory_bytes: 25664
#include<iostream>
using namespace std;
typedef long long ll;
int l[100050],r[100050];
int main()
{
	int n,m;
	cin>>n>>m;
	int a=0,b=n;
	for(int i=0;i<m;i++)
	{
		cin>>l[i]>>r[i];
		if(a<l[i])
		a=l[i];
		if(b>r[i])
		b=r[i];
	}
	int ans=b-a+1;
	if(ans>n)
	cout<<n<<endl;
	else if(ans<=0)
	cout<<0<<endl;
	else
	cout<<ans<<endl;
	return 0;
}

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

count = 0
for i in range(n):
  ds = input().split()
  d1 = ds[0]
  d2 = ds[1]
  
  if d1 == d2:
    count += 1
  else:
    count = 0
  
  if count == 3:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 62100
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
using namespace std;
signed main(){
    int a,b,c,d,n=101;
    cin >> a >> b >> c >> d;
    vec(f,n);
    REP(i,n){
        f[i] = 0;
    }
    FOR(i,a,b){
        f[i]++;
    }
    FOR(i,c,d){
        f[i]++;
    }
    int ans=0;
    REP(i,n){
        if(f[i] == 2) ans++;
    }
    cout << ans;
    return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// ABC055B - Training Camp
int main(){
  int64_t N; // 1e5
  cin >> N;

  const int64_t MOD = 1e9 + 7;
  int64_t p = 1;
  for (int i = 1; i <= N; ++i) {
    p = p * i % MOD;
  }

  cout << p << endl;
  return 0;
}



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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 * 100 + 47;

string s;
int CNT[MAX][26];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	RFOR(i, SZ(s), 0)
	{
	    FOR(j,0, 26) CNT[i][j] = CNT[i + 1][j];
	    CNT[i][s[i] - 'a']++;
	}
	
	LL ans = 0;
	FOR(i,0, SZ(s))
	{
	    ans += SZ(s) - i - CNT[i][s[i] - 'a'];
	}
	
	ans++;
	cout << ans << endl;
}

Measured memory_bytes: 20884
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, k, a[100100], b[100100], ans;
int main(){
    scanf("%d %d %d",&n,&m,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    for(int i=1;i<=m;i++) scanf("%d",b+i);
    ans = *min_element(a+1, a+1+n) + *min_element(b+1, b+1+m);
    for(int i=1;i<=k;i++){
        int c, d, e; scanf("%d %d %d",&c,&d,&e);
        ans = min(ans, a[c] + b[d] - e);
    }
    printf("%d",ans);
}

Measured memory_bytes: 1024
#!/usr/bin/env perl
use 5.10.0;
use utf8;
use strict;
use warnings;
use open qw( :utf8 :std );
use Data::Dumper;

chomp( my $line = readline );

my $amount = $line;

my $very = int( $amount / 500 );
#warn "\$very: $very";

my $remain = $amount - $very * 500;
#warn "\$remain: $remain";

my $small = int( $remain / 5 );
#warn "\$small: $small";

say $very * 1000 + $small * 5;


exit;



Measured memory_bytes: 2048
function main(input) { 
  const array = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
  console.log(array[input - 1]); 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
N, Y = map(int, input().split())

answer = (-1, -1, -1)

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if (10000 * x) + (5000 * y) + (1000 * z) == Y:
            answer = (x, y, z)
            break

print(*answer)


Measured memory_bytes: 3060
s = input()
n = (len(s) - 1)
ans = 0
for i in range(2 ** n):
    s2 = s
    for j in range(n):
        if (i >> j) & 1:
            s2 = s2[:(n - j)] + " " + s2[n - j:]
    ans += sum([int(x) for x in s2.split()])

print(ans)


Measured memory_bytes: 71168
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
    int n;
    map<int, int> numbers;
    while (cin >> n) {
        numbers[n]++;
    }
    int maxMode = 0;
    vector<int> maxNumber;
    for (map<int,int>::iterator it=numbers.begin(); it != numbers.end(); ++it) {
        if (it->second > maxMode) {
            maxMode = it->second;
            maxNumber.clear();
            maxNumber.push_back(it->first);
        }
        else if (it->second == maxMode) {
            maxMode = it->second;
            maxNumber.push_back(it->first);
        }
    }
    for (int i = 0; i != maxNumber.size(); ++i) {
        cout << maxNumber[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;

int main() {
	int N;
	LL A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	bool OK = 0;
	rep(i, N + 1) {
		if ((C + D)*i - D*(N - 1) <= B - A&&B - A <= (C + D)*i - C*(N - 1)) {
			OK = 1;
			break;
		}
	}
	if (OK) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int A,B,Q;
ll s[SIZE],t[SIZE],x[SIZE];

int main(){
  cin >> A >> B >> Q;
  rep(i,0,A)cin >> s[i];
  rep(i,0,B)cin >> t[i];
  rep(i,0,Q)cin >> x[i];

  rep(i,0,Q){
    int al,ar,bl,br;
    ar = lower_bound(s,s+A,x[i]) - s;
    al = ar-1;
    br = lower_bound(t,t+B,x[i]) - t;
    bl = br-1;

    ll sr,sl,tr,tl;
    sr = ((ar!=A)?s[ar]:INF);
    sl = ((al!=-1)?s[al]:-INF);
    tr = ((br!=B)?t[br]:INF);
    tl = ((bl!=-1)?t[bl]:-INF);

    ll y = x[i];

    ll ans = min({max(y-sl,y-tl),max(sr-y,tr-y),2*tr-sl-y,2*sr-tl-y,y+sr-2*tl,y+tr-2*sl});
    cout << ans << endl;

  }

  return 0;
}


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


string str;
int input(){
    cin >> str;
    return 0;
}

int solve(){
    int size = str.length();
    // cout << size;
    if (str[size-1] == 's'){
        cout << str << "es" << endl;
    }else{
        cout << str << 's' << endl;
    };
    return 0;
}

int main(){
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3020
def main():
    a = [list(map(int, input().split())) for i in range(3)]
    if (a[1][0] - a[0][0] == a[1][1] - a[0][1]) \
        and (a[1][1] - a[0][1] == a[1][2] - a[0][2]) \
        and (a[2][0] - a[1][0] == a[2][1] - a[1][1]) \
        and (a[2][1] - a[1][1] == a[2][2] - a[1][2]) \
        and (a[0][1] - a[0][0] == a[1][1] - a[1][0]) \
        and (a[1][1] - a[1][0] == a[2][1] - a[2][0]) \
        and (a[0][2] - a[0][1] == a[1][2] - a[1][1]) \
        and (a[1][2] - a[1][1] == a[2][2] - a[2][1]):
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
// D - Ki
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

vi ans(200000);
vvi ab(200000);

void dfs(int p, int c, int v){
	ans[c] += v;
	for(int cc:ab[c]) if(cc!=p) dfs(c,cc,ans[c]);
}

int main(){
	int n,q; cin>>n>>q;

	for(int i=0; i<n-1; i++){
		int a,b; cin>>a>>b;
		ab[--a].push_back(--b);
		ab[b].push_back(a);
	}

	for(int i=0; i<q; i++){
		int p,x; cin>>p>>x;
		ans[--p] += x;
	}

	dfs(-1,0,0);

	for(int i=0; i<n; i++) cout<< ans[i] <<(i<n-1?" ":"\n");
}

Measured memory_bytes: 23424
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

struct team{
  int ans,id,p[10],pena;
  bool operator<(const team &a)const{
    if(this->ans != a.ans){
      return this->ans > a.ans;
    }else if(this->pena != a.pena){
      return this->pena < a.pena;
    }else{
      return this->id < a.id;
    }
  }
};

int main(){
  int t,p,r;
  while(cin>>t>>p>>r){
    if(t==0)break;
    team T[t];
    memset(T,0,sizeof(T));
    for(int i=0;i<t;i++)T[i].id=i+1;

    int tid,pid,tm;
    string mes;
    for(int i=0;i<r;i++){
      cin>>tid>>pid>>tm>>mes;
      tid--;pid--;
      if(mes=="CORRECT"){
	T[tid].ans++;
	T[tid].pena+=T[tid].p[pid]*1200 + tm;
      }else{
	T[tid].p[pid]++;
      }
    }
    sort(T,T+t);
    for(int i=0;i<t;i++)
      cout << T[i].id << " " << T[i].ans << " " << T[i].pena << endl;
  }
  return 0;
}

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

AB=[list(map(int,input().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

for i in range(1,N):
    AB[i][0]+=AB[i-1][0]

s=0

for i in range(N):
    if AB[i][0]>AB[i][1]:
        s=1

if s==0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 53596
var
  a,b:longint;
Function max(x,y,z:longint):longint;
begin
  if (x>=y) and (x>=z) then exit(x);
  if (y>=x) and (y>=z) then exit(y);
  if (z>=x) and (z>=y) then exit(z);
end;
begin
  read(a,b);
  write(max(a+b,2*a-1,2*b-1));
end.


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

using namespace std;

typedef long long ll;

vector< int > divisor(int n) {
  vector< int > ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int N;
  cin>>N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 2 == 0) continue;
    vector<int> div = divisor(i);
    if (div.size() == 8) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
const int MAX_V = 10000;

int V, E;
vi G[MAX_V];
int deg[MAX_V];
bool used[MAX_V];

void solve() {
   for (int i = 0; i < V; i++) {
       if (!used[i] && deg[i] == 0) {
           cout << i << endl;
           used[i] = true;

           for (auto to : G[i]) {
               deg[to]--;
           }

           i = -1;
       }
   } 
}

int main() {
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;

        G[s].push_back(t);
    }

    for (int i = 0; i < V; i++) {
        for (auto to : G[i]) {
            deg[to]++;
        }
    }

    solve();
}

Measured memory_bytes: 1884
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) sort(x.begin(),x.end()) 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    map<int,int> mp;
    int a,b;
    void solve()
    {
        cin>>n>>a>>b;
        fo(i,1,n+1)
        {
            fo(j,i+1,n+1)
            mp[min({j-i,abs(a-i)+1+abs(b-j),abs(b-i)+1+abs(a-j)})]++;
        }

        fo(i,1,n)
        cout<<mp[i]<<endl;
        
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 384
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let mut c: Vec<Vec<char>> = vec![];

    for i in 0..3{
        c.push(read_as_string().chars().collect::<Vec<char>>());
    }

    for i in 0..3{
        print!("{}", c[i][i]);
    }
    println!("");
}


Measured memory_bytes: 4352
package main

import (
	"fmt"
)

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)

	q := make([][]int, 0)

	patterns := [][]int{
		{2, 0, 0},
		{0, 2, 0},
		{0, 0, 2},
		{1, 1, 0},
		{0, 1, 1},
		{1, 0, 1},
	}

	q = append(q, []int{A, B, C, 0})

	d := make(map[[3]int]bool)
	ans := 0
	for len(q) > 0 {
		q0 := q[0]
		q = q[1:]
		a, b, c, x := q0[0], q0[1], q0[2], q0[3]

		k := [3]int{a, b, c}
		if d[k] {
			continue
		}
		d[k] = true

		if a == b && b == c {
			ans = x
			break
		}

		for _, p := range patterns {
			q = append(q, []int{a + p[0], b + p[1], c + p[2], x + 1})
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 17408
N=int(input())
A=list(map(int,input().split()))
p=sum(A)//2
S=0
cost=0
i=0
while S<p:
  S=S+A[i]
  i=i+1
#print(i,S,A[i-1])
if S==p:
  cost=0
else:
  if sum(A[0:i])>sum(A[i-1:N]):
    cost=sum(A[i-1:N])-sum(A[0:i-1])
  else:
    cost=sum(A[0:i])-sum(A[i:N])
print(cost)

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int main() {
	int N; cin >> N;
	string S; cin >> S;
	int cnt[26] = {};
	for (int i = 0; i < N; i++) {
		cnt[S[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		cnt[i]++;
	}
	long long ans=1;
	for (int i = 0; i < 26; i++) {
		ans *= cnt[i];
        ans%=mod;
	}
	ans--;
    ans%=mod;
	cout << ans << endl;
}

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

int main() {
    int n; cin >> n;
    for (int b = 0; b < 1 << n; b++) {
        cout << b << ":";
        for (int i = 0; i < n; i++) if (b >> i & 1) cout << " " << i;
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
until (n=gets.to_i)==0
  l1=gets.split.map(&:to_i)
  l2=Array.new(n)
  count=0
  loop do
    l1.each.with_index do |num,id|
      l2[id]=l1.count{|item| item==num}
    end
    l1==l2 ? break : l1=l2.dup
    count+=1
  end
  puts "#{count}\n#{l1.join(" ")}"
end

Measured memory_bytes: 8776
#include <iostream>
#include <iomanip>
#include <vector>

void process_table(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    if (n <= 0)
        return;
    std::vector<int> col_sums(n, 0);
    for (int i = 0; i < n; ++i) {
        int row_sum = 0;
        for (int j = 0; j < n; ++j) {
            int x;
            in >> x;
            col_sums[j] += x;
            row_sum += x;
            out << std::setw(5) << x;
        }
        out << std::setw(5) << row_sum << '\n';
    }
    int sum = 0;
    for (auto const& col_sum: col_sums) {
        out << std::setw(5) << col_sum;
        sum += col_sum;
    }
    out << std::setw(5) << sum << '\n';
}

int main() {
    while (std::cin) {
        process_table(std::cin, std::cout);
    }
}



Measured memory_bytes: 3064
import math
import sys
n, p=map(int,input().split())

if n==1:
    print(p)
    sys.exit()
gcd=1
limit = math.ceil(math.sqrt(p))
if p%2==0:
    cnt=0
    while p%2==0:
        cnt += 1
        p//=2
    if cnt>=n:
        cnt//=n
        gcd *= 2**cnt

for i in range(3,limit+1,2):
    if i>p:
        break
    cnt=0
    while p%i==0:
        cnt+=1
        p//=i
    if cnt>=n:
        cnt//=n
        gcd *= i**cnt
print(gcd)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

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

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

    vector<bool> era(1000001);
    vector<int> prime={2};
    for(int i=3; i<=1000000; i+=2){
        if(!era[i]){
            prime.push_back(i);
            era[i]=true;
            for(int j=i+i; j<=1000000; j+=i) era[j]=true;
        }
    }
    
    ll n;
    cin>>n;
    int answer=0;
    for(int i : prime){
        int cnt=0;
        while(n%i==0){
            n/=i;
            cnt+=1;
        }
        int j=1;
        while(j*(j+1)/2<=cnt) j+=1;
        answer+=j-1;
    }
    if(n!=1) answer+=1;
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3944
#include<stdio.h>

int main()
{
    int a,b,c,out;

    scanf("%d%d%d",&a,&b,&c);

    if(b>=c && b>=a)
        b=b*10;
    else if(c>a && c>b)
        c=c*10;
    else
        a=a*10;

    out=a+b+c;

    printf("%d",out);



}


Measured memory_bytes: 128
/*
 * If you're not willing to make sacrifices yourself, you'll never be
 * able to change anything. In order to overcome monsters, you must
 * be willing to abandon your own humanity.
 * ~ Arlert
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  int ans = 0;
  VI vals;
  for (auto v : m) vals.PB(v.F);
  for (auto v : vals) {
    for (int j = -1; j <= 1; j++) {
      ans = max(ans, m[j + v - 1] + m[j + v] + m[j + v + 1]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5120
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math


NN = 202020
MOD = 10**9+7
# MOD = 998244353
INF = float("inf")

x = int(input())
for a in range(1, 1000):
    if pow(a, 5) - pow(a-1, 5) > x:
        break
    b = a-1
    while pow(a, 5) - pow(b, 5) <= x:
        if pow(a, 5) - pow(b, 5) == x:
            print(a, b)
            exit()
        else:
            b -= 1



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

int main() {
  int n, s;
  scanf("%d %d", &n, &s);
  vector<int> v(n);
  for(int i = 0; i < n; i++){
  	scanf("%d", &v[i]);
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  for(int i = 0; i < -s + (int)v.size(); i++){
  	sum += v[i];
  }
  printf("%lld\n", sum);
}

Measured memory_bytes: 1024
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = collections.Counter(a)
cnt = 0
c = b.most_common()
s = 0
for i in range(len(c)):
	cnt += 1
	if cnt > k:
		for j in range(i,len(c)):
			s += c[j][1]
		break
print (s)

Measured memory_bytes: 39320
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;
    int k = 1;
    while (true) {
        if (k * (k + 1) <= 2 * n && 2 * n < (k + 1) * (k + 2))
            break;
        k++;
    }
    vector<int> v;
    for (int i = 1; i <= k; i++)
        v.push_back(i);
    int d = n - k * (k + 1) / 2;
    for (int i = 0; i < d; i++)
        v[k - 1 - i]++;
    for (auto && x : v)
        cout << x << "\n";
}

Measured memory_bytes: 384
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import Data.Bifunctor (first)
import Data.Bits

type Mat = V.Vector (U.Vector Int64)
type BitSet = Int

{-
scoreOne :: Int -> Mat -> BitSet -> Int64
scoreOne !n !mat !set = go 0 [i | i <- [0..n-1], testBit set i]
  where
    go !acc [] = acc
    go !acc (x:xs) = let !r = mat V.! x
                     in go (acc + sum [r U.! y | y <- xs]) xs
-}

-- sort (bitSubsets x) == sort (map (foldl' (.|.) (bit x0)) $ sequence $ map (\i -> [0,bit i]) [i | i <- [0..n-1], testBit set i])
bitSubsets :: Int -> [Int]
bitSubsets 0 = [0]
bitSubsets set = let !i = countTrailingZeros set
                     set' = clearBit set i
                     ss = bitSubsets set'
                 in map (.|. bit i) ss ++ ss

main = do
  n <- readLn
  mat <- V.replicateM n $ do
    U.unfoldrN n (readInt64 . BS.dropWhile isSpace) <$> BS.getLine
  let -- scoreOneV == U.generate (2^n) (scoreOne n mat)
      scoreOneV :: U.Vector Int64
      scoreOneV = U.create $ do
        vec <- UM.replicate (2^n) minBound
        UM.write vec 0 0
        let go !set = do
              v <- UM.read vec set
              if v == minBound
                then do let !i = countTrailingZeros set
                        let !set' = clearBit set i
                        v0 <- go set'
                        let !v = v0 + sum [(mat V.! i) U.! j | j <- [i+1..n-1], testBit set' j]
                        UM.write vec set v
                        return v
                else return v
        mapM_ go [1..2^n-1]
        return vec
  let result :: Int64
      result = runST $ do
        vec <- UM.replicate (2^n) minBound
        UM.write vec 0 0
        forM_ [0..n-1] $ \i -> do
          UM.write vec (bit i) 0
        let go !set = do
              v <- UM.read vec set
              if v == minBound
                then do let v0 = scoreOneV U.! set
                        let i0 = countTrailingZeros set
                        v <- foldM (\x a -> max x <$> a) v0 [ (+) (scoreOneV U.! set') <$> (go (set `xor` set'))
                                                            | set'' <- bitSubsets (clearBit set i0)
                                                            , let set' = set'' .|. bit i0
                                                            , set' /= set
                                                            ]
                        UM.write vec set v
                        return v
                else return v
        go (2^n-1)
  print result

readInt64 :: BS.ByteString -> Maybe (Int64, BS.ByteString)
readInt64 s = first fromIntegral <$> BS.readInt s


Measured memory_bytes: 12668
a,b = map(int,input().split())

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table    

def isPrime(n):
  if n < 2:
    return False
  if n == 2:
    return True
  for p in range(2, int(n**0.5)+1):
      if n % p == 0:
        return False
  return True

n = gcd(a,b)
lst = divisor(n)

ans = []
for x in lst:
    if isPrime(x):
        ans.append(x)
print(len(ans) + 1)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int main(){
    fast;
	ll a,b;
	cin>>a>>b;
	cout<<2*b-a;	
    return 0;
}


Measured memory_bytes: 3552
use proconio::{fastout, input};
use std::cmp;

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        mut k: u64,
        r#as: [u64; n],
        bs: [u64; m],
    }

    let mut i = 0;
    let mut j = 0;

    while i < n && r#as[i] <= k {
        k -= r#as[i];
        i += 1;
    }
    while j < m && bs[j] <= k {
        k -= bs[j];
        j += 1;
    }

    let mut max = i + j;

    while i > 0 {
        k += r#as[i - 1];
        i -= 1;
        while j < m && bs[j] <= k {
            k -= bs[j];
            j += 1;
        }
        max = cmp::max(max, i + j);
    }

    println!("{}", max);
}


Measured memory_bytes: 9468
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n;
    ll a,b;
    ll k,t;
    cin>>a>>b;
    if(a>=13) cout<<b<<endl;
    else if(a>=6) cout<<b/2<<endl;
    else cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    int N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    vector<pair<int64_t, int64_t> > CB(M);
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> CB[i].second >> CB[i].first;

    sort(A.begin(), A.end());
    sort(CB.rbegin(), CB.rend());
    
    priority_queue<int64_t> que;
    for(int i = 0; i < M; i++){
        for(int j = 0; j < CB[i].second; j++){
            que.push(CB[i].first);
            if(que.size() == N) break;
        }
        if(que.size() == N) break;
    }

    int64_t ans = 0;
    for(int i = 0; i < N; i++){
        while(que.size() != 0 && que.top() < A[i]) que.pop();
        if(que.size() != 0){
            ans += que.top();
            que.pop();
        }else{
            ans += A[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include "math.h"

using namespace std;

int main() {
    
    int n;
    
    cin >> n;
    
    double saihu1 = 0;
    double saihu2 = 0;
    
    double y;
    string a;
    
    for (int i=0; i<n; i++) {
        cin >> y >> a;
        if (a == "JPY") {
            saihu1 += y;
        } else {
            saihu2 += y;
        }
    }
    
    cout << saihu1 + saihu2 * 380000 << endl;
    
    return 0;
    
}

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

int main() {
  int n, d1;
  cin >> n >> d1;
  vector<int> vec = {d1};
  for (int i = 0; i < n - 1; i++){
    int d;
    cin >> d;
    vec.push_back(d);
    for (int j = 0; j < vec.size() - 1; j++){
      if (vec.at(j) == d){
        vec.pop_back();
        break;
      }
    }
  }
  cout << vec.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    ll N;
    cin >> N;
    vector<ll>a(N),b(N);
    for(ll &x:a){cin >> x;}
    for(ll &y:b){cin >> y;}
    if(a>b){
        swap(a,b);
    }
    ll cnt = 0;
    while(a<b && ++cnt){
        next_permutation(ALL(a));
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
	int a,b;
	cin >> a >> b;
	
	cout << (a+b+1)/2 <<endl;
	
	
	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
void quicksort(signed long number[],signed long first,signed long last){
   signed long i, j, pivot, temp;

   if(first<last){
      pivot=first;
      i=first;
      j=last;

      while(i<j){
         while(number[i]<=number[pivot]&&i<last)
            i++;
         while(number[j]>number[pivot])
            j--;
         if(i<j){
            temp=number[i];
            number[i]=number[j];
            number[j]=temp;
         }
      }

      temp=number[pivot];
      number[pivot]=number[j];
      number[j]=temp;
      quicksort(number,first,j-1);
      quicksort(number,j+1,last);

   }
}

int main()
{
    signed long n,k;
    signed long long result=0;
    scanf("%ld%ld",&n,&k);
    signed long* arr = (signed long*) malloc(n * sizeof(signed long));
    signed long count = n;
    for(count = 0;count<n;count++)
    {
        scanf("%ld",arr+count);
        result = result + arr[count];
    }
    if(k>=n)
     result = 0;
    else if(k!=0)
    {
    quicksort(arr,0,n-1);
    for(count = 0;count<k;count++)
    {
        result = result - arr[n-1-count];
    }
    }
    printf("%lld",result);

    return 0;
}


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

int howmanytracks(vector<int>& s,int p){
  int x=0,counter=0;
  for(const auto& i:s){
    if(x+i<=p){
      x+=i;
    }else{
      counter++;
      x=0;
      x+=i;
    }
  }
  if(x!=0) counter++;
  return counter;
}

int main(){
  int n,k,w,max_p=0,sum_p=0,mid;
  vector<int> s;

  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> w;
    s.push_back(w);
    max_p > w ? : max_p=w;
    sum_p+=w;
  }

  while(sum_p - max_p > 1){
    mid = (sum_p + max_p)/2;
    if(howmanytracks(s,mid) <= k){
      sum_p = mid;
    }else{
      max_p = mid;
    }
  }
  cout << (howmanytracks(s,max_p) <= k ? max_p : sum_p) << endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const double PI = 3.14159265358979323846;

int main() {
    double R;
    cin >> R;
    double ans = 2 * PI * R;
    printf("%.12f\n", ans);
}


Measured memory_bytes: 3736
/*input
4 5
1 2
2 5
#.###
####.
#..##
#..##
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{int res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(int* a, int* b){shuffle(a,b,grndm);}

const int MX = 1005;

bool seen[MX][MX];

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	int n, m; cin >> n >> m;
	pair<int, int> s, t;
	cin >> s.first >> s.second;
	cin >> t.first >> t.second;
	s.first--;
	s.second--;
	t.first--;
	t.second--;
	vector<string> v(n);
	for(int i = 0; i < n; i++) {
		cin >> v[i];
	}
	deque<pair<int, pair<int, int> > > q;
	q.push_back({0, s});
	while(q.size()) {
		auto now = q.front();
		q.pop_front();
		if(seen[now.second.first][now.second.second]) continue;
		if(now.second == t) {
			cout << now.first << endl;
			return 0;
		}
		seen[now.second.first][now.second.second] = true;
		for(int i = -1; i <= 1; i++) {
			for(int j = -1; j <= 1; j++) {
				if(abs(i) + abs(j) > 1 || i == 0 && j == 0) continue;
				int x = now.second.first + i, y = now.second.second + j;
				if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == '.') {
					q.push_front({now.first, {x, y}});
				}	
			}
		}
		for(int i = -2; i <= 2; i++) {
			for(int j = -2; j <= 2; j++) {
				if(abs(i) + abs(j) <= 1) continue;
				int x = now.second.first + i, y = now.second.second + j;
				if(x >= 0 && x < n && y >= 0 && y < m && v[x][y] == '.') {
					q.push_back({now.first + 1, {x, y}});
				}
			}
		}	
	}
	cout << "-1" << endl;
	return 0;
}




















Measured memory_bytes: 7048
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <set>
#include <queue>
#include <math.h>
#include <stdbool.h>

#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const int MAXN=1000005;

int main()
{
    int X,A;
    cin >> X >> A;
    if (X<A)
        printf("0\n");
    else
        printf("10\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
bool dp[maxn];

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	dp[0] = false;
	for (int i = 0; i < k; i++) {
		for (auto now : a) {
			if (!dp[i + now] && !dp[i])dp[i + now] = true;
		}
	}
	if (dp[k])cout << "First";
	else cout << "Second";
	return 0;
}

Measured memory_bytes: 512
from collections import Counter
import math

N = int(input())
s = []
for i in range(N):
    s.append(list(input()))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

[s[i].sort() for i in range(len(s))]

s = [' '.join(s[i]) for i in range(len(s))]
mycounter = Counter(s)
mycounter = list(mycounter.values())

mycounter = [mycounter[i] for i in range(len(mycounter)) if mycounter[i] > 1]
mycounter = [combinations_count(mycounter[i], 2) for i in range(len(mycounter))]

print(sum(mycounter))

Measured memory_bytes: 32500