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

int main(){

    long long n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    bool flag = false;
    for(long long m = 0; m < n; m++){
        if(c * (n - 1 - m) - d * m <= b - a && b - a <= - c * m + (n - 1 - m) * d){
            flag = true;
            break;
        }
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ll long long
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    cout << "No" << endl;
    return 0;
  }
  if (a == b || b == c || c == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}



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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cout << #a << " = " << a << endl

const ll mod = 1e9+7;
const int INF = 1001001001;

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

vector<int> to[100001];

int main() {
    int N, M;
    cin >> N >> M;
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        --A; --B;
        to[A].push_back(B);
        to[B].push_back(A);
    }

    queue<int> q;
    vector<int> dist(N, INF);
    vector<int> pre(N, -1);
    dist[0] = 0;
    q.push(0);

    while (!q.empty()) {
        int v = q.front(); q.pop();
        for (int u : to[v]) {
            if (dist[u] != INF) continue;
            dist[u] = dist[v]+1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    REP(i, N) {
        if (i == 0) continue;
        cout << ++pre[i] << endl;
    }
    return 0;
}


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

using ll = long long int;
#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()


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}

ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}





// substr(start, len)

int main(){

  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int K; cin >> K;

  cout << a[K-1] << endl;
  

// CHECK if it's possible to overflow!!
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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


int a, b;

int main(){
	cin >> a >>b;
	
	cout << (a-1) * (b-1) << endl;
	
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
S = [0]*(N+1)
S[0], d[0] = 0, 1
for i in range(1, N+1):
  S[i] = S[i-1] + A[i-1]
  d[S[i]] += 1

ans = 0
for val in d.values():
  ans += val * (val - 1) // 2

print(ans)

Measured memory_bytes: 40864
import time
import random


class TreapNode:
    def __init__(self, key, pri):
        self.left = None
        self.right = None
        self.key = key
        self.pri = pri


class Treap:
    def __init__(self):
        self.root = None

    def search_lower(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk < key:
                ret = pk
                ptr = ptr.right
            else:
                ptr = ptr.left
        return ret

    def search_higher(self, key):
        if key == None:
            return None
        ptr = self.root
        ret = None
        while ptr is not None:
            pk = ptr.key
            if pk > key:
                ret = pk
                ptr = ptr.left
            else:
                ptr = ptr.right
        return ret

    def insert(self, key):
        pri = random.randrange(0, 2**32)
        ptr = self.root
        elem = TreapNode(key, pri)
        if ptr is None or ptr.pri < pri:
            self.root = elem
        else:
            while True:
                if key < ptr.key:
                    left = ptr.left
                    if left is None or left.pri < pri:
                        ptr.left = elem
                        ptr = left
                        break
                    ptr = left
                else:
                    right = ptr.right
                    if right is None or right.pri < pri:
                        ptr.right = elem
                        ptr = right
                        break
                    ptr = right
        left = elem
        right = elem
        while ptr is not None:
            if key < ptr.key:
                right.left = ptr
                right = ptr
                ptr = ptr.left
            else:
                left.right = ptr
                left = ptr
                ptr = ptr.right
        left.right = None
        right.left = None
        elem.left, elem.right = elem.right, elem.left

# デバッグ用
    def dump(self):
        self.__dump(self.root, 0)

    def __dump(self, idx, dep):
        if idx is not None:
            self.__dump(idx.right, dep + 1)
            for _ in range(0, dep):
                print("   ", end="")
            print([idx.key, idx.pri])
            self.__dump(idx.left, dep + 1)

def main():
    n = int(input())
    p = list(map(int, input().split()))
    idx = [0] * n
    for i in range(0, n):
        idx[i] = i
    idx.sort(key=lambda i: - p[i])
    t = Treap()
    t.insert(-1)
    t.insert(n)
    ans = 0
    for i in idx:
        nex = t.search_higher(i)
        nexnex = t.search_higher(nex)
        pre = t.search_lower(i)
        prepre = t.search_lower(pre)
        if prepre != None:
            ans += p[i] * (pre - prepre) * (nex - i)
        if nexnex != None:
            ans += p[i] * (i - pre) * (nexnex - nex)
        t.insert(i)
    print(ans)


main()


Measured memory_bytes: 84968
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

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

	int ans = 1;

	for (int i = 1; i <= n; i++) {
		ans *= i;
		ans %= mod;
	}

	cout << ans << endl;	

	return 0;
}


Measured memory_bytes: 256
#import collections
#aa = collections.Counter(a) # list to list
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    C = []
    S = []
    F = []
    for i in range(n-1):
        c,s,f = readInts()
        C.append(c)
        S.append(s)
        F.append(f)

    for i in range(n):
        t = 0
        for j in range(i,n-1):
            if t < S[j]: #行ってみたけどまだ開通式始まってない
                t = S[j] # 一番最初に行われるであろう処理
            elif t%F[j] == 0: #割り切れるとき
                pass # t + Ci秒後に到着する
            else:
                t = t + F[j] - t % F[j] # 開通式は終わったけど、なんか途中
                # 今は10秒とすると、次発車するのは12秒、 t + 3 - 10 % 3 (1) 秒まで待つことになる
            t += C[j]
        print(t)




if __name__ == '__main__':
  main()


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n,m;
int p[200000];
int pa[200000];
int root(int x){
	if(pa[x]==x) return x;
	return pa[x]=root(pa[x]);
}
void unite(int x,int y){
	x=root(x);y=root(y);
	pa[x]=y;
}
signed main() {
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>p[i];
		pa[i]=i;
	}
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		unite(x,y);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(root(i)==root(p[i])) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<unordered_map>
using namespace std;

int main()
{   
    long long N;

    cin >> N;
    
    int num = N%10;
    if(num==3){
        cout << "bon" << endl;
    }else if((num==0)||(num==1)||(num==6)||(num==8)){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(void)
{
	int a,b,c,d;

	cin >> a >> b >> c >> d;

	if (a <= b)
	{
		if (c <= d)
		{
			cout << a + c << endl;
		}
		else
		{
			cout << a + d << endl;
		}
	}
	else
	{
		if (c <= d)
		{
			cout << b + c << endl;
		}
		else
		{
			cout << b + d << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
for j in range(20):
    try:
        d = int(input())
        size = 0
        
        for i in range(600//d - 1):
            #print(i, i*d, (i*d)**2, d, size)
            i += 1
            size += ((i*d)**2) *d
            
        print(int(size))
        
    except:     break


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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 605;
const int mo = 1e9+7;

int n;
int a[N];
bool bz[N];
bool can[N];
LL f[N][305][305];

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();
	fo(i,1,n*2)a[i]=get();
	fo(i,1,n*2)if (a[i]!=-1)bz[a[i]]=1;
	fo(i,1,n*2)can[i]=1;
	fo(i,1,n)
	if (a[i*2-1]!=-1&&a[i*2]!=-1)can[a[i*2-1]]=can[a[i*2]]=0;
	f[n*2+1][0][0]=1;
	fd(i,n*2,1)
	if (can[i]){
		if (bz[i]){
			fo(j,0,n)
				fo(k,0,n)
				if (f[i+1][j][k]){
					//(
					if (j)f[i][j-1][k]=add(f[i][j-1][k],f[i+1][j][k]);
					//)
					f[i][j][k+1]=add(f[i][j][k+1],f[i+1][j][k]);
				}
		}
		else{
			fo(j,0,n)
				fo(k,0,n)
				if (f[i+1][j][k]){
					//(
					if (j)f[i][j-1][k]=add(f[i][j-1][k],f[i+1][j][k]);
					if (k)f[i][j][k-1]=(f[i][j][k-1]+f[i+1][j][k]*k)%mo;
					//)
					f[i][j+1][k]=add(f[i][j+1][k],f[i+1][j][k]);
				}
		}
	}
	else fo(j,0,n)fo(k,0,n)f[i][j][k]=f[i+1][j][k];
	int cnt=0;
	fo(i,1,n)
	if (a[i*2-1]==-1&&a[i*2]==-1)cnt++;
	LL ans=f[1][0][0];
	fo(i,1,cnt)ans=ans*i%mo;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 437760
#include <iostream>

using namespace std;

int main()
{
  int i,a,b,c;
  for(i=1; i<=3000; i++)
  {
    cin >> a >> b;
    if (a==0 && b==0)
    break;
     if ( a > b )
     {
     c=a;
     a=b;
     b=c;
      }

  cout << a << " " << b << endl;
  }
}


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

using ld=long double;
int main(){
    int n;
    cin>>n;
    vector<ld> p(n);
    for(int i=0;i<n;i++) cin>>p[i];
    vector<vector<ld>> dp(n+1,vector<ld>(n+1,0));
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]+=dp[i][j]*p[i];
            dp[i+1][j]+=dp[i][j]*(1-p[i]);
        }
    }
    ld res=0;
    for(int i=n/2+1;i<=n;i++){
        res+=dp[n][i];
    }
    cout<<setprecision(10)<<fixed;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 141056
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector<int> cnt(13,0);
	cnt[0]++;
	for(int i =0; i < N; i++) {
		int d;
		cin >> d;
		cnt[d]++;
	}
	if(cnt[0] > 1 || cnt[12] > 1) {
		cout << "0\n";
		return 0;
	}
	for(int i =0; i < 13; i++) if(cnt[i] > 2) {
		cout << "0\n";
		return 0;
	}
	for(int i =0; i < 12; i++) if(cnt[i] >= 1 && cnt[i+1] == 2) {
		cout << "1\n";
		return 0;
	}
	for(int i =0; i < 12; i++) if(cnt[i] == 2 && cnt[i+1] >= 1) {
		cout << "1\n";
		return 0;
	}
	vector<int> D;
	for(int i =0; i < 13; i++)
		for(int j =0; j < cnt[i]; j++) D.push_back(i);
	int s =0;
	for(int i =0; i < (1<<(N+1)); i++) {
		vector<int> v;
		for(int j =0; j <= N; j++) {
			if((i>>j)&1) v.push_back(D[j]);
			else v.push_back((24-D[j])%24);
		}
		int sc =100;
		for(int j =0; j <= N; j++) for(int k =0; k < j; k++) {
			int d =abs(v[j]-v[k]);
			sc =min(sc,min(d,24-d));
		}
		s =max(s,sc);
	}
	cout << s << "\n";
	return 0;}

// look at my code
// my code is amazing


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

int main()
{
	int N;
	int A[100010],B[100010],C[100010];
	lint a,c;
	lint ans=0;
	
	cin >> N;
	for(int i=0;i<N;i++)cin >> A[i];
	for(int i=0;i<N;i++)cin >> B[i];
	for(int i=0;i<N;i++)cin >> C[i];
	
	sort(A,A+N);
	sort(B,B+N);
	sort(C,C+N);
	
	for(int i=0;i<N;i++)
	{
		a=lower_bound(A,A+N,B[i])-A;
		c=C+N-upper_bound(C,C+N,B[i]);
		ans+=a*c;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int A[5];

int main() {
for(int i=0;i<3;i++) {
int x,y;
cin >> x >> y;
A[x]++;
A[y]++;
}
bool flag = true;
for(int i=1;i<5;i++) if(A[i]>2) flag = false;
if(flag) cout << "YES\n";
else cout << "NO\n";
return 0;
}


Measured memory_bytes: 256
import std.array;
import std.conv;
import std.string;
import std.algorithm;
import std.stdio;

void main() {
	auto n = readln.chomp.to!int;
	auto a = readln.chomp.split(' ').map!(to!long).array;

	auto dp = new long[][](n, n);
	dp[0][0] = 1000;

	foreach (i;0..n) {
		foreach (j;i + 1..n) {
			if (a[i] < a[j]) {
				dp[i + 1][j] = max(dp[i][j - 1], dp[i][j], dp[i][i] / a[i] * a[j] + dp[i][i] % a[i]);
			} else {
				dp[i + 1][j] = max(dp[i][j - 1], dp[i][j]);
			}
		}
	}

	writeln(dp[n - 1][n - 1]);
}


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

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

vector<pair<char, int>> balls;
VI whites;
VI blacks;
int N;
int wmore[2048];
int bmore[2048];

int mem[2048][2048];
int wcost[2048][2048];
int bcost[2048][2048];

int main(int argc, const char* argv[]) {
	scanf("%d\n", &N);

	balls.resize(2 * N);
	whites.resize(N);
	blacks.resize(N);
	{
		int i = 0;
		foreach (b, balls) {
			scanf("%c %d\n", &b.first, &b.second);
			b.second--;
			if (b.first == 'W')
				whites[b.second] = i;
			else
				blacks[b.second] = i;
			i++;
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++)
			if (whites[j] < whites[i])
				wmore[j]++;
	}

	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++)
			if (blacks[j] < blacks[i])
				bmore[j]++;
	}

	{
		VI wpos(whites);
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j < N; j++) {
				int mypos = wpos[j] + wmore[j];
				int needpos = i + j;
				wcost[i][j] = mypos - needpos;
			}
			if (i < N) {
				int bb = blacks[i];
				for (int j = 0; j < N; j++)
					if (whites[j] < bb) {
						wpos[j]++;
					}
			}
		}
	}

	{
		VI bpos(blacks);
		for (int i = 0; i <= N; i++) {
			for (int j = 0; j < N; j++) {
				int mypos = bpos[j] + bmore[j];
				int needpos = i + j;
				bcost[i][j] = mypos - needpos;
			}
			if (i < N) {
				int ww = whites[i];
				for (int j = 0; j < N; j++)
					if (blacks[j] < ww) {
						bpos[j]++;
					}
			}
		}
	}

	mem[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		mem[i][0] = mem[i-1][0] + wcost[0][i-1];
	}

	for (int i = 1; i <= N; i++) {
		mem[0][i] = mem[0][i-1] + bcost[0][i-1];
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			mem[i][j] = min(mem[i-1][j] + wcost[j][i-1], mem[i][j-1] + bcost[i][j-1]);
		}
	}

	printf("%d\n", mem[N][N]);

	return 0;
}


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

using namespace std;

int stoi(string s){ 
        if(s == "A"){
                return 0;
        }   
        if(s == "B"){
                return 1;
        }   
        if(s == "O"){
                return 3;
        }else{
                return 2;
        }   
}

int main(){
        int type[4] = {0};
        int a;
        char b;
        string c;
        while(cin >> a){ 
                cin >> b >> c;
                type[stoi(c)]++;
        }   
        int i = 0;
        while(i < 4){ 
                cout << type[i++] << endl;
        }   
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      if ((abs(b - a) <= d && abs(c - b) <= d) || (abs(c - a) <= d)) cout << "Yes" << endl;
      else cout << "No" << endl;
    }

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

 int main(){
     string s;cin>>s;
     int ans = 0;
     for(int i=0;(i+1)*2<s.size();i++){
         if(s.substr(0,i+1)==s.substr(i+1,i+1)){
           ans=i+1;
         }
     }
     cout<<ans*2<<endl;
 }

Measured memory_bytes: 256
### constant

DXYS = [
  [ 1,  0], [ 1, -1], [ 0, -1], [-1, -1],
  [-1,  0], [-1,  1], [ 0,  1], [ 1,  1]
]

### main

loop do
  h, w = gets.split.map(&:to_i)
  break if (h | w) == 0

  dnts = h.times.map{gets.strip}
  #p dnts

  maxlen = 0
  spells = []

  for y0 in (0...h)
    for x0 in (0...w)
      DXYS.each do |dx, dy|
        x = x0
        y = y0
        str = dnts[y][x]
        len = 1
        loop do
          x = (x + dx) % w
          y = (y + dy) % h
          break if x == x0 && y == y0

          str += dnts[y][x]
          len += 1

          spells[len] = {} if spells[len].nil?
          if spells[len][str].nil?
            spells[len][str] = 0
          else
            spells[len][str] = 1
            maxlen = len if maxlen < len
          end
        end
      end
    end
  end
  #p maxlen
  #p spells

  if maxlen == 0
    puts 0
  else
    puts spells[maxlen].select{|k, v| v > 0}.keys.min
  end
end

Measured memory_bytes: 49368
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r) for(int i = l; i < r; i++)
#define RFOR(i, l,r) for(int i= (l)-1; i>= (r) ; i--)

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

void reset(string& n, char x)
{
    REP(i, n.size())
        n[i] = x;
}

string solve(string n, vector<int> av)
{
    string ret;
    int up = 0;
    RREP(i, n.size())
    {
        auto ite = find_if(av.begin(), av.end(), bind1st(less<int>(), n[i]-'0'-1 + up));
        if(ite != av.end())
        {
            if(up == 1)
                reset(ret, av[0] + '0');
            up = 0;
            ret.push_back(char('0' + *ite));
        }
        else
        {
            reset(ret, av[0] + '0');
            up = 1;
            ret.push_back(av[0] + '0');
        }
    }
    if(up == 1)
    {
        ret = av[0] == 0 ? av[1] + '0' : av[0] + '0';
        REP(i, n.size())
        {
            ret.push_back(av[0] + '0');
        }
    }
    else
    {
        reverse(ret.begin(), ret.end());
        REP(i, n.size())
        {
            if(ret[i] > n[i])
                FOR(j, i + 1, n.size())
                ret[j] = av[0] + '0';
        }
    }
    return ret;
}


int main()
{
    ios::sync_with_stdio(false);
    string n;
    int  k;
    bool d[10] = {};
    cin >> n >> k;
    REP(i, k)
    {
        int tmp;
        cin >> tmp;
        d[tmp] = true;
    }
    vector<int> av;
    REP(i, 10)
    {
        if(!d[i])
            av.push_back(i);
    }
    cout << solve(n, av) << '\n';
}



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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;
#define sorti(x) sort(x.begin(), x.end())

int main() {
  int n,k; cin >> n >> k;
  ll res = 0;

  if (k == 0) {
    ll res = (ll)pow(n,2);
    cout << res << endl;
    return 0;
  }

  for (int i = k+1; i <= n; ++i) {
    ll num = i - k;
    ll cnt = floor((double) n / i);
    res += cnt * num;

    ll pos = k + (i * cnt);
    if (pos <= n) {
      res += n - pos + 1;
    }
  }

  cout << res << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x(x % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
} comb(100005);

mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    mint ans = 0;
    rep(i, N) {
        ans += mint(A[i]) * comb(i, K - 1); // max
        ans -= mint(A[i]) * comb(N - 1 - i, K - 1); // min
    }

    cout << ans.x << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string s;
	
	int n;
	
	while (1){
		int m[11] = { 0 };
		int fe = 0;
		cin >> n;
		if (n == 0)break;
		cin >> s;
		for (int i = 0; i < 100; i++){
			if (s[i] == 'M'){
				m[i%n]++;
			}
			if (s[i] == 'S'){
				fe += m[i%n];
				fe++;
				m[i%n] = 0;
			}
			if (s[i] == 'L'){
				m[i%n] += (fe + 1);
				fe = 0;
			}
		}
		sort(m, m + n);
		for (int i = 0; i < n-1; i++){
			cout << m[i] << " ";
		}
		cout <<m[n-1]<<" "<< fe << endl;
	}
}

Measured memory_bytes: 1224
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int n,m,mapx[108][108];
bool pd[108][108];
char c;
long long read()
{
	long long x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main()
{
	n=read();
	m=read();
	for(int i=1;i<=n;++i)
	  for(int j=1;j<=m;++j)
	  {
	  	cin>>c;
	  	if(c=='#')
	  	{
	  		pd[i][j]=1;
	  		mapx[i-1][j-1]++;
	  		mapx[i-1][j]++;
	  		mapx[i-1][j+1]++;
	  		mapx[i][j-1]++;
	  		mapx[i][j+1]++;
	  		mapx[i+1][j-1]++;
	  		mapx[i+1][j]++;
	  		mapx[i+1][j+1]++;
		}
	  }
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=m;++j)
		{
			if(pd[i][j]==1)
			{
				printf("#");
				continue;
			}
			printf("%d",mapx[i][j]);
		}
		printf("\n");
	}
	return 0;
}

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

#define rep(i,f,n) for(int i = (f); i < (int)(n); i++)


int main(){

    int N; cin >> N;
    char storeName[110];
    pair<pair<string,int>,int> record[110];

    rep(i,0,N){

        int rank;scanf("%s%d",storeName,&rank);
        string tmp = storeName;
        record[i] = make_pair(make_pair(tmp,-rank),i+1);

    }

    sort(record,record+N);

    rep(i,0,N) printf("%d\n",record[i].second);



}


Measured memory_bytes: 256
# coding=utf-8

# write code...

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

if b-a>k or c-a>k or d-a>k or e-a>k or c-b>k or d-b>k or e-b>k or d-c>k or e-c>k or e-d>k:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    ll ans = 0;
    int n = s.size();
    int cnt = 0;
    rep(i,n){
        if(s[i] == 'B') cnt++;
        else ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>

#include <vector>

using namespace std;

int main()
{
    int n,m,ans=300;

    cin>>n>>m;

    int a[n][m];

    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            cin>>a[i][j];

    for(int i=0;i<m;i++)
    {
        int x[300+10]={},y[2]={};

        for(int j=0;j<n;j++)
            x[a[j][0]]++;

        for(int j=1;j<=300;j++)
        {
            if(x[j]>y[1])
            {
                y[0]=j;

                y[1]=x[j];
            }
        }

        ans=min(ans,y[1]);

        for(int j=0;j<n;j++)
            for(int k=(m-2);k+1;k--)
                if(a[j][k]==y[0])
                    for(int l=k;l<(m-i-1);l++)
                        swap(a[j][l],a[j][l+1]);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7

def cmb(n, k):
    if k > n:
        return 0
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = 10 ** 5 + 10 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)

N = ir()
A = lr()
double = 0
used = set()
for i, a in enumerate(A):
    if a in used:
        double = a
        index_back = i
        break
    used.add(a)

index_front = A.index(double)
x = N + 1 - (index_back - index_front)
print(N)
for i in range(2, N+1):
    answer = cmb(N+1, i) - cmb(x-1, i-1)
    print(answer % MOD)

print(1)
# 10

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

typedef long long int ll;

const int MAX_N = 1010;
const ll INF = (1LL << 60);
ll S[MAX_N];
ll L[MAX_N];
ll dp[MAX_N][MAX_N];
int N,W;

void input(){
  for(int i = 0 ; i < N ; i++){
    cin >> L[i];
  }
  S[0] = L[0];
  for(int i = 1 ; i < N ; i++){
    S[i] = S[i-1] + L[i];
  }
}

ll getCost(int i,int j){
  return S[i] - S[j] + L[j];
}

void solve(){
  input();
  for(int i = 0 ; i <= N ; i++ ){
    for(int j = 0 ; j <= N ; j++){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  for(int i = 0 ; i < N ; i++){
    for(int j = 0 ; j <= i ; j++){
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
      dp[i+1][i+1] = min(dp[i+1][i+1],dp[i][j] + labs(getCost(i,j) - W));
    }
  }
  
  ll res = INF;

  for(int i = 0 ; i < N ; i++){
    res = min(res,dp[N][i] + max(0LL,getCost(N-1,i)-W));
  }
  cout << res << endl;
}

int main(){
  int cnt = 1;
  while(cin >> N >> W,N || W){
    cout << "Case " << cnt++ << ": ";
    solve();
  }
  return 0;
}

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

using namespace std;

#define int long long
// #define double long double
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt(x) __builtin_popcount(x)
#define lbit(x) __builtin_ffsll(x)
#define rbit(x) __builtin_clzll(x)
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()

template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
// const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
#define PI 3.141592653589793238

signed main() {
    LCIN(N);
    SCIN(S);
    S.erase(unique(All(S)), S.end());
    cout << S.size() << "\n";
}


Measured memory_bytes: 1020
#include<stdio.h>
int main(){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0) break;
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2==0)printf("#");
				else printf(".");
			}
			printf("\n");
		}
	printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A[3];
  cin >> A[0] >> A[1] >> A[2]; 
  sort(A,A+3);
  if(A[0] + A[1] == A[2]){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{
    string s,t;
    cin>>s>>t;
    ll n=s.length();
    ll m=t.length();
    ll i,j;
    ll res=1e5;
    for(i=0;i<n;i++)
    {
        if(i+m-1>=n)continue;
        ll tans=0;
        for(j=0;j<m;j++)
        {
            if(s[i+j]!=t[j])
            {
                tans++;
            }
        }
        res=min(tans,res);
    }
    cout<<res<<"\n";
}



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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n;
    cin >> n;
    ll a[n];
    rp(i,n) cin >> a[i];
    ll ans = INF;
    rep(i,-100,101){
        ll sum = 0;
        rp(j,n){
            sum += (a[j]-i)*(a[j]-i);
        }
        if(sum < ans ) ans = sum;
    }
    cout << ans;
    cout <<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() {
  int N, M; cin >> N >> M;
  using P = pair<int, int>;
  vector<P> A(M);
  rep(i, 0, M) {
    int a, b; cin >> a >> b;
    A[i] = P(b, a);
  }
  sort(A.begin(), A.end());
  int left = 0;
  int ans = 0;
  rep(i, 0, M) {
    if(left > A[i].second) continue;
    left = A[i].first;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int *sort_sub(int *T, int N){
	int *ans = (int *)malloc(sizeof(int) * N);
	if(N == 1){
		ans[0] = T[0];
	}
	else{
		int N1 = N / 2;
		int N2 = (N + 1) / 2;
		int *sub1 = sort_sub(&T[0] , N1);
		int *sub2 = sort_sub(&T[N1], N2);
		int i, j, k;
		for(i = 0, j = 0, k = 0; i < N; i++){
			if((sub1[j] > sub2[k] && j != N1) || (k == N2)){
				ans[i] = sub1[j];
				j++;
			}
			else{
				ans[i] = sub2[k];
				k++;
			}
		}
		free(sub1);
		free(sub2);
	}
	return ans;
}

int *sort(int *T, int N){
	int *ans = sort_sub(T, N);
	free(T);
	return ans;
}

int main(){
	int N, i;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * 3 * N);
	for(i = 0; i < 3 * N; i++){
		scanf("%d", &a[i]);
	}
	a = sort(a, 3 * N);
	long long int ans = 0;
	for(i = 0; i < N; i++){
		ans += a[2 * i + 1];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,mo=998244353;
int n,a[N],i,ans=1;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	sort(a+1,a+n+1);
	for(i=1;i<=n;++i)
		ans=1ll*ans*__gcd(a[i],i-1)%mo;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
using System;
class ProgramA
    {
        static void Main(string[] args)
        {
            
            string[] input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            if(a <= 2 * b)
                Console.WriteLine("0");
            else
                Console.WriteLine(a - 2 * b);
                
        }
    }

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

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

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i, n) {
        rep(j, n-1) {
            cin >> a[i][j];
            a[i][j]--;
        }
        reverse(all(a[i]));
    }
    vector<P> q;
    auto check = [&](int i) {
        if (a[i].size() == 0) return 0;
        int j = a[i].back();
        if (a[j].size() == 0) return 0;
        if (a[j].back() == i) {
            P p(i, j);
            if (p.second < p.first) swap(p.first, p.second);
            q.pb(p);
        }
    };
    rep(i, n) {
        check(i);
    }
    int day = 0;
    while (q.size() > 0) {
        day++;
        sort(all(q));
        q.erase(unique(all(q)), q.end());
        vector<P> prevQ;
        swap(prevQ, q);
        for (P p : prevQ) {
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (P p : prevQ) {
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }
    rep(i, n) {
        if (a[i].size() != 0) {
            puts("-1");
            return 0;
        }
    }
    cout << day << endl;
    return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> a(m);
  r(i,m)cin>>a.at(i);

  int sumL=0,sumH=0;
  for(int i=0;i<m;i++){
    if(a.at(i)<x)sumL++;
    else if(a.at(i)>x)sumH++;
  }
  cout<<min(sumH,sumL)<<endl;



return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  ll res = 0;
  for (int i=0; i<N; i++) {
    if (A[i]>=2) {
      res += A[i]/2; // 同じ数字同士でペア
      // 1枚余ったら，次の数字とペアが組めないか試す
      if (A[i]%2!=0&&i+1<N&&A[i+1]>=1) {
        res++;
        A[i+1]--;
      }
    }
    else if (A[i]==1&&i+1<N&&A[i+1]>=1) {
      res++;
      A[i+1]--;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 2e9;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  rep(i, n) {
    pair<int, int> pa;
    int x, l;
    cin >> x >> l;
    pa.first = x+l;
    pa.second = x-l;
    p[i] = pa;
  }
  sort(p.begin(), p.end());
  int ans = 0;
  int cur = -INF;
  rep(i, n) {
    if(cur <= p[i].second) {
      ans++;
      cur = p[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>

typedef double db;
typedef int in;
typedef long int li;
typedef long long int lli;
typedef long ld;
typedef long lld;

#define pi M_PI
#define in scanf
#define out printf
#define inf INT_MAX
#define rep(i,n) for(int i=0;i<n;++i)
#define debugd(d) printf("%d\n",d)
#define debugs(s) printf("%s\n",s)
#define debugc(c) printf("%c\n",c)
#define debugf(f) printf("%f\n",f)


int main (void)
{
  char s[11];
  in("%s\n",s);
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
  {
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

void traverse(vector<int> *v, int node, vector<int> &ans, vector<int> &visited)
{
	if(visited[node] == 1)return;
	else if(v[node].empty())ans[node] = 0;
	else
	{
		visited[node] = 1;
		for(int i=0; i<v[node].size(); i++)
		{
			int neighbor = v[node][i];
			traverse(v,neighbor,ans,visited);
			ans[node] = max(ans[node],1+ans[neighbor]);
		}
	}
}

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> v[n];
	REP(i,0,m)
	{
		int a,b;
		cin >> a >> b;
		v[a-1].push_back(b-1);
	}
	vector<int> dp(n,-1);
	vector<int> visited(n,0);
	REP(i,0,n)
	{
		if(visited[i] == 0)
		{
			traverse(v,i,dp,visited);
		}
	}
	int maxval = 0;
	REP(i,0,n)maxval = max(maxval,dp[i]);
	cout << maxval;
}



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

int main() {
  string S; cin >> S;
  int ans = 0;
  int N = S.length();
  rep(i, N/2) {
    if (S[i] != S[N - i - 1])ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

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

signed main() {
    int n;
    cin >> n;
    int p[n * n];
    rep(i, n * n) {
        cin >> p[i];
        p[i]--;
    }
    int c[n][n];
    rep(y, n) {
        rep(x, n) {
            c[y][x] = min({y, x, n - 1 - y, n - 1 - x});
        }
    }
    bool a[n][n];
    fill(a[0], a[n], true);
    int ans = 0;
    rep(i, n * n) {
        int y = p[i] / n, x = p[i] % n;
        ans += c[y][x];
        a[y][x] = false;
        queue<P> que;
        que.emplace(y, x);
        while(!que.empty()){
            int y = que.front().first, x = que.front().second;
            que.pop();
            rep(i, 4) {
                int ny = y + dy[i], nx = x + dx[i];
                if (ny < 0 || n <= ny || nx < 0 || n <= nx) continue;
                if (c[ny][nx] <= c[y][x] + a[y][x]) continue;
                c[ny][nx] = c[y][x] + a[y][x];
                que.emplace(ny, nx);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5844