akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    cout << max(A - K, (ll)0) << ' ' << max(B - max((K - A), (ll)0), (ll)0) << endl;
}


Measured memory_bytes: 3520
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

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

const int X = 250000 + 5;
const int N = 1e6 + 5;
const ull B = 259;
ull invB;

/***************************************************************************/

ull power(ull a, ull n) {
	if(n == 0) return 1;
	ull p = power(a, n>>1);
	p = p * p;
	if(n & 1) p = p * a;
	return p;
}

string S;
ull powB[N];

inline ull& pow(int n) {
	if(n < 0) n += N;
	return powB[n];
}

map<ull, int> M;

int main() {

	boost;
	invB = power(B, (ull(1)<<63)-1);
	assert(B * invB == 1);

	pow(0) = 1;
	for(int i=1; i<X; i++) {
		pow(i) = pow(i-1) * B;
		pow(-i) = pow(-i+1) * invB;
	}

	int n; cin>>n;
	cin>>S;

	ull phas = 0, chas = 0;

	int p = 0;
	for(auto it : S) {
		if(it == '+') phas += pow(p);
		else if(it == '-') phas -= pow(p);
		else if(it == '>') p++;
		else p--;
	}

	ll ans = 0;
	M[phas]++;
	p = 0;

	for(auto it : S) {
		if(it == '+') chas += pow(p);
		else if(it == '-') chas -= pow(p);
		else if(it == '>') p++;
		else p--;

		ans += M[chas];
		M[chas + pow(p) * phas]++;
	}

	cout<<ans<<"\n";

	return 0;
}

Measured memory_bytes: 37396
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

int k[16000000];
int n, a, z, cnt;
string S;

int main() {
	memset(k, 0, sizeof(k));
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> S;
		z = 0;
		for (int j = 0; j < S.size(); j++) {
			z += (int)(S[j] - 'A' + 1)*pow(27, S.size() - j - 1);
		}
		cin >> a;
		k[z] += a;
	}
	for (int i = 0; i < 16000000; i++) {
		if (k[i] >= 1) {
			for (int j = 4; j >= 0; j--) {
				z = (int)(i / (int)pow(27, j)) % 27;
				if (z >= 1) {
					cout << (char)(z + 'A' - 1);
				}
			}
			cout << ' ';
			cout << k[i] << endl;
		}
	}
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

int cal(int n) {
  return n * (n - 1) / 2;
}

signed main() {
#ifdef _DEBUG
  freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), cnt(n + 1);
  for (auto &i : a) {
    cin >> i;
    cnt[i]++;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += cal(cnt[i]);
  }
  for (auto &i : a) {
    cout << sum - cnt[i] + 1 << '\n';
  }
}


Measured memory_bytes: 5760
n,m,x=map(int,input().split())
book=[]
mon=[]
ans=0
for i in range(n):
      cnt=list(map(int,input().split()))
      mon.append(cnt[0])
      book.append(cnt[1:])
min_total=100000000000000
for i in range(2**n):
        a=[0]*m
        total=0
        for j in range(n):
                if ((i >>j)&1):
                        total+=mon[j]
                        for k in range(m):
                                a[k]+=book[j][k]
                if min(a) >=x and min_total>=total:
                        min_total=total
if min_total!=100000000000000:
        print(min_total)
else:
        print('-1')

Measured memory_bytes: 9116
N = int(input())
A = list(map(int, input().split()))



sumA = [0]
buf = 0
for i in A:
    buf += i
    sumA.append(buf)

ans = []
for i in sumA:
    if i >= sumA[-1] / 2:
        ans.append(temp)
        ans.append(i)
        break
    temp = i

print(int(min(abs(sumA[-1] / 2 - ans[0]), abs(sumA[-1] / 2 - ans[1])) * 2))

Measured memory_bytes: 26220
/*
/*
https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/7/ITP1_7_B
a+b+c=x (a<b<c,c<=n)
3+c<x の時,解なし
n<=c,b<=c-1,a<=b-1(=c-2)の全試行を行えば解は求まる。
*/

#include <iostream>

int main()
{
    int n, x;
    int c, ans; //cを基にa,bの値を下げていく
    while (true)
    {
        std::cin >> n >> x;
        c = n;
        ans = 0;
        if (n == 0 && x == 0)
        {
            break;
        }
        for (int i = c; i >= 3; i--)
        {
            for (int j = i - 1; j >= 2; j--)
            {
                for (int k = j - 1; k >= 1; k--)
                {
                    if (i + j + k == x)
                    {
                        ans++;
                    }
                }
            }
        }

        std::cout << ans << std::endl;
    }
}


Measured memory_bytes: 3100
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

long long gcd(long long a, long long b)
{
    if (b == 0)
        return a;

    return gcd(b, a%b);
}

long long lcm(long long a, long long b)
{
    return a * b / gcd(a, b);
}

long long cnt(long long n, long long v)
{
    return n / v;
}

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

    long long ans = B - A + 1;
    ans -= cnt(B, C) - cnt(A - 1, C);
    ans -= cnt(B, D) - cnt(A - 1, D);

    long long lcmCD = lcm(C, D);
    ans += cnt(B, lcmCD) - cnt(A - 1, lcmCD);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
As = list(map(int, input().split()))
yen = 1000
kabu = 0
for n in range(N-1):
    if As[n] < As[n+1]:
        kabu += yen // As[n]
        yen -= kabu * As[n]
        yen += kabu * As[n+1]
        kabu = 0
print(yen)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int64_t power(int64_t x, int64_t n, int64_t mod) {
  int64_t ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
    int N;
    cin >> N;
    vector<lint> A(N);
    lint ans = 0;
    REP(i, N) cin >> A[i];
    REP(k, 60) {
        lint zero = 0;
        lint one = 0;
        REP(i, N) {
            if((A[i]>>k)&1 == 1) {
                one++;
            } else {
                zero++;
            }
        }
        ans = (ans + power(2, k, MOD) * zero % MOD * one % MOD) % MOD;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	long long N, M;
	vector<long long> T(100000), X(100000), P(100000);
	cin >> N;
	long long total = 0;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
		total += T[i];
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> P[i];
		cin >> X[i];
	}
	for (int i = 0; i < M; ++i) {
		cout << total + (X[i] - T[P[i] - 1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[])
{
  int a, b;
  cin >> a >> b;

  int result = -1;
  for (int i = 0; i <= 1000; i++) {
    if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
      result = i;
      break;
    }
  }

  cout << result << "\n";
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int a,b;cin>>a>>b;
	cout<<(a==b?"Yes":"No")<<endl;
}

Measured memory_bytes: 888
#include<stdio.h>

int main(void){
  long long n , t;
  scanf("%lld %lld",&n ,&t);

  long long a[n];
  for(int i = 0;i < n;i ++){
    scanf("%lld",&a[i]);
  }

  long long ans = 0;

  for(int i = 0;i< n-1;i ++){
    if(a[i+1] - a[i] > t){
      ans += t;
    }
    else{
      ans += a[i+1] - a[i];
    }
  }
  
  ans += t;
  printf("%lld\n",ans);

  return 0;
  
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
 
int n, q, k;
vector<pair<int, ll> > g[100005];
ll dis[100005];
bool used[100005];
 
void setDis(int from) {
	FOR(i, g[from].size()) {
		int to = g[from][i].first;
		if (used[to]) continue;
		dis[to] = dis[from] + g[from][i].second;
		used[to] = true;
		setDis(to);
	}
	return;
}
 
int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	FOR(i, n-1) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		g[a].push_back(make_pair(b, c));
		g[b].push_back(make_pair(a, c));
	}
	cin >> q >> k;
	used[k] = true;
	setDis(k);
	vector<ll> ans(q);
	FOR(i, q) {
		int x, y;
		cin >> x >> y;
		ans[i] = dis[x] + dis[y];
	}
	// FOR(i, n+1) cout << dis[i] << endl;
	FOR(i, q) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <complex>
#include <cmath>

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )

using namespace std;
typedef complex<double> P;
// OÏ (cross product) : a~b = |a||b|sin¦
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
int main(){
  double x1,y1,x2,y2,x3,y3,x4,y4;
  int n;
  P a,b;
  for(cin>>n;n>0;n--){
    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    a = P(x2-x1,y2-y1);
    b = P(x4-x3,y4-y3);
    if EQ(cross(a,b),0.0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

char s[111];
ll k;

int main(){
	scanf("%s%lld", s, &k);
	int i = 0;
	while(s[i] == '1' && i < strlen(s))i++;
	if(k <= i)puts("1");
	else printf("%c\n", s[i]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];

    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0; i < 1000; i++){
        int num = 0;
        for(int j = 0; j < n; j++) if(p[j] >= i) num++;
        if(num >= i) ans = i;
    }

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



Measured memory_bytes: 3156
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto a = aryread();
    if (a.lineup())
        power_mod(2, n / 2).writeln();
    else
        writeln(0);
}

bool lineup(T)(T ary)
{
    long[long] dic;
    foreach (e; ary)
    {
        if (e in dic)
            dic[e]++;
        else
            dic[e] = 1;
    }
    bool ret = true;
    foreach (i; iota((ary.length % 2 ? 0 : 1), ary.length, 2))
    {
        ret &= (i in dic && dic[i] == (i == 0 ? 1 : 2));
    }
    return ret;
}

// 累積二乗法
long power_mod(long a, long n, long mod = MOD)
{
    long ret = 1;
    while (n)
    {
        if (n % 2)
        {
            ret *= a;
            ret %= mod;
        }
        a^^=2;
        a %= mod;
        n >>= 1;
    }
    return ret % mod;
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int num(){
    char s[11];
    int i, n;
    for(i=0; i<sizeof(s); i++){
        s[i] = getchar();
        if(s[i] == ' ' || s[i] == '\n'){
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

int main(void)
{
    int i, ok, b=1, c=0;
    int n, a[200];
    n = num();
    for(i=0; i<n; i++){
        a[i] = num();
    }
    
    do{
        ok = 0;
        for(i=0; i<n; i++) {
            if(a[i]%2 != 0){
                printf("%d\n", c);
                
                return 0;

            }
            else{
                a[i] = a[i]/2;
            }
        }
        for(b=0; b<n; b++){
            if(a[b]%2 == 0)
                ok++;
        }
        c++;
    }while(ok == n);
    
    printf("%d\n", c);
    
    return 0;
}

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

#define MOD (1000000000+7)
#define N 100000

int main() {
	int n;

	cin >> n;

	int ans = 0;
	int div = 100;
	for( int i = 0; i < 3; i++ ) {
		int d = n / div;
		if( d == 1 ) {
			ans += 9 * div;
		}
		else {
			ans += 1 * div;
		}
		n %= div;
		div /= 10;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import defaultdict

n,m  = li()
query = []
for _ in range(m):
    mi,ma = li()
    if mi > ma:
        mi,ma = ma,mi
        
    query.append((mi,ma))

root = defaultdict(list)
for l,r in query:
    root[l].append(r)


even = -1
odd = -1
for k, v in root.items():
    if len(v)%2 == 0 and even == -1:
        even = k
        
    elif len(v)%2 == 1 and odd == -1:
        odd = k

# 偶数個つながっているノードをルートに
top = even
dist = [0]*n
for l,r in query:
    if l==top:
        dist[r-1] += 1
    
    elif r==top:
        dist[l-1] += 1
    
    else:
        dist[r-1] += 1
        dist[l-1] += 1
        
exist = False
if top != -1 and all([disti % 2 == 0 for disti in dist]):
    exist = True
    

# 奇数個つながっているノードをルートに
top = odd
dist = [0]*n
for l,r in query:
    if l==top:
        dist[r-1] += 1
    
    elif r==top:
        dist[l-1] += 1
    
    else:
        dist[r-1] += 1
        dist[l-1] += 1
        
if top != -1 and all([disti % 2 == 0 for disti in dist]):
    exist = True

if exist:
    print("YES")
else:
    print("NO")   

Measured memory_bytes: 28452
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid u1(5, 10); u1(rnd);

int main() {
    fast;
    ll a,b; cin>>a>>b;
    ll o =0, mn=a, mx = 1;
    for(int q=0; q<b; q++){
        ll v,vv; cin>>v>>vv;
        mx = max(mx, v);
        mn = min(mn, vv);
    }
    cout<<max(0LL, mn-mx+1)<<endl;
}

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    string s;
    cin >> s;
    
    int cnt = 0, max_cnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cnt++;
        else {
            if(max_cnt < cnt) max_cnt = cnt;
            cnt = 0;
        }
    }
    if(max_cnt < cnt) max_cnt = cnt;
    cout << max_cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3728
unittest
{
	assert( [ "2002", "2017" ].parse.expand.solve == 2032 );
	assert( [ "4500", "0" ].parse.expand.solve == -4500 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto r = input.front.strip.to!( long );
	input.popFront;
	auto g = input.front.strip.to!( long );
	return tuple( r, g );
}

auto solve( long r, long g )
{
	return 2 * g - r;
}


Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	a := N * A
	fmt.Println(min(a, B))
}


Measured memory_bytes: 640
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-20;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int n,a,b,c,d;scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	int ret=min((n+a-1)/a*b,(n+c-1)/c*d);
	printf("%d\n",ret);
}


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

using namespace std;

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

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    while (h[i] > 0) {
      int r;
      for (r = i; r < N; ++r) if (h[r] == 0) break;
      for (int x = i; x < r; ++x) h[x]--;
      ans++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define rep(i, a, n) for(int i = (a); i < (n); i++)

int main(){
    int d, w;
    while(cin >> d >> w, d+w){
        int mat[d][w];
        for(int i = 0; i < d*w; i++)    cin >> mat[i/w][i%w];

        int ans = 0;

        rep(i, 0, d) rep(j, 0, w){
            rep(ni, i+2, d) rep(nj, j+2, w){
                int surround = 10, water = 0, lakesum = 0;
                rep(di, i, ni+1) rep(dj, j, nj+1){
                    if(di == i || di == ni || dj == j || dj == nj){
                        surround = min(surround, mat[di][dj]);
                    }else{
                        water = max(water, mat[di][dj]); 
                        lakesum += mat[di][dj];
                    }
                }

                if(surround <= water)   continue;

                int lakeA = (ni-i-1)*(nj-j-1);
                ans = max(ans, surround*lakeA - lakesum);
            }
        }

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


Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define rep(p,q) for(int i = p;i < q;i++)

#define LL long long int

#define inf 10000000000

//1
int main(void) {
	vector<int> ar = vector<int>();
	int n;
	cin >> n;
	rep(0, n) {
		int a;
		cin >> a;
		ar.push_back(a);
	}
	for (int j = 0; j < n-1; j++)cout << ar[j] << " ";
	cout << ar[n-1] << endl;
	rep(1, n) {
		int v = ar[i];
		for (int j = i - 1; -1 < j && v < ar[j]; j--) {
			ar[j + 1] = ar[j];
			ar[j] = v;
		}
		for (int j = 0; j < n-1; j++)cout << ar[j] << " ";
		cout << ar[n-1] << endl;
	}
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <vector>
#include <utility>
#include <set>
#define inf 1e9
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, n, m, l, a, b, c, q;
  scanf("%lld%lld%lld", &n, &m, &l);
  vector< pair<ll, ll> > vec[n];
  ll ans[n][n];
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &a, &b, &c);
    if(c > l) continue;
    vec[--a].push_back(make_pair(--b, c));
    vec[b].push_back(make_pair(a, c));
  }
  pair<ll, ll> d[n];
  pair< pair<ll, ll>, ll> p;
  pair<ll, ll> tmp;
  for(i = 0; i < n; ++i) {
    set< pair< pair<ll, ll>, ll> > s;
    for(j = 0; j < n; ++j) d[j] = make_pair(inf, inf);
    d[i] = make_pair(0, 0);
    for(j = 0; j < n; ++j) s.insert(make_pair(d[j], j));
    while(s.size()) {
      p = *s.begin(), s.erase(s.begin());
      if(p.first.first == inf) break;
      for(j = 0; j < vec[p.second].size(); ++j) {
        tmp = make_pair(p.first.first, p.first.second + vec[p.second][j].second);
        if(tmp.second > l) tmp.first++, tmp.second = vec[p.second][j].second;
        if(d[vec[p.second][j].first] > tmp) {
          s.erase(make_pair(d[vec[p.second][j].first], vec[p.second][j].first));
          d[vec[p.second][j].first] = tmp;
          s.insert(make_pair(tmp, vec[p.second][j].first));
        }
      }
    }
    for(j = 0; j < n; ++j) ans[i][j] = (d[j].first == inf ? -1 : d[j].first);
  }
  scanf("%lld", &q);
  for(i = 0; i < q; ++i) {
    scanf("%lld%lld", &a, &b);
    printf("%lld\n", ans[--a][--b]);
  }
  return 0;
}

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

int main(){
	double X=0,Y=0,A=0;
	int V,B;
	while(1){
		scanf("%d,%d",&V,&B);
		if(!V && !B)
			break;
		X+=sin(M_PI*A/180.0)*(double)(V);
		Y+=cos(M_PI*A/180.0)*(double)(V);
		A+=(double)(B);
	}
	printf("%d\n%d\n",(int)(X),(int)(Y));
	return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(a) printf("Case %d: ", a)

using namespace std;
int main()
{
    int n;
    cin>>n;

    ll sum = 0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                sum += __gcd(i, __gcd(j, k));
            }
        }
    }
    cout<<sum;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
const int N=55;
int n;
int res;
int a[N];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
			res+=a[i]*a[j];
	printf("%d\n",res);
	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n; 
    vector<int> a(n); 
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    sort(a.begin(),a.end(),greater<>());

    long sum=a[0];

    int index=1;

    for(int i=2; i<n; i++){
        sum+=a[index];
        if(i%2==1){
            index++;
        }
    }

    cout << sum << endl;

}

Measured memory_bytes: 4028
#include<stdio.h>
int main()
{
	int a,b,c,d,e,f,r;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	r=a+b*5+c*10+d*50+e*100+f*500;
	if(r>=1000){
		printf("1\n");
	}else{
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 2624
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;

using namespace std;

ll n, m, k;

int main(){
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll ret = 0;
    for (int i=1; i<n; ++i){
        ret += a[i/2];
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 4460
#include<stdio.h>

int main()
{
    int n = 0;
	int x = 0,y = 0,z = 0;
	scanf("%d %d %d",&x,&y,&z);
	n = x/(y+z);
	if((x-n*(y+z))>=z) printf("%d",n); 
	else printf("%d",n-1); 
    return 0; 
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(){
  int K;
  char S[101];
  
  scanf("%d", &K);
  scanf("%s", S);
  
  if(strlen(S) <= K){
    printf("%s\n", S);
  }else{
    for(int i=0; i<K; i++){
      printf("%c", S[i]);
    }printf("...\n");
  }
}

Measured memory_bytes: 1656
#!/usr/bin/env python3
import sys
import math

def solve(K: int):
    answer = 0
    # GCDLIST = [[1]*(K+1) for _ in range(K+1)]

    # for i in range(1,K+1):
    #     for j in range(1,K+1):
    #         g = math.gcd(i,j)
    #         GCDLIST[i][j] = g
    #         GCDLIST[j][i] = g
    
    for i in range(1,K+1):
        for j in range(1,K+1): 
            for k in range(1,K+1):
                answer += math.gcd(math.gcd(i,j),k)
    
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67768
def main():
    N = int(input())
    s = input()
    t = input()
    if s == t:
        print(N)
    else:
        count = 1
        for i in range(1,N):
            tmp = s+t[-i:]
            if s == tmp[:N] and t == tmp[-N:]:
                break
            count += 1
        print(N+count)
if __name__ == '__main__':
    main()

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  char c;
  cin >> c;
  if ('A' <= c && c <= 'Z') {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}


Measured memory_bytes: 3520
n = list(map(int, list(input())))
k = int(input())
l = len(n)

ans = 0
if k == 1:
    ans = n[0] + (l - 1) * 9
elif k == 2:
    if l == 1:
        ans = 0
    else:
        for i in range(l - 1):
            p = True
            for j in range(i + 1, l):
                if i == 0 and p:
                    ans += (n[i] - 1) * 9 + n[j]
                elif i == 0:
                    ans += n[i] * 9
                else:
                    ans += 9 * 9
                if n[j] != 0:
                    p = False
else:
    if l <= 2:
        ans = 0
    else:
        for i in range(l - 2):
            p1 = True
            for j in range(i + 1, l - 1):
                p2 = True
                for k in range(j + 1, l):
                    if i == 0 and p1 and p2:
                        ans += (n[i] - 1) * 9 * 9
                        ans += (n[j] - 1) * 9 + n[k] if n[j] != 0 else 0
                    elif i == 0 and p1 and not p2:
                        ans += (n[i] - 1) * 9 * 9 + n[j] * 9
                    elif i == 0 and not p1:
                        ans += n[i] * 9 * 9
                    else:
                        ans += 9 * 9 * 9
                    if n[k] != 0:
                        p2 = False
                if n[j] != 0:
                    p1 = False
print(ans)


Measured memory_bytes: 68268
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
#include <list>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    using P = pair<int, int>;
    vector<P> v;
    for(int i = 0; i < n; i++) v.push_back(P(p[i], i));
    sort(v.begin(), v.end());
    int ans = n;
    int max_cnt = 1;
    int cnt = 1;
    for(int i = 1; i < n; i++)
    {
        if(v[i - 1].second < v[i].second)
        {
            cnt++;
        }
        else cnt = 1;
        max_cnt = max(max_cnt, cnt);
    }
    cout << ans - max_cnt << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3188
import sys

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


def solve():
    x = int(input())

    q1, r1 = divmod(x, 500)
    x -= q1 * 500
    q2, r2 = divmod(x, 5)
    print(q1 * 1000 + q2 * 5)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d %d", &n,&k,&x);
	f(i, 10) {
		x *= n;
		x -= k;
		printf("%d\n", x);
}


	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int all;
	int book[9];
	int i;
	
	while (1){
		scanf("%d", &all);
		if (all == 0){
			break;
		}
		
		for (i = 0; i < 9; i++){
			scanf("%d", &book[i]);
			all -= book[i];
		}
		printf("%d\n", all);
	}
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    for(int x=0; x<=Y/10000; x++){
        for(int y=0; y<=Y/5000; y++){
            int z=N-x-y;
            if(10000*x+5000*y+1000*z==Y and 0<=z and z<=N){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = 5
    MP = [[[0]*4 for i in range(N)] for j in range(N)]
    dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
    ds = "LURD"
    for i in range(N):
        s = readline().strip()
        for j in range(N-1):
            if s[j] == '1':
                MP[i][j][2] = MP[i][j+1][0] = 1
        if i < 4:
            s = readline().strip()
            for j in range(N):
                if s[j] == '1':
                    MP[i][j][3] = MP[i+1][j][1] = 1
    x = 1; y = 0; cd = 2
    de = [3, 0, 1, 2]
    ans = [2]
    while not x == y == 0:
        e = MP[y][x]
        for d in de:
            if e[cd + d - 4]:
                cd = (cd + d) % 4
                ans.append(cd)
                dx, dy = dd[cd]
                x += dx; y += dy
                break
    write("".join(map(ds.__getitem__, ans)))
    write("\n")
solve()


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

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

	int d = a / b;
	int r = a % b;
	double f = a / static_cast<double>(b);

	cout << fixed << setprecision( 10 );
	cout << d << " " << r << " " << f << endl;
}



Measured memory_bytes: 3292
"""
in1 = '5'
in2 = '3'
in3 = '10000'
in4 = '9000' #48000
in1 = '2'
in2 = '3'
in3 = '10000'
in4 = '9000' #20000
"""
in1 = input()
in2 = input()
in3 = input()
in4 = input()

N = int(in1)
K = int(in2)
X = int(in3)
Y = int(in4)
RC = 0

if N <= K:
    RC = X * N
else:
    RC = (X * K) + (Y * (N - K))

print(RC)


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
    var a, b, ans int
    var op string

    KEISAN:
    for {
        fmt.Scanf("%d %s %d", &a, &op, &b)
        switch op {
        case "+":
            ans = a + b
        case "-":
            ans = a - b
        case "*":
            ans = a * b
        case "/":
            ans = a / b
        case "?":
            break KEISAN
        }
        fmt.Printf("%d\n", ans)
    }

}


Measured memory_bytes: 1172
import java.io.*;
import java.util.*;
public class Main {

    public static void main(String args[]) throws Exception {
        int minCnt = Integer.MAX_VALUE;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long target = sc.nextLong();
        
        int[] numArr = new int[n];
        int[] scores = new int[n];
        for(int i = 0; i < n; i++) {
            numArr[i] = sc.nextInt();
            scores[i] = sc.nextInt();
        }
        for(int i = 0; i < Math.pow(2, n); i++) {
            long sum = 0;
            int cnt = 0;
            for(int j = 0; j < n; j++) {
                if((i >> j & 1) == 1) {
                    sum += scores[j];
                    sum += numArr[j] * (j + 1) * 100;
                    cnt += numArr[j];
                }
            }
            if(sum < target) {
                int j = n - 1;
                for(; j >=0; j--)
                    if((i >> j & 1) == 0)
                        break;

                for(int k = 0; k < numArr[j] - 1; k++) {
                    sum += (j + 1) * 100;
                    cnt++;
                    if(sum >= target)
                        break;
                }
            }
            if(sum >= target) {
                minCnt = Math.min(minCnt, cnt);
            }
        }
        System.out.println(minCnt);
    }
}

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

using namespace std;

vector<int> a;

int main() {
	int n, x; scanf("%d", &n);
	while (n--) {
		scanf("%d", &x);
		auto it = upper_bound(a.begin(), a.end(), x, greater<int>());
		if (it == a.end()) a.push_back(x);
		else *it = x;
	}
	cout << a.size();
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1000000007;
vector<ll> fac(1000005);
vector<ll> ifac(1000005);
ll modpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    return ans;
}
ll comb(ll a, ll b){
    if(a == 0 && b == 0)
        return 1;
    if(a < b || a < 0)
        return 0;
    ll tmp = ifac[a - b] * ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans = 0;
    if((x + y) % 3 != 0 || 2 * x < y || 2 * y < x){
        cout << "0" << endl;
        return 0;
    }
    ll n, m;
    n = (2 * y - x) / 3;
    m = (2 * x - y) / 3;
    
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i < max(x, y); i++){
        fac[i + 1] = fac[i] * (i + 1) % mod;
        ifac[i + 1] = ifac[i] * modpow(i + 1, mod - 2) % mod;
    }
    cout << comb(n + m, n) << endl;
    return 0;
}

Measured memory_bytes: 18672
n = int(input())
b = list(map(int,input().split()))
bc = b[::-1]
a = []
while bc:
    for i in range(len(bc)):
        if bc[i] == len(bc)-i:
            a.append(bc[i])
            bc.pop(i)
            break
    else:
        print(-1)
        exit()
        
a = a[::-1]
for k in a:
    print(k)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  vector<bool> s(n, false);
  for (int i = 0; i < k; i++) {
    int d; cin >> d;
    for (int j = 0; j < d; j++) {
      int a; cin >> a;
      a--;
      s[a] = true;
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (!s[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define inf 20021225
#define ll long long
#define mxn 100100
using namespace std;

map<ll,int> s;
map<ll,bool> h;
bool isp[10100];
ll p[1310],cnt;
void get(int n)
{
	isp[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!isp[i])	p[++cnt]=i;
        for(int j=1;j<=cnt&&p[j]*i<=n;j++)
        {
            isp[p[j]*i]=1;
            if(i%p[j]==0)	break;
        }
    }
}
ll a[mxn],b[mxn]; int n;
int main()
{
	get(10000);// printf("%d\n",cnt);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		ll q=a[i]; a[i]=b[i]=1ll;
		for(int j=1;j<=cnt;j++)
		{
			int qwq=0;
			if(q==1)	break;
			if(q%p[j]==0)
			{
				while(q%p[j]==0)
				{
					q/=p[j];
					qwq++;
				}
				qwq%=3;
				if(qwq==1)	b[i]*=(ll)p[j]*p[j],a[i]*=p[j];
				if(qwq==2)	b[i]*=p[j],a[i]*=(ll)p[j]*p[j];
			}
		}
		if(q!=1)
		{
			ll x=(ll)sqrt(q);
			if(x*x == q)	b[i]*=x,a[i]*=x*x;
			else	b[i]*=q*q,a[i]*=q;
		}
	}
	for(int i=1;i<=n;i++)	s[a[i]]++;
	int	ans=0;// printf("%d\n",ans);
	for(int i=1;i<=n;i++)
	{
		if(!h[a[i]])
		{
			h[a[i]]=h[b[i]]=1;
			if(a[i]==b[i])	ans++;
			else	ans+=max(s[a[i]],s[b[i]]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 26880
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n)for(int i=0;i<n;i++)
#define MAXCOST 5000
double dp[51][MAXCOST+1];
int v[4];
struct INFO{
	int type,val;
	INFO(){
		type=0;val=0;
	}; 
};
INFO mass[51];    
int main(){
	int x,y,z;
	while(cin >> x >> y >> z , x){
		rep(i,51)mass[i] = INFO(); 
		rep(i,51)rep(j,MAXCOST+1)dp[i][j] = 0;
		rep(i,x)cin >> v[i];      
		int mxcost = 0;   
		rep(i,z){       
			int N;           
			cin >> N;          
			cin >> mass[N].type >> mass[N].val;       
			if(mass[N].type == 2)mxcost += mass[N].val;       
		}    
		double baseProb = 1.0/x;  
		dp[0][0] = 1;      
		for(int pos = 0; pos < y ; pos++){      
			for(int cost = 0 ; cost <= mxcost ; cost++){         
				rep(i,x){                 
					int nextPos = pos+v[i];               
					if(nextPos > y)nextPos = y;         
					if(mass[nextPos].type == 0){          
						dp[nextPos][cost] += dp[pos][cost] * baseProb;    
					}                            
					if(mass[nextPos].type == 1){    
						int newPos = nextPos + mass[nextPos].val;   
						if(newPos > y)newPos = y;        
						dp[newPos][cost] += dp[pos][cost] * baseProb;     
					}                 
					if(mass[nextPos].type == 2){         
						int newCost = mass[nextPos].val + cost;        
						dp[nextPos][newCost] += dp[pos][cost] * baseProb;      
					}                  
					if(mass[nextPos].type == 3){  
						int newCost = cost - mass[nextPos].val;      
						if(newCost < 0)newCost = 0;              
						dp[nextPos][newCost] += dp[pos][cost] * baseProb;   
					}            
				}      
			}       
		}   
		double sum = 0;    
		for(int i = 0; i <= mxcost ;i++){     
			sum += dp[y][i] * i;     
		}      
		cout << (int)sum << endl;     
	}
}

Measured memory_bytes: 2856
#import<cstdio>
#import<map>
#define I(M,A)for(i=0;i<M;i++)scanf("%d",&x),A[i+1]=A[i]+x;
main(){for(int n[1501],m[1501],o,a,b,i,j,x;scanf("%d%d",&a,&b),a;printf("%d\n",o)){std::map<int,int>z;*n=*m=o=0;I(a,n)I(b,m)for(i=0;i<=a;i++)for(j=0;j<=b;)z[n[i]+m[j++]]++;for(typeof(z.begin()) p=z.begin();p!=z.end();p++)o+=p->second*(p->second-1)/2;}}

Measured memory_bytes: 18000
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int N;
  cin>>N;
  int a[N], b[N];
  LL suma=0, sumb=0;
  LL j1=0, j2=0;
  REP(i, N) {
    cin>>a[i];
    suma+=a[i];
  }
  REP(i, N) {
    cin>>b[i];
    sumb+=b[i];
  }
  if(suma>sumb) {
    cout<<"No"<<endl;
    return 0;
  }

  REP(i, N){
    if(a[i]>b[i]){
      j1 += (a[i]-b[i]);
    }
    else{
      j2 += (b[i]-a[i])/2;
    }
    //cout<<judge<<endl;
  }
  if(j1>j2) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;




  return 0;
}


Measured memory_bytes: 384
import sys
mod = pow(10, 9) + 7
def C(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
NNN = (10**6)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, NNN+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n,m,k=map(int,input().split())
#n=m=k=2
print(C(n*m,k)*k*(k-1)%mod*(n+m)*inverse[6]%mod)


Measured memory_bytes: 127700