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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

string S;

signed main() {
    cin >> S;
    ll cnt = 0;
    REP(i, S.length()) {
        if(S[i] == 'o') cnt++;
    }
    if(cnt + (15 - S.length()) >= 8)
        cout << "YES"
             << "\n";
    else
        cout << "NO"
             << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i, count;
  i=0;
  count=1;
  cin >> N;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++) {
    cin >> vec.at(i);
  }
  
  i=0;
    
  while (vec.at(i)!=2 && count<N+2) {
    i=vec.at(i)-1;
    count++;
  }
  if (count>N) {
    cout << "-1" << endl;
  }
  else {
    cout << count << endl;
  }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)
int main(){
    ll n, m, ans=0, a, b, c;
    cin >> n >> m;
    vector<ll> A, NewA(n);
    RAP(i, n){
        cin >> a;
        A.push_back(a);
    }
    vector<pair<ll, ll>> CB(m);
    RAP(i, m){
        cin >> b >> c;
        CB[i] = make_pair(c, b);
    }
    sort(A.begin(), A.end(), greater<>());
    sort(CB.begin(), CB.end(), greater<>());
    ll check = 0;
    bool flag = true;
    RAP(i, m){
        RAP(j, CB[i].second){
            if(check<n){
                NewA[n-1-check] = CB[i].first;
                check++;
            }else{
                flag = false;
                break;
            }
        }
        if(!flag){
            break;
        }
    }
    RAP(i, n){
        if(NewA[i]<A[i]){
            NewA[i] = A[i];
        }else{
            break;
        }
    }
    RAP(i, n){
        ans += NewA[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
    int r;
    cin >> r;
    float p = M_PI;
    cout << 2*p*(float)r << endl; 
   return 0;
}


Measured memory_bytes: 3784
def main():
    t_hp, t_atk, a_hp, a_atk = map(int, input().split(' '))

    while True:
        a_hp -= t_atk
        t_hp -= a_atk
        if a_hp <= 0 and t_hp > 0:
            print('Yes')
            exit(0)
        elif t_hp <= 0 and a_hp > 0:
            print('No')
            exit(0)
        elif a_hp <= 0 and t_hp <= 0:
            print('Yes')
            exit(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,x,n) for(int i=(x);i<(n);i++)
#define sortn(a) sort(a.begin(),a.end())
#define sortr(a) sort(a.begin(),a.end(),greater<int>())
#define INT_MAX 2147483647
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
 
int main(){
    
    int n;
    cin >> n;
    vi a(n);
    rep(i,n){
        cin >> a[i];
        a[i] = -a[i];
    }
    int c=0;
    vi p;
    vi::iterator itr;
 
    rep(i,n){
        itr = upper_bound(p.begin(),p.end(),a[i]);
        if(itr != p.end()){
            *itr = a[i];
        }else{
            p.push_back(a[i]);
            c++;
        }
    }
 
    cout << c << endl;
    
    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */



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

    int n, t; cin >> n >> t;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int minv=a[0];
    int maxpro=0;
    repr(i, 1, n){
        chmax(maxpro, a[i]-minv);
        chmin(minv, a[i]);
    }

    minv=a[0];
    int ans=0;
    repr(i, 1, n){
        if(a[i]-minv==maxpro) ++ans;
        chmin(minv, a[i]);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll a, b, c, x, y;std::cin >> a >> b >> c >> x >> y;
  ll ans = 1000000000000;
  for(int i=0;i<=200000;i+=2){
    ll tmp = i*c;
    ll A = max((ll)0, x - i/2);
    ll B= max((ll)0, y - i/2);
    ans = min(ans, tmp+A*a+B*b);
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

char bits[250000];
int primes[100000];
int n_primes; 

void sieve(){
	int i, j;
	memset(bits, 1, sizeof(bits));
	bits[0] = bits[1] = 0;
	for (i = 0; i < 505; i++)
		if (bits[i])
			for (j = i * i; j < 250000; j += i)
				bits[j] = 0;
	for (i = j = 0; i < 250000; i++)	
		if (bits[i]) primes[j++] = i;
	n_primes = j;
}

int main(){
	sieve();
	while(1){
		int n,ret=0;
		cin>>n;
		if(n==0)return 0;
		FOR(i,n+1, 2*n+1)ret+=bits[i];
		cout<<ret<<endl;
	}
}

Measured memory_bytes: 1504
def dfs(lls, curr_num, lim):
    if curr_num > lim: return
    lls.append(curr_num)
    last_num = int(str(curr_num)[-1])
    if last_num > 0:
        dfs(lls, curr_num*10+last_num-1, lim)
    if last_num < 9:
        dfs(lls, curr_num*10+last_num+1, lim)
    dfs(lls, curr_num*10+last_num, lim)


def main():
    k = int(input())
    lls = []
    for i in range(1,10):
        dfs(lls, i, 3234566668)

    lls.sort()
    print(lls[k-1])
    


if __name__ == "__main__":
    main()

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

int n;
string s;
cin >> n >> s;
int w[1000000]={0}, e[1000000]={0}; 
if(s[0]=='W') w[0]++;
else e[0]++;
for(int i=1; i<n; i++) {
    if(s[i]=='W') w[i]=w[i-1]+1; // i+1人目までのWの人数和
    else w[i]=w[i-1];
}
for(int i=1; i<n; i++){
    e[i]=i+1-w[i]; // i+1人目までのEの人数和
}

int ans=e[n-1];
for(int i=1; i<n; i++){
    ans=min(ans, w[i-1]+e[n-1]-e[i]);
    //cout << ans << endl;
}
cout << ans << endl;
//rep(i,n) cout << w[i];
//cout << endl;
//rep(i,n) cout << e[i];
//cout << endl;

}

Measured memory_bytes: 8452
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int mod=1e9+7;
const int MAXN=65;
LL n;
int f[MAXN][2][2];//<=n 进位 
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	n=read();
	if(n&1)f[0][1][0]=2,f[0][1][1]=1;
	else f[0][1][0]=1,f[0][0][0]=1,f[0][1][1]=1;
	for(int i=0;i<60;i++)for(int u=0;u<=1;u++)for(int v=0;v<=1;v++)if(f[i][u][v])
	{
		int t=f[i][u][v];
		if(n&(1LL<<(i+1)))
		{
			if(v==1)ad(f[i+1][u][0],t);else ad(f[i+1][1][0],t);//00
			if(v==1)ad(f[i+1][1][1],t);else ad(f[i+1][u][0],t);//10
			if(v==1)ad(f[i+1][u][1],t);else ad(f[i+1][1][1],t);//11
		}
		else
		{
			if(v==1)ad(f[i+1][0][0],t);else ad(f[i+1][u][0],t);//00
			if(v==1)ad(f[i+1][u][1],t);else ad(f[i+1][0][0],t);//10
			if(v==1)ad(f[i+1][0][1],t);else ad(f[i+1][u][1],t);//11
		}
	}pr2(f[60][1][0]);
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        Map<Integer, Integer> squares = new HashMap<>();
        for (int i = 1; i <= 150; i++) {
            for (int j = 1; j <= 150; j++) {
                for (int k = 1; k <= 150; k++) {
                    squares.merge((i + j) * (i + j) + (i + k) * (i + k) + (j + k) * (j + k), 1, Integer::sum);
                }
            }
        }
        for (int i = 1; i <= n; i++) {
            System.out.println(squares.getOrDefault(2 * i, 0));
        }
    }
}


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

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Side = Tuple!(long, "from", long, "to");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

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

long n, m;
long[][] graph;

void main()
{
    scan(n, m);
    auto g = new long[][](n, 0);
    auto sides = new Side[](m);
    foreach (i; iota(m))
    {
        long a, b;
        scan(a, b);
        g[a - 1] ~= [b - 1];
        g[b - 1] ~= [a - 1];
        sides[i] = Side(a - 1, b - 1);
    }
    graph = g;
    long cnt;
    foreach (e; sides)
    {
        auto visited = new long[](n);
        visited[0] = 1;
        dfs(0, 0, e, visited);
        // writeln();
        // visited.writeln();
        if(visited.sum != n)
            cnt++;
    }
    cnt.writeln();
}

void dfs(long vertex, long neighbor, Side invail, long[] visited)
{
    if (neighbor >= graph[vertex].length)
        return;

    auto next = graph[vertex][neighbor];
    if (!visited[next])
    {
        // writef("vertex = %s next = %s ,", vertex + 1, next + 1);
        if(Side(vertex, next) == invail || Side(next, vertex) == invail)
        {
            dfs(vertex, neighbor + 1, invail, visited);
        }
        else
        {
            visited[next] = 1;
            dfs(next, 0, invail, visited);
        }
        dfs(vertex, neighbor + 1, invail, visited);
    }
    else
    {
        dfs(vertex, neighbor + 1, invail, visited);
    }
}


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


int dp[100010];
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &x : a) cin >> x;
    dp[1] = 0;
    dp[2] = abs(a[1] - a[0]);

    for(int i = 3; i <= n; i++){
        dp[i] = min(dp[i-1] + abs(a[i-1] - a[i-2]), dp[i-2] + abs(a[i-1] - a[i-3]));
    }

    cout << dp[n] << endl;


    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
#define pcii pair<char, pair<int, int>>
using namespace std;

const ll N = 105, mod = 1e9 + 7;
const int inf = 1e9;

void solve(){
    int n, k;
    cin >> n >> k;
    vi a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> dp(n, inf);
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        if(i < k){
            dp[i] = abs(a[i] - a[0]);
            continue;
        }
        for(int j = i - 1; j >= i - k; j--)
            dp[i] = min(dp[j] + abs(a[i] - a[j]), dp[i]);
    }
    cout << dp[n - 1] << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


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

using namespace std;

int main()
{
long x;
cin>>x;
int u[100001];long sum=0;
for(int i=0;i<x;i++)
{
    cin>>u[i];
}bool k=false;
while(k==false)
{k=true;
for(int i=0;i<x;i++)
{
    if(u[i]==i+1&&i>0)
    {k=false;
        if(u[i-1]==i)
        {swap(u[i],u[i-1]);sum++;}
    }
    if(u[i]==i+1&&i+1!=x)
    {k=false;
        if(u[i+1]==i+2)
        {swap(u[i],u[i+1]);sum++;}
    }
   if(u[i]==i+1&&i+1!=x)
    {k=false;
    if(u[i+1]!=i+1)
        {swap(u[i],u[i+1]);sum++;}
    }
          if(u[i]==i+1&&i>0)
    {k=false;
    if(u[i-1]!=i)
        {swap(u[i],u[i-1]);sum++;}
    }
 else if(u[i]==i+1&&i+1!=x)
 {swap(u[i],u[i+1]);sum++;k=false;}
} 
}

cout<<sum<<endl;
return 0;
}
//bbgg

Measured memory_bytes: 640
while(1):
  table = {}
  output = ''
  table_number = int(input())
  if table_number == 0:
    break
  for i in xrange(table_number):
    a, b = raw_input().split()
    table[a] = b
  string_number = int(input())
  for i in xrange(string_number):
    string = raw_input()[0]
    if string in table:
      output += table[string]
    else:
      output += string
  print output

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

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

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    Vl red(A), green(B), pure(C);
    for (int i = 0; i < A; i++) {
        cin >> red[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> green[i];
    }
    for (int i = 0; i < C; i++) {
        cin >> pure[i];
    }
    sort(red.begin(), red.end(), greater<ll>());
    sort(green.begin(), green.end(), greater<ll>());
    sort(pure.begin(), pure.end(), greater<ll>());

    int idx_r, idx_g, idx_p;
    idx_p = -1;
    idx_r = X - 1;
    idx_g = Y - 1;
    bool flag = true;
    while (flag) {
        if (idx_r >= 0 && idx_g >= 0) {
            if (red[idx_r] < green[idx_g]) {
                if (red[idx_r] < pure[idx_p + 1]) {
                    --idx_r;
                    ++idx_p;
                }
                else if (green[idx_g] < pure[idx_p + 1]) {
                    --idx_g;
                    ++idx_p;
                }
                else {
                    flag = false;
                }
            }
            else {
                if (green[idx_g] < pure[idx_p + 1]) {
                    --idx_g;
                    ++idx_p;
                }
                else if (red[idx_r] < pure[idx_p + 1]) {
                    --idx_r;
                    ++idx_p;
                }
                else {
                    flag = false;
                }
            }
        }
        else if (idx_r < 0 && idx_g < 0) {
            idx_p = X + Y - 1;
            flag = false;
        }
        else if (idx_r < 0) {
            if (green[idx_g] < pure[idx_p + 1]) {
                --idx_g;
                ++idx_p;
            }
            else {
                flag = false;
            }
        }
        else {
            if (red[idx_r] < pure[idx_p + 1]) {
                --idx_r;
                ++idx_p;
            }
            else {
                flag = false;
            }
        }

        if (idx_p == C - 1) {
            flag = false;
        }
    }


    ll ans = 0;
    for (int i = 0; i <= idx_r; i++) {
        ans += red[i];
    }
    for (int i = 0; i <= idx_g; i++) {
        ans += green[i];
    }
    for (int i = 0; i <= idx_p; i++) {
        ans += pure[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair

using namespace std;

const int INF = 2000000000;
const double pi = 3.1415926;
const int base = 1000000007;
const int p = 31;

long long n, a, b;

long long count1(long long x)
{
    if (x == 1) return 2;
    long long tek = count1(x / 2);
    tek = tek  % base;
    if (x % 2 == 0) return (tek * tek) % base;
    else return ((tek * tek) % base * 2) % base;
}
long long dpm(long long num, long long x)
{
    if (x == 1) return num % base;
    long long tek = dpm(num, x / 2);
    tek = tek  % base;
    if (x % 2 == 0) return (tek * tek) % base;
    else return ((tek * tek) % base * num  % base) % base;
}


int main()
{
    //ifstream cin ("sysadmin.in");
    //ofstream cout ("sysadmin.out");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(20);
    cin >> n >> a >> b;
    if (a > b) swap(a, b);
    long long p2 = count1(n) % base;
    //cout << p2;
    p2--;
    long long fa = 1, fb = 1, ofa = 1, ofb = 1;
    for (int i = 2; i <= b; i++)
    {
        if (i <= a) fa = (fa % base * i % base) % base;
        fb = (fb % base * i % base) % base;
    }
    for (int i = n - b + 1; i <= n; i++)
    {
        if (i >= n - a + 1) ofa = (ofa % base * i % base) % base;
        ofb = (ofb % base * i % base) % base;
    }
    fa = dpm(fa, base - 2) % base;
    fb = dpm(fb, base - 2) % base;
    ofa = (ofa % base * fa % base) % base;
    ofb = (ofb % base * fb % base) % base;
    p2 = (p2 % base - ofa % base + base) % base;
    p2 = (p2 % base - ofb % base + base) % base;
    cout << p2;
    return 0;
}


Measured memory_bytes: 256
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
#define ll long long
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> pii;
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false);
int main(){fast;
	
	int n; cin>>n;
	vector<int> a(n);
	rep(i, n){
		cin>>a[i];
	}	
	sort(all(a));
	int alice = 0, bob = 0;
	bool ok = true;
	for(int i = n - 1; i >=0; i--){
		if(ok){
			alice += a[i];
			ok = false;
		}
		else {
			bob += a[i];
			ok = true;
		}
	}
	cout<<alice - bob<<endl;
}


Measured memory_bytes: 256
"""
author : halo2halo
date : 12, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

ADK = list(map(int, read().split()))
print('Yay!' if ADK[4] - ADK[0] <= ADK[-1] else ':(')


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

int gcd(int a, int b){ return (a % b) ? gcd(b, a % b) : b;}
int lcm(int a, int b){ return (a / gcd(a, b)) * b;}

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

const int inf = 1012345678;
int main(){
    int n;
    int a[100005];

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

    int ans = ngcd(n, a);

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 2092
n = int(input())
s = input()

csum_w = [0] * n
if s[0] == 'W':
    csum_w[0] = 1
for i in range(1, n):
    cnt = csum_w[i - 1]
    if s[i] == 'W':
        cnt += 1
    csum_w[i] = cnt

ans = float('inf')
for i in range(n):
    buf = 0
    if i >0:
        buf += csum_w[i - 1]
    buf += (n - 1 - i) - (csum_w[n - 1] - csum_w[i])
    ans = min(buf, ans)
print(ans)

Measured memory_bytes: 15812
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s: Vec<usize> = (0..3).map(|_| read()).collect();
    s.sort();
    println!("{}", s.into_iter().map(|x| x.to_string())
        .collect::<Vec<String>>()
        .join(" "));
}


Measured memory_bytes: 5036
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		long lcm = Math.max(a, b);
		while (lcm % Math.min(a, b) != 0) {
			lcm += Math.max(a, b);
		}
		System.out.println(lcm);
	}
}


Measured memory_bytes: 21844
from itertools import accumulate
from bisect import bisect_right
N, M, K = map(int, input().split())
A = list(accumulate([int(i) for i in input().split()]))
B = list(accumulate([int(i) for i in input().split()]))

ans = bisect_right(B,K)
for i,a in enumerate(A):
    if K < a:
        break
    n = bisect_right(B, K-a)
    ans = max(ans, i + 1 + n)
            

print(ans) 

Measured memory_bytes: 127028
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    while (true) {
        int w, d;
        cin >> w >> d;

        if (!(w | d)) break;

        vector<int> h_w(w);
        for (int i = 0; i < w; i++) cin >> h_w[i];

        vector<int> h_d(d);
        for (int i = 0; i < d; i++) cin >> h_d[i];

        int ans1 = accumulate(h_w.begin(), h_w.end(), 0);
        int ans2 = accumulate(h_d.begin(), h_d.end(), 0);

        {
            map<int, int> M;
            for (int i = 0; i < w; i++) M[h_w[i]]++;
            for (int i = 0; i < d; i++) {
                if (M[h_d[i]] > 0) M[h_d[i]]--;
                else ans1 += h_d[i];
            }
        }
        {
            map<int, int> M;
            for (int i = 0; i < d; i++) M[h_d[i]]++;
            for (int i = 0; i < w; i++) {
                if (M[h_w[i]] > 0) M[h_w[i]]--;
                else ans2 += h_w[i];
            }
        }

        cout << max(ans1, ans2) << endl;

    }

    return 0;
}












































































Measured memory_bytes: 2960
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int N = 110;
ll nums[N];
int n;

int main(){
	si(n);
	repi(i,1,n){
		sl(nums[i]);
	}
	sort(nums + 1,nums + n + 1); 
	int res = 0;
	repi(i,1,n){
		repi(j,i,n){
			if(nums[i] == nums[j])
				continue;
			repi(k,j,n){
				if(nums[k] == nums[j])
					continue;
				if(nums[i] + nums[j] > nums[k]){
					res++;
				}
			}
		}
	}
	cout<<res<<endl;
	return 0;
} 

Measured memory_bytes: 3756
# coding: utf-8
# Your code here!

table = [[0 for i in range(2001)] for j in range(2001)]

x1,y1,w1,h1 = [int(i) for i in input().split()]
x2,y2,w2,h2 = [int(i) for i in input().split()]

ans = 0

for i in range(x1,x1+w1):
    for j in range(y1,y1+h1):
        table[i][j] = 1
        ans += 1

for i in range(x2,x2+w2):
    for j in range(y2,y2+h2):
        if table[i][j] == 0:
            table[i][j] = 1
            ans += 1
        else:
            table[i][j] = 0
            ans -= 1

print(ans)



Measured memory_bytes: 38048
N,K=(map(int,input().split()))
if N==K:
    print(0)
elif N<K:
    if 2*N<=K:
        print(N)
    else:
        print(K-N)
else:
    if N%K==0:
        print(0)
    else:
        print(min(N%K, K-(N%K)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }


int N;
int A[100010];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    int S = accumulate(RNG(A, 0, N), 0LL);

    int xN = S;
    for(int i = 0;i < N-1;i+=2) xN -= 2*A[i];

    int prev = 2*A[N-1]-xN;
    cout << prev << ' ';
    rep(i, 1, N-1) prev = 2*A[i-1]-prev, cout << prev << ' ';
    cout << xN << endl;

    return 0;
}

Measured memory_bytes: 2048
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

bool solve(vector<int> a)
{
    int n = a.size();
    if(n == 0)
        return true;

    if(n == 14){
        sort(a.begin(), a.end());
        for(int i=0; i<13; ++i){
            if(a[i] == a[i+1]){
                vector<int> b = a;
                b.erase(b.begin()+i, b.begin()+i+2);
                if(solve(b))
                    return true;
            }
        }
        return false;
    }

    if(a[0] == a[1] && a[1] == a[2]){
        a.erase(a.begin(), a.begin()+3);
        return solve(a);
    }

    vector<int>::iterator it;
    it = find(a.begin(), a.end(), a[0]+1);
    if(it == a.end())
        return false;
    a.erase(it);
    it = find(a.begin(), a.end(), a[0]+2);
    if(it == a.end())
        return false;
    a.erase(it);
    a.erase(a.begin());

    return solve(a);
}

int main()
{
    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        vector<int> a(13);
        for(int i=0; i<13; ++i)
            a[i] = s[i] - '0';

        vector<int> ret;
        for(int i=1; i<=9; ++i){
            vector<int> b = a;
            b.push_back(i);
            if(count(b.begin(), b.end(), i) > 4)
                continue;

            if(solve(b))
                ret.push_back(i);
        }

        if(ret.size() == 0){
            cout << 0 << endl;
        }else{
            cout << ret[0];
            for(unsigned i=1; i<ret.size(); ++i)
                cout << ' ' << ret[i];
            cout << endl;
        }
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,M,ans=0;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++){
    cin>>A[i];
    ans+=A[i];
  }
  M=A[0];
  for(int i=0;i<N;i++) M=max(M,A[i]);
  cout<<ans-M/2<<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int n = in.nextInt();
			int w = in.nextInt();
			int h = in.nextInt();
			if(w == 0) break;
			clock = 0;
			Comparator<Cake> cmp = new Comp1();
			ArrayList<Cake> cakes = new ArrayList<Cake>();
			cakes.add(new Cake(w, h, 0));
			for(int i=0; i<n; i++){
				clock++;
				int p = in.nextInt();
				int s = in.nextInt();
				cakes.addAll(cut(cakes.remove(p-1), s));
				Collections.sort(cakes, cmp);
			}
			Collections.sort(cakes, new Comp2());
			out(cakes);
		}
	}
	
	public static int clock;
	public static void out(ArrayList<Cake> cakes){
		StringBuilder sb = new StringBuilder();
		for(Cake c: cakes){
			sb.append(c.size+" ");
		}
		System.out.println(sb.toString().trim());
	}
	
	public static ArrayList<Cake> cut(Cake cake, int s){
		int w = cake.w;
		int h = cake.h;
		s %= w + h;
		ArrayList<Cake> res = new ArrayList<Cake>();
		if(s<w){
			res.add(new Cake(s, h, clock));
			res.add(new Cake(w-s, h, clock));
		}else{
			s -= w;
			res.add(new Cake(w, s, clock));
			res.add(new Cake(w, h-s, clock));
		}
		return res;
	}
}

class Cake{
	int w, h;
	int size;
	int time;
	public Cake(int w, int h, int time){
		this.w = w;
		this.h = h;
		this.time = time;
		size = w*h;
		if(size == 0){
			System.err.println("!error size!");
		}
	}
	
	public String toString(){
		return size+"";
	}
}

class Comp1 implements Comparator<Cake>{
	@Override
	public int compare(Cake o1, Cake o2) {
		if(o1.time != o2.time) return o1.time-o2.time;
		return o1.size - o2.size;
	}
}

class Comp2 implements Comparator<Cake>{
	@Override
	public int compare(Cake o1, Cake o2) {
		return o1.size-o2.size;
	}
}

Measured memory_bytes: 48108
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
int main(){
    string s; cin >> s;
    ll count = 0;
    rep(i,(int)s.length()){
        count += s[i] - '0';
    }
    cout << (count % 9 == 0 ? "Yes" :  "No");
    return 0;
    

} 

Measured memory_bytes: 3752
import math
import numpy as np

n, d = map(int, input().split())

x = np.zeros([n, d])

for i in range(n):
    line = list(map(int, input().split()))
    for j in range(d):
        x[i, j] = line[j]

cnt = 0

for i in range(n):
    for j in range(i+1, n):
        xx = (x[i] - x[j]) ** 2
        dist = math.sqrt(xx.sum())
        if dist % 1 == 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 13336
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int>x(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i);
  }
  vector<int>copy(n);
  copy=x;
  sort(copy.begin(),copy.end());
  for(int i=0;i<n;i++){
    if(x.at(i)>=copy.at(n/2)){
      cout << copy.at((n/2)-1) << endl;
    }
    else{
      cout << copy.at(n/2) << endl;
    }
  }
}

Measured memory_bytes: 4832
#include <iostream>
#include <vector>

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

using namespace std;

const long long int MOD=1000000007;
vector<vector<long long int> > C;

long long int cmb(int n, int r) {
    if(n==r || r==0) return C[n][r]=1;
    if(r==1 || (n-r)==1) return C[n][r]=n;
    
    if(C[n][r]!=0) return C[n][r];
    if(n<r) return C[n][r]=0;
    
    C[n-1][r-1] = cmb(n-1, r-1)%MOD;
    C[n-1][r] = cmb(n-1, r)%MOD;
    return C[n][r]=C[n-1][r-1]+C[n-1][r];
}

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

    C.resize(N+1, vector<long long int>(N+1, 0));
    
    
    // cout << "min = " << min << endl;
    
    for(int i=1; i<=K; i++) {
        // cout << N-K+1 << "C" << i << " x " << K-1 << "C" << \
        i-1 << endl;
        // cout << " = " << cmb(N-K+1, i) << " x " << cmb(K-1, i-1) << endl;
        cout << cmb(N-K+1, i)*cmb(K-1, i-1)%MOD << endl;
    }


    return 0;
    
}

Measured memory_bytes: 31744
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    sort(a, a+n); 
    reverse(a, a+n);

    ll tate = 0, yoko = 0, ans;
    int t = a[0];
    int cnt = 0;
    rep(i, n) {
        if(a[i] == t) {
            cnt++;
        }
        else {
            t = a[i];
            cnt = 1;
        }

        if(cnt == 2) {
            if(!tate) {
                tate = a[i];
                cnt = 0;
            }
            else {
                yoko = a[i];
                break;
            }
        }
    }

    ans = tate * yoko;
    
    cout << ans << endl;
    return 0;
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;

const int INF = 2e18;
int n, a, b, c, d;
map<int, int> m;

int solve(int p) {
	if (p == 0)
		return 0;

	if (p == 1)
		return d;

	vector<int>  multi = {2, 3, 5};
	vector<int>  cost = {a, b, c};
	if (m.count(p))
		return m[p];

	int ans = INF;
	if (p < INF / d)
		ans = p * d;
	for (int i = 0; i < multi.size(); i++) {
		if (p % multi[i] == 0) {
			ans = min(ans, solve(p / multi[i]) + cost[i]);
		}
		else {
			int down = (p / multi[i]) * multi[i];
			ans = min(ans, solve(down / multi[i]) + d * (p - down) + cost[i]);
			int up = down + multi[i];
			ans = min(ans, solve(up / multi[i]) + d * (up - p) + cost[i]);
		}
	}
	m[p] = ans;
	return ans;
}


int32_t main()
{
	GO;
	int t;
	cin >> t;
	while (t--) {
		cin >> n >> a >> b >> c >> d;

		int ans = solve(n);
		m.clear();
		cout << ans << endl;
	}
	return 0;
}

//!

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

typedef long long int lli;

lli fact[300001];

lli extgcd(lli a, lli b, lli &x, lli &y) {
        lli g = a; x = 1LL; y = 0LL;
        if (b != 0LL) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
        return g;
}

lli mod_inverse(lli a, lli m) {
        lli x, y;
        extgcd(a, m, x, y);
        return (m + x % m) % m;
}

lli mod_fact(lli n, lli p, lli& e) {
        e = 0;
        if (n == 0) return 1LL;

        lli res = mod_fact(n / p, p, e);
        e += n / p;

        if (n / p % 2 != 0) return res * (p - fact[n % p]) % p;
        return res * fact[n % p] % p;
}

lli mod_comb(lli n, lli k, lli p) {
        if (n < 0 || k < 0 || p < 0) return 0LL;

        lli e1, e2, e3;
        lli a1 = mod_fact(n, p, e1),
            a2 = mod_fact(k, p, e2),
            a3 = mod_fact(n - k, p, e3);

        if (e1 > e2 + e3) return 0LL;
        return a1 * mod_inverse(a2 * a3 % p, p) % p;
}

int main() {
        lli p = 998244353;
        lli n, a, b, k;
        cin >> n >> a >> b >> k;

        fact[1] = 1;
        for (lli i = 2; i <= 300000; i++) {
                fact[i] = fact[i - 1] * i % p;
        }

        lli sum = 0;
        for (lli i = 0; i <= n; i++) {
                lli x = i;
                lli y = floor((k - a * x) / b);

                if (x * a + y * b != k || x > n || y > n || x < 0 || y < 0) continue;

                sum += mod_comb(n, x, p) * mod_comb(n, y, p) % p;
                sum %= p;
        }

        cout << sum << endl;

        return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<set>
using namespace std;
typedef long long li;
#define yn(i) ((i)?"Yes":"No")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

int reach(vector<int>& vec,int x,int head=0){
  set<int> st;
  st.insert(0);
  int n=vec.size();
  rep(i,n){
    set<int> st0;
    for(int t:st){
      int temp=t+vec[i];
      st0.insert(temp);
      temp=t-vec[i];
      if(temp<0) temp*=-1;
      st0.insert(temp);
    }
    st=st0;
  }
  return st.count(x-head) or st.count(head-x);
}

int main(){
  string s; cin >>s;
  int x,y; cin >>x >>y;
  int n=s.size();
  int head=0;
  int i=0;
  for(;i<n;i++){
    if(s[i]=='T') break;
    head++;
  }
  int flag=0;
  vector<int> ew,ns;
  int cnt=0;
  for(;i<n;i++){
    if(s[i]=='T'){
      if(cnt)(flag?ns:ew).push_back(cnt);
      flag^=1;
      cnt=0;
      continue;
    }
    cnt++;
  }
  (flag?ns:ew).push_back(cnt);
  if(df)print("ns:",ns,"\new:",ew);
  print(yn(reach(ns,y) and reach(ew,x,head)));
}


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

public class Main {
  private static String solve(long a, long b, long k) {
    if (a > k) {
      return String.format("%d %d", a - k, b);
    }
    if (a + b > k) {
      return String.format("%d %d", 0, b - (k - a));
    }
    return "0 0";
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    long a = reader.nextLong();
    long b = reader.nextLong();
    long k = reader.nextLong();
    out.println(solve(a, b, k));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21204