akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> C(26, 0); // C[i]
vector<vector<int> > S(365, vector<int>(26, 0)); // S[d][i]
int D;
int N;

int score(vector<int> V) {
	vector<int> c = C;
	int s = 0;
	for (int d = 0; d < D; d++) {
		c[V[d]] = 0;
		s += S[d][V[d]];
		s -= accumulate(c.begin(), c.end(), 0);
		for (int i = 0; i < N; i++) {
			c[i] += C[i];
		}
	}
	return s;
}

vector<int> findmin() {
	vector<int> V(D, 0);
	vector<int> c = C;
	int s = 0;
	for (int d = 0; d < D; d++) {
		int mi = 0;
		for (int i = 0; i < N; i++) {
			if (S[d][mi] + c[mi] < S[d][i] + c[i]) mi = i;
		}
		V[d] = mi;
		c[V[d]] = 0;
		s += S[d][V[d]];
		s -= accumulate(c.begin(), c.end(), 0);
		for (int i = 0; i < N; i++) {
			c[i] += C[i];
		}
	}
	return V;
}

int main() {
	cin >> D;
	N = 26;
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}
	for (int d = 0; d < D; d++) {
		for (int i = 0; i < N; i++) {
			cin >> S[d][i];
		}
	}
	vector<int> V(D, 0);
	for (int d = 0; d < D; d++) {
//		cin >> V[d];
//		V[d]--;
		int i = 0;
		for (int j = 1; j < N; j++) {
			if (S[d][i] < S[d][j]) i = j;
		}
		V[d] = i;
	}

	vector<int> sV = findmin();
	if (score(V) < score(sV)) V = sV;

	random_device seed_gen;
	mt19937 engine(seed_gen());
	uniform_real_distribution<> dist1(0.0, 1.0);

	vector<int> newV = V;
//	cout << "cur " << score(V);
//	for (int d = 0; d < D; d++) { cout << " " << V[d]+1; }
//	cout << endl;
	int ms = score(V);
	for (int j = 0; j < 10000; j++) {
		newV = V;
		for (int k = 0; k < 1; k++) {
			newV[int(dist1(engine) * D)] = int(dist1(engine) * N);
		}
		int ns = score(newV);
//		cout << "new " << ns;
//		for (int d = 0; d < D; d++) { cout << " " << newV[d]+1; }
//		cout << endl;
		if (ms < ns) V = newV;
	}

	for (int d = 0; d < D; d++) {
		cout << V[d] + 1 << endl;
	}
	return(0);
}


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

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

	vector<int> a(M);
	vector<vector<int>> c(M);
	for (int i = 0; i < M; i++) {
		int b;
		cin >> a[i] >> b;
		c[i].resize(b);
		for (int j = 0; j < b; j++) cin >> c[i][j];
	}

	vector<int> dp(1 << N, 1e9+7);
	dp[0] = 0;
	for (int i = 0; i < (1 << N); i++) {
		for (int j = 0; j < M; j++) {
			int dx = i;
			for (int k = 0; k < c[j].size(); k++) dx = dx | (1 << (c[j][k] - 1));
			dp[dx] = min(dp[dx], dp[i] + a[j]);
		}
	}


	if (dp[(1 << N) - 1] == 1e9+7) {
		cout << -1 << endl;
	} else {
		cout << dp[(1 << N) - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mod 998244353

using namespace std;
typedef long long ll;
const int MAXN = 300005;
int n,cnt[3],x[3],y[3];
char str[MAXN];

int main()
{
	cin >> n >> str+1;
	n *= 3;
	ll ans = 1;
	for(int i = 1; i<=n; i++)
	{
		memcpy(x,cnt,sizeof(x)), sort(x,x+3);
		int op = 0;
		if(str[i]=='R')
			op = 0;
		if(str[i]=='G')
			op = 1;
		if(str[i]=='B')
			op = 2;
		cnt[op]++;
		memcpy(y,cnt,sizeof(y)), sort(y,y+3);
		if(x[2]!=y[2])
			;
		else if(x[0]!=y[0])
			ans = ans*(x[1]-x[0])%mod;
		else
			ans = ans*(x[2]-x[1])%mod;
	}
	n /= 3;
	for(int i = 1; i<=n; i++)
		ans = ans*i%mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

vector<vector<int>> d; //d[from][to]:=2点間の最短距離
void Warshall_Floyd(int n){ //頂点数n
    rep(i,n){               //経由点i
        rep(j,n){           //始点j
            rep(k,n){       //終点k
				d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
            }
        }
	}
}
int main(){
	int h,w; cin>>h>>w;
    d=vector<vector<int>>(10,vector<int>(10,1e9));
    rep(i,10)rep(j,10){
        int c; cin>>c;
        d[i][j]=c;
    }
	Warshall_Floyd(10);
    long long ans=0;
	rep(i,h)rep(j,w){
        int a; cin>>a;
        if(a==-1) continue;
        ans+=d[a][1];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()

	var ans int = 0
	ans += count(n)
	ans += count(m)

	fmt.Print(ans)
}

func count(n int) int {

	count := 0
	for i := 0; i < n; i++ {
		for j := (i + 1); j < n; j++ {
			count++
		}
	}
	return count
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int A, B, C, K;
  cin >> A >> B >> C;
  cin >> K;
  for (int i=0; i<K; i++){
    if (A >= B) B *= 2;
    else C *= 2;
    if (A < B && B < C) break;
  }
  cout << ((A < B && B < C) ? "Yes" : "No") << "\n";
  return 0;
}

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

int main(){
    int N;
    float x[20];
    string u[20];

    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> x[i] >> u[i];
    }
    float total = 0;
    for (int i = 0; i < N; i++){
        if (u[i] == "JPY"){
            total += x[i];
        }
        if (u[i] == "BTC"){
            total += x[i] * 380000;
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  
string S;
  cin >>S;

  ll x=S.size();
  while(S.size()>0) {
    ll x=S.size();
   if(x>=7&&S.substr(x-7,7)=="dreamer"){
  S.erase(x-7,7);
   }
    else if(x>=5&&S.substr(x-5,5)=="dream"){
S.erase(x-5,5);
  }
   else if(x>=5&&S.substr(x-5,5)=="erase"){
S.erase(x-5,5);
   }
   else if(x>=6&&S.substr(x-6,6)=="eraser"){
S.erase(x-6,6);
   }
    else {
      break;
    }
  }
   if(S.size()==0) {
     cout<<"YES"<<endl;
   }
    else {
      cout<<"NO"<<endl;
    }
    
  }
  
  

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
vector<int> data[30];
bool used[30];
int n,m;

bool canUse(int x){
    rep(i,data[x].size()){
        if(used[data[x][i]]==false)return false;
    }
    return true;
}
int main(){
    vector<int> ans;
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--,y--;
        data[y].pb(x);
    }
    rep(i,30)used[i]=false;
    
    int c=n;
    rep(i,n){
        if(data[i].size()==0){
            used[i]=true;
            ans.pb(i);
            c--;
        }
    }
    while(c){
        rep(i,n){
            if(used[i]==true)continue;
            if( canUse(i) ){
                used[i]=true;
                ans.pb(i);
                c--;
            }
        }
    }
    rep(i,ans.size()){
        cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 3104
const input = require('fs').readFileSync('/dev/stdin', 'UTF-8');

const swappingTwoNumbers = input => {
  const arr = input.split('\n');
  let result = [];

  arr.forEach(val => {
    const innerArr = val
      .split(' ')
      .map(Number)
      .sort((a, b) => a - b);

    if (innerArr.some(val => val !== 0)) {
      result.push(String(innerArr.join(' ')));
    }
  });

  console.log(result.join('\n'));
};

swappingTwoNumbers(input);



Measured memory_bytes: 17780
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	bool ok = a % 2 == 0 && b % 2 == 0 && c % 2 == 0;
	bool same = a == b && b == c;

	if (same && ok) {
		cout << "-1" << endl;
		return 0;
	}

	int ans = 0;
	int ta = 0;
	int tb = 0;
	int tc = 0;

	int cnt = 0;
	while (ok) {
		
		ans++;

		ta = a;
		tb = b;
		tc = c;

		a = (tb + tc) / 2;
		b = (tc + ta) / 2;
		c = (ta + tb) / 2;

		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
			ok = false;
		}
	}

	cout << ans << endl;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using LL  = long long;

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

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    LL ans = 1;
    LL minus = 1;
    for(int i=0;i<n;i++){
        ans *= 3;
        if(a[i]%2 == 0){
            minus *= 2;
        }
    }
    ans -= minus;
    cout << ans << endl;
    return 0;
}


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

int main(){
	int N,X;
	cin >> N >> X;
	vector<int> x(N);
	for(int i=0;i<N;i++) {
		cin >> x[i];
		x[i]=abs(x[i]-X);
	}
	int ans=x[0];
	for(int i=1;i<N;i++) {
		ans=__gcd(ans,x[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
num_of_test = int(input())

acums = {"AC":0,
         "WA":0,
         "TLE":0,
         "RE":0}

for i in range(num_of_test):
  temp_input = input()
  acums[temp_input] += 1

print("AC x {}".format(acums["AC"]))
print("WA x {}".format(acums["WA"]))
print("TLE x {}".format(acums["TLE"]))
print("RE x {}".format(acums["RE"]))

Measured memory_bytes: 9204
X, Y = map(int, input().split())
money = 0

if X == 1:
  money += 300000
elif X == 2:
  money += 200000
elif X == 3:
  money += 100000

if Y == 1:
  money += 300000
elif Y == 2:
  money += 200000
elif Y == 3:
  money += 100000


if X == 1 and Y ==1:    
    money += 400000

print(money)


Measured memory_bytes: 3060
{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

read' :: B.ByteString -> Int
read' bs | Just (n, _) <- B.readInt bs = n

solve :: Int -> [Int] -> Bool
solve 0 _       = True
solve _ []      = False
solve !n (x:xs)
    | n < 0     = False
    | otherwise = solve (n - x) xs || solve n xs

print' :: Bool -> IO ()
print' True  = putStrLn "yes"
print' False = putStrLn "no"

main :: IO ()
main = do
    B.getLine
    as <- fmap read' . B.words <$> B.getLine
    B.getLine
    ms <- fmap read' . B.words <$> B.getLine
    mapM_ (print' . flip solve as) ms



Measured memory_bytes: 4948
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
 
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define db double
#define ld long double
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long long, long long>
#define piii pair<int, pii>
#define all(x) (x).begin(),(x).end()
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//#define int long long
 
const int N = 1e5 + 1, inf = 2e9 + 7, mod = 1e9 + 7;
const ll INF = 2e18 + 7, MOD = 1e15 + 7;

double dp[3003][3003], a[3003], ans;

signed main() { __
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    // fill dp with 1 ???
    dp[1][0] = 1.0 - a[1];
    dp[1][1] = a[1];
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
//            if (i - 1 <= j) {
                dp[i][j] += dp[i - 1][j] * (1.0 - a[i]);
//            }r
            dp[i][j] += dp[i - 1][j - 1] * a[i];
//            dp[i][j] = dp[i - 1][j] * (1 - a[i]) + dp[i][j - 1] * a[i];
        }
    }
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << setprecision(10) << ans << '\n';
    return 0;
}


Measured memory_bytes: 68992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
int n;
ll a[N],f[N],inv[N],sum[N];
int main()
{
    f[0]=f[1]=inv[0]=inv[1]=1;
    for(int i=2;i<N;i++) f[i]=f[i-1]*i%mod,inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    for(int i=1;i<N-1;i++) sum[i]=(sum[i-1]+inv[i+1])%mod;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    ll ans=0;
    for(int i=1;i<=n;i++)
        ans=(ans+a[i]*f[n]%mod*(sum[i-1]+sum[n-i]))%mod;
    for(int i=1;i<=n;i++) ans=(ans+a[i]*f[n])%mod;
    printf("%lld\n",ans);
}


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

int main(){
  int a,b,c,k; cin>>a>>b>>c>>k;
  int ans = 0;
  
  while(a--){
    if(k==0) break;
    ans++;
    k--;
  }
  while(b--){
    if(k==0) break;
    k--;
  }
  while(c--){
    if(k==0) break;
    ans--;
    k--;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3628
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 305;
const long long INF = (long long)1000000000 * MAX_N * 2;

struct Info {
    int from;
    int to;
    long long dist;
};

bool compare (const Info& i1, const Info& i2) {
    return i1.dist < i2.dist;
}

int N;
long long A[MAX_N][MAX_N];

long long C[MAX_N][MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            std::cin >> A[i][j];
        }
    }

    std::vector<Info> infos;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            Info in;
            in.from = i;
            in.to = j;
            in.dist = A[i][j];
            infos.push_back(in);
        }
    }
    std::sort(infos.begin(), infos.end(), compare);

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            C[i][j] = INF;
        }
        C[i][i] = 0;
    }

    long long ret = 0;
    for (auto info : infos) {
        if (C[info.from][info.to] < info.dist) {
            std::cout << -1 << std::endl;
            return 0;
        } else if (info.dist < C[info.from][info.to]) {
            C[info.from][info.to] = info.dist;
            C[info.to][info.from] = info.dist;
            ret += info.dist;
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= N; j++) {
                    C[i][j] = std::min(C[i][j], C[i][info.from] + C[info.from][info.to] + C[info.to][j]);
                    C[i][j] = std::min(C[i][j], C[i][info.to] + C[info.to][info.from] + C[info.from][j]);
                }
            }
        }
    }

    std::cout << ret << std::endl;
    return 0;

}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long n;
  cin >> n;
  string ans;
  while(n){
    n--;
    ans+='a'+n%26;
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
}

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

using namespace std;

const int N = 200200;

int h, w, n;
char s[N], t[N];
int sr, sc;

void win() {
   cout << "NO\n"; exit(0);
}

int main() {
   scanf("%d %d %d %d %d %s %s", &h, &w, &n, &sr, &sc, s + 1, t + 1);
   {
      int r = sr;
      for (int i = 1; i <= n; ++i) {
         if (s[i] == 'U') r--;
         if (r == 0) win();
         if (t[i] == 'D' && r < h) r++;
      }
   }
   {
      int r = sr;
      for (int i = 1; i <= n; ++i) {
         if (s[i] == 'D') r++;
         if (r == h + 1) win();
         if (t[i] == 'U' && r > 1) r--;
      }
   }
   {
      int c = sc;
      for (int i = 1; i <= n; ++i) {
         if (s[i] == 'L') c--;
         if (c == 0) win();
         if (t[i] == 'R' && c < w) c++;
      }
   }
   {
      int c = sc;
      for (int i = 1; i <= n; ++i) {
         if (s[i] == 'R') c++;
         if (c == w + 1) win();
         if (t[i] == 'L' && c > 1) c--;
      }
   }
   cout << "YES\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<" = "<<x<<endl
#define sz(a) (int)(a.size())
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
int n,m;
int a[105][105];
char s[105][105];
int solve(int x,int y) {
    if(x>=0&&x<n&&y>=0&&y<m) {
        return s[x][y]=='#';
    } else return 0;
}
int main() {

    while(~scanf("%d%d",&n,&m)) {
        for(int i=0;i<n;++i) {
            scanf("%s",s[i]);
        }
        memset(a,0,sizeof a);
        rep(i,0,n-1) {
            rep(j,0,m-1) {
                if(s[i][j]=='#') continue;
                a[i][j]+=solve(i-1,j-1);
                a[i][j]+=solve(i-1,j);
                a[i][j]+=solve(i-1,j+1);
                a[i][j]+=solve(i,j-1);
                a[i][j]+=solve(i,j+1);
                a[i][j]+=solve(i+1,j-1);
                a[i][j]+=solve(i+1,j);
                a[i][j]+=solve(i+1,j+1);

            }
        }
        rep(i,0,n-1) {
            rep(j,0,m-1) {
                if(s[i][j]=='#') printf("#");
                else printf("%d",a[i][j]);
            }puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num[11][11];
	int i, j, n;
	
	while(scanf("%d", &n) != EOF && n != 0){
		for(i = 0;i < 11;i++){
			for(j = 0;j < 11;j++){
				num[i][j] = 0;
			}
		}
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				scanf("%d", &num[i][j]);
			}
		}
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				num[i][n] += num[i][j];
			}
		}
		for(j = 0;j <= n;j++){
			for(i = 0;i < n;i++){
				num[n][j] += num[i][j];
			}
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				printf("%5d", num[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100
 
int main(){
    int n, arr[MAX][MAX];
  
    while(cin >> n,n){
	for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j < n ; j++){
		cin >> arr[i][j];
	    }
	}
 
	int cnt[MAX][MAX];
	memset(cnt,0,sizeof(cnt));
	for(int i = 0 ; i < n ; i++){
	    int min = 1e9, max = 0;
	    for(int j = 0 ; j < n ; j++){
		min = std::min(min,arr[i][j]);
		max = std::max(max,arr[j][i]);
	    }
	    for(int j = 0 ; j < n ; j++){
		if(arr[i][j] == min){
		    ++cnt[i][j];
		}
		if(arr[j][i] == max){
		    ++cnt[j][i];
		}
	    }
	}
 
	int ans = -1;
	for(int i = 0 ; i < n ; i++){
	    for(int j = 0 ; j < n ; j++){
		if(cnt[i][j] == 2){
		    ans = max(ans, arr[i][j]);
		}
	    }
	}
	cout << (ans==-1?0:ans) << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int sum = 0;
	for (int i = 0; i < 5; ++i) {
		int a; cin >> a;
		sum += max(a, 40);
	}
	cout << sum / 5 << endl;
	return 0;
}

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

void getAC() {	
	ios_base :: sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; ++i) cin >> v[i];
	int mn = v[0];
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		mn = min(mn, v[i]);
		if(v[i] <= mn) {
			ans++;
		}
	}
	cout << ans << endl;
}
 
int main() {	
	getAC();
	return 0;
}

Measured memory_bytes: 1024
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
 
#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 <queue>
#include <bitset>
#include <iomanip>
#include <fstream>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false); // 🏁 👀 💕
  cin.tie(NULL);
  
  string str1, str2;
  cin >> str1 >> str2;
  cout << str2 + str1 << endl;  

  return 0;
}

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

using namespace std;

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

  vector<int> r[N+1];

  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    r[a].push_back(b);
    r[b].push_back(a);
  }

  int ans[N+1];
  bool ex[N+1]; 
  memset(ans, 0, sizeof(ans));
  memset(ex, false, sizeof(ex));

  vector<int>n; n.push_back(1); ans[1] = 1;
  int a = 0;
  while (n.size() != N) {
    int i = n[a];
    if (!ex[i]) { 
      for (auto jt = r[i].begin(); jt != r[i].end(); jt++) {
        if (ans[*jt] == 0) {
          n.push_back(*jt);
          ans[*jt] = i;
        }
      }
      ex[i] = true;
    }
    a++;
  }

  cout << "Yes" << endl;
  for (int i = 1; i < N; i++) {
    cout << ans[i+1] << endl;
  }
  return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

t = make_divisors(N)
if len(t) % 2 != 0:
    i = len(t) // 2
    print(t[i] + t[i] - 2)
else: 
    i = len(t) // 2 - 1
    print(t[i] + t[i+1] - 2) 


Measured memory_bytes: 3272
def battle(a,b,c,d):
    while True:
        c -= b
        if c<=0:
            break
        a -= d
        if a<=0:
            break
   
    if a<=0:
        print('No')
    else:
        print('Yes')

a,b,c,d = [int(i) for i in input().split()]
battle(a,b,c,d)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);
ll power(ll a, ll n) {ll p = 1; while (n > 0) {if (n % 2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1; while (n > 0) {if (n % 2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
vector<ll> scanVector(ll n, vector<ll> &v)
{
	ll temp;
	for (ll i = 0; i < n ; i++)
	{
		cin >> temp;
		v.pb(temp);
	}
	return v;
}


void solve() {
	ll x;
	cin>>x;
	if(x>=30) {
		cout<<"Yes\n";
	} else cout<<"No\n";
}

int main() {
	FAST
// #ifndef ONLINE_JUDGE
// 	// for getting input from input.txt
// 	freopen("input.txt", "r", stdin);
// 	// for writing output to output.txt
// 	freopen("output.txt", "w", stdout);
// #endif
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+3;
int a[M];
int main(){
	int n,k,q;
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0;i<n;i++)a[i]=k-q;
	for(int i=0;i<q;i++){
		int m;
		scanf("%d",&m);
		a[m-1]++;
	}
	for(int i=0;i<n;i++){
		if(a[i]<=0)printf("No\n");
		else printf("Yes\n");
	}
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
int h,n;
int main()
{
    scanf("%d%d",&h,&n);
    printf("%d\n",(h+n-1)/n);
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	ans := 0
	for _, x := range xs {
		ans += min(k-x, x) * 2
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

using namespace std;
using ll = long long;

#define MOD 1000000007
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;
 
struct MComb {
   std::vector<mint> fact;
   std::vector<mint> inversed;
   MComb(int n) { // O(n+log(mod))
       fact = std::vector<mint>(n+1,1);
       for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*mint(i);
       inversed = std::vector<mint>(n+1);
       inversed[n] = fact[n] ^ (MOD-2);
       for (int i = n - 1; i >= 0; i--) inversed[i]=inversed[i+1]*mint(i+1);
   }
   mint ncr(int n, int r) {
        if (n < r) return 0;
        if (n < 0 || r < 0) return 0;
       return (fact[n] * inversed[r] * inversed[n-r]);
   }
   mint npr(int n, int r) {
        if (n < r) return 0;
        if (n < 0 || r < 0) return 0;
       return (fact[n] * inversed[n-r]);
   }
   mint nhr(int n, int r) {
       assert(n+r-1 < (int)fact.size());
       return ncr(n+r-1, r);
   }
   mint fac(int n) {
       if(n < 0)return 0;
       return fact[n];
   }
};
MComb comb(200000);
 
mint ncr(int n, int r) {
   mint res = 1;
   for (int i = n - r + 1; i <= n; i++) res *= i;
   for (int i = 1; i <= r; i++) res /= i;
   return res;
}


int main()
{
    int n, k; cin >> n >> k;
    cout << (mint(k)^n) << endl;
}


Measured memory_bytes: 4256
#!/usr/bin/env python3


def main():
    from collections import deque

    def prime_factorization_list(n: int):
        """
        入力された整数nを素因数分解し，素因数が列挙されたリストで返却
        Parameters
        ----------
        n : int
            素因数分解したい整数
        Returns
        -------
        prime_factorization_lst : lst
            [素因数]の形で素因数が列挙された素因数分解結果
        """
        fct = []  # prime factor
        b = 2     # base factor
        while b * b <= n:
            while n % b == 0:
                n //= b
                fct.append(b)
            b += 1
        if n > 1:
            fct.append(n)
        return fct

    N = int(input())

    q = deque(prime_factorization_list(N))
    memo = []
    while q:
        p = q.popleft()
        res = p
        while res in memo and q:
            can = q.popleft()
            if can == p:
                res *= can
            else:
                res = can
                break
        if res not in memo:
            memo.append(res)
    print(len(memo))


if __name__ == '__main__':
    main()


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

if n%10 == 3:
  print('bon')
elif n%10 == 0:
  print('pon')
elif n%10 == 1:
  print('pon')
elif n%10 == 6:
  print('pon')
elif n%10 == 8:
  print('pon')
else:
  print('hon')

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

int main() {
    int n, m;
    cin >> n >> m;
    int A[n][m], B[m], C[n];
    for (int i = 0; i < n; i++) {
        C[i] = 0;
        for (int j = 0; j < m; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> B[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            C[i] += A[i][j] * B[j];
        }
        cout << C[i] << endl;
    }

}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c=0,sum=0,n;
    char s[16];
    scanf("%d",&n);
    map <map<char,int> ,int> m2;
    for(int i=0;i<n;i++)
    {
        map <char,int> m;
        scanf(" %s",s);
        for(int j=0;s[j];j++)
        m[s[j]]++;
        m2[m]++;
    }
    long long int ans=0;
    map <map<char,int> ,int>::iterator it;
    for(it=m2.begin();it!=m2.end();it++)
    {
        long long int num=it->second;
        ans+=((num)*(num-1))/2;
    }
    printf("%lld",ans);
}

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

#define OM ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define pi 3.14159265358979323846

typedef long long ll;

/*LETS BEGIN WITH THE NAME OF MAHADEV*/

int main(){
	OM;
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 0, last, x; i < n; ++i){
		cin >> x;
		if(i){
			if(x >= last)
				last = x;
			else
				ans += last - x;

		}else
			last = x;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <functional>

inline void
rep(int n, std::function<void(int)> f) {
    for (int i = 0; i < n; i++) {
        f(i);
    }
};

typedef std::pair<int, int> P;

int main() {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	
	std::deque<int> v;
	
	int tmp, k;
	rep(5, [&](int i) {
			std::cin >> tmp;
			v.push_back(tmp);
			});
	std::cin >> k;
	std::cin.ignore();
	
	std::sort(v.begin(), v.end());
	if (std::abs(v.front() - v.back()) > k) {
		std::cout << ":(" << '\n'; 
	}
	else {
		std::cout << "Yay!" << '\n'; 
	}
	

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int d[100010];
int toInt(string number){
	stringstream ss;
	ss << number;
	int x;
	ss >> x;
	return x;
}

int main(void){

	int n;
	cin >> n;
	string s;
	REP(i,n){
		char c;
		cin >> c;
		s+=c;
	}

	int i,j;
	for(i=1;i<=5;i++){
		for(j=0;j<=n-i;j++){
			string ss=s.substr(j,i);
			if(i!=1 && ss[0]=='0') continue;
			int x=toInt(ss);
			d[x]++;
		}
	}

	int ans;
	for(i=0;i<=100000;i++){
		if(d[i]==0){
			ans=i; break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  valarray<bool> odd(n), three(n), five(n);

  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    odd[i] = m % 2 != 0;
    three[i] = m % 3 == 0;
    five[i] = m % 5 == 0;
  }

  valarray<bool> ans = odd | three | five;
  cout << (all_of(begin(ans), end(ans), [](auto a){return a;}) ? "APPROVED" : "DENIED") << endl;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d>>s;
    a--;b--;c--;d--;
    {
        int i=a;
        while(i!=c){
            if(i+2<=c&&s[i+2]=='.'){
                i+=2;
            }else if(s[i+1]=='.'){
                i++;
            }else{
                Yes(0);
                return 0;
            }
        }
    }
    {
        int i=b;
        while(i!=d){
            if(i+2<=d&&s[i+2]=='.'){
                i+=2;
            }else if(s[i+1]=='.'){
                i++;
            }else{
                Yes(0);
                return 0;
            }
        }
    }
    if(d<c){
        rep2(i,b,d+1){
            if(s[i]=='.'&&s[i-1]==s[i]&&s[i]==s[i+1]){
                break;
            }
            if(i==d){
                Yes(0);
                return 0;
            }
        }
    }
    Yes(1);
}

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

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 2e6 + 10;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

int main()
{
  initFactorials();

  ios::sync_with_stdio(0);
  int x,y;
  cin >> x >> y;
  if((x + y) % 3 != 0)
  {
    cout << "0\n";
    return 0;
  }
  int z = (x + y)/3;
  int m = 2* z - y;
  int n = y - z;

  cout << C(n + m, n) << endl;

  return 0;
}

Measured memory_bytes: 34904
#include <bits/stdc++.h>
using namespace std;
typedef signed long long lint;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n, k;
  cin >> n >> k;
  vector< lint > a(n);
  for (lint i=0; i<n; ++i) cin >> a[i];
  lint ans = 0, mod = 1e9+7;
  for (lint i=0; i<n; ++i) {
    lint h=0;
    for (lint j=0; j<n; ++j) {
      if (a[i]>a[j]) h++;
    }
    lint s = 0;
    for (lint j=i+1; j<n; ++j) {
      if (a[i]>a[j]) s++;
    }
    ans += k*(k-1)/2%mod*h%mod;
    ans %= mod;
    ans += k*s%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


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

void Main() {
	int K, len = 0;
	string S;
	cin >> K >> S;
	bool isBiggerS = K < S.size();
	len = isBiggerS ? K : S.size();

	if (isBiggerS) {
		S = S.substr(0, len);
		S = S + "...";
	}

	cout << S << endl;
}
int main() {
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3600
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 左の子(left child), r:右の兄弟(right sibling)*/

typedef struct Node_struct Node;

Node T[MAX];
int D[MAX],H[MAX],n;

void setDepth(int u, int p){
  if(u==NIL)return;
  D[u] = p;
  setDepth(T[u].l,p+1);
  setDepth(T[u].r,p+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL)h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL)h2=setHeight(T[u].r)+1;
  return H[u]=(h1>h2 ? h1:h2);
}

int getSibling(int u){
  if(T[u].p==NIL)return NIL;
  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL)return T[T[u].p].l;
  if(T[T[u].p].r!=u && T[T[u].p].r!=NIL)return T[T[u].p].r;
  return NIL;
}

void print(int u){
  int i, c;
  printf("node %d: parent = %d, sibling = %d, ", u,T[u].p,getSibling(u));
  int deg=0;
  if(T[u].l!=NIL)deg++;
  if(T[u].r!=NIL)deg++;
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);


  if(T[u].p==-1) printf("root");
  else if(T[u].l==NIL && T[u].r==NIL) printf("leaf");
  else printf("internal node");

  printf("\n");

}


int main(){
  int i,v,left,right,root = 0;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&left,&right);
    T[v].l=left;
    T[v].r=right;
    if(left!=NIL)T[left].p=v;
    if(right!=NIL)T[right].p=v;
  }


  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == NIL) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)
  setDepth(root, 0);
  setHeight(root);
  //出力 (output)
  for(i=0; i<n; i++) print(i);

  return 0;
}



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

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	byte[] cc;
	boolean pal(int i, int j) {
		while (i < j) {
			if (cc[i] != cc[j])
				return false;
			i++; j--;
		}
		return true;
	}
	void main() {
		cc = sc.next().getBytes();
		int n = cc.length;
		int h = (n - 1) / 2;
		println(pal(0, n - 1) && pal(0, h - 1) && pal(h + 1, n - 1) ? "Yes" : "No");
	}
}


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

int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];	
	}
	sort(a, a + 3);
	cout << a[0] + a[1] << endl;
	return 0;
}


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

public class Main {

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

            List<Integer> soutedList = new ArrayList<>();
            List<Integer> originalList = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                int x = Integer.parseInt(sc.next());
                soutedList.add(x);
                originalList.add(x);
            }

            Collections.sort(soutedList);

            int left = soutedList.get(n / 2 - 1);
            int right = soutedList.get(n / 2);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                int removedElement = originalList.get(i);
                if (removedElement <= left) {
                    // System.out.print(right);
                    sb.append(right);
                } else {
                    // System.out.print(left);
                    sb.append(left);
                }
                // System.out.println(" ");
                sb.append("\n");
            }
            System.out.println(sb.toString());

        }
    }

}


Measured memory_bytes: 73292
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
 cin>>n;
 long double a[n];
 for(int i=0;i<n;i++)
 {
     cin>>a[i];
 }
 sort(a,a+n);
 for(int i=1;i<n;i++)
 {
     a[i]=(a[i]+a[i-1])/2;
 }
 cout<<fixed<<setprecision(12)<<(double)a[n-1];
}

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

#define rep(i, n)  for (int i = 0; i < (int) (n); i++)
#define Rrep(i, n) for (int i = ((int) n - 1); i >= 0; i--)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
#define INF 2e15
#define MOD 10e9 + 7

typedef vector <int> vint;
typedef long long    ll;



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

    int n;
    cin >> n;
    string str;
    cin >> str;
    int index     = -1;
    int pastindex = 0;
    int pass      = 0;
    int count     = 0;

    while (pass < 1000) {
        int hyaku = pass / 100;
        rep(i, str.size()) {
            if (str.at(i) - 48 == hyaku) { index = i; break; }
        }
        if (index == -1) { hyaku = 0; index = -1; pastindex = 0; pass++; continue; }
        int jyu = (pass - hyaku * 100) / 10;
        pastindex = index;

        for (int j = index + 1; j < (int) str.size(); j++) {
            if (str.at(j) - 48 == jyu) { index = j; break; }
        }
        if (index == pastindex) { hyaku = 0; jyu = 0; index = -1; pastindex = 0; pass++; continue; }
        int ichi = (pass - hyaku * 100 - jyu * 10);
        pastindex = index;

        for (int k = index + 1; k < (int) str.size(); k++) {
            if (str.at(k) - 48 == ichi) { index = k; count++; break; }
        }
        hyaku = 0; jyu = 0; ichi = 0; index = -1; pastindex = 0;
        pass++;
    }

    cout << count << endl;


    return 0;
}


Measured memory_bytes: 384