akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())

mod = 10**9 + 7
def mpow(x, n):
  ans = 1
  while n != 0:
    if n&1:
      ans = ans * x % mod
    x = x * x % mod
    n = n // 2
  return ans

fac = [0] * (n+2)
finv = [0] * (n+2)
inv = [0] * (n+2)
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1

for i in range(2, n+1):
  fac[i] = fac[i-1] * i % mod
  inv[i] = mod - inv[mod%i] * (mod // i) % mod
  finv[i] = finv[i-1] * inv[i] % mod

def choose(n,k):
  if n == 0 and k == 0:
    return 1
  if n < 0:
    return 0
  if n < k:
    return 0
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod

for i in range(1, k+1):
    val = (choose(n-k+1, i) * choose(k-1, i-1)) % mod
    print(val)

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  char turn = 'a';
  char winner;
  while(1){
    if(turn == 'a'){
      if(!a.size()){
        winner = 'A';
        break;
      }
      turn = a[0];
      a.erase(a.begin() + 0);
    }else if(turn == 'b'){
      if(!b.size()){
        winner = 'B';
        break;
      }
      turn = b[0];
      b.erase(b.begin() + 0);
    }else{
      if(!c.size()){
        winner = 'C';
        break;
      }
      turn = c[0];
      c.erase(c.begin() + 0);
    }
  }
  cout << winner << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
  if a[i]+1 == a[i+1]:
    ans += c[a[i]-1]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000
int N,ma,mb;
struct package
{
    int a;
    int b;
    int c;
}p[45];
int dp[42][410][410];
//这个问题是一个是范围,一个是取值的问题
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N>>ma>>mb;

    for(int i=1;i<=N;i++)
    {
        cin>>p[i].a>>p[i].b>>p[i].c;
    }

        for(int j=0;j<=400;j++)
        {
            for(int k=0;k<=400;k++)
            {
                dp[1][j][k]=INF;
            }
        }
        dp[1][0][0]=0;
        dp[1][p[1].a][p[1].b]=p[1].c;

    for(int i=2;i<=N;i++)
    {
        for(int va=0;va<=400;va++)
        {
            for(int vb=0;vb<=400;vb++)
            {
                if(va-p[i].a>=0&&vb-p[i].b>=0)
                {
                    dp[i][va][vb]=min(dp[i-1][va][vb],dp[i-1][va-p[i].a][vb-p[i].b]+p[i].c);
                }
                else
                {
                    dp[i][va][vb]=dp[i-1][va][vb];
                }
//                if(va<=15&&vb<=15)
//                {
//                    cout <<"dp["<<i<<"]"<<"["<<va<<"]["<<vb<<"]="<<dp[i][va][vb]<<endl;
//                }
            }
        }
    }
    int ans=INF;
    for(int k=1;k*ma<=400&&k*mb<=400;k++)
    {
        ans=min(ans,dp[N][k*ma][k*mb]);
    }
    if(ans==INF)
    {
        ans=-1;
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T> void chmin(T &a,T b){if(a>b) a=b;}
template<typename T> void chmax(T &a,T b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m,k;
  cin>>n>>m>>k;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  const Int INF = 1e15;
  vector<Int> dp(n+1,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++){
    Int x=a[i],y=a[i];
    chmin(dp[i+1],dp[i]+k);
    for(Int j=0;j<m;j++){
      if(i+j+1>n) break;
      chmax(x,a[i+j]);
      chmin(y,a[i+j]);
      chmin(dp[i+j+1],dp[i]+k+(j+1)*(x-y));
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(3*n);
  for(int i=0; i<3*n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long long int ans=0;
  for(int i=0; i<n; i++){
    ans += a.at(2*i+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
n = int(input())
p = list(map(int, input().split()))

ans = 0
sanko = []
ssanko = []
for i in range(1, n-1):
    sanko = [p[i-1], p[i], p[i+1]]
    ssanko = sorted(sanko)
    if sanko[1] == ssanko[1]:
        ans += 1
print(ans)


Measured memory_bytes: 61868
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize,
        csf: [(u64, u64, u64); n-1]
    }

    for i in 0..n {
        let mut k = i;
        let mut t = 0;
        while k != n-1 {
            let (c, s, f) = csf[k];
            if t < s {
                t = s + c;
                k += 1;
            } else {
                t = s + ceil_div(t - s, f) * f + c;
                k += 1;
            }
        }
        println!("{}", t);
    }
}

#[allow(dead_code)]
fn ceil_div(x: u64, y: u64) -> u64 {
    (x + y - 1) / y
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int num(int n)
{
    int result=1,divisor=10,count=0;
    while(result!=0)
	{
		result=n/divisor;
		count++;
		divisor=divisor*10;
	 }
	 return count;
}
int main()
{
    int n,f=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(num(i)%2==1)
            ++f;
    }
    cout<<f;
    return 0;
}

Measured memory_bytes: 256
//BISMILLAHIR RAHMANIR RAHIM
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define     ll          long long 
#define     MP          make_pair
#define     MT          make_tuple 
#define     endl        '\n'
#define     iscanf(a)   scanf("%d",&a)
#define     llscanf(a)  scanf("%lld",&a)
#define     flp(n)      for(i=0;i<n;i++)
#define     inlp(n)     for(i=n-1;i>=0;i--)
#define     PB          push_back
#define     IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     inout       freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define     mset(arr,n) memset(arr,n,sizeof(arr))
#define     vci         vector<int>
ll gcd(ll a,ll b){ while(b^=a^=b^=a%=b); return a;}

int main(){
int arr[27];
mset(arr,0);
string s;

cin>>s;
for(int i=0;i<4;i++)arr[s[i]-'A']++;
  int tot=0;
for(int i=0;i<27;i++)if(arr[i]==2)tot++;
  if(tot==2)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;

}

Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  string s;
  cin >> k >> s;
  int len;
  len=s.size();
  if(len<=k){
    cout << s << endl;
    return 0;
  }else{
    for(int i=0;i<k;i++){
      cout << s.at(i);
    }
  }
  cout << "..." << endl;
}

Measured memory_bytes: 3548
#from collections import deque
#from heapq import heapify, heappop, heappush
#from bisect import insort, bisect_left
#import sys
#sys.setrecursionlimit(10**9)
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
#N = int(input())
#N, K = map(int, input().split())
S = input()
eda = []
flag = False
N = len(S)
if S[-1] == '1':
  flag = True
if S[0] == '0':
  flag = True
if S[-2] == '0':
  flag = True
for k in range((N-1)//2):
  if S[k] != S[-k-2]:
    flag = True
  if S[k] == '1':
    eda.append(k+1)
if N%2 == 0:
  if S[N//2 -1] == '1':
    eda.append(N//2)
if flag:
  print(-1)
  exit()
ans = []
eda.reverse()
before = eda.pop()
while eda:
  after = eda.pop()
  for k in range(before, after):
    ans.append((k, after))
  before = after
ans.append((before, before+1))
for k in range(before+2, N+1):
  ans.append((before+1, k))
while ans:
  item = ans.pop()
  print(item[0], item[1])
#ans = 0
#for k in range(N):
#print(ans)
#print('Yes')
#print('No')

Measured memory_bytes: 79412
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int e[101][101];
int t;
pai edge[10001];
int c[10001];
int sz[10001];
int n;
int P[10001];
int ans;
int x, y;
void init(int k)
{
    repp(i, 1, k+1)
    {
        P[i]=i;
        sz[i]=1;
    }
}
int root(int a)
{
    if(P[a]==a)
    {
        return a;
    }
    else
    {
        return (P[a]=root(P[a]));
    }
}
bool is_same_set(int a, int b)
{
    return (root(a)==root(b));
}
void unite(int a, int b)
{
    if(sz[root(a)]<sz[root(b)])
    {
        swap(a, b);
    }
    sz[root(a)]+=sz[root(b)];
    P[root(b)]=root(a);
}
int main()
{
    cin >> n;
    rep(i, n)
    {
        rep(j, n)
        {
            cin >> e[i+1][j+1];
        }
    }
    t=0;
    rep(i, n)
    {
        repp(j, i+1, n)
        {
            if((i<j)&&(e[i+1][j+1]!=-1))
            {
                edge[t]=make_pair(e[i+1][j+1]*1000+i+1, j+1);
                //cout << edge[t].first << ' ' << j+1 << ' ' << t << endl;
                t++;
            }
        }
    }
    sort(edge, edge+t);
    //rep(i, t)
    //{
    //	cout << edge[i].first << ' ' << edge[i].second << endl;
    //}
    rep(i, t)
    {
        c[i]=edge[i].first / 1000;
        edge[i]=make_pair(edge[i].first%1000, edge[i].second);
        // cout << c[i] << ' ' << edge[i].first << ' ' << edge[i].second << endl;
    }
    init(n);
    ans=0;
    rep(i, t)
    {
    if(!is_same_set(edge[i].first, edge[i].second))
        {
            unite(edge[i].first, edge[i].second);
            ans+=c[i];
            // cout << edge[i].first << ' ' << edge[i].second << ' ' << i << ' ' << ans << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int makeNumber(int a, int b) {
	vector<int> digit;
	while (b > 0) { digit.push_back(b % 10); b /= 10; }
	while (a > 0) { digit.push_back(a % 10); a /= 10; }
	
	int mul = 1;
	int ret = 0;
	for (int i = 0; i < digit.size(); i++) {
		ret += digit[i] * mul;
		mul *= 10;
	}
	return ret;
}

int n;
int a[10000];

int main() {
	int i, j;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	
	vector<int> koho;
	for (i = 0; i < min(n, 4); i++) {
		for (j = 0; j < min(n, 4); j++) {
			if (i == j) continue;
			koho.push_back(makeNumber(a[i], a[j]));
		}
	}
	sort(koho.begin(), koho.end());
	
	cout << koho[2] << endl;
	return 0;
}

Measured memory_bytes: 3156
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=10007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H,W,i,n;cin>>W>>H>>n;
	vector<vector<int>>zyama(W+2);
	for(i=1;i<=H;i++){zyama[W+1].pub(i);}
	for(i=1;i<=W;i++){zyama[i].pub(H+1);}
	for(i=0;i<n;i++){int x,y;cin>>x>>y;zyama[x].pub(y);}
	vector<bool>tka(H+5);tka[1]=1;
	int sta=1;
	for(int i=1;i<=W;i++){
		for(auto it:zyama[i+1]){
			if(tka[it]){cout<<i<<endl;return 0;}
		}
		if(find(zyama[i+1].begin(),zyama[i+1].end(),sta+1)==zyama[i+1].end()){
			tka[sta+1]=1;
			sta++;
		}
	}
	
	return 0;
}


Measured memory_bytes: 12020
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n;
    cin >> n;
    vi a(n);
    ll sum = 0;
    for(auto &ai : a) {
        cin >> ai;
        sum += ai;
    }
    
    // x_0 = S - 2(a_1 + a_3 + ... + a_{n-2})
    // x_1 = S - 2(a_2 + a_4 + ... + a_{n-1})
    ll tot0 = 0;
    rep(i, (n-1)/2) tot0 += a[2*i+1];
    ll tot1 = sum - tot0 - a[0];
    
    rep(i, n){
        if(i%2 == 0) {
            cout << sum - 2*tot0 << " ";
            tot0 -= a[(i+1)%n];
            tot0 += a[i];
        }
        else {
            cout << sum - 2*tot1 << " ";
            tot1 -= a[(i+1)%n];
            tot1 += a[i];
        }
    }
    cout << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 1792
n=list(map(int,input().split()))
n.sort()
c=0
while True:
    if(n[0]==n[1] and n[0]==n[2]):
        break
    if(n[0]==n[1]):
        n[0]+=1
        n[1]+=1
    else:
        n[0]+=2
    n.sort()
    c+=1
print(c)

Measured memory_bytes: 3060
n = input()
a = list(map(int, input().split()))

Alice_sum = 0
Bob_sum = 0
a.sort(reverse=True)
for i in range(0,len(a)):
    if i % 2 == 0:
        Alice_sum += a[i]
    else:
        Bob_sum += a[i]

print(Alice_sum - Bob_sum)

Measured memory_bytes: 3060
#include<iostream>

int main(){
  int a,b;
  std::cin>>a>>b;
  if(b%2!=0){
    std::cout<<"No"<<std::endl;
  }else if(a*2<=b&&a*4>=b){
    std::cout<<"Yes"<<std::endl;
  }else std::cout<<"No"<<std::endl;
  return 0;
}

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

using namespace std;

int dp[1010][1010] = {};

int main(void) {
    int sz, tz;
    string s, t;
    cin >> s >> t;
    sz = s.size();
    tz = t.size();

    for (int i = 0; i <= tz; i++)
        dp[0][i] = i;
    for (int i = 0; i <= sz; i++)
        dp[i][0] = i;

    for (int i = 1; i <= sz; i++) {
        for (int j = 1; j <= tz; j++) {
            if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1];
            else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
        }
    }
    
    cout << dp[sz][tz] << endl;

    return 0;
}


Measured memory_bytes: 7096
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int N, P;
bool flag[102000];
vector<int> v;

int main() {
  REP(i,0,102000) flag[i] = true;
  for(int i = 2; i<102000; i++){
    if(!flag[i]) continue;
    v.push_back(i);
    for(int j = i*2; j<102000; j += i){
      flag[j] = false;
    }
  }

  while(1){
    cin>>N>>P;
    if(N==-1&&P==-1) break;
    int pos;
    REP(i,0,v.size()){
      if(N < v[i]){
        pos = i;
        break;
      }
    }
    vector<int> tv, nums;
    int cnt = 0;
    REP(i,pos,v.size()){
      if(cnt>=1000) break;
      tv.push_back(v[i]);
      REP(j,0,tv.size()){
        cnt++;
        nums.push_back(v[i]+tv[j]);
      }
    }
    sort(nums.begin(),nums.end());
    cout<<nums[P-1]<<endl;
  }

  return 0;
}

Measured memory_bytes: 3248
/* 
* Binary Tree
* output 1)node_number, 2)parent_number, 3)depth, 4)kind_of_node, 5)child_list
*/

/* inclution */
#include <stdio.h>

/* Definition */
#define MAX 100000
#define NIL -1


/* Prototype */
void preOrder(int);
void inOrder(int);
void postOrder(int);
void printTree(int);

/* Global Variables */
struct node {
  int parent, left, right;
};
typedef struct node Node;

Node T[MAX]; //array for tree
int n; //number of tree array

/* main */
int main(){
  int i,j,key,left,right,root=0;
  
  /* input the number of A[] */
  scanf("%d",&n);
  
  /* initialize array */
  for(i=0;i<n;i++) { //??¨??????NIL??§?????????
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }
  
  /* input datas */
  for(i=0;i<n;i++){
    scanf("%d", &key);
    scanf("%d %d",&left, &right);
    //??????????´?
    T[key].left = left;
    T[key].right = right;

    //???????????¨????????????????????????????¨????
    if(left != NIL) {
      T[left].parent = key;
    }
    if(right != NIL) {
      T[right].parent = key;
    }
  }

//  /* print out */
//  for(i=0;i<n;i++) {
//    printTree(i); //print????????????
//  }
//  
  /* set root node */
  for(i=0;i<n;i++){
    if(T[i].parent == NIL) {
      root = i;
    }
  }

  /* printing */
  printf("Preorder\n");
  preOrder(root);
  printf("\n");
  printf("Inorder\n");
  inOrder(root);
  printf("\n");
  printf("Postorder\n");
  postOrder(root);
  printf("\n");

  return 0;
}

/* Print ???????????? */
void printTree(int u) { //u???node??????
  int i, c;
  /* each elements */
  printf("node %d: ",u); //node
  printf("parent = %d, ", T[u].parent);

  /* print child list */
  printf("[");
  c = T[u].left; //??????????????????
  while(c!=NIL){ //?????????????????¨????????????????????????????????????
    if(c==T[u].left){ //???????????????????????´
      printf("%d",c);
    }else {
      printf(", %d", c); 
    }
    c = T[c].right; //?????????????????????
  }
  printf("]\n");
}


/*????????????*/
void preOrder(int u){ 
  if (u != NIL) {
    //????????????
    printf(" ");
    printf("%d",u);
    //???
    preOrder(T[u].left);
    //???
    preOrder(T[u].right);
  }
}

/*????????????*/
void inOrder(int u){
  if(u != NIL){
    //???????????¨?????¨
    inOrder(T[u].left);
    printf(" ");
    //???????????¨?????????(?????????)
    printf("%d",u);
    //?????¨?????¨
    inOrder(T[u].right);
  }
}


/*????????????*/
void postOrder(int u){
  if (u != NIL) {
    postOrder(T[u].left);
    postOrder(T[u].right);
    printf(" ");
    printf("%d",u);
  }
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int N;
    cin >> N;
    int ans = N%1000;
    if(ans > 0)
    {
        ans = 1000-ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  if(abs(pow(10, round(log10(N))) - N) < 1){
    cout << 10 << rt;
  }
  else{
    ll sum{};
    while(N > 0){
      sum += N%10;
      N /= 10;
    }
    cout << sum << rt;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,m;
  cin>>n>>k;
  m=1;
  for(int i=n;i>0;i--){
    int a,b;
    a=m+k;
    b=2*m;
    if(a<b){
      m=a;
    }
    else{
      m=b;
    }
  }
  cout<<m<<endl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>

#define Rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())

#define eb emplace_back
#define pf push_front
#define dbg(x) cout<<#x" = "<<((x))<<endl
#define fs first
#define sc second
     
using namespace std;
     
     
typedef long long ll;
typedef pair<ll, ll> P;
     
     
int main(){
  ll N;

  cin >> N;

#ifdef DEBUG
  cout << "N=" << N << endl;
#endif

  vector<int> colorToVal;
  for(int i = 0; i < N; ++i){
    int tmp;
    cin >> tmp;
    
    auto itr = lower_bound(colorToVal.begin(), colorToVal.end(), tmp);
    if(itr == colorToVal.begin()) {
      colorToVal.insert(colorToVal.begin(), tmp);
    } else {
      itr--;
      *itr = tmp;
    }
  }

  cout << colorToVal.size() << endl;
  
  return 0;
}


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

int main(){
	
  	int A, B, K;
  	int ans = -1;
  
  	cin >> K >> A >> B;
  
  	for(int i = A; i <= B; i++){
    	if(i%K == 0){
        	ans = i;
          	break;
        }
    }
  
  	if(ans != -1)	cout << "OK" << endl;
  	else	cout << "NG" << endl;
  	
  	return 0;
}

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

int A, B;
int S[5010];
int T[5010];

int subseq(int lo, int hi) {
  int h = -1;
  for (int i=lo; i<=hi; i++) {
    while (S[++h] != T[i]) {
      if (h >= A) return -1;
    }
  }
  if (h >= A) return -1;
  return h;
}

int main() {
  cin >> A >> B;
  for (int i=0; i<A; i++) cin >> S[i];
  for (int i=0; i<B; i++) cin >> T[i];

  int ans = 0;
  int lo = 0, hi = 0;
  while (hi <= B) {
    int h = subseq(lo, hi);
    if (h == -1) {
      if (hi - lo == 0) hi++;
      lo++;
      continue;
    }

    while (hi < B) {
      h++;
      while (S[h] != T[hi+1] && h < A) h++;
      if (h == A) {
        ans = max(ans, hi - lo + 1);
        if (hi - lo == 0) hi++;
        lo++;
        break;
      }
      hi++;
      ans = max(ans, hi - lo + 1);
    }
  }
  cout << ans << "\n";
  return 0;
}

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

int main(){
    string a,b;
    cin>>a>>b;
    int min=INT_MAX;
    for(int i=0; i<a.length(); i++){
        int co=b.length();
        for(int j=0; j<b.length(); j++){
            if(i+j>=a.length()){
                co=b.length();
                break;
            }
            if(b[j]==a[i+j]){
                co--;
            }
        }
        if(co<min)
            min=co;
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int diffA = Math.abs(x - a);
        int diffB = Math.abs(x - b);
        boolean judge = diffA <= diffB;
        String result = judge ? "A" : "B";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21460
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String S = in.next();
            out.println("ABC"+S);
            
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

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

int foo(char * c)
{
  int rc = 0;
  if( *c == ' ' ){
    *c = '3';
  } else if( *c == '3' ){
    *c = '5';
  } else if( *c == '5' ){
    *c = '7';
  } else if( *c == '7' ){
    *c = '3';
    rc = 1;
  }
  return rc;
}

int main()
{
  char orig[12],digi[12],chk[3];
  int n,i,j,cnt;
  scanf("%d",&n);
  sprintf(orig,"%10d",n);
  /* printf("%s\n",orig); */
  for(i=0;i<10;i++){ digi[i] = ' '; }
  digi[10] = (char)0;
  cnt = 0;
  while(1){
    if( foo(&(digi[9])) ){
      for(j=8;j>=0;j--){
        if(!foo(&(digi[j]))) break;
      }
    }
    if( digi[0] != ' ' ) break;
    memset(chk,0,sizeof(chk));
    for(i=0;i<10;i++){
      if(digi[i]=='3') chk[0] ++;
      if(digi[i]=='5') chk[1] ++;
      if(digi[i]=='7') chk[2] ++;
    }
    if( chk[0]==0 || chk[1]==0 || chk[2]==0 ) continue;
    sscanf(digi,"%d",&i);
    if( i>n ) break;
    cnt++;
  }
  printf("%d\n",cnt);
  
  return EXIT_SUCCESS;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 N;
    cin >> N;

    u64 ans = 0;
    for(u64 a=1; a<N; a++) {
        u64 tans = (N - 1) / a;
        ans += tans;
    }

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

Measured memory_bytes: 3632
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	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(); 
	}
    for (int k = 0; k < N; k++){
		System.out.print(A[k]);
		if(k != N-1)System.out.print(" ");
    }   
	    System.out.println("");
	for(int i = 1;i < N;i++){
	    int v = A[i];
	    int j = i - 1;
	    while(j >= 0 && A[j] > v){
		A[j+1] = A[j];
		j--;
		A[j+1] = v;
	    }
	    for (int k = 0; k < N; k++){
		System.out.print(A[k]);
		if(k != N-1)System.out.print(" ");
	    }
	    System.out.println("");
	}
	    
    }
}


Measured memory_bytes: 33960
N, M = gets.split.map( &:to_i )
A, B = Array.new( N ) do ||
	gets.split.map( &:to_i )
end. transpose
C, D = Array.new( M ) do ||
	gets.split.map( &:to_i )
end. transpose

N.times do |i|
	res = 0
	M.times do |j|
		if ( A[i] - C[j] ).abs + ( B[i] - D[j] ).abs < ( A[i] - C[ res ] ).abs + ( B[i] - D[ res ] ).abs
			res = j
		end
	end
	puts res + 1
end


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll n;
  cin>>n;
  cout<<n*n*n<<endl;

  return 0;
}


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

int main() {
  string S; cin >> S;
  int yy{(S[0] & 0xF) * 10 + (S[1] & 0xF)};
  int mm{(S[2] & 0xF) * 10 + (S[3] & 0xF)};

  if (1 <= yy && yy <= 12 && 1 <= mm && mm <= 12) {
    cout << "AMBIGUOUS";
  } else if (1 <= yy && yy <= 12) {
    cout << "MMYY";
  } else if (1 <= mm && mm <= 12) {
    cout << "YYMM";
  } else {
    cout << "NA";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int N;
  cin >> N;
  ll k_max = -1 * LINF;
  ll k_min = LINF;
  ll l_max = -1 * LINF;
  ll l_min = LINF;
  rep(i,N) {
    ll x, y;
    cin >> x >> y;
    k_max = max(k_max, x + y);
    k_min = min(k_min, x + y);
    l_max = max(l_max, y - x);
    l_min = min(l_min, y - x);
  }

  ll ans = max(k_max - k_min, l_max - l_min);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Jan  7 16:28:50 2019
//
package main

import (
	"fmt"
	"sort"
)

type point struct {
	x, y int
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	points := make([]point, N)

	for i := range points {
		fmt.Scan(&points[i].x, &points[i].y)
	}

	xs := make([]int, N)
	ys := make([]int, N)
	for i := range xs {
		xs[i] = points[i].x
		ys[i] = points[i].y
	}
	sort.Ints(xs)
	sort.Ints(ys)

	ans := 1 << 62
	for _, xlower := range xs {
		for _, xupper := range xs {
			for _, ylower := range ys {
				for _, yupper := range ys {
					num := 0
					for _, p := range points {
						x, y := p.x, p.y
						if xlower < xupper && ylower < yupper && xlower <= x && x <= xupper && ylower <= y && y <= yupper {
							num++
						}
					}
					if num >= K {
						area := (xupper - xlower) * (yupper - ylower)
						if area < ans {
							ans = area
						}
					}
				}
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
#list(map(int,input().split()))
n,m=map(int,input().split())
it=[[0 for i in range(m)] for j in range(n)]
for i in range(n):
    j=input()
    for k in range(m):
        if j[k]=="#":
            it[i][k]=0
        else:
            it[i][k]=1
dp=[[0 for i in range(m)] for j in range(n)]
for i in range(n):
    for j in range(m):
        
        if(i>0 or j>0):
            if(i==0):
                dp[i][j]=dp[i][j-1]
                if(it[i][j-1]==1 and it[i][j]==0):
                    dp[i][j]+=1
            elif j==0:
                dp[i][j]=dp[i-1][j]
                if(it[i][j]==0 and it[i-1][j]==1):
                    dp[i][j]+=1
            else:
                a=0
                b=0
                if(it[i][j]==0):
                    if(it[i-1][j]==1):
                        a=1
                    if(it[i][j-1]==1):
                        b=1
                dp[i][j]=min(dp[i-1][j]+a,dp[i][j-1]+b)
        else:
            if it[i][j]==0:
                dp[i][j]=1

print(dp[n-1][m-1])


Measured memory_bytes: 42864
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Edge{
    ll to;
    ll cost;
    Edge(ll to, ll cost): to(to), cost(cost) {}
};

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

    // input
    int N;
    cin >> N;

    vector<ll> A(N-1);
    vector<ll> B(N-1);
    vector<ll> C(N-1);

    FOR(i, 0, N-1){
        ll a, b, c;
        cin >> a >> b >> c;
        A[i] = a-1;
        B[i] = b-1;
        C[i] = c;
    }

    // グラフ
    vector<vector<Edge> > graph(N);
    FOR(i, 0, N-1){
        graph[A[i]].push_back(Edge(B[i], C[i]));
        graph[B[i]].push_back(Edge(A[i], C[i]));
    }

    int Q, K;
    cin >> Q >> K;
    K--;

    // Kからの最短距離
    vector<ll> d(N);
    fill(ALL(d), inf);
    d[K] = 0;
    
    // 訪問フラグ
    vector<bool> visited(N);
    fill(ALL(visited), false);
    visited[K] = true;
    
    queue<int> que;
    que.push(K);
    while(!que.empty()){
        ll front = que.front();
        que.pop();
        
        for(auto edge : graph[front]){
            if(!visited[edge.to]){
                visited[edge.to] = true;
                d[edge.to] = d[front] + edge.cost;
                que.push(edge.to);
            }
        }
    }

    FOR(i, 0, Q){
        int x, y;
        cin >> x >> y;

        // x -> K -> y
        p(d[x-1] + d[y-1]);
    }
    
    return 0;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

// graph template
template<typename T>
class Edge{
	public:
		int src, to; T cost;

		Edge(int to, T cost): src(-1), to(to), cost(cost){}
		Edge(int src, int to, T cost): src(src), to(to), cost(cost){}
};
template<typename T>
using Edges = vector<Edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

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

	Edges<int> es;
	for(int i = 0; i < N-1; i++){
		es.push_back(Edge<int>(0, i+1, 1));
	}
	int n = 0;
	for(int i = 1; i <= N - 2; i++) n += i;
	if(n < K){
		cout << -1 << '\n';
		return 0;
	}

	if(n > K){
		for(int i = 1; i < N; i++){
			for(int j = i+1; j < N; j++){
				es.push_back(Edge<int>(i, j, 1));
				n--;
				if(n == K) break;
			}
			if(n == K) break;
		}
	}

	int M = (int) es.size();
	cout << M << '\n';
	for(int i = 0; i < M; i++){
		cout << es[i].src+1 << ' ' << es[i].to+1 << '\n';
	}

	return 0;
}

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

int main() {
  //入力値取得
  int H, W;	cin >> H >> W;
  vector<string> vec(H);
  for(int i=0; i<H; i++)
    cin >> vec.at(i);
  
  //cout << vec(0).size() << endl;  ←エラー
  //cout << vec(1).size() << endl;
  
  //出力
  //上辺
  for(int i=0; i<W+2; i++)
    cout << '#';
  cout << endl;
  
  //左辺+中身+右辺
  for(int i=0; i<H; i++){
    //左辺
    cout << '#';
    //中身
    cout << vec.at(i);
    //右辺
    cout << '#';
    //改行
    cout << endl;
  }

  //底辺
  for(int i=0; i<W+2; i++)
    cout << '#';
  cout << endl;
  
  
  //確認用
  //cout << H << W << endl;
  //cout << vec.at(0) << endl;
  //cout << vec.at(1) << endl;
}


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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end(), greater<>());

    int alice = 0, bob = 0;
    for (int i = 0; i < n; ++i) {
        if (i % 2 == 0) alice += a[i];
        else bob += a[i];
    }

    cout << alice - bob << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
  N = int(input())
  A = [int(i) for i in input().split()]
  
  if 0 in A:
    print(0)
    return
  
  c = 1
  for i in A:
    c *= i
    
    if c > 10**18:
      print(-1)
      return
  print(c)
  
main()

Measured memory_bytes: 21568
li = [int(x) for x in input().split()]
H,W = max(li),min(li)
ans = float('inf')
if(H%3==0 or W%3==0):
    ans = 0
else:
    ans = W

S0 = [0]*3

for h in range(H+1):
    S0[0] = (H-h)*(W//2)
    S0[1] = (H-h)*(W//2+(W%2))
    S0[2] = h*W
    ans = min(ans,max(S0)-min(S0))

for w in range(W+1):
    S0[0] = (W-w)*(H//2)
    S0[1] = (W-w)*(H//2+(H%2))
    S0[2] = w*H
    ans = min(ans,max(S0)-min(S0))

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int m;
      cin >> m;
      cout << 48-m << endl;
      return 0;}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  int N = SZ(S);

  bool lose = true;
  for(int i=1;i+1<N;++i)
	lose = lose && S[i-1] == S[i+1];

  if(lose)
	cout << "Second" << endl;
  else
	cout << ((N-2)%2 == (S[0]==S.back())?"Second":"First") << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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() {
  double a,b,x;
  cin>>a>>b>>x;
  double v = a*a*b;

  if (v<=x*2){
    double rad = atan(2*(v-x)/(a*a*a));
    double t = rad * 180 / M_PI;
    printf("%.10f\n",t);
  } else {
    double rad = M_PI/2 - atan(2*x/(a*b*b));
    double t = rad * 180 / M_PI;
    printf("%.10f\n",t);
  }
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#define travel(x, i) for (int i = fir[x]; i; i = e[i].nxt)
using namespace std;

const int N = 2e5 + 5;

struct edge {
  int nxt, to;
} e[N];
int fir[N], cnt = 0;
int deg[N], sg[N], cyc[N], tot = 0, Sg[N];
bool tab[N];
queue <int> Q;
set <int> O[N];

inline void add(int x, int y) {
  deg[y] ++;
  e[++ cnt] = (edge){fir[x], y};
  fir[x] = cnt;
}

inline int mex(const set <int> &fut) {
  if (fut.size() == 0) return 0;
  int t = 0;
  for (set <int> :: iterator it = fut.begin(); it != fut.end(); it ++, t ++)
    if ((*it) != t) return t;
  return t;
}

inline bool check(int x) {
  set <int> tmp;
  Sg[1] = x;
  for (int i = 2; i <= tot; i ++) {
    tmp = O[cyc[i]];
    tmp.insert(Sg[i - 1]);
    Sg[i] = mex(tmp);
  }
  tmp = O[cyc[1]];
  tmp.insert(Sg[tot]);
  if (mex(tmp) == x) return true;
  return false;
}

int main() {
  int n, x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i ++) {
    scanf("%d", &x);
    add(i, x);
  }
  memset(sg, -1, sizeof sg);
  for (int i = 1; i <= n; i ++)
    if (!deg[i]) Q.push(i), sg[i] = 0;
  while (!Q.empty()) {
    x = Q.front();
    Q.pop();
    travel(x, i) {
      deg[e[i].to] --;
      O[e[i].to].insert(sg[x]);
      if (!deg[e[i].to]) {
	sg[e[i].to] = mex(O[e[i].to]);
	Q.push(e[i].to);
      }
    }
  }
  int p = 0;
  for (int i = 1; i <= n; i ++)
    if (deg[i]) {p = i; break;}
  if (!p) return !puts("POSSIBLE");
  bool st = 1;
  for (int i = p; st || i != p; st = 0) {
    cyc[++ tot] = i;
    travel(i, j)
      if (deg[e[j].to]) {
	i = e[j].to;
	break;
      }
  }
  set <int> tmp = O[p];
  x = mex(tmp);
  if (check(x)) return !puts("POSSIBLE");
  tmp.insert(x);
  x = mex(tmp);
  if (check(x)) return !puts("POSSIBLE");
  puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 23936
#include<iostream>
using namespace std;
int GCD(int n,int m){
  if(n<m){
    int t;
    t = m;
    m = n;
    n = t;
  }
  int i;
  while(n%m != 0){
    i = n%m;
    n = m;
    m = i;
  }
  return m;
    
}
int main(){
  int n,m,i=0,a[50],b[50];
  while(cin >> n >> m){
    a[i] = GCD(n,m);
    b[i] = m/GCD(n,m)*n;
    i++;
    n = 0;
    m = 0;
  }
  for(n=0;n<i;n++) cout << a[n] << " " << b[n] << endl;
  return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define hell (int)(1e9+7)
#define int long long int
#define inf 1000000000000

using namespace std;

void solve(){
    string s;
    cin>>s;
    vector <char> a(500005,'#');
    for(int i=0;i<s.length();i++)
        a[i+200005]=s[i];
    int q,f,r;
    f=200004;
    r=200005+s.length();
    cin>>q;
    bool rev=false;
    while(q--){
        int t;
        cin>>t;
        if(t==1)
            rev=!rev;
        else{
            int fi;
            char c;
            cin>>fi>>c;
            if(fi==1){
                if(!rev)
                    a[f--]=c;
                else
                    a[r++]=c;
            }
            else{
                if(!rev)
                    a[r++]=c;
                else
                    a[f--]=c;
            }
        }
    }
    string s1="";
    for(int i=f+1;i<r;i++)
        s1.push_back(a[i]);
    if(rev)
        reverse(begin(s1),end(s1));
    cout<<s1;
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t,c;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}


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

int main() {
  long n,ma,mb,ans=999999999;
  cin >> n >> ma >> mb;
  vector<long> a(n),b(n),c(n);
  vector<vector<long>> k(401,vector<long>(401,999999999));
  for(long i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  
  k[0][0]=0;
  for(long i=0;i<n;i++) {
    for(long j1=400-a[i];j1>=0;j1--) {
      for(long j2=400-b[i];j2>=0;j2--) {
        k[j1+a[i]][j2+b[i]]=min(k[j1+a[i]][j2+b[i]],k[j1][j2]+c[i]);
      }
    }
  }
  for(long i=1;max(ma,mb)*i<=400;i++) ans=min(ans,k[ma*i][mb*i]);
  if(ans==999999999) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 4908
#include <iostream>

int main() {
    int n,y;
    std::cin >> n >> y;
    int nn,nnn,yy,yyy;
    for(int i = 0; i <= y/10000; i++){
        nn = n - i;
        yy = y - 10000*i;
        for(int j = 0; j <= yy/5000 && j <= nn; j++){
            nnn = nn - j;
            if(10000*i + 5000*j + 1000*nnn == y){
                std::cout << i << " " << j << " " << nnn << std::endl;
                return 0;
            }
        }
    }
    std::cout << "-1 -1 -1" << std::endl;
}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M = map(int, readline().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, readline().split())
        G[u - 1].append(v - 1)
    S, T = map(int, readline().split())
    S -= 1
    T -= 1

    dist = [[-1] * 3 for _ in range(N)]
    dist[S][0] = 0
    queue = deque([(S, 0)])
    while queue:
        v, step = queue.popleft()
        if step == 0 and v == T:
            break

        for nv in G[v]:
            if dist[nv][(step - 1) % 3] != -1:
                continue
            dist[nv][(step - 1) % 3] = dist[v][step] + 1
            queue.append((nv, (step - 1) % 3))

    if dist[T][0] == -1:
        print(-1)
    else:
        print(dist[T][0] // 3)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 42580