akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <cstdio>
#define INF (10e9+1)
#define int long long
using namespace std;
int comp;
void merge(int* A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  vector<int> L(n1+1), R(n2+1);
  for( int i = 0; i < n1 ; ++i)
    L[i] = A[left + i] ;
  for( int i = 0; i < n2 ; ++i)
    R[i] = A[mid + i];
  L[n1] = INF;
  R[n2] = INF;
  int i = 0, j = 0;
  for (int k = left ; k < right ; ++k){
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else {
      A[k] = R[j];
      j = j + 1;
    }
    comp++;
  }
}

void mergeSort(int* A, int left, int right){
  if (left+1 < right){
    int mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int s[500000];
signed main(){
  int n;
  scanf("%lld", &n);
  for (int i=0;i<n;i++){
    scanf("%lld", s+i);
  }
  comp = 0;
  mergeSort(s, 0, n);
  for (int i=0;i<n;i++){
    if (i!=0) printf(" ");
    printf("%lld", s[i]);
  }
  printf("\n%d\n", comp);
  return 0;
}


Measured memory_bytes: 10116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 1000001;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
	int n, k; cin >> n >> k;
	vector<ll> a(n);
	COMinit();
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	sort(a.begin(), a.end());
	ll ans = 0;
	for(int i = n - 1; i >= k - 1; i--) {
		ans += (a[i] * COM(i, k - 1)) % MOD;
		 ans %= MOD;
	}
	for(int i = 0; i <= n - k; i++){
		ans = ans - (a[i] * COM(n - i - 1, k - 1)) % MOD + MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 24448
package main

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

var (
	N      int
	X      [100]int
	answer int
)

func readVariables() {
	N = nextInt()
	for i := 0; i < N; i++ {
		X[i] = nextInt()
	}
}

func main() {
	readVariables()
	answer = 1234567890123456
	for i := 0; i < 101; i++ {
		s := 0
		for j := 0; j < N; j++ {
			s += (X[j] - i) * (X[j] - i)
		}
		answer = MinInt(s, answer)
	}
	fmt.Println(answer)
}

/* 以下、テンプレート*/

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt は、2つの整数を受け取り、最小値を返します。
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt は、2つの整数を受け取り、最大値を返します。
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt は、整数の絶対値を返します。
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow は整数の累乗関数で、剰余もサポートします。
//base^exponentの値をmoduleで割った余りを返します。
//moduloが1以下の場合には、剰余演算をしません。
//baseが負の値である場合には、返す値が負になることがあります。
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd は、引数の整数全ての最大公約数を返します。
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm は、与えられた整数の最小公倍数を返します。
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,M;
    int s,t;
    vector<pair<int,int>> ST;
    vector<int> G[628];
    cin >> N >> M;
    REP(i,M){
        cin >> s >> t;
        s--;t--;
        ST.push_back({s,t});
        G[s].push_back(t);
    }
    
    double D[600]={};
    double Ans=INF;
    REP(k,N+1){
        REP(i,N){
            D[i]=INF;
        }
        D[N-1]=0;
        RREP(i,N){
            double v=0;
            double mx=0;
            REP(j,G[i].size()){
                v+=D[G[i][j]];
                mx=max(mx,D[G[i][j]]);
            }
            int Y=G[i].size();
            if(k==i){
                v-=mx;
                Y--;
            }
            if(Y==0)continue;
            v/=Y;
            v+=1.0;
            D[i]=v;
        }
        
        Ans=min(Ans,D[0]);
        /*REP(i,N){
            printf("%.4f ",D[i]);
        }cout << endl;*/
    }
    printf("%.8f\n",Ans);
    return 0;
}



Measured memory_bytes: 7912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int[] w = new int[n];
		int[] e = new int[n];
		// i番目の位置よりも左側にいくつのWが存在するか
		for(int i = 0 ; i < n - 1 ; i++) {
			if(s.charAt(i) == 'W') w[i + 1] = w[i] + 1;
			else w[i + 1] = w[i];
		}
		// i番目の位置よりも右側にいくつのEが存在するか
		for(int i = n - 1 ; i >= 1 ; i--) {
			if(s.charAt(i) == 'E') e[i - 1] = e[i] + 1;
			else e[i - 1] = e[i];
		}
		int ans = Integer.MAX_VALUE;
		for(int i = 0 ; i < n ; i++) {
			ans = Math.min(ans, w[i] + e[i]);
		}
//		System.out.println(Arrays.toString(w));
//		System.out.println(Arrays.toString(e));
		System.out.println(ans);
	}
}


Measured memory_bytes: 30740
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=3e5+10;
const ll MOD=10;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
int H,W,M;
int col[MAXN];
int row[MAXN];
void solve(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>H>>W>>M;
    set<pair<int,int>>tgt;
    for(int u=0;u<M;u++){
        int h,w;
        cin>>h>>w;
        tgt.insert({h,w});
        row[h]++;
        col[w]++;
    }
    vector<pair<int,int>>r,c;
    for(int u=1;u<=H;u++){
        if(row[u])r.push_back({row[u],u});
    }
    for(int u=1;u<=W;u++){
        if(col[u])c.push_back({col[u],u});
    }
    sort(r.begin(),r.end());
    reverse(r.begin(),r.end());
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    int ans=0;
    int acr=r.front().first;
    for(auto p:c){
        int t=acr+p.first;
        if(tgt.count({r.front().second,p.second}))t--;
        ans=max(ans,t);
    }
    acr=c.front().first;
    for(auto p:r){
        int t=acr+p.first;
        if(tgt.count({p.second,c.front().second}))t--;
        ans=max(ans,t);
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 28024
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

    int N,A,B;
    cin >> N >> A >> B;
    cout << min(A,B) << endl;
    if(N-A-B >= 0) cout << 0 << endl;
    else cout << A+B-N << endl;

    return 0;
}*/

/*
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    int ans = 0;
    for(int i=0; i<N; i++){
        if(A[i] == B[i] && A[i] != C[i]) ans++;
        if(A[i] == C[i] && A[i] != B[i]) ans++;
        if(B[i] == C[i] && A[i] != B[i]) ans++;
        if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i]) ans += 2;
        //cout << ans << " " << i << endl;
    }
    cout << ans << endl;
    
    return 0;
}*/



/*
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    LL A[100000], B[100000];
    vector<pair<LL,int> > tmp;
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
        tmp.push_back(MP(A[i]+B[i],i));
    }
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());

    LL p1 = 0;
    LL p2 = 0;
    for(int i=0; i<N; i++){
        if(i%2 == 0) p1 += A[tmp[i].second];
        else p2 += B[tmp[i].second];
    }
    cout << p1 - p2 << endl;
    
    return 0;
}*/


int N,M;
int A[100000],B[100000];
vector<int> oya[100000];

int dp[100000];
int solve(int now){
    if(dp[now] != -1) return dp[now];
    if(oya[now].size() == 0) return dp[now] = 0;
    if(oya[now].size() == 1) return dp[now] = solve(oya[now][0]) + 1;
    int tmp = -1;
    int p = -1;
    for(int i=0; i<oya[now].size(); i++){
        if(solve(oya[now][i]) > tmp){
            tmp = solve(oya[now][i]);
            p = oya[now][i];
        }
    }
    oya[now].clear();
    oya[now].push_back(p);
    return dp[now] = tmp + 1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> M;
    for(int i=0; i<N-1+M; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        oya[B[i]].push_back(A[i]);
    }

    for(int i=0; i<N; i++) dp[i] = -1;
    for(int i=0; i<N; i++){
        int t = solve(i);
        if(t == 0) cout << 0 << endl;
        else cout << oya[i][0]+1 << endl;
    }
    
    return 0;
}


/*

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

Measured memory_bytes: 12416
#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.at(i);
  sort(a.begin(),a.end());
  int ans=0;
  for(int i=0;i<N;++i) ans+=a.at(i)-1;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      
      int n =  sc.nextInt();
      	int[] a = new int[n];
      
      for(int i=0;i<n;i++){
      	a[i] = sc.nextInt();
      }
      int count = 0;
      while(true){
      	      for(int i=0;i<n;i++){
                if (a[i] % 2 == 1){
                	System.out.println(count);
                  return;
                }
                a[i] = a[i] / 2;
      }
        count++;
      }
	}
}

Measured memory_bytes: 21972
n, k = gets.chomp.split.map(&:to_i)
R, S, P = gets.chomp.split.map(&:to_i)
t = gets.chomp.split('')

def win(hand)
  case hand # 相手の
  when 'r'
    P
  when 's'
    R
  when 'p'
    S
  end
end

ans = 0
n.times do |i|
  if i <= k - 1
    ans += win(t[i])
  else
    if t[i] == t[i-k]
      t[i] = 'no'
    else
      ans += win(t[i])
    end
  end
end
p ans


Measured memory_bytes: 8828
a = 3.times.map { gets.split.map(&:to_i) }
n = gets.to_i
b = n.times.map { gets.to_i }

hitted = Array.new(3) { Array.new(3, false) }
3.times do |i|
  3.times do |j|
    hitted[i][j] = true if b.any? { |n| n == a[i][j] }
  end
end

transposed = hitted.transpose
ans = 'No'

3.times do |i|
  ans = 'Yes' if hitted[i].all? || transposed[i].all?
end

if [hitted[0][0], hitted[1][1], hitted[2][2]].all? || [hitted[0][2], hitted[1][1], hitted[2][0]].all?
  ans = 'Yes'
end

puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <map>
#include <queue>


using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

void search_depth(vector<ll>& ans, vector<int>& flag, vector< vector<int> >& vt, int next_p, ll tmp, map<int,int>& M){
    tmp+=M[next_p];
    ans[next_p]=tmp;
    flag[next_p]=1;
    for(auto nt: vt[next_p]){
        if(flag[nt]==0) search_depth(ans, flag, vt, nt, tmp, M);
    }
}

int main(){
    int N,Q;
    cin >> N >> Q;
    vector< vector<int> > vt(N);
    vector<int> flag(N,0);
    map<int,int> M;
    for(int i=0,a,b; i<N-1; i++){
        cin >> a >> b;
        a--;b--;
        vt[a].push_back(b);
        vt[b].push_back(a);
    }
    for(int i=0,p,x; i<Q; i++){
        cin >> p >> x;
        p--;
        M[p]+=x;
    }
    vector<ll> ans(N,0);

    search_depth(ans, flag, vt, 0, 0, M);
    for(int i=0; i<ans.size()-1; i++){
        cout << ans[i] << ' ';
    }
    cout << ans[ans.size()-1] << endl;




    return 0;
}

Measured memory_bytes: 47884
// AOJ ITP1_9_D Transformation
// 2018.4.30 bal4u
 
#include <stdio.h>
 
char str[1005];
char p[1005];
 
int main()
{
    int q, a, b;
    char op[10], *x, *y, c;
     
    scanf("%s%d", str, &q);
    while (q--) {
        scanf("%s%d%d", op, &a, &b);
        if (op[2] == 'i') {             // print
            b++, c = *(str+b), *(str+b) = 0, puts(str+a), *(str+b) = c;
        } else if (op[2] == 'v') {      // reverse
            x = str+a, y = str+b;
            while (x < y) {
                c = *x, *x = *y, *y = c;
                x++, y--;
            }
        } else {                        // replace
            scanf("%s", p);
            x = str+a, y = p;
            while (*y) *x++ = *y++;
        }
    }
    return 0;
}


Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> h(13);
	++h[0];
	for(int i = 0; i < n; ++i){
		int di;
		cin >> di;
		++h[di];
	}
	if(h[0] >= 2 || h[12] >= 2){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i < 12; ++i){
		if(h[i] >= 3){
			cout << 0 << endl;
			return 0;
		}
	}
	int fixed = 0, variable = 0;
	if(h[0]  == 1){ fixed |= (1 << 12); }
	if(h[12] == 1){ fixed |= (1 <<  0); }
	for(int i = 1; i < 12; ++i){
		if(h[i] == 2){
			fixed |= (1 << (12 - i));
			fixed |= (1 << (12 + i));
		}else if(h[i] == 1){
			variable |= (1 << i);
		}
	}
	int answer = 0;
	for(int i = ((1 << 13) - 1) & variable; i >= 0; i = ((i - 1) & variable)){
		int set = fixed;
		for(int j = 0; j <= 12; ++j){
			if(variable & (1 << j)){
				if(i & (1 << j)){
					set |= (1 << (12 + j));
				}else{
					set |= (1 << (12 - j));
				}
			}
		}
		int s = 24;
		int last = __builtin_ctz(set);
		for(int j = last + 1; j < 24; ++j){
			if(set & (1 << j)){
				const int t = j - last;
				s = min(s, min(t, 24 - t));
				last = j;
			}
		}
		const int t = last - __builtin_ctz(set);
		if(t > 0){ s = min(s, min(t, 24 - t)); }
		answer = max(answer, s);
		if(i == 0){ break; }
	}
	cout << answer << endl;
	return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}


void solve()
{
  ll a, b; cin >> a;
  string s; cin >> s;
  b = (s[0]-'0') * 100 + (s[2]-'0')*10 + (s[3]-'0');
  
  ll ans = 0;
  ans = a * b;
  cout <<( ans / 100) << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<int, int> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;
const int MAX = 100005;

int min_swap(vector<int> prm){
    int n = prm.size(); int res = 0;
    rep(i, n){
        rep(j, i){
            if(prm[j] > prm[i]) res++;
        }
    }
    return res;
}

int main(){
    int n; cin >> n;
    vector<int> a, b;
    rep(i, n * 2){
        int x; cin >> x;
        if(i < n) a.push_back(x);
        else b.push_back(x);
    }
    int max = (1<<n); int ans = 10000;
    rep(bit, max){
        vector<pair<int, P> > vec;
        rep(j, n){
            if(!(bit & (1<<j))) vec.push_back(make_pair(a[j], make_pair(j, 0)));
            else vec.push_back(make_pair(b[j], make_pair(j, 1)));
        }
        sort(all(vec), [](auto const &l, auto const &r)->bool{
            if(l.fi != r.fi) return l.fi < r.fi;
            return l.se.fi < r.se.fi;
        });

        bool isok = true;
        rep(j, n){
            if((j + vec[j].se.fi + vec[j].se.se) % 2 == 0) continue;
            int k = 1;
            while(true){
                if(j + k >= n || vec[j].fi != vec[j+k].fi){
                    isok = false;
                    break;
                }
                if((j + vec[j+k].se.fi + vec[j+k].se.se) % 2 == 0){
                    for(int l = k; l >= 1; l--) swap(vec[j+l], vec[j+l-1]);
                    break;
                }
                k++;
            }
            if(!isok) break;
        }

        if(isok){
            vector<int> prm;
            rep(j, n){
                prm.push_back(vec[j].se.fi);
            }
            ans = min(ans, min_swap(prm));
        }
    }
    if(ans == 10000) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $Y);

$k5 = 0;
$answer = "-1 -1 -1";

$k10max = floor($Y / 10000);
for ($i = 0; $i <= $k10max; $i++) {
    $k1 = ($Y - $i * 10000) / 1000;
    if ((($i + $k1) - $N) % 4 == 0) {
        $k5 = (($i + $k1) - $N) / 4;
        $k1 -= $k5 * 5;
        if ($k5 < 0 || $k1 < 0) continue;

        $answer = "{$i} {$k5} {$k1}";
        break;
    }
}

echo $answer . PHP_EOL;


Measured memory_bytes: 4984
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int v[N];
  vector<int> arr1, arr2;
  map<int, int> amap, bmap;
  for(int i=0;i<N;++i) {
    cin>>v[i];
    if(i%2==0) {
      if(amap[v[i]]==0) arr1.push_back(v[i]);
      amap[v[i]]++;
    }
    else {
      if(bmap[v[i]]==0) arr2.push_back(v[i]);
      bmap[v[i]]++;
    }
  }
  vector<pair<int, int> > arr11, arr22;
  for(int i=0;i<arr1.size();++i) arr11.push_back(mp(amap[arr1[i]], arr1[i]));
  for(int i=0;i<arr2.size();++i) arr22.push_back(mp(bmap[arr2[i]], arr2[i]));
  sort(arr11.begin(), arr11.end(), greater<pair<int, int> >());
  sort(arr22.begin(), arr22.end(), greater<pair<int, int> >());
  int ans = inf;
  if(arr11[0].se!=arr22[0].se) {
    ans = min(ans, N-arr11[0].fi-arr22[0].fi);
  }
  else if(arr11.size()>1 && arr22.size()>1) {
    ans = min(ans, N-arr11[0].fi-arr22[1].fi);
    ans = min(ans, N-arr11[1].fi-arr22[0].fi);
  }
  else if(arr11.size()==1 && arr22.size()>1) {
    ans = min(ans, N-arr11[0].fi-arr22[1].fi);
    ans = min(ans, N-arr22[0].fi);
  }
  else if(arr11.size()>1 && arr22.size()==1) {
    ans = min(ans, N-arr22[0].fi-arr11[1].fi);
    ans = min(ans, N-arr11[0].fi);
  }
  else {
    ans = min(ans, N-arr11[0].fi);
    ans = min(ans, N-arr22[0].fi);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 9744
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// chrono::steady_clock sc;
 //  	auto start = sc.now();
 //  	ifstream cin;
 //  	cin.open("INPUT.txt");

	string s,t;
	cin>>s>>t;
	int n=s.length();
	int m=t.length();
	int dp[n+1][m+1]={0};
	for (int i = 0; i < n+1; ++i)
	{
		for (int j = 0; j < m+1; ++j)
		{
			dp[i][j]=0;
		}
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			if(s[i-1]==t[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int i=s.length();
	int j=t.length();
	string res="";
	while(i>0 && j>0)
	{
		if(dp[i][j]==dp[i-1][j])
		{
			i--;
		}
		else if(dp[i][j]==dp[i][j-1])
		{
			j--;
		}
		else
		{
			res=s[i-1]+res;
			i--;
			j--;
		}
	}
	cout<<res<<endl;
	
	// cin.close();
	// auto end = sc.now();
 //   	auto time_span = static_cast<chrono::duration<double>>(end - start);
 //   	cout<<"Operation took: "<<time_span.count()<<" seconds";

	return 0;
}

Measured memory_bytes: 35456
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w,n;
int G[250001][22];
bool used[22][250001];

bool C(int v){
	for(int i=0;i<20;i++){
		memset(used[i+1],false,sizeof(used[i+1]));
		if((v>>i) & 1){
			for(int j=0;j<w*h;j++){
				if(used[i][j]){
					if(used[i+1][G[j][i]])return true;
					used[i+1][G[j][i]]=true;
				}
			}
		}else{
			for(int j=0;j<w*h;j++){
				used[i+1][j]=used[i][j];
			}
		}
	}
	return false;
}


int main(void){
	scanf("%d%d%d",&h,&w,&n);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int r,c;
			scanf("%d%d",&r,&c);
			G[i*w+j][0]=r*w+c;
		}
	}
	for(int i=0;i<n;i++){
		int r,c;
		scanf("%d%d",&r,&c);
		used[0][r*w+c]=true;
	}
	for(int i=1;i<20;i++){
		for(int j=0;j<h*w;j++){
			G[j][i]=G[G[j][i-1]][i-1];
		}
	}
	int l=0,r=h*w+1;
	while(r-l>1){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r==h*w+1?-1:r);
	return 0;
}

Measured memory_bytes: 29780
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;

    int rating;
    cin >> rating;

    cout << ((rating >= 1200) ? "ARC" : "ABC") << endl;
}


Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define mkp make_pair
#define no {cout << "-1\n"; return;}

const int N = 1e6 + 7;

int d[N];

void precalc() {
    loop1(i, N - 1)
        d[i] = 1;
    for (int i = 2; i < N; ++i) {
        if (d[i] == 1) {
            d[i] = 2;
            for (int j = 2 * i; j < N; j += i) {
                int deg = 0, jj = j;
                while (jj % i == 0) {
                    jj /= i; ++deg;
                }
                d[j] *= (deg + 1);
            }
        }
    }
    loop1(i, N - 1)
        d[i] += d[i - 1];
}

void solve() {
    int n; cin >> n;
    cout << d[n - 1];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    precalc();
    solve();
    return 0;
}

Measured memory_bytes: 11468
# -*- coding: utf-8 -*-
# 整数の入力

N = int(raw_input())

b = map(int, raw_input().split(' '))
if 1 not in b:
    print -1
    exit()
a = []

for i in range(N, 0, -1):
    for j in range(i, 0, -1):
        if b[j-1] == j:
            a.append(j)
            b.pop(j-1)
            break


if len(b) != 0:
    print -1
    exit()


for i in (reversed(a)):
    print i


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

using namespace std;

int main() {
    string n2str[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
    int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

    int n, m;
    cin >> n >> m;

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

    vector<string> dp(n + 10, "");
    for (int i = 0; i < m; i++) {
        dp[cost[a[i]]] = n2str[a[i]];
    }

    for (int i = 2; i < n; i++) {
        if (dp[i] == "") {
            continue;
        }

        for (int j = 0; j < m; j++) {
            string s = dp[i + cost[a[j]]];
            string t = n2str[a[j]][0] >= dp[i][0] ? n2str[a[j]] + dp[i] : dp[i] + n2str[a[j]];
            if (s.size() != t.size() ? s.size() < t.size() : s < t) {
                dp[i + cost[a[j]]] = t;
            }
        }
    }

    cout << dp[n] << endl;
}


Measured memory_bytes: 34944
#include<iostream>
#include<algorithm>
using namespace std;
int d(int n,int l);
int a[100],ar[10];
bool q;
int main(){
int a0,l;
    while(1){
        q=false;
        cin>>a0>>l;  
    if(a0==0&&l==0)return 0;
    a[0]=a0; 
    int j=1;
    while(1){
        a[j]=d(a[j-1],l);
        for(int k=0;k<j;k++){
            if(a[k]==a[j])
            {
                cout<<k<<" "<<a[k]<<" "<<j-k<<endl;
                q=true;
                break;
            }
        }
        if(q)break;
        j++;
    }
    }
}

int d(int n,int l){
    for(int i=0;i<l;i++){
        ar[i]=n%10;
        n/=10;
    }
    sort(ar,ar+l);
    int max=0,min=0;
    for(int i=0;i<l;i++){
        min*=10;
        min+=ar[i];
    }
    for(int i=l-1;i>-1;i--){
        max*=10;
        max+=ar[i];
    }
    return max-min;
}



Measured memory_bytes: 3148
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	string s,t;
	cin >> s >> t;
	t.erase(s.size());
	if(s==t)
	cout << "Yes";
	else
	cout << "No" ;
	
	
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int N,M;
int T[110];
int P[110],X[110];
int main()
{
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> T[i];
  }
  cin >> M;
  for(int i=0;i<M;++i){
    cin >> P[i] >> X[i];
  }
  int sum=0;
  for(int i=0;i<N;++i){
    sum+=T[i];
  }
  for(int i=0;i<M;++i){
    int res=sum+X[i]-T[P[i]-1];
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
# 入力
O=list(input())
E=list(input())

s=''
while True:
  # 各文字列両方とも空になったら終了
  if len(O)==0 and len(E)==0:
    break

  if len(O)!=0:
    s+=O[0]
    O.remove(O[0])

  if len(E)!=0:
    s+=E[0]
    E.remove(E[0])

# 出力
print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a[25];
int ans,n;
bool f=true;
int main() {
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++) {
		f=true;
		for(int j=i-1; j>0; j--) {
			if(a[i]<a[j]) {
				f=false;
				break;
			}
		}
		if(f==true)
			ans++;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
int solve()
{
	char t;
	cin>>t;
	if(t=='z')
		cout<<"a"<<endl;
	else
		t++, cout<<t<<endl;
	



}
signed main()
{
	fastio;
	clock_t start, end;
//	test
	{
		start=clock();
		solve();
		end=clock();
		double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
//		cout<<time_taken<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }


struct UnionFind{
	vector<int> data;
	
	UnionFind(int n){
		data.assign(n,-1);
	}
	
	bool unite(int x,int y){
		x=find(x),y=find(y);
		if(x==y) return(false);
		if(data[x]>data[y]) swap(x,y);
		data[x]+=data[y];
		data[y]=x;
		return(true);
	}
	
	int find(int k){
		if(data[k]<0) return(k);
		return(data[k]=find(data[k]));
	}
	
	int size(int k){
		return(-data[find(k)]);
	}
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,k;cin >> n >> m >> k;
	UnionFind uf = UnionFind(n);
	vector<vector<int>> g(n,vector<int>());
	vector<int> cnt(n);
	rep(i,m){
		int a,b;cin >> a >> b;
		a--;b--;
		uf.unite(a,b);
		cnt[a]++;
		cnt[b]++;
	}
	rep(i,k){
		int a,b;cin >> a >> b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	vector<int> ans(n);
	rep(i,n){
		ans[i] = uf.size(i) - cnt[i] - 1;
		for(auto j : g[i]){
			if(uf.find(i) == uf.find(j)) ans[i]--;
		}
	}
	rep(i,n){
		cout << ans[i] << (i != n - 1 ? ' ' : '\n');
	}
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,t;
  cin >> n >> t;
  int min = 1010;
  vector<vector<int>> time(n,vector<int>(2));
  for(int i = 0;i < n;i++){
    cin >> time.at(i).at(0) >> time.at(i).at(1);
    if(time.at(i).at(1) <= t){
      if(time.at(i).at(0) < min) min = time.at(i).at(0);
    }
  }
  if(min > 1000) cout << "TLE" << endl;
  else cout << min << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>

typedef long long ll;

#define MAX_N 100'001

using namespace std;

int A[MAX_N];
int B[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i <= N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  ll cnt = 0;
  for (int i = N - 1; i >= 0; --i) {
    cnt += (ll)min(B[i], A[i + 1]);
    B[i] = max(0, B[i] - A[i + 1]);
    cnt += (ll)min(B[i], A[i]);
    A[i] = max(0, A[i] - B[i]);
  }
  printf("%lld\n", cnt);
}

Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
  vector<int> ans(n+1);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int s = x*x + y*y + z*z;
        s += x*y + y*z + z*x;
        if (s > n) continue;
        ans[s]++;
      }
    }
  }
 
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

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

int main(){
    int t;
    t=1;
    while(t--){
        string s;
        cin >> s;
        int ans = 0;
        for(int i=0;i<s.length();i++){
            ans=(ans%9+(s[i]-'0')%9)%9;
            
        }
        if(ans == 0)cout << "Yes" << endl;
            else{
                cout << "No"<< endl;
            }
    }
}

Measured memory_bytes: 3732
# -*- coding: utf-8 -*-

mod = int(1e9+7)

def comb_mod(n, r, mod):
    if n < r:
        return 0
    elif n < 0 or r < 0:
        return 0
    else:
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, n + 1):
            fac.append(fac[-1] * i % mod)
            inv.append(-inv[mod % i] * (mod // i) % mod)
            finv.append((finv[-1] * inv[-1]) % mod)
        return int(fac[n] * finv[r] * finv[n - r] % mod)

X,Y = (int(x) for x in input().split())
count = 0
if (X+Y)%3!=0 or 2*X<Y or 2*Y<X:
    print("0")
    exit()
else:
    N=(X+Y)/3 # 合計移動回数
    mov_x=(2*X-Y)/3 #(+2,+1)の移動回数
    print(comb_mod(int(N), int(mov_x), mod))


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

    vector<int> pm(N);
    pm.at(0) = -1;
    for (int i = 1; i < N; i++) pm.at(i) = A.at(i) - A.at(i-1);

    ll money = 1000, money_old = 1000, kabu = 0, min_v = 201, max_v = 99;
    int i = 0;

    while (true) {
        if (pm.at(i) < 0) {
            min_v = A.at(i);
            while (true) {
                if (pm.at(i) <= 0) {
                    min_v = A.at(i);
                    i++;
                    if (i > N - 1) break;
                    else continue;
                } else {
                    money_old = money;
                    kabu = money / min_v;
                    money -=  min_v * kabu;
                    break;
                }
            }
        } else if (pm.at(i) > 0) {
            max_v = A.at(i);
            while (true) {
                if (pm.at(i) >= 0) {
                    max_v = A.at(i);
                    i++;
                    if (i > N - 1) {
                        money += max_v * kabu;
                        kabu = 0;
                        break;
                    } else continue;
                } else {
                    money +=  max_v * kabu;
                    kabu = 0;
                    break;
                }
            }
        } else i++;
        
        if (i > N - 1) {
            if (kabu > 0) money += A.at(N - 1) * kabu;
            break;
        }
        else continue;
    }
    cout << max(money, money_old) << endl;
    //cout << money << endl;
    return 0;
}


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

template <typename T>
void my_unique(T &vt)
{
	sort(vt.begin(), vt.end());
	vt.erase(unique(vt.begin(), vt.end()), vt.end());
}

int main()
{
	vector<string> pvec;
	string s;
	int n;
	cin >> n;
	while (n--) {
		cin >> s;
		pvec.push_back(s);
	}
	my_unique(pvec);

	cout << pvec.size();
	return 0;
}


Measured memory_bytes: 11616
#include <iostream>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;
typedef long long lint;

int x, y, s;

int tax(int price, int rate){
	return price * (rate+100) / 100;
}

int main(){
	while(true){
		cin >> x >> y >> s;
		if(!x) return 0;
		int ans = 0;
		For(i, 1, s-1)For(j, 1, s-1)if(tax(i, x)+tax(j, x) == s){
			ans = max(ans, tax(i, y)+tax(j, y));
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3048
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	long[][][] DP;
	
	long maxDP(int x, int y){
		return  Math.max(DP[x][y][3],
					Math.max(DP[x][y][2],
					Math.max(DP[x][y][1], DP[x][y][0])));
	}

	public Main() {
		FastScanner scanner = new FastScanner();
		int R = scanner.nextInt();
		int C = scanner.nextInt();

		DP = new long[C+1][R+1][4];
		long[][] values = new long[C+1][R+1];

		int K = scanner.nextInt();
		for (int i = 0; i < K; i++) {
			int y = scanner.nextInt();
			int x = scanner.nextInt();
			values[x][y] = scanner.nextLong();
		}
		

		for (int y = 1; y <= R; y++) {
			for (int x = 1; x <= C; x++) {
				long value = values[x][y];
				DP[x][y][0] = Math.max(DP[x-1][y][0], maxDP(x,y-1));
				DP[x][y][1] = Math.max(DP[x-1][y][1], DP[x][y][0]   + value);
				DP[x][y][2] = Math.max(DP[x-1][y][2], DP[x-1][y][1] + value);
				DP[x][y][3] = Math.max(DP[x-1][y][3], DP[x-1][y][2] + value);
			}
		}

		System.out.println(maxDP(C, R));
	}

	public static void main(String[] args) {
		new Main();
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 602160
while True:
    W, H, x, y, r = map(int, input().split())
    if W > 0 and W <= 100:
        if H > 0 and H <= 100:
            if x >= -100 and x <= 100:
                if y >= -100 and y <= 100:
                    if r > 0 and r <= 100:
                        break
         
if x+r <= W and x-r >= 0 and y+r <= H and y-r >= 0:
    print("Yes")
else :
    print("No")


Measured memory_bytes: 5596
#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))

const ll mod = 1000000007ll;
const ll nyaaaa = 407182070ll;
const int MAX_N = 2000000;
ll A[2002002], B[2002002]={1}, C[2002002]={1},D[2002002]={1};
void nyan(){
    A[MAX_N] = nyaaaa;
    for(int i=1; i<=MAX_N; i++){
        A[MAX_N-i] = A[MAX_N-i+1] * (MAX_N-i+1) % mod;
        B[i] = B[i-1] * i % mod;
        C[i] = C[i-1] * 25 % mod;
        D[i] = D[i-1] * 26 % mod;
    }
    return;
}
int k;
char s[1001001];
int main(){
    nyan();
    scanf("%d%s", &k, s);
    int l = strlen(s);
    ll ans = 0;
    for(int i=0; i<=k; i++){
        ans += D[k-i] * C[i] % mod * B[l+i-1] % mod * A[l-1] % mod * A[i] % mod;
        ans %= mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 65244
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>d(N);
	rep(i, N)cin >> d[i];
	sort(d.begin(), d.end());
	cout << d[N / 2] - d[N / 2 - 1];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

void solve()
{
    ll n,ans=0;
    cin >> n;
    for(ll i=1;i<n;i++)
    {
        for(ll j=1;j*i<n;j++)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 1000000007;
vector< vector< pair< int, long long int > > >v;
bool ec(int id, long long int* a, bool* b, long long int cs ) {
  a[id] = cs;
  b[id] = true;
  vector <pair<int, long long int> > vv = v[id];
  for(int i = 0; i < vv.size(); i++) {
    if(b[vv[i].first]) continue;
    ec(vv[i].first,a,b,vv[i].second + cs);
  }
}

int main() {
  int N;
  cin >> N;
  int a[N-1],b[N-1],c[N-1];
  for(int i = 0; i < N-1; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  int Q,K;
  cin >> Q >> K;
  K--;
  int x[Q],y[Q];
  for(int i = 0; i < Q; i++) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  long long int n_c[N];
  bool visit[N];
  for(int i = 0; i < N; i++) {
    v.push_back(std::vector<pair<int, long long int > >());
  }
  for(int i = 0; i < N-1; i++) {
    v[a[i]-1].push_back(pair<int, long long int >(b[i]-1,c[i]));
    v[b[i]-1].push_back(pair<int, long long int >(a[i]-1,c[i]));
  }
  for(int i = 0; i < N; i++) {
    n_c[i] = 0;
    visit[i] = false;
  }

  ec(K,n_c,visit,0);

  for(int i = 0; i < Q; i++){
    cout << (n_c[x[i]] + n_c[y[i]]) << endl;
  }

}


Measured memory_bytes: 24176
#include <bits/stdc++.h>
using namespace std ;
int main(int argc, char const *argv[])
{
	
	string n; 
	cin >> n ; 
	cout << 10 - (n[0]-'0') << 10 - (n[1]-'0') << 10 - (n[2]-'0') << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b,sum,k=1,count=0,x;
    while(1){
        x = scanf("%d %d",&a,&b);
        if(x==EOF)
            break;
        
        sum=a+b;
        k=1;
        count=0;
        while(1){
            if(sum/k==0)
                break;
            k=k*10;
            count++;
        }
        printf("%d\n",count);
        
    }
    
    return 0;
    
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s, t, test;
  cin >> s >>  t;

  int l, fl = 0;
  l = s.length();

  for(int i=0;i<l;i++){
    if(s[i] == t[0]){
        test = s.substr(i, l - i);
        test += s.substr(0,i);
        if(test == t){
            fl = 1;
            break;
        }
    }
  }
  if(fl == 1) cout <<"Yes\n";
  else cout <<"No\n";
  return 0;
}


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

int main(){
  string  s;
  cin>> s;
  
  string ans="Yes";
  for (int i=0; i<s.size(); i++){
    if (i%2==0){
      if(s.at(i)=='L'){
      ans="No";
      break;
      }
    }
    else if (s.at(i)=='R'){
      ans="No";
      break;
    }
  }
  cout<< ans <<endl;
}

Measured memory_bytes: 256
function main(lines) {
    const n = lines.split('\n')[0]
    const rn = lines.split('\n').slice(1).map(Number)
    let max = rn[1] - rn[0];
    let min = rn[0];
    for(let i=1; i<n; i++){
        max = Math.max(rn[i]-min, max)
        min = Math.min(rn[i],min)
    }
    console.log(max)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

int main (void){
    char S[5];

    cin >> S;

    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }


    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
ll n, m, res;
int main(void){
    // Your code here!
    cin >> n >> m;
    res = (n - m) * 100 + m * 1900;
    res *= pow(2, m);
    cout << res << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N, M = LI()
    import collections
    ab = collections.defaultdict(list)
    for i in range(N):
        a, b = LI()
        ab[a].append(-1*b)

    dprint(ab)
    import heapq
    sumb = 0
    tgt = []
    heapq.heapify(tgt)

    for i in range(1, M+1):
        b_list = ab[i]
        for b in b_list:
            heapq.heappush(tgt, b)

        dprint(tgt)
        if len(tgt) != 0:
            mn = heapq.heappop(tgt)
            sumb += mn
            dprint(mn, sumb)
        dprint(tgt)

    print(sumb*-1)

solve()

Measured memory_bytes: 27696