akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  long long s[N];
  for (int i = 0; i < N; i++) cin >> s[i];

  long long dp[N];
  long long max = 0;
  for (int c = 1; c < N - 1; c++) {
    dp[0] = 0;
    for (int k = 1; k * c < N - 1; k++) {
      if ((N - 1) % c == 0 && 2 * (k + 1) > (N - 1) / c + 1) break;
      if (N - 1 - k * c <= c) break;

      dp[k] = dp[k - 1] + s[N - 1 - k * c] + s[k * c];

      if (dp[k] > max) max = dp[k];
    }
  }

  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1408
import Control.Applicative
import Data.Maybe
import Data.List

findLast :: (a->Bool) -> [a] -> Maybe Int
findLast p xs = h p xs 0 Nothing
                where h _ [] _ acc = acc
                      h p (x:xs) ind acc = if p x
                                           then h p xs (ind+1) next
                                           else h p xs (ind+1) acc
                        where next = (Just ind) <|> acc

solve :: String -> Maybe Int
solve s = do x <- findIndex (=='A') s :: Maybe Int
             y <- findLast (=='Z') s :: Maybe Int
             Just (y-x+1) :: Maybe Int

main = do
  s <- getLine
  putStrLn $ show $ fromJust $ solve s


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

using namespace std;

int main()
{
//    freopen("TEST.INP", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    long long ans = 1LL * (n / 500) * 1000;
    n %= 500;
    cout << ans + 1LL * (n / 5) * 5;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef pair<int, int> P;

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  ll X, K, D;
  cin >> X >> K >> D;
  ll x = abs(X);

  ll s = x / D;
  ll m = x % D;

  if (s > K) {
    cout << x - K * D << endl;
  } else {
    ll a = K - s;
    if (a % 2 == 0) {
      cout << m << endl;
    } else {
      cout << abs(m - D) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
typedef vector<pairs> p;


ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    ld ans;
    for(ll i=1;i<=n;++i){
        ll flag = 1.08*i;
        if(flag == n){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using static System.Console;
using static System.Math;

namespace Topic05
{
    class ALDS1_5_A
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] A = ReadLine().Split()
                .Select(k => int.Parse(k)).ToArray();
            int q = int.Parse(ReadLine());
            int[] m = ReadLine().Split()
                .Select(k => int.Parse(k)).ToArray();

            bool[] dp = new bool[20 * 2000 + 1];
            List<int> arrive = new List<int>();

            dp[0] = true;
            arrive.Add(0);

            for (int i = 0; i < n; i++)
            {
                List<int> newArrive = new List<int>();
                foreach (int cur in arrive)
                {
                    newArrive.Add(cur + A[i]);
                    dp[cur + A[i]] = true;
                }
                arrive.AddRange(newArrive);
                arrive = arrive.Distinct().ToList();
            }

            for (int j = 0; j < q; j++)
            {
                WriteLine(dp[m[j]] ? "yes" : "no");
            }
            ReadKey();
        }
    }
}



Measured memory_bytes: 18256
N, K = map(int, input().split())
A_list = list(map(int, input().split()))

K_seq_sum1 = K*(K+1)//2
K_seq_sum2 = K*(K-1)//2
# print(K_seq_sum)
# その中での転倒数と
# 自分より低い数を持っておく
inv_num_in_original_list = []
inv_num_all_list = []
diff_lst = []
res = 0
for n1, a1 in enumerate(A_list):
    cnt1 = 0
    cnt2 = 0
    for n2, a2 in enumerate(A_list):
        if a1 > a2:
            cnt2 += 1
            if n1 < n2:
                cnt1 += 1
    diff = cnt2 - cnt1
    # a1から見たときの数を出す
    # (自分のリストの中での転倒の数 * K回) + (自分より左のリストとの転倒数)
    # res_tmp = cnt1 * K + cnt2 * K_seq_sum
    # res += res_tmp s
    res_tmp = diff * K_seq_sum2 + cnt1 * K_seq_sum1
    res += res_tmp
    res = int(res % (10**9+7))
print(res)



Measured memory_bytes: 9340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int l[11];
    int mx=0;
    int sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l[i];
        sum+=l[i];
        mx=max(mx,l[i]);
    }
    if(sum>mx*2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = [1, n]
for i in range(m):
  l, r = map(int, input().split())
  x[0] = max(x[0], l)
  x[1] = min(x[1], r)
print(max(x[1] - x[0] + 1, 0))

Measured memory_bytes: 3060
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long x = sc.nextLong();
        
        long[] a = new long[N];
        for(int i=0;i<N;i++) {
        	a[i]=sc.nextLong();
        }
        
        long s;
        long sum=0;
        for(int i=0;i<N-1;i++) {
        	s=a[i]+a[i+1]-x;
        	if(s>0) {
        		if(s<a[i+1]) {
        			a[i+1]=a[i+1]-s;
        		} else {
        			a[i+1]=0;
        		}
        		sum=sum+s;
        	}
        }
        System.out.println(sum);        	
                		
    }

}

Measured memory_bytes: 50768
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  bool col[8];
  for(int i=0;i<8;i++)
    col[i] = false;


  int free = 0;

  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    if(tmp/400 <8){
      col[tmp/400] = true;
    }
    else
      free++;
  }

  int ans=0;
  for(int i=0;i<8;i++)
    if(col[i])
      ans++;

  //min
  if(ans==0)
    cout << 1 << " ";
  else
    cout << ans << " ";

  //max
//  if(ans + free > 8)
//    cout << 8 << endl;
//  else
    cout << ans + free << endl;

  return 0;
}

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

int main() {
    
    int t;
    cin >> t;
    int arr[t], sum=0;
    for(int i=0; i<t; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    
    sort(arr, arr+t);
    
    sum = sum - arr[t-1];
    if(arr[t-1]>=sum) cout << "No" << endl;
    else cout << "Yes" << endl;
    
	return 0;
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
const int mod = 1e9 + 7;
const int N = 22;
int dp[1 << N];
int a[N][N];
int n;
void add(int& a, int b) {
	a += b;
	if (a >= mod)
		a -= mod;
}

int bit(int x) {
	int ans = 0;
	while (x) {
		x = x & (x - 1);
		ans++;
	}
	return ans;
}

int go(int mask) {
	if (mask == 0)
		return 1;
	if (dp[mask] != -1)
		return dp[mask];
	int bits = bit(mask) - 1;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[bits][i] and mask & (1 << i)) {
			add(ans, go(mask ^ (1 << i)));
		}
	}
	return dp[mask] = ans;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	memset(dp, -1, sizeof(dp));
	int mask = (1 << n) - 1;

	cout << go(mask);
}


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

int main(){
    int n;
    cin >> n;
    n--;
    vector<int> b(n);
    for(int i=0;i<n;i++) cin >> b[i];
    int prev = b[n-1];
    int ans = prev;
    for(int i=n-2;i>=0;i--){
        ans += min(prev,b[i]);
        prev = b[i];
    }
    ans += prev;
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from functools import lru_cache

@lru_cache(maxsize=None)
def solve(l):
    if l == 0:
        return 1, 1
    x, y = solve(l - 1)
    return x * 2 + 1, y * 2 + 3


def main():
    N, X = [int(x) for x in input().split()]
    b = []
    for y in range(51):
        b.append(solve(y))

    # print(b)
    ans = 0
    for y in range(N, -1, -1):
        if X >= b[y][1] * 2 + 1:
            X -= b[y][1]
            X -= b[y][1]
            ans += b[y][0]
            ans += b[y][0]
            ans += 1
        elif X >= b[y][1] + 1:
            X -= b[y][1]
            ans += b[y][0]
            ans += 1
            X -= 2
        elif X >= b[y][1]:
            X -= b[y][1]
            ans += b[y][0]
        else:
            X -= 1

    print(ans)




if __name__ == '__main__':
    main()



Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d;
	cin>>a>>b>>c;
	d = a;
	a = b;
	b = d;
	d = a;
	a = c;
	c = d;
	cout<<a<<' '<<b<<' '<<c<<endl;
	return 0;
}



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

const int MAXN = 600;
vector<vector<int>> to(MAXN);

double ans(int block){
	int n = to.size();
	vector<double> dp(n);
	
	for(int v = n-1; v >= 0; v--){
		int deg = to[v].size();
		
		if(v==block && deg>1){
			double maxdp = 0;
			for(auto next : to[v]) maxdp = max(maxdp,dp[next]);
			for(auto next : to[v]) dp[v] += dp[next];
			dp[v] -= maxdp;
			dp[v] /= deg-1;
			dp[v]++;
		}
		else{
			if(deg==0) continue;
			for(auto next : to[v]) dp[v] += dp[next];
			dp[v] /= deg;
			dp[v]++;
		}
	}
	
	return dp[0];
}


int main(){
	
	int n,m;
	cin >> n >> m;
	
	rep(i,m){
		int s,t;
		cin >> s >> t;
		--s; --t;
		to[s].push_back(t);
	}
	
	double res = MAXN;
	rep(i,n) res = min(res,ans(i));
	
	printf("%.10f", res);
	return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;

int main()
{
    ll x;cin >>x;
    ll m=100;
    ll ans=0;
    while(m<x){
        m=m+m/100;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a[27],s,d,f,g,h,i,j;
	char z[100001];
	for(i=0;i<26;i++) a[i]=0;
	scanf("%s",z);
	for(i=0;i<strlen(z);i++){
		a[z[i]-'a']++;
	}
	s=0;
	for(i=0;i<26;i++){
		if(a[i]==0){
			s=1;
			printf("%c\n",i+'a');
			break;
		}
	}
	if(s==0)
		printf("None\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int min(int x,int y)
{
	if(y!=0 && y<x) return y;
	return x;
}

int main(void)
{
	int i,j,N,M,d[1000],C[1000],dp[1001][1001],s;
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++)
	{
		scanf("%d",&d[i]);
	}
	for(i=0;i<M;i++)
	{
		scanf("%d",&C[i]);
	}
	for(i=0;i<N+1;i++)
	{
	    dp[i][0]=0;
	}
	for(i=1;i<M+1;i++)
	{
		dp[0][i]=0;
	}
	for(i=1;i<N+1;i++)
	{
		for(j=i;j<M+1;j++)
		{
			dp[i][j]=min(dp[i-1][j-1]+d[i-1]*C[j-1],dp[i][j-1]);
		}
	}
	s=-1;
	for(i=N;i<M+1;i++)
	{
		if(s<0 || dp[N][i]<s) s=dp[N][i];
	}
	printf("%d\n",s);
	return 0;
}

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

using namespace std;

#define bug(x) do{cerr<<#x<<": "<<x;}while(0) 
#define bugv(x) do{for(auto&e:x)cerr<<e<<" ";cerr<<"\n";}while(0) 
#define rep(i, a,b) for(int i=(a);i<=(b);++i)
#define _rep(i, a,b) for(int i=(a);i>=(b);--i)
#define fn1(e) [&](int p1){return (e);}
#define fn2(e) [&](int p1, int p2){return (e);}
#define iter(it) begin(it),end(it)
#define INF (0x3f3f3f3f)

#define MOD ((int)(1e9+7))
#define LIM (100*1000+10)


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

    int N, T; cin >> N >> T;
    vector<int> cc(N), tt(N);
    rep(i, 0, N-1) cin >> cc[i] >> tt[i];

    int cost = INF;
    rep(i, 0, N-1) {
        if (tt[i] <= T) {
            cost = min(cost, cc[i]);
        }
    }

    if (cost == INF) cout << "TLE\n"; else cout << cost << endl;

    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int A,B;
    string S;
    cin >> A >> B >> S;
    bool ok = true;
    for (int i = 0; i < S.size(); i++) {
        if (i!=A&&S[i] == '-')ok = false;
    }
    if (S[A] != '-')ok = false;

    cout <<((ok)?"Yes":"No")<< endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int n, a, b;
		cin >> n >> a >> b;
		for(int i = a ; i <= b ; i++){
			if(i % n == 0){
				cout << "OK";
				return 0;
			}
		}
		cout << "NG";
	}
	return 0;
}

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

int x,m,k,y,z,dp[10000000],ar[10000000];

int main() {
	scanf("%d",&x);
	for (int a = 1; a <= x; a++) {
		scanf("%d",&ar[a]);
	}
	dp[2] = abs(ar[2]-ar[1]);
	for (int a = 3; a <= x; a++) {
		dp[a] = min(dp[a-1]+abs(ar[a]-ar[a-1]),dp[a-2]+abs(ar[a]-ar[a-2]));
	}
	cout << dp[x] << "\n";
	return 0;
} 

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquestring;
typedef priority_queue<int> priqueint;
typedef priority_queue<ll> priquell;
typedef priority_queue<char> priquechar;
typedef priority_queue<string,vector<string>,greater<string>> rpriquestring;
typedef priority_queue<int,vector<int>,greater<int>> rpriqueint;
typedef priority_queue<ll,vector<ll>,greater<ll>> rpriquell;
typedef priority_queue<char,vector<char>,greater<char>> rpriquechar;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

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

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    //int n;
    //string s;
    int h,m,h2,m2,k;cin >> h >> m >> h2 >> m2 >> k;
    cout << h2*60+m2-h*60-m-k << endl;
}

Measured memory_bytes: 3688
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 300
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

ll a[maxn+5];
int can[2][2];

int main()
{
    int n; scanf("%d",&n);
    rep(i,1,n) scanf("%lld",&a[i]);
    ll C=0;
    rep(i,3,n) C^=a[i];
    ll M=(1<<20)-1;
    memset(can,-1,sizeof can);
    rep(low,0,M)
    {
        ll tmp1=(a[1]&M)-low;
        ll tmp2=((C&M)^low)-(a[2]&M);
        int mark1=0,mark2=0;
        //if(low==1) printf("?? %lld %lld\n",tmp1,tmp2);
        if(tmp1<0) tmp1+=M+1,mark1=1;
        if(tmp2<0) tmp2+=M+1,mark2=1;
        if(tmp1==tmp2) can[mark1][mark2]=max(can[mark1][mark2],low);
    }
    ll ans=0;
    rep(high,0,M)
    {
        ll tmp1=(a[1]>>20)-high;
        ll tmp2=((C>>20)^high)-(a[2]>>20);
        //if(high==0) printf("?? %lld %lld\n",tmp1,tmp2);
        ll cha=tmp1-tmp2;
        if(llabs(cha)<=1 && tmp1>=0 && tmp2>=0)
        {
            if(cha==1) ans=can[1][0]==-1?ans:max(ans,(((ll)high)<<20)+can[1][0]);
            else if(cha==-1) ans=can[0][1]==-1?ans:max(ans,(((ll)high)<<20)+can[0][1]);
            else
            {
                ans=can[0][0]==-1?ans:max(ans,(((ll)high)<<20)+can[0][0]);
                if(tmp1>0) ans=can[1][1]==-1?ans:max(ans,(((ll)high)<<20)+can[1][1]);
            } 
        }
    }
    if(ans==0) puts("-1");
    else 
    {
        printf("%lld\n",a[1]-ans);
        assert(((ans^(a[2]+a[1]-ans))==C));
    }
    return 0;
}

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

int main() {

	ll n, m; cin >> n >> m;
	vector<bool> isBroken(n + 1, false);
	for (ll i = 0; i < m; i++) {
		ll a; cin >> a;
		isBroken[a] = true;
	}
	const ll mod = 1000000007;
	vector<ll> dp(n + 1, 0);
	dp[0] = 1;
	if (!isBroken[1]) dp[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (!isBroken[i - 1]) {
			dp[i] += dp[i - 1];
			dp[i] %= mod;
		}
		if (!isBroken[i - 2]) {
			dp[i] += dp[i - 2];
			dp[i] %= mod;
		}	
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1000000007;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>>ab;
    int a,b;
    for(int i=0;i<M;i++){
        cin>>a>>b;
        ab.pb(make_pair(a,b));
    }
    sort(ALL(ab));
    int m=N;
    int sub=1;
    for(int i=0;i<M;i++){
        if(ab[i].first>=m){
            sub++;
            m=ab[i].second;
        }
        else{
            m=min(m,ab[i].second);
        }
    }
    cout<<sub<<endl;
}

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

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

bool NO,WE,EA,SO;
string S;




int main()
{

	cin >> S;

	NO=false;
	WE=false;
	EA=false;
	SO=false;
	int a = S.size();
	REP(i,a){
		switch(S[i]){
		case 'N':
			NO = true;
			break;
		case 'S':
			SO = true;
			break;
		case 'W':
			WE=true;
			break;
		case 'E':
			EA=true;
			break;

		}
	}


	if((NO && !SO) || (!NO && SO) || (!WE && EA) || (WE && !EA) )
		cout << "No";
	else
		cout << "Yes";

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int len;
bool flag=true;
string s1,s2;

int main(){
	cin>>s1;
	len=s1.length();
	s2=s1;
	for(int i=0;i<len;i++){
		s2[i]=s1[len-i-1];
		if(s2[i]=='b'){
			s2[i]='d';
			continue;
		}
		if(s2[i]=='d'){
			s2[i]='b';
			continue;
		}
		if(s2[i]=='p'){
			s2[i]='q';
			continue;
		}
		if(s2[i]=='q'){
			s2[i]='p';
			continue;
		}
	}
	for(int i=0;i<len;i++)
		if(s1[i]!=s2[i]) flag=false;
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1000006;
const ll MOD = 1000000007;

ll n, a, b, sum;
ll h[MAXN];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n >> a >> b;

    REP (i, n) {
        cin >> h[i];
    }

    ll l = 0, r = MOD;
    while (l < r - 1) {
        ll m = (l + r) >> 1;
        ll cnt = 0;
        REP (i, n) {
            cnt += max(0LL, (h[i] - b*m + (a-b) - 1) / (a-b));
        }
        if (cnt <= m) {
            r = m;
        } else {
            l = m;
        }
    }

    cout << r << endl;

    return 0;
}


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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    map<string,ll> x;
    ll ans = 0;
    rep(i,n){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
        x[s[i]]++;
        ans += (x[s[i]]-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 18176
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		int N = int.Parse(Console.ReadLine());

		//x座標とy座標を合わせたジャグ配列
		//ソートの都合上、{y,x}とする
		int[][] redCoord = new int[N][];
		//ソート の都合上、{x,y}とする
		int[][] blueCoord = new int[N][];

		//読み込む
		for(int i=0; i<N; i++){
			string[] S = Console.ReadLine().Split(' ');
			int a = int.Parse(S[0]);
			int b = int.Parse(S[1]);

			redCoord[i] = new int[2]{b,a};
		}
		for(int i=0; i<N; i++){
			string[] S = Console.ReadLine().Split(' ');
			int c = int.Parse(S[0]);
			int d = int.Parse(S[1]);

			blueCoord[i] = new int[2]{c,d};
		}

		//座標の順に並び替え
		Array.Sort(redCoord,StructuralComparisons.StructuralComparer);
		Array.Sort(blueCoord,StructuralComparisons.StructuralComparer);

		/*debug
		for(int i=0; i<N; i++){
			Console.WriteLine("red:y={0},x={1} | blue:x={2},y={3}",redCoord[i][0],redCoord[i][1],
			blueCoord[i][0],blueCoord[i][1]);
		}
		*/

		//既に選ばれたペアの数
		int ans = 0;

		//各赤について、既にペアがいるかを示す
		bool[] selectedRed = new bool[N];

		//貪欲に、各青が一番ギリギリの赤を取っていく
		for(int i=0; i<N; i++){
			for(int j=N-1; j>=0; j--){
				//既に選ばれている場合、スキップ
				if(selectedRed[j]){
					continue;
				}
				//ペアになれる場合ペアにして、次の青へ
				/*
				redとblueでxyが逆なので注意
				*/
				else if(redCoord[j][1] < blueCoord[i][0] && redCoord[j][0] < blueCoord[i][1]){
						ans ++;
						selectedRed[j] = true;
						//Console.WriteLine("red:{0},blue{1}",j,i);
						break;
				}
			}
		}

		Console.WriteLine(ans);
	}
}



Measured memory_bytes: 18284
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long ans = calc(b) ^ calc(a - 1);
        System.out.println(ans);
    }
    public static long calc(long x) {
        if (x <= 0) {
            return 0;
        }
        x++;
        long ans = 0;
        for (int i = 0; i < 50; i++) {
            long loop = (1L << (i + 1));
            long cnt = (x / loop) * (loop / 2);
            cnt += Math.max(0, (x % loop) - (loop / 2));
            if (cnt % 2 == 1) {
                ans += (1L << i);
            }
        }
        return ans;
    }
}


Measured memory_bytes: 21716
#!/usr/bin/env perl

use strict;
use warnings;
use 5.18.2;

use constant FIVE_HUNDRED_COIN => 500;
use constant HUNDRED_COIN => 100;
use constant FIFTY_COIN => 50;

my $input = do { local $/; <> };

chomp $input;

my ($fivecoin, $hundredcoin, $fiftycoin, $goal) = split /\n/, $input;

my $way_count = 0;

for my $fiveh (0..$fivecoin) {
    for my $hund (0..$hundredcoin) {
        for my $five (0..$fiftycoin) {
            my $total = $fiveh * FIVE_HUNDRED_COIN + $hund * HUNDRED_COIN + $five * FIFTY_COIN;
            if ($total == $goal) {
                $way_count++;
            }
        }
    }
}

say $way_count;


Measured memory_bytes: 768
import java.util.*;
import java.util.stream.IntStream;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.CountDownLatch;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];
        for(int i=0; i<n; i++){
            d[i] = Integer.parseInt(sc.next());
        }
        
        try{
            SleepSort.sort(d);
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        
        int ans = n;
        for(int i=0; i<n-1; i++){
            if(d[i]==d[i+1]){
                ans--;
            }
        }
        
        System.out.println(ans);
    }
}

class SleepSort{
    public static void sort(int[] array) throws InterruptedException{
        int taskCount = array.length;
        final CountDownLatch latch = new CountDownLatch(taskCount);
        
        List<Integer> res = new ArrayList<>();
        
        for(final int num : array){
            new Thread(new Runnable(){
                public void run(){
                    try{
                        TimeUnit.MILLISECONDS.sleep(num*10);
                        synchronized (res){
                            res.add(num);
                        }
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }finally{
                        latch.countDown();
                    }
                }
            }).start();
        }
        
        latch.await();
        
        int i=0;
        for(int v : res){
            array[i] = v;
            i++;
        }
        
    }
}

Measured memory_bytes: 38876
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BTollGates {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n, m, x;
        in >> n >> m >> x;
        vi A(m);
        in >> A;
        int pos = lower_bound(all(A), x) - A.begin(), res = min(pos, m - pos);
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BTollGates solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdint>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}

template <class T>
void print(const T &value)
{
	std::cout << value << std::endl;
}

int main()
{
	string s;
	cin>>s;
	string t="abcdefghijklmnopqrstuvwxyz";
	map<char,bool>alpha;
	int n=s.size();
	rep(i,s.size()){
		alpha[s[i]]=true;
	}
	if(n==26){
		if(s=="zyxwvutsrqponmlkjihgfedcba"){
			cout<<-1<<endl;
		}else{
			string ss=s;
			rep(i,26){
				bool ans=false;
				int ite=25-i;
				rep(j,26){
					string tmp=ss;
					tmp[ite]=t[j];
					if(tmp>s&&!alpha[t[j]]){
						cout<<tmp<<endl;
						ans=true;
						j=26;
						i=26;
					}
				}
				if(!ans){
					alpha[ss[ite]]=false;
					ss.pop_back();
				}
			}
		}
	}else{
		
		rep(i,26){
			string tmp=s;
			tmp.push_back(t[i]);
			if(tmp>s&&!alpha[t[i]]){
				cout<<tmp<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
#if 1

#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];

int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        a[i] -= i;
    }
    sort(a+1,a+n+1);
    long long ans = 0;
    for(int i = 1;i <= n;i++)
    {
        ans += abs(a[n/2+1]-a[i]);
    }
    printf("%lld",ans);
}

#endif // 1++


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
 
typedef struct{
  double i;
  double j;
}Point;
 
void koch(Point,Point,int);
  
int main()
{
 
  Point a,b;
  int num;
 
  scanf("%d",&num);
 
  a.i=0;
  a.j=0;
  b.i=100;
  b.j=0;
 
  printf("%f %f\n",a.i,a.j);
  koch(a,b,num);
  printf("%f %f\n",b.i,b.j);
 
  return 0;
}
 
void koch(Point a,Point b,int num)
{
 
  if(num==0) return;
 
  Point s,t,u;
 
  s.i=(2.0*a.i+1.0*b.i)/3.0;
  s.j=(2.0*a.j+1.0*b.j)/3.0;
  t.i=(1.0*a.i+2.0*b.i)/3.0;
  t.j=(1.0*a.j+2.0*b.j)/3.0;
  u.i=(t.i-s.i)*cos(M_PI/3)-(t.j-s.j)*sin(M_PI/3)+s.i;
  u.j=(t.i-s.i)*sin(M_PI/3)+(t.j-s.j)*cos(M_PI/3)+s.j;
 
  koch(a,s,num-1);
  printf("%f %f\n",s.i,s.j);
  koch(s,u,num-1);
  printf("%f %f\n",u.i,u.j);
  koch(u,t,num-1);
  printf("%f %f\n",t.i,t.j);
  koch(t,b,num-1);
}


Measured memory_bytes: 2052
N, K = map(int, input().split())
A = list(map(int, input().split()))
b = [0 for i in range(N+2)]
if K > 70:
    ans = [N for i in range(N)]
    print(*ans)
else:
    for _ in range(K):
        for i in range(N+2):
            b[i] = 0
        for i in range(N):
            b[max(0, i+1-A[i])] += 1
            b[min(N+1, i+1+A[i]+1)] -= 1
        for i in range(1, N+1):
            b[i] += b[i-1]
            A[i-1] = b[i]
    print(*A)


Measured memory_bytes: 115596
s=input()
p=""
q=[]
cnt=0
for i in range(len(s)):
	if s[i]!="x":
		p+=s[i]
		q.append(cnt)
		cnt=0
	else:
		cnt+=1
q.append(cnt)
if p!=p[::-1]:
	print(-1)
	exit()
ans=0
for i in range(len(q)):
	ans+=abs(q[i]-q[-i-1])
print(ans//2)


Measured memory_bytes: 4108
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define int unsigned long long
using namespace std;
const int mods=1e9+7;
inline int fpow(int b,int p,int k);
signed main()
{
	int n;
	cin>>n;
	int a=fpow(10,n,mods),b=fpow(9,n,mods),c=fpow(8,n,mods);
	int ans=(a-b+mods)%mods;
	ans=(ans-b+mods)%mods;
	ans=(ans+c)%mods;
	cout<<ans%mods;
	return 0;
}

inline int fpow(int b,int p,int k)
{
	int ans=1;
	while(p)
	{
		if(p%2==1)
		ans=ans*b%k;
		b=b*b%k;
		p/=2;
	}
	return ans%mods;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
const int maxn = 300010;
ll n, x;
ll solve(ll a, ll b){
	if(b % a == 0)return b * 2;
	return b / a * a * 2 + a + b % a + solve(b % a, a - b % a);
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> x;
	cout << solve(n-x, x) + x << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int INF = 1 << 30;
int N, C;
int D[30][30];
int c[510][510];
int cnt[3][30];

int calc(int x, int y, int z) {
  int res = 0;
  for (int i = 0; i < C; i++) {
    res += cnt[0][i] * D[i][x];
  }
  for (int i = 0; i < C; i++) {
    res += cnt[1][i] * D[i][y];
  }
  for (int i = 0; i < C; i++) {
    res += cnt[2][i] * D[i][z];
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> C;
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      cin >> D[i][j];
    }
  }  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> c[i][j];
      c[i][j]--;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cnt[(i + j) % 3][c[i][j]]++;
    }
  }
  int ans = INF;
  for (int i = 0; i < C; i++) {
    for (int j = 0; j < C; j++) {
      for (int k = 0; k < C; k++) {
        if (i == j || j == k || k == i) continue;
        ans = min(ans, calc(i, j, k));
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;



int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, T;
  cin >> N >> T;

  int res = 2e9;

  for (int i = 0; i < N; ++i)
  {
    int c, t;
    cin >> c >> t;
    if (t <= T) res = min(res, c);
  }

  if (res == 2e9) cout << "TLE\n";
  else cout << res << "\n";


  return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define ll long long
#define INF 100000000000000

using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  ll cntK = 0, cnthalf = 0;
  if (K % 2 == 0) {
    for (ll i = 1; i <= N; i++) {
      if (i % K == 0)
        cntK++;
      else if (i % K == K / 2)
        cnthalf++;
    }
  } else {
    for (ll i = 1; i <= N; i++) {
      if (i % K == 0)
        cntK++;
    }
  }

  cout << cnthalf * cnthalf * cnthalf + cntK * cntK * cntK << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include <vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORL(i,a,b) for(ll i=(a);i<(b);++i)
#define REPL(i,n) FORL(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define RREP(i,n)   RFOR(i,n,0)
using namespace std;

/*
1 CountingSort(A, B, k)
2     for i = 0 to k
3         C[i] = 0
4
5      C[i] に i の出現数を記録する 
6     for j = 1 to n
7         C[A[j]]++
8
9      C[i] に i 以下の数の出現数を記録する
10    for i = 1 to k
11        C[i] = C[i] + C[i - 1]
12
13    for j = n downto 1
14        B[C[A[j]]] = A[j]
15        C[A[j]]--
*/

void CountingSort(int A[], int B[], int k, int n){
	int *C;
	C = new int[k];
	REP(i, k + 1){
		C[i] = 0;
	}
	FOR(i, 1, n + 1){
		C[A[i]]++;
	}
	FOR(i, 1, k + 1){
		C[i] = C[i] + C[i - 1];
	}
	RFOR(j, n, 1){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main(){
	int n, A[2000001], B[2000001], k = 10000;
	scanf("%d", &n);
	FOR(i, 1, n + 1){
		scanf(" %d", &A[i]);
	}

	CountingSort(A, B, k, n);
	FOR(i, 1, n + 1){
		if (i != 1){
			printf(" ");
		}
		printf("%d", B[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 18732
///
// File:  cgl_1_b.cpp
// Author: ymiyamoto
//
// Created on Mon Oct 23 00:28:22 2017
//
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;
#define EPS 1e-10
#define equals(x, y) (fabs(x - y) < EPS)

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double dot(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  double cross(vector_t a)
  {
    return x * a.y - y * a.x;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }
};

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }

  point_t operator+(const vector_t vec)
  {
    return point_t({x + vec.x, y + vec.y});
  }

  vector_t operator-(const point_t p)
  {
    return vector_t({x - p.x, y - p.y});
  }

  point_t project(point_t p1, point_t p2)
  {
    vector_t vec1(x - p1.x, y - p1.y);
    vector_t vec2(p2.x - x, p2.y - y);
    return point_t({x, y}) + vec1 * (vec1.dot(vec2) / vec1.norm2());
  }

  point_t reflect(point_t p1, point_t p2)
  {
    point_t proj = project(p1, p2);
    return p2 + (proj - p2) * 2.0;
  }
};

enum pos_t {
  CCLOCKWISE = -1,
  CLOCKWISE = 1,
  ONLINE_BACK = 2,
  ONLINE_FRONT = -2,
  ON_SEGMENT = 0,
};

pos_t ccw(point_t p0, point_t p1, point_t p2)
{
  if ((p1 - p0).cross(p2 - p0) > EPS) {
    return CCLOCKWISE;
  } else if ((p1 - p0).cross(p2 - p0) < -EPS) {
    return CLOCKWISE;
  } else if ((p1 - p0).dot(p2 - p0) < -EPS) {
    return ONLINE_BACK;
  } else {
    if ((p1 - p0).norm2() < (p2 - p0).norm2()) {
      return ONLINE_FRONT;
    } else {
      return ON_SEGMENT;
    }
  }
}

bool intersection(point_t p0, point_t p1, point_t p2, point_t p3)
{
  // cout << "--" << endl;
  // cout << ccw(p0, p1, p2) << endl;
  // cout << ccw(p0, p1, p3) << endl;
  // cout << ccw(p2, p3, p0) << endl;
  // cout << ccw(p2, p3, p1) << endl;
  // cout << "--" << endl;
  return (ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0) && (ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0);
}

struct segment_t {
  point_t x;
  point_t y;
};

int32_t main()
{
  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    double x, y;
    cin >> x >> y;
    point_t p0({x, y});
    cin >> x >> y;
    point_t p1({x, y});
    cin >> x >> y;
    point_t p2({x, y});
    cin >> x >> y;
    point_t p3({x, y});
    cout << (int)intersection(p0, p1, p2, p3) << endl;
  }

  return 0;
}

Measured memory_bytes: 3232
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

    int A, B, m; cin>>A>>B>>m;
    vector<int> a(A), b(B);
    for(int i=0; i<A; i++) cin>>a[i];
    for(int i=0; i<B; i++) cin>>b[i];

    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    while(m--){
        int x, y, c; cin>>x>>y>>c;
        x--, y--;
        chmin(ans, a[x] + b[y] - c);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,h[100005],a,b,ans[100005]={};
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	for(int i=0;i<m;i++){
		cin>>a>>b;
		if(h[a-1]<h[b-1] || h[a-1]==h[b-1]){
			if(ans[a-1]==0){
				ans[a-1]=1;
				n--;
			}
		}
		if(h[a-1]>h[b-1] || h[a-1]==h[b-1]){
			if(ans[b-1]==0){
				ans[b-1]=1;
				n--;
			}
		}
	}
	cout<<n<<endl;
  return(0);
}

Measured memory_bytes: 4404
#include <stdio.h>

typedef struct Edge_{
  int a, b, color;
  struct Edge_ *right;
} Edge;
typedef struct {
  Edge *up;
  Edge *down;
} Node;
static Edge edge[100000];
static Node node[100000];
static int maxColornum = 0;

void paint(Node *np, int nodeColor) {
  int color = 0;
  Edge *ep = np->down;
  while (ep) {
    color++;
    if (color == nodeColor) color++;
    ep->color = color;
    paint(&(node[ep->b]), color);
    ep = ep->right;
  }
  if (maxColornum < color) { maxColornum = color; }
}

int main() {
  int i,n, a, b;
  scanf("%d", &n);

  for (i = 0; i < n - 1; i++) {
    Edge *ep = &(edge[i]);
    scanf("%d %d", &a, &b); a--; b--;
    ep->a = a;
    ep->b = b;
    ep->right = (node[a].down);
    node[a].down = ep;
    if (node[b].up) {
    } else {
      node[b].up = ep;
    }
  }
  paint(&(node[0]), -1);

  printf("%d\n", maxColornum);
  for (i = 0; i < n - 1; i++) {
    printf("%d\n", edge[i].color);
  }
}




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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define STR(s) string s;cin>>s

int main(){
  INT(n);
  map<int, string> hist;
  cout << 0 << endl << flush;
  STR(s);
  hist[0] = s;
  int l = 0, r = n - 1, prv = 0;
  REP(19){
    if (hist[prv] == "Vacant"){break;}
    int c = (l + r) / 2;
    if (c == l || c == r){
      if (hist.count(l)){
        c = r;
      } else {
        c = l;
      }
    }
    cout << c << endl << flush;
    cin >> s;
    hist[c] = s;
    if (prv == l){
      if ((hist[l] == s) == ((c - l) % 2 == 0)){
        l = c;
      } else {
        r = c;
      }
    } else {
      if ((hist[r] == s) == ((r - c) % 2 == 0)){
        r = c;
      } else {
        l = c;
      }
    }
    prv = c;
  }
  return 0;
}

Measured memory_bytes: 852