akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<int> s(1<<n);
    rep(i, 1<<n) cin >> s[i];
    sort(s.begin(), s.end());
    map<int, int> mp;
    vector<int> now;
    now.push_back(s.back());
    string ans = "Yes";
    bool ok = true;

    rep(i, (1<<n)-1) {
        mp[s[i]]++;
    }
    rep(i, n) {
        vector<int> ad;
        for (int e: now) {
            auto it = mp.lower_bound(e);
            if (it==mp.begin()) {
                ok = false;
                break;
            }
            it--;
            ad.push_back(it->first);
            (it->second)--;
            if (it->second==0) mp.erase(it->first);
        }
        if (!ok) break;
        for (int e: ad) {
            now.push_back(e);
        }
    }

    if (!ok) {
        ans = "No";
    } 
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main(){
        string S;
        cin >> S;
        string ans = "No";
        for(int i=0; i<2; i++){
                if(S[i] == '9') ans = "Yes";
        }
        cout << ans;
}


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

using namespace std;

const int maxn = 305;
using ld = long double;
int n;
int a[maxn];

ld dp[maxn][maxn][maxn];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	int num1 = 0;
	int num2 = 0;
	int num3 = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 1) num1++;
		if (a[i] == 2) num2++;
		if (a[i] == 3) num3++;
	}

	for (int k = 0; k <= n; k++) {
		for (int j = 0; j <= n; j++) {
			for (int i = 0; i <= n; i++) {
				if (i == 0 && j == 0 && k == 0) continue;
				
				dp[i][j][k] = n*1.0/(i+j+k);
				if (i) {
					dp[i][j][k] += i*1.0/(i+j+k) * dp[i-1][j][k];
				}
				if (j) {
					dp[i][j][k] += j*1.0/(i+j+k) * dp[i+1][j-1][k];
				}
				if (k) {
					dp[i][j][k] += k*1.0/(i+j+k) * dp[i][j+1][k-1];
				}
			}
		}
	}


	cout << fixed << setprecision(15);
	cout << dp[num1][num2][num3] << endl;
}

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

int main() {
    int x,n;
    cin>>x>>n;
    if(n==0){
        cout<< x<< endl;
        return 0;
    }
    int p[n],fl=0;
    rep(i,n)cin>>p[i];
    rep(i,101){
        fl=0;
        rep(j,n){
            if(p[j]==x-i)fl=1;
        }
        if(fl==0){
            cout<< x-i << endl;
            return 0;
        }
        fl=0;
        rep(j,n){
            if(p[j]==x+i)fl=1;
        }
        if(fl==0){
            cout<< x+i << endl;
            return 0;
        }
    }
}

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

typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9+10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

int read() {
	int xx=0,ww=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-') ww=-ww;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		xx=10*xx+ch-48;
		ch=getchar();
	}
	return xx*ww;
}

int n,m;
int a[100010],b[100010];
ll sum=0;

int main() {
	n=read();
	m=read();
	for(int i=1; i<=m; i++) a[i]=read();
	sort(a+1,a+m+1);
	if(n>=m) {
		printf("0\n");
		return 0;
	}
	for(int i=1; i<m; i++) b[i]=a[i+1]-a[i];
	sort(b+1,b+m);
	for(int i=1; i<=m-n; i++) sum+=(ll)b[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,n,m,x;
	cin>>n>>m;
	a=n+m;
	b=n-m;
	c=n*m;
	x=max(a,max(b,c));
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    if n % 2 == 0:
        cnt = 0
        for i in range(1, 10 ** 10):
            pw = pow(5, i)
            if pw <= n:
                cnt += n // pw // 2
            else:
                print(cnt)
                exit()
    else:
        print(0)


if __name__ == '__main__':
    solve()


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

int main() {
  int N, i; cin >> N;
  map<string, int> map;
  rep (i, N) {
    string s;
    cin >> s;
    map[s] ++;
  }
  int max = 0;
  for (const auto& x : map) {
    int b = x.second;
    if (b >= max) max = b;
  }
  for (auto ite=map.begin(); ite!=map.end(); ite++) {
    if (ite->second >= max) cout << ite->first << endl;
  }
  return 0;
}


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

int main() {
    string A;
    cin >> A;

    if (A[A.size() - 1] == 's')
        A += "es";
    else
        A += 's';

    cout << A << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

/*
 S = 10^9 * y3 - x2
*/

int main() {
    ll s; cin >> s;

    ll a = pow(10, 9); ll b = 1;
    ll y = ceil((long double)s / (double)a);
    ll x = a * y - s;
    cout << "0 0  " << a << " " << b << " " << x << " " << y << endl;
    return 0;
}

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

int main(){
  int K,T;
  cin>>K>>T;
  int k=0;
  for(int i=0;i<K;i++){
    int j;
    cin>>j;
    k=max(j,k);
  }
  cout<<max((k-(K/2)-1)*2+(K+1)%2,0)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
	int max,min,N,a;
    cin >> N;
    cin >> a;
    min = a;
    max = a;
    for(int i = 1; i < N;i++){
        cin >> a;
        if(min > a){
            min = a;
        }
        if(max < a){
            max = a;
        }
    }
    cout << max -min << endl;
	return 0;
}

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

namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            int x = 0;
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            int max = 0;
            for (int i = 0; i < S.Length; i++) 
            {
                if (S.Substring(i, 1) == "I") x++;
                else x--;
                if (max < x) max = x;
            }

            //結果を出力
            Console.WriteLine(max.ToString());
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 2648
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;

const ll inf = 1000000000000000000;
ll n, m, k, x, y, z, a[3005][3005], dp[3005][3005][5];
bool used[3005][3005];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> k;
    for (ll i = 1; i <= k; ++i) {
        cin >> x >> y >> z;
        a[x][y] = z;
        used[x][y] = true;
    }
    for (ll i = 1; i <= n; ++i)
        for (ll j = 1; j <= m; ++j)
            for (ll k = 0; k <= 3; ++k)
                dp[i][j][k] = -inf;
    dp[1][1][0] = 0;
    for (ll i = 1; i <= n; ++i)
        for (ll j = 1; j <= m; ++j) {
            if (dp[i][j][0] != -inf) {
                if (i + 1 <= n) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][0]);
                    if (used[i][j])
                        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][0] + a[i][j]);
                }
                if (j + 1 <= m) {
                    dp[i][j + 1][0] = max(dp[i][j + 1][0], dp[i][j][0]);
                    if (used[i][j])
                        dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][0] + a[i][j]);
                }
            }
            if (dp[i][j][1] != -inf) {
                if (i + 1 <= n) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][1]);
                    if (used[i][j])
                        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][1] + a[i][j]);
                }
                if (j + 1 <= m) {
                    dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][1]);
                    if (used[i][j])
                        dp[i][j + 1][2] = max(dp[i][j + 1][2], dp[i][j][1] + a[i][j]);
                }
            }
            if (dp[i][j][2] != -inf) {
                if (i + 1 <= n) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][2]);
                    if (used[i][j])
                        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][2] + a[i][j]);
                }
                if (j + 1 <= m) {
                    dp[i][j + 1][2] = max(dp[i][j + 1][2], dp[i][j][2]);
                    if (used[i][j])
                        dp[i][j + 1][3] = max(dp[i][j + 1][3], dp[i][j][2] + a[i][j]);
                }
            }
            if (dp[i][j][3] != -inf) {
                if (i + 1 <= n) {
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][3]);
                    //if (used[i][j])
                    //    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][2] + a[i][j]);
                }
                if (j + 1 <= m) {
                    dp[i][j + 1][3] = max(dp[i][j + 1][3], dp[i][j][3]);
                    //if (used[i][j])
                    //    dp[i][j + 1][3] = max(dp[i][j + 1][3], dp[i][j][2] + a[i][j]);
                }
            }
        }
    cout << max(dp[n][m][0] + a[n][m], max(dp[n][m][1] + a[n][m], max(dp[n][m][2] + a[n][m], dp[n][m][3])));
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    ll sum = 0;
    vector<ll> s(n);
    for (int i = 0; i < n; ++i) {
        ll a, b;
        cin >> a >> b;
        s[i] = a + b;
        sum -= b;
    }
    sort(s.begin(), s.end());
    for (int i = n - 1; i >= 0; i -= 2) {
        sum += s[i];
    }
    cout << sum;
}


Measured memory_bytes: 1024
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = input()
ln = len(s)
if s == s[::-1]:
    front = s[:(ln-1)//2]
    back = s[(ln+3)//2-1:]
    #print(front,back)
    if front == front[::-1] and back == back[::-1]:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()


int main(){
  int n,max=0,smax=0;
  cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
    if(max<a[i])  max=a[i];
    else if(smax<a[i])  smax=a[i];
  }
  //cout << max << "," << smax << endl;

  rep(i,n){
    if(max==a[i]) cout << smax << endl;
    else cout << max << endl;
  }
}

Measured memory_bytes: 2432
/**
 * ??¬????????\?±??????°

?????§?????????????????¢????????¨?±?????????????????????¬???????£??????????????????????????????¬????????\?±??????????????????±???????????????????????¨?±??????\?±??????°???????????????????????°?????????????????????????????????

n??¶????????±????????????????????????????????±??§?????????????????´??°b, f, r,
v????????????????????????????????????b?£?f??????r???????????¨?±????v??????????????§??\?±????????????¨??????????????????v?????????????????´??????v????????????????????¨??????????????????

???????????¨????????¨?±?????????°?????\?±????????????????????????¨????????????

Input
????????????????????±?????° n ????????????????????????

?¶??????? n ??¶????????±????????????????????????????????±?????????????????´??° b, f, r, v
????????????????????§??????????????????????????????

Output
????£???????????????\?±??????°???????????????????????????????£???????????????????????????????????????????????????\?±??????°??????????????????????????????????????????????????????????????????????????????????????????????????¨?±??????\?±??????°????????????????????????????????\?±??????°???????????????????????????????????????????????????????????????????£?????????????####################(20??????#)??§????????£???????????????

Constraints
????????£????£??????????????????¨?±???????????????????????????????
?????????????¨???§?????¨?±??????\?±??????°?????????????°??????????????????¨????????????
?????????????¨???§?????¨?±??????\?±??????°???9???????????????????????¨????????????
Sample Input
3
1 1 3 8
3 2 2 7
4 3 8 1
Sample Output
 0 0 8 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 7 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
####################
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 0 0 0
 0 0 0 0 0 0 0 1 0 0
 */

#include <iostream>
#include <sstream>
#include <vector>

int main(int argc, char const *argv[]) {
  std::vector<std::vector<std::vector<int>>> Residents(
      4, std::vector<std::vector<int>>(3, std::vector<int>(10, 0)));
  unsigned int n = 1;
  std::string Param;

  getline(std::cin, Param);
  std::istringstream iss(Param);
  iss >> n;
  iss.clear();

  unsigned short b, f, r;
  short v;
  b = f = r = v = 0;

  unsigned short count = n;
  while (count) {
    getline(std::cin, Param);
    iss.str(Param);
    iss >> b >> f >> r >> v;
    iss.clear();
    b--;
    f--;
    r--;
    Residents[b][f][r] += v;
    count--;
  }
  unsigned short NumOfBuildings = Residents.size();
  for (const auto &Buildings : Residents) {
    for (const auto &Floors : Buildings) {
      for (const auto &Rooms : Floors) {
        std::cout << " " << Rooms;
      }
      std::cout << std::endl;
    }
    if (NumOfBuildings > 1) { // Don't print separator below the last building
      std::cout << "####################" << std::endl;
    }
    NumOfBuildings--;
  }
  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
#define min(a,b) ((a)<(b)?(a):(b))

int n,ww;
int w[110];
int v[110];
long long int c[110][100100];

int main(void){
    scanf("%d %d",&n,&ww);
    int max=0;
    for(int i=0; i<n; i++){
        scanf("%d %d",w+i,v+i);
        max+=v[i];
    }
    for(int i=0; i<n+1; i++)
        for(int j=1; j<max+1; j++)
            c[i][j]=-1;
    for(int i=1; i<n+1; i++){
        for(int j=1; j<max+1 ; j++){
            if( j<v[i-1]){
                c[i][j]=c[i-1][j];
            }else{
                int a=c[i-1][j];
                if(a>ww) a=-1;
                int b=c[i-1][j-v[i-1]]<0?(-1):c[i-1][j-v[i-1]]+w[i-1];
                if(b>ww) b=-1;
                if(a<0){
                    if(b>=0) c[i][j]=b;
                }else{
                    if(b<0){
                        c[i][j]=a;
                    }else{
                        c[i][j]=min(a,b);
                    }
                }
            }
            //printf("%2d ",c[i][j]);
        }//printf("\n");
    }
    int i;
    for(i=max;i>=0;i--)
        if(c[n][i]>0) break;
    
    printf("%d",i);
}

Measured memory_bytes: 80000
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	a, b := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		a[i], b[i] = nextInt()-1, nextInt()-1
	}

	ans := make([]int, m+1)
	ans[m] = n * (n - 1) / 2
	uf := NewUnionFind(n)
	for i := m - 1; i >= 0; i-- {
		if uf.Same(a[i], b[i]) {
			ans[i] = ans[i+1]
		} else {
			ans[i] = ans[i+1] - uf.Size(a[i])*uf.Size(b[i])
			uf.Unite(a[i], b[i])
		}
	}

	for i := 1; i <= m; i++ {
		puts(ans[i])
	}
}

type UnionFind struct {
	Par []int
}

func NewUnionFind(n int) *UnionFind {
	uf := &UnionFind{
		Par: make([]int, n),
	}
	uf.Init(n)
	return uf
}

func (uf *UnionFind) Init(n int) {
	for i := 0; i < n; i++ {
		uf.Par[i] = -1
	}
}

func (uf *UnionFind) Find(x int) int {
	if uf.Par[x] < 0 {
		return x
	}
	uf.Par[x] = uf.Find(uf.Par[x])
	return uf.Par[x]
}

func (uf *UnionFind) Unite(x, y int) {
	x, y = uf.Find(x), uf.Find(y)
	if x == y {
		return
	}

	if uf.Par[x] > uf.Par[y] {
		x, y = y, x
	}
	uf.Par[x] += uf.Par[y]
	uf.Par[y] = x
}

func (uf *UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func (uf *UnionFind) Size(x int) int {
	return -uf.Par[uf.Find(x)]
}


Measured memory_bytes: 6528
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

int main()
{
	std::vector<int> a(3,0);
	for (int i = 0; i < 3; i++)
	{
		std::cin >> a[i];
	}

	std::sort(a.begin(), a.end());

	std::cout << a[0] + a[1] << std::endl;

	return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
ans = [-1, -1, -1]

for x in range(N+1):
    for y in range(0, N-x+1):
        z = N - (x + y)
        if 10000*x + 5000*y + 1000*z == Y:
            ans[0] = x
            ans[1] = y
            ans[2] = z
            break

print(ans[0], ans[1], ans[2])


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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	string s; cin >> s;
	int ans = 700;
	rep(i, 0, 3){
		if(s[i]=='o') ans += 100;
	}
	cout << ans << endl;
	return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  map<int, int> a;
  for (int i=0; i<n; i++) {
    int ai;
    cin>>ai;
    ++a[ai];
  }

  vector<pair<long long, long long> > b;
  for (auto e: a) {
    if (e.second > 1) {
      b.push_back(make_pair(e.first, e.second));
    }
  }
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());

  if (b.size() <= 1) {
    cout<<"0"<<endl;
  } else if (b[0].second > 3) {
    cout<<b[0].first*b[0].first<<endl;
  } else {
    cout<<b[0].first*b[1].first<<endl;
  }
}

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

int main(){
int a, b, c, d;
cin >> a >> b >> c >> d;

if(a+b== c+d){
cout << "Balanced" << endl;
}
else if(a+b < c+d)cout << "Right" << endl;
else if(a+b > c+d)cout << "Left" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	// your code goes here
	string a,b;
	getline(cin,a);
	getline(cin,b);
	ll n=a.length();
	ll cnt=0;
	for(int i=0;i<n;i++){
		if(a[i]!=b[i])
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string ans = "";
    int K;
    cin >> K;
    for(int i=0;i<K;i++) ans += "ACL";
    cout << ans << "\n";
}

Measured memory_bytes: 3644
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

bool dp[2][16384];

bool f(const vector<int> &s, int sum) {
  if (abs(sum) > 8000) return false;
  memset(dp, 0, sizeof(dp));
  dp[0][8192] = true;
  REP(i,s.size()) {
    int v = s[i];
    REP(j,16384) dp[(i+1)&1][j] = false;
    REP(j,16384) {
      if (dp[i&1][j]) {
        dp[(i+1)&1][j + v] = true;
        dp[(i+1)&1][j - v] = true;
      }
    }
  }
  return dp[s.size() & 1][sum + 8192];
}

void solve(string s, ll x, ll y) {
  const int n = s.size();
  int p = 0;
  while (p < n && s[p] == 'F') { ++p; --x; }
  vector<int> vec;
  while (p < n) {
    ++p;
    int c = 0;
    while(p < n && s[p] == 'F') { ++p; ++c; }
    vec.push_back(c);
  }
  vector<int> xs, ys;
  REP(i,vec.size()) {
    if (i % 2) xs.push_back(vec[i]);
    else ys.push_back(vec[i]);
  }
  cout << (f(xs, x) && f(ys, y)) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll x;
	ll y;
	string s;
	cin >> s;
	scanf("%lld", &x);
	scanf("%lld", &y);
	solve(s, x, y);
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	#ifdef LOCAL
//		freopen("in1.txt", "r", stdin);
//		freopen("in1.txt", "w", stdout);
	#endif
	ll k;
	cin >> k;
	set<int> vis;
	ll n = 0;
	int ans = 0;
	do {
		while (n<k) {
			n *= 10;
			n += 7;
			ans++;
		}
		ll div = n/k;
		n -= div*k;
		if (vis.count(n)) {
			cout << -1 << '\n';
			return 0;
		}
		vis.insert(n);
	} while(n);
	cout << ans << '\n';
}

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;

  long long A[X], B[Y], C[Z];
  for (int i = 0; i < X; i++) cin >> A[i];
  for (int i = 0; i < Y; i++) cin >> B[i];
  for (int i = 0; i < Z; i++) cin >> C[i];

  sort(A, A + X, greater<long long>());
  sort(B, B + Y, greater<long long>());
  sort(C, C + Y, greater<long long>());

  int KX = min(X, K);
  int KY = min(Y, K);
  int KZ = min(Z, K);

  long long AB[KX * KY];
  int k = 0;
  for (int i = 0; i < KX; i++) {
    for (int j = 0; j < KY; j++) {
      AB[k++] = A[i] + B[j];
    }
  }

  sort(AB, AB + KX * KY, greater<long long>());
  int KXY = min(KX * KY, K);
  long long ABC[KXY * KZ];
  k = 0;
  for (int i = 0; i < KXY; i++) {
    for (int j = 0; j < KZ; j++) {
      ABC[k++] = AB[i] + C[j];
    }
  }

  sort(ABC, ABC + KXY * KZ, greater<long long>());
  for (int i = 0; i < K; i++) cout << ABC[i] << endl;

  return 0;
}


Measured memory_bytes: 31616
import sys
sys.setrecursionlimit(500000)

def knapsack(VW, limit):
    n = len(VW)
    dp = [[0] * (limit+1) for _ in range(n+1)]
    for idx, (v, w) in enumerate(VW, 1):
        for we in range(limit+1):
            dp[idx][we] = dp[idx-1][we]
            if we >= w:
                dp[idx][we] = max(dp[idx][we], dp[idx-1][we-w]+v)
    return dp

def main():
    N, T = map(int, input().split())
    VW = []
    ma = 0
    ama = -1
    for i in range(N):
        w, v = map(int, input().split())
        if ma < v:
            ma = v
            ama = i
        VW.append([v, w])
    dp1 = knapsack(VW, T-1)
    VW.reverse()
    dp2 = knapsack(VW, T-1)
    dp2.reverse()
    VW.reverse()
    #for d in dp2:
    #    print(d)
    ans = 0
    for (v, w), d1, d2 in zip(VW, dp1[:-1], dp2[1:]):
        #print(v, w, d1, d2)
        for i in range(1, T):
            d1[i] = max(d1[i], d1[i-1])
            d2[i] = max(d2[i], d2[i-1])
        for dd1, dd2 in zip(d1, d2[::-1]):
            ans = max(ans, dd1+dd2+v)
    print(ans)


main()


Measured memory_bytes: 184408
/*
 * Author       : YangDavid
 * Created Time : 2019年11月23日 星期六 20时05分08秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int f(int x) {
	if(x == 3) return 100000;
	else if(x == 2) return 200000;
	else if(x == 1) return 300000;
	return 0;
}
int main() {
	int x, y, sum = 0;
	cin >> x >> y;
	sum = f(x) + f(y) + (x==1&&y==1 ? 400000 : 0);
	cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("trapv")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 2e5 + 55;
const int mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a, b, k, t;
	cin >> a >> b >> k;
	t = min(a, k);
	k-=t;
	a-=t;
	t = min(b, k);
	k-=t;
	b-=t;
	cout << a << " " << b << "\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
using lint = long long;

#pragma GCC optimize ("-O3","unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,arch=ivybridge")


const int nmax = 204800, block = 8192, unrl = 8;
int a[nmax], b[nmax];

int main() {

	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &a[i]);
	for (int i = 0; i < N; i++) scanf("%d", &b[i]);

	int ans = 0;
	for (int i = 0; i + unrl <= N; i += unrl) {
		for (int j = 0; j + block <= N; j += block) {
			for (int k = j; k < block + j; k++) {

				ans ^= (a[i + 0] + b[k]) ^ (a[i + 1] + b[k]);
				ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
				ans ^= (a[i + 4] + b[k]) ^ (a[i + 5] + b[k]);
				ans ^= (a[i + 6] + b[k]) ^ (a[i + 7] + b[k]);

			}
		}
	}

	for (int i = 0; i < N / unrl * unrl; i++) {
		for (int j = N / block * block; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}	
	for (int i = N / unrl * unrl; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans ^= a[i] + b[j];
		}
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
using namespace std;

int main() {
	string s;
	cin >> s;
	bool ans = true;
	int num = s.size();
	if (num < 2) ans = false;
	if (num % 2 != 0) ans = false;

	for (int i = 0; i < num; i++) {
		if (i % 2 == 0) {
			if (s.at(i) != 'h') {
				ans = false;
			}
		}
		if (i % 2 == 1) {
			if (s.at(i) != 'i') {
				ans = false;
			}
		}
	}
	if (ans) cout << "Yes" << endl;
	else if (!ans) cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <tr1/unordered_set>
using namespace std;

int n , v[20] , ans = 0;

tr1::unordered_set<int> memo[20];

int X[421] , Y[421] , top;
 
int main(){
	while(scanf("%d\n",&n)&& n){
		int dp2[21] = {0};
		for(int i = 0 ; i < n ; i++) scanf("%d",&v[i]) , memo[i].clear();
		for(int i = n-1 ; i >= 0 ; i--) dp2[i] = dp2[i+1] + v[i];
		ans = 99999999;
		top = 0;
		X[top] = 0;
		Y[top] = 0;
		while(~top){
			int pos = X[top] , sum = Y[top]; top--;
			if(pos==n) ans = min(ans,sum);
			else{
				if( ( sum >= dp2[pos] && ans <= sum-dp2[pos] ) || memo[pos].count(sum)) continue;
				else memo[pos].insert(sum);
				X[++top] = pos+1;
				Y[top]   = sum+v[pos];
				X[++top] = pos+1;
				Y[top]   = abs(sum-v[pos]);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int n,ans;
int a[100000],cnt[100005];
int main()
{
  cin>>n;
  for (int i = 0; i < n;i++)
  {
    cin >> a[i];
  }
  sort(a, a + n);
  for(int i=0;i<n;i++)
  {
    cnt[a[i]]++;
  }
  int ans2 = 1;
  for (int i = 0;i<n-1;i++)
  {
    ans = cnt[i] + cnt[i + 1] + cnt[i + 2];
    ans2 = max(ans, ans2);
  }
  cout << ans2 << endl;
}

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

int N, M;

int node[52][52] = {};
int visit[52] = {};

void dfs(int n){
  visit[n] = 1;
  for(int i = 1; i <= N; i++){
    if(node[n][i] && !visit[i])
      dfs(i);
  }
}

int main(){
  int i, j;
  pair<int, int> t[50];
  cin >> N >> M;
  int cnt = 0;
  for(i = 0; i < M; i++){
    cin >> t[i].first >> t[i].second;
    node[t[i].first][t[i].second] = 1;
    node[t[i].second][t[i].first] = 1;
  }
  for(i = 0; i < M; i++){
    node[t[i].first][t[i].second] = 0;
    node[t[i].second][t[i].first] = 0;
    dfs(1);
    for(j = 1; j <= N; j++){
      if(visit[j] == 0){
        cnt++;
        break;
      }
    }
    node[t[i].first][t[i].second] = 1;
    node[t[i].second][t[i].first] = 1;
    for(j = 1; j <= N; j++){
      visit[j] = 0;
    }
  }
    
  cout << cnt << endl;

  return 0;
}


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

int main(void)
{
    int x,y;
    while(1)
    {
        cin >> x >> y;
        if(x == 0 && y == 0)break;
        if(x > y)cout << y << " " << x << endl;
        else cout << x << " " << y << endl;
    }
    return 0;
}


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M; cin >> N >> M;
    vi e(N), a(M), b(M); 
    REP(i, M) cin >> a[i] >> b[i], a[i]--, b[i]--;
    REP(i, M)
    {
        if(a[i] == 0) e[b[i]] = 1;
        if(b[i] == 0) e[a[i]] = 1;
    }
    REP(i, M)
    {
        if((a[i] == N-1 && e[b[i]] == 1) || b[i] == N-1 && e[a[i]] == 1)
        {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 5512
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let mut ans = 5000;
    for i in 0..s.len() - t.len() + 1 {
        let mut count = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] {
                count += 1;
            }
        }
        ans = if ans > count { count } else { ans }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2184
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int N,K;cin>>N>>K;
  double P = 0.0;
  for(int i=1;i<N+1;++i) {
    // int t = log2(K/i) + 1;
    double tmp = 1.0/N;
    int now = i;
    while(now<K) {
      tmp /= 2;
      now *= 2;
    }
    P += tmp;
  }
  printf("%.12f\n",P);
  return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vi a(n),b(m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];
  auto am = max_element(ALL(a));
  auto bm = min_element(ALL(b));
  if(*am<*bm&&x<y&&*am<y&&x<*bm) cout << "No War" <<endl;
  else cout << "War" << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int min = 0, max = 0;

		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			if (i == 0) {
				min = x;
				max = x;
			}else if (min > x) {
				min = x;
			} else if (x > max) {
				max = x;
			}
		}
		
		System.out.println((max - min));

		sc.close();
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<string> ans(10);
  ans.at(0) = "pon";
  ans.at(1) = "pon";
  ans.at(2) = "hon";
  ans.at(3) = "bon";
  ans.at(4) = "hon";
  ans.at(5) = "hon";
  ans.at(6) = "pon";
  ans.at(7) = "hon";
  ans.at(8) = "pon";
  ans.at(9) = "hon";
  
  cout << ans.at(n%10) << endl;
}

Measured memory_bytes: 3596
#include <iostream>

 

 

 

using namespace std;

 

 

 

int main()
{
    int i, x;
    
    for(i=1; i<=10000; i++)
    
    {
        cin >> x;
        if (x==0)
       break;
        cout << "Case" << " "<< i << ":" << " " << x <<endl; 
    
   
      
    }
}


Measured memory_bytes: 2984
n = input()
n_list = n.split(" ")

a = int(n_list[0])
b = int(n_list[1])

p = a + b
mi = a - b
mu = a * b

if p >= mi and p >= mu:
    print(p)
elif mi >= p and mi >= mu:
    print(mi)
elif mu >= p and mu >=mi:
    print(mu)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
string data[12];

void dfs(int y,int x){
    data[y][x]='0';
    
    int dx[]={0,1,0,-1};
    int dy[]={1,0,-1,0};
    rep(i,4){
        int ddx=x+dx[i],ddy=y+dy[i];
        if(ddx<0||ddy<0||ddx>=12||ddy>=12||data[ddy][ddx]!='1'){}
        else{
            dfs(ddy,ddx);
        }
    }
}


int main(){
    string s;
    while(cin>>s){
        data[0]=s;
        rep(i,11){
            cin>>data[i+1];
        }
        int c=0;
        rep(i,12){
            rep(j,12){
                if(data[i][j]=='1'){
                    dfs(i,j);
                    c++;
                }
            }
        }
        cout<<c<<endl;
    }
}

Measured memory_bytes: 1204
from collections import Counter
N, X, Y = map(int, input().split())

ans = []
for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        min_dis = min(abs(j - i),
                      abs(X - i) + 1 + abs(j - Y),
                      abs(Y - i) + 1 + abs(j - X))
        ans.append(min_dis)

c = Counter(ans)
for i in range(1, N):
    print(c[i])


Measured memory_bytes: 73164
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
class pur{
	long dat;
	int type;
	pur(long d,int t)
	{
		dat=d;
		type=t;
	}
}
class sortee implements Comparator<pur>{

	@Override
	public int compare(pur o1, pur o2) {
		if(o1.dat>o2.dat)
		{
			return -1;
			
		}else if(o1.dat<o2.dat)
		{
			return 1;
		}else {
			return 0;
		}
	}

	
	
}
public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int k=scan.nextInt();
		int []t=new int[1000007];
		long []d=new long[1000007];
		int[] visited=new int[1000007];
		for(int i=0;i<n;i++)
		{
			t[i]=scan.nextInt();
			d[i]=scan.nextLong();
			
		}
		ArrayList<pur> Lst=new ArrayList<>();
		for(int i=0;i<n;i++)
		{
			Lst.add(new pur(d[i],t[i]));
		}
		Collections.sort(Lst,new sortee());
		PriorityQueue<Long> PQ=new PriorityQueue<>();
		long var=0;
		long sum=0;
		
		for(int i=0;i<k;i++)
		{
			if(visited[Lst.get(i).type]==0)
			{
				var++;
				visited[Lst.get(i).type]=1;
			}else {
				PQ.add(Lst.get(i).dat);
			}
			
			sum+=Lst.get(i).dat;
						
		}
		long max=sum+(var*var);
		for(int i=k;i<n;i++)
		{
			long res=sum;
			if(PQ.isEmpty()) {
				break;
			}
			if(visited[Lst.get(i).type]==0)
			{
				res-=PQ.poll();
				res+=Lst.get(i).dat;
				sum=res;
				res+=((var+1)*(var+1));
				
				var++;
				
				max=Math.max(res, max);
				visited[Lst.get(i).type]=1;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 109288
#include <cstdio>
#include <algorithm>
#define INF (ll)1<<32
using namespace std;
typedef long long ll;
int n,m;
ll ans;
ll f(int k) {
	if (k<3)
		return INF;
	if (k%3==0)
		return 0;
	return 1;
}
int main() {
	scanf("%d %d",&n,&m);
	ans=min(f(n)*m,f(m)*n);
	for (int i=1;i<m;i++) {
		ll a=(ll)n*i,b=(ll)(n/2)*(m-i),c=(ll)(n-n/2)*(m-i);
		ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
	}
	for (int i=1;i<n;i++) {
		ll a=(ll)m*i,b=(ll)(m/2)*(n-i),c=(ll)(m-m/2)*(n-i);
		ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
<?php
function data_split($str, $start, $end) {
  $head = "";
  if ($start > 0) {
    $head = substr($str, 0, $start);
  }

  $tail = "";
  if ($end < strlen($str) - 1) {
    $tail = substr($str, $end + 1);
  }

  $target = substr($str, $start, $end - $start + 1);
  return array($head, $target, $tail);
}


$data = trim(fgets(STDIN));
$num_op = trim(fgets(STDIN));

do {
  $input = trim(fgets(STDIN));
  $op = explode(" ", $input);

  List($head, $target, $tail) = data_split($data, $op[1], $op[2]);
  switch ($op[0]) {
  case "print":
    echo $target . PHP_EOL;
    break;
  case "reverse":
    $target = implode(array_reverse(str_split($target)));
    $data = $head . $target . $tail;
    break;
  case "replace":
    $data = $head . $op[3] . $tail;
    break;
  default:
    echo "Syntax Error." . PHP_EOL;
  }

  $num_op--;
} while ($num_op > 0);

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

void solve(std::vector<long long> A)
{
    cout << (A[0] + A[1] + A[2] > 21 ? "bust" : "win") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::vector<long long> A(3);
    for (int i = 0; i < 3; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
  const args = input.trim().split("\n");

  let n = args.length;
  for (let i = 0; i < n; i++) {
    let tmp = args[i].split(" ").map((x) => Number(x));
    let h = tmp[0];
    let w = tmp[1];
    if (h === 0 && w === 0) {
      break;
    }
    let s = "",
      t = "";
    for (let x = 0; x < w; x++) {
      s += "#";
      if (x !== 0 && x !== w - 1) {
        t += ".";
      } else {
        t += "#";
      }
    }
    for (let y = 0; y < h; y++) {
      if (y === 0 || y === h - 1) {
        console.log(s);
      } else {
        console.log(t);
      }
    }
    console.log();
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 17760
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 2e5;
int arr[N + 5];

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 0;i < n;i++) cin>>arr[i];
	int ada = 0;
	for(int i = 0;i < n;i++) {
		if(arr[i] == ada + 1) ada++;
	}
	if(ada == 0) ada = n + 1;
	cout<<n - ada<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


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

#define NSIZE 1024

using namespace std;

class Stack
{
  private:
    int index; 
    int *array;

  public:
    Stack(){}
    Stack(const int N)
    {
          index = -1; 
          array = new int[N];
        }
    ~Stack(){ delete[] array; }

    void Push(const int value)
    { array[++index] = value; }

    int Pop()
    { return array[index--]; }

};

int main()
{

  string s;
  Stack Stacker(NSIZE);

  while(cin >> s)
  {
    if(s == "+" || s == "-" || s == "*")
    {
      int b = Stacker.Pop();
      int a = Stacker.Pop();

      if(s == "+")
	Stacker.Push(a + b);
      else if(s == "-")
	Stacker.Push(a - b);
      else if(s == "*")
	Stacker.Push(a * b);

    }
    else if( s != "" && s != " ")
    {
      Stacker.Push(atoi(s.c_str()));
    }
  }
  cout << Stacker.Pop() << endl;
  return 0;
}





Measured memory_bytes: 3204
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
//constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll dp[3007][3007];

int main(){
  ll A,C,B,D,ANS=0;
  cin >> A >>  B >>  C >> D;
  rep(i,3002){
    rep(j,3002){
      dp[i][j]=0;
    }
  }
  dp[A][B]=1;
  Rep(i,A,C+1){
    Rep(j,B,D+1){
      dp[i+1][j]=(dp[i+1][j]+dp[i][j]*j)%MOD;
      dp[i][j+1]=(dp[i][j+1]+dp[i][j]*i)%MOD;
      dp[i+1][j+1]=(dp[i+1][j+1]+MOD-dp[i][j]*i*j)%MOD;
    }
  }
  cout << dp[C][D] << endl;
}


Measured memory_bytes: 74056
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
int main() {
    int N;
    cin >> N;
    vector<int>B(N);
    rep(i, 0, N-1) cin >> B[i];
    int ans = 0;
    int r = B[N-2];
    for(int i = N-2; i>0; i--){
        r += min(B[i], B[i-1]);
    }
    ans = r+B[0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


	int t[500005] = {};


using namespace std;
int main() {
	
	
	int n;
	cin >> n;


	for (int i = 0; i < n; i++) {

		int a;
		cin >> a;
		t[a]++;
	}
	int r = 0;
	int p = 0;

	for (int i = 0; i <= 500000; i++) {
		p += t[i];
		if (p == n / 2)r++;
		if (p > n / 2)break;
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 640