akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    string s;
    cin >> s;
    int g = s.length();
    int l = 0;
    for(int i = 0; i < g; i++){
        if(s[i] == '+'){
            l++;
        }else{
            l--;
        }
    } 
    cout << l;
    return 0;
}

Measured memory_bytes: 3556
// 2011/01/31 Tazoe

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	while(!cin.eof()){
		string str;
		getline(cin, str);
		if(str.empty())
			continue;

		istringstream ist(str);
		int n;
		ist >> n;

		int num = n%39;
		if(num==0)
			num = 39;

		cout << "3C" << setw(2) << setfill('0') << num << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int x;
	cin >> x;
	int ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define rep(i,a,b) for(auto i=(a);i<=(b);++i)
#define per(i,a,b) for(auto i=(a);i>=(b);--i)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define root 1,cnum,1
#define Pr pair<int,int>
#define Prd pair<double,double>
#define Prl pair<LL,LL>
#define fi first
#define se second
#define Abs(x) (x>0?x:x*-1)
#define lowbit(x) (x&(-x))
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF = 0x7FFFFFFF;
const LL LINF = 0x7FFFFFFFFFFFFF;
void guan() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

const LL mod = 1e9+7; 
const int maxn = 1010101;
LL a[maxn];
LL pre[maxn];
LL inv[maxn];
LL A[maxn];
void init() {
    inv[1] = 1;
    rep(i,2,maxn-1) {
        inv[i] = inv[mod%i]*(mod-mod/i)%mod;
    }
    pre[0] = 0;
    rep(i,1,maxn-1) pre[i] = (pre[i-1]+inv[i])%mod;
    A[0] = 1;
    rep(i,1,maxn-1) A[i] = A[i-1]*i%mod;
}
int main() {
    guan();
    int d, h, k, p, q;
    LL n, m;
    init();
    while(cin >> n) {
        LL ans = 0;
        rep(i,1,n) {
            cin >> m;
            ans = (ans + (pre[i] + pre[n-i+1] - 1 + mod) % mod * m % mod * A[n] % mod) % mod;
        }
        cout << ans << endl;
    }
    return 0;
}

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



int main()
{
    int n,leg;
    int b, t;
    cin >> n >> leg;

    for (int i = 0; i <= 100; i++) {
        if (leg % 2 != 0)
            break;
        if (leg - 4 * i < 0)
            break;

        t = (leg - 4 * i) / 2;
        if (i + t == n && 2 * t + 4 * i == leg) {
            cout << "Yes" << endl;
            return 0;
        }


        /*
        for (int j = 0; j <= 100; j++) {
            if (i + j == n && 2 * i + 4 * j == leg) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        */
    }
   

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REP1(i,a,b) for(ll i=(a);i<=(b);i++)
#define mkp make_pair
#define pb push_back
const ll INF=1e18;
const ll MA=1e6+5;
const ll MOD=1e9+7;
//}}}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n;
	cin>>n;
	ll ans=0;
	ans+=n/11*2;
	n%=11;
	if(n){
		if(n<=6)
			ans++;
		else
			ans+=2;
	}
	cout<<ans<< '\n';
	return 0;
}


Measured memory_bytes: 384
n = int(input())
init = [0, 0, 0, 0, 0]
for i in range(n):
    name = input()
    first = name[0]
    if first == "M":
        init[0] += 1
    elif first == "A":
        init[1] += 1
    elif first == "R":
        init[2] += 1
    elif first == "C":
        init[3] += 1
    elif first == "H":
        init[4] += 1

ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += init[i]*init[j]*init[k]
print(str(ans))

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main() {
	int a;
	int ans = 0;
	char s[50];
	cin >> a;
	rep(i, a) {
		cin >> s[i];
	}
	rep(i, a - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
sum_1 = 0
for i in range(n):
    if i==0:
        sum_1+=abs(a[i])
    else:
        sum_1+=abs(a[i]-a[i-1])
sum_1 +=abs(a[-1])
sum_2 = 0
for i in range(n):
    if i==0:
        sum_2 = sum_1 - abs(a[i])-abs(a[i]-a[i+1])+abs(a[i+1])
    elif i==n-1:
        sum_2 = sum_1 -abs(a[i])-abs(a[i-1]-a[i])+abs(a[i-1])
    else:
        sum_2 = sum_1 - abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])
    print(sum_2)


Measured memory_bytes: 14048
#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 a, b, c;
    cin >> a >> b >> c;
    if((a + b - 1) / b <= c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=set(a);B=set(b)
if len(A)!=len(a) or len(B)!=len(b):
  print(0)
else:
  L=[[0 for j in range(m)] for i in range(n)]
  c=1;cn=0;cm=0
  for k in range(m*n,0,-1):
    if k in A and k in B:
      L[n-cn-1][m-cm-1]=k
      cn+=1;cm+=1
    elif k in A:
      c*=cm;cn+=1
    elif k in B:
      c*=cn;cm+=1
    else:
      c*=(cm*cn-m*n+k)
    if c==0:
      break
    c=c%(10**9+7)
  print(c)

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

int main(){
    int N,M; cin >> N >> M;
    vector<int> P(M),Y(M);
    for(int i = 0; i < M; i++) cin >> P[i] >> Y[i], P[i]--;
    vector<vector<int>> vals(N);
    for(int i = 0; i < M; i++)vals[P[i]].push_back(Y[i]);
    for(int v = 0; v <N; v++){
        sort(vals[v].begin(),vals[v].end());
        vals[v].erase(unique(vals[v].begin(),vals[v].end()),vals[v].end());
    }
    for(int i = 0; i < M; i++){
        int v = P[i];
        printf("%06d",v+1);
        int id = lower_bound(vals[v].begin(),vals[v].end(),Y[i]) - vals[v].begin();
        printf("%06d\n",id + 1);
    }
    
}


Measured memory_bytes: 9352
#include<iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    
    if(a==b){
        cout << a+b << endl;
    }
    else if(a>b){
        cout << 2*a-1 << endl;
    }
    else {
        cout << 2*b-1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <cstring>

#define MAX 1000000000
#define Debug(X) debug( __LINE__, X )
template<class T>
void debug( int line, T dbg ){
	std::cout << line << ": " << dbg << std::endl;
}

class State{
public:
	int p, s, c;
	State():p(0), s(0), c(0){}
	State(int P, int S, int C):p(P), s(S), c(C){}
	bool operator < (const State &s) const{
		return c > s.c;
	}
};

int c, n, m, s, d;
int route[101][101];
std::priority_queue<State> que;
bool used[101][11];


int main(){
	while( std::cin >> c >> n >> m >> s >> d, c * n * m * s * d ){
		for( int i = 0; i < 101 * 101; ++i )
			route[i / 101][i % 101] = MAX;
		
		memset( used, 0, sizeof( used ) );
		que = std::priority_queue<State>();

		int tmp[3];
		while( m-- ){
			int cnt = 3;
			while( cnt-- ) std::cin >> tmp[2 - cnt];

			route[tmp[0]][tmp[1]] = tmp[2];
			route[tmp[1]][tmp[0]] = tmp[2];
		}

		que.push(State( c, s, 0 ));

		while( true ){
			State data = que.top(); que.pop();

			if( used[data.s][data.p] )continue;
			used[data.s][data.p] = 1;

			if( data.s == d ){
				std::cout << data.c << std::endl;
				break;
			}

			for( int i = 1; i <= n; ++i ){
				if( i == data.s || route[data.s][i] == MAX )continue;

				if( data.p > 0 )
					que.push( State( data.p - 1, i, data.c + route[data.s][i] / 2 ) );

				que.push( State( data.p, i, data.c + route[data.s][i] ) );				
			}

		}

	}
}

Measured memory_bytes: 1328
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> table(h, vector<char>(w));
    rep(i, h) rep(j, w) cin >> table[i][j];

    vector<vector<char>> table2(h*2, vector<char>(w));
    rep(i, h*2) rep(j, w) {
        table2[i][j] = table[i/2][j];
    }

    rep(i, h*2) rep(j, w) {
        cout << table2[i][j];
        if (j == w-1) cout << endl;
    }
}

Measured memory_bytes: 3688
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int p = 0;
        int sum = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            p = scanner.nextInt();
            sum += p;
            max = Math.max(max, p);
        }
        
        sum = sum - max + max /2;
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

struct pkt
{
    ll x, y;
};

ll mini(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

ll maxi(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

int Szukaj(vector<ll>& a, ll x)
{
    for (int i = 0; i < a.size(); ++i)
        if (a[i] == x)
        return i;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<pkt> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i].x >> a[i].y;
    ll odp = 9223372036854775800;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (i != j)
            {
                ll minx = mini(a[i].x, a[j].x);
                ll maxx = maxi(a[i].x, a[j].x);
                ll miny = mini(a[i].y, a[j].y);
                ll maxy = maxi(a[i].y, a[j].y);
                vector<ll> y;
                for (int l = 0; l < n; ++l)
                    if (a[l].x >= minx && a[l].x <= maxx)
                        y.push_back(a[l].y);
                sort(y.begin(), y.end());
                ll I = Szukaj(y, miny);
                ll J = Szukaj(y, maxy);
                for (int l = 0; l <= I; ++l)
                {
                    for (int o = J; o < y.size(); ++o)
                    {
                        int il = o - l + 1;
                        if (il >= k)
                            odp = mini(odp, (maxx - minx) * (y[o] - y[l]));
                    }
                }
            }
        }
    }
    cout << odp;
    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;

int main() {
  
  int x, y, z;
  cin >> x >> y >> z;
  
  cout << (x-z)/(y+z) << endl;
  
}

Measured memory_bytes: 3592
A, B, C, D = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

lcm = int(C*D / gcd(C, D))

def func(x):
    return x - x//C - x//D + x//lcm

print(func(B) - func(A-1))

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int[] t = new int[110000];
        int[] x = new int[110000];
        int[] y = new int[110000];
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        for (int i = 0; i < N; i++) {
            t[i+1] = scanner.nextInt();
            x[i+1] = scanner.nextInt();
            y[i+1] = scanner.nextInt();
        }

        boolean result = true;

        for (int i = 0; i < N; i++) {
            int dt = t[i + 1] - t[i];
            int dist = Math.abs(x[i + 1] - x[i]) + Math.abs(y[i + 1] - y[i]);
            if (dt < dist) {
                result = false;
                break;
            }
            if (dt % 2 != dist %2) {
                result = false;
                break;
            }
        }

        if (result) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 90452
#include<stdio.h>
int main(void){
  int i,n,h;
  scanf("%d",&n);
  h=n/100;
  if(n%100>10*h+h){
    for(i=0;i<3;i++)printf("%d",h+1);
  }
  else if(n%100<=10*h+h){
      for(i=0;i<3;i++)printf("%d",h);
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <complex>
using namespace std;
int main() {
	int n, x;
	int b;
	int a[100100];
	cin >> n;
	cin >> x;
	for (int i = 0;i < n;i++) {
		cin >> b;
		a[i] = abs(b - x);
	}
	if (n == 1) {
		cout << a[0] << endl;
		return 0;
	}
	int answer;
	int m = a[0], n_;
	answer = m;
	for (int i = 1;i < n;i++) {
		n_ = a[i];
		while (m != 0 && n_ != 0)
		{
			
			if (m > n_) m = m%n_;
			else         n_ = n_%m;
		}
		if (n_ == 0) {
			answer = m;
		}
		if (m == 0) {
			answer = n_;
		}
		m = answer;
	}
	cout << answer << endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
ll n,q,k;
DVector tree;
map<P,ll> costs;
Vector ans;

void dfs(ll root, ll parent, ll edge, ll cost){
  costs[mkp(root,edge)] = cost;
  costs[mkp(edge,root)] = cost;
  each(itr,tree[edge]){
    if(itr == parent)continue;
    dfs(root, edge, itr, cost+costs[mkp(edge,itr)]);
  }
}

int main(){
  cin.sync_with_stdio(false);
  cin >> n;
  tree.resize(n);
  rep(i,n-1){
    ll a,b,c;
    cin >> a >> b >> c;
    tree[a-1].pb(b-1);
    tree[b-1].pb(a-1);
    costs[mkp(a-1,b-1)] = c;
    costs[mkp(b-1,a-1)] = c;
  }

  cin >> q >> k;
  k--;
  dfs(k,-1,k,0);
  rep(i,q){
    ll x,y;
    cin >> x >> y;
    ans.pb(costs[mkp(x-1,k)]+costs[mkp(k,y-1)]);
  }
  rep(i,q)cout << ans[i] << endl;
}


Measured memory_bytes: 45680
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toLong)
    val data = mutableListOf<Triple<Long, Long, Long>>()
    (1..m).forEach {
        val (p, y) = readLine()!!.split(' ').map(String::toLong)
        data.add(Triple(it, p, y))
    }
    data.sortBy { it.third }
    data.sortBy { it.second }
    val result = mutableMapOf<Long, String>()
    var countP = 1
    var currentP = data[0].second
    result[data[0].first] = data[0].second.toString().padStart(6, '0') + countP.toString().padStart(6, '0')
    for (i in 1 until m.toInt()) {
        if (currentP != data[i].second) {
            currentP = data[i].second
            countP = 1
        } else {
            countP++
        }
        result[data[i].first] = data[i].second.toString().padStart(6, '0') + countP.toString().padStart(6, '0')
    }
    (1..m).forEach { println(result[it]) }
}


Measured memory_bytes: 133484
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j; i <= k; i++)
char a[3][3] = {{'a', 'a', '.'}, {'.', '.', 'a'}, {'.','.','a'}};
char b[4][4] = {{'a', 'a', 'b', 'c'}, 
				{'d', 'd', 'b', 'c'},
				{'b', 'c', 'a', 'a'},
				{'b', 'c', 'd', 'd'}};
char c[5][5] = {{'a', 'a', 'b', 'b', 'a'},
				{'b', 'c', 'c', '.', 'a'},
				{'b', '.', '.', 'c', 'b'},
				{'a', '.', '.', 'c', 'b'},
				{'a', 'b', 'b', 'a', 'a'}};
char d[6][6] = {{'a', 'a', 'b', 'c', '.', '.'},
				{'d', 'd', 'b', 'c', '.', '.'},
				{'.', '.', 'a', 'a', 'b', 'c'},
				{'.', '.', 'd', 'd', 'b', 'c'},
				{'b', 'c', '.', '.', 'a', 'a'},
				{'b', 'c', '.', '.', 'd', 'd'}};
char e[7][7] = {{'a', 'a', 'b', 'b', 'c', 'c', '.'},
				{'d', 'd', '.', 'd', 'd', '.', 'a'},
				{'.', '.', 'd', '.', '.', 'd', 'a'}, 
				{'.', '.', 'd', '.', '.', 'd', 'b'},
				{'d', 'd', '.', 'd', 'd', '.', 'b'},
				{'.', '.', 'd', '.', '.', 'd', 'c'},
				{'.', '.', 'd', '.', '.', 'd', 'c'}};
char ans[1005][1005];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n ;
	cin >> n;
	//char **p[4] = {NULL, NULL, NULL, NULL};
	//p[0] = b; p[1] = c, p[2] = d, p[3] = a;
	if (n == 2) return cout << -1 << endl,  0;
	if (n == 3) {
		rep(i,0,2) {
			rep(j,0,2) cout << a[i][j];
			cout << endl;
		}
	}
	if (n == 4) {
		rep(i,0,3) {
			rep(j,0,3) cout << b[i][j];
			cout << endl;
		}
	}
	if (n == 5) {
		rep(i,0,4) {
			rep(j,0,4) cout << c[i][j];
			cout << endl;
		}
	}
	if (n == 6) {
		rep(i,0,5) {
			rep(j,0,5) cout << d[i][j];
			cout << endl;
		}
	}
    if (n <= 6) return 0;
	int k = n % 4;
    k += 4;
	switch(k) {
		case 7:rep(i,0,6) rep(j,0,6) ans[i][j] = e[i][j]; break;
		case 4:rep(i,0,3) rep(j,0,3) ans[i][j] = b[i][j]; break;
		case 5:rep(i,0,4) rep(j,0,4) ans[i][j] = c[i][j]; break;
		case 6:rep(i,0,5) rep(j,0,5) ans[i][j] = d[i][j]; break;
	}
	while (k < n) {
        //cout << k << " ! " << endl;
		rep(i,0,3) rep(j,0,3) ans[i + k][j + k] = b[i][j];
		k += 4;
	}
	rep(i,0,n-1) {rep(j,0,n-1) cout << (ans[i][j]? ans[i][j]: '.'); cout << endl;}
}



Measured memory_bytes: 2176
package main

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

// (l, r]
func lowerbound(a []int, k int) int {
	l := -1
	r := len(a)
	for r-l > 1 {
		mid := (l + r) / 2
		if a[mid] >= k {
			r = mid
		} else {
			l = mid
		}
	}
	return r
}

func main() {
	var n int
	fmt.Scan(&n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := make([]int, n)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Ints(a)
	ans := 0
	for k := 1; k <= a[n-1]; k++ {
		if lowerbound(a, k) == n/2 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;

int main(){
    int n;
    cin >> n;
    int w;
    cin >> w;
    vector<ll>dp(w+1),dp2(w+1);
    while(n--){
        int a,b;
        cin >> a >> b;
        rep(i,w+1)if(i>=a)dp[i] = max(dp[i],dp2[i-a]+b);
        dp2 = dp;
    }
    cout << *max_element(dp.begin(),dp.end()) << endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    string s_l, s_r;
    s_l = s.substr(0, n);
    s_r = s.substr(n);
    reverse(s_r.begin(), s_r.end());
    map< pair<string, string>, ll > left, right;
    set< pair<string, string> > check;

    for (int b = 0; b < (1 << n); ++b) { //前半全列挙
        bitset<20> bs(b);
        string red, blue;
        for (int i = 0; i < n; ++i) {
            if (bs[i]) red.push_back(s_l[i]);
            else blue.push_back(s_l[i]);
        }
        left[make_pair(red, blue)]++;
        check.insert(make_pair(red, blue));
    }

    for (int b = 0; b < (1 << n); ++b) { //後半全列挙
        bitset<20> bs(b);
        string red, blue;
        for (int i = 0; i < n; ++i) {
            if (bs[i]) red.push_back(s_r[i]);
            else blue.push_back(s_r[i]);
        }
        right[make_pair(red, blue)]++;
        check.insert(make_pair(red, blue));
    }

    ll ans = 0;
    for (auto itr = check.begin(); itr != check.end(); ++itr) {
        ans += left[*itr] * right[*itr];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 157440
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var hs = new HashSet<long>();
            for(var i=0;i<N;++i)
            {
                var a = Sarray()[0];
                if (hs.Contains(a))
                    hs.Remove(a);
                else
                    hs.Add(a);
            }
            WriteLine(hs.Count);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 48792
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
pii num[2005];
bool cmp (pii a, pii b) {
  if (a.fi != b.fi) return (a.fi > b.fi);
  return (a.se < b.se);
}
ll memo[2005][2005];
ll cost (int p, int i) {
  return 1LL * abs(p - num[i].se) * num[i].fi;
}
ll dp (int l, int r, int i) {
  if (l == r) return cost(l, i);
  else if (memo[l][r] != -1) return memo[l][r];
  return memo[l][r] = max(dp(l, r - 1, i + 1) + cost(r, i), dp(l + 1, r, i + 1) + cost(l, i));
}
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n) {
    scanf("%d", &num[i].fi);
    num[i].se = i;
  }
  sort(num + 1, num + n + 1, cmp);
  SET(memo, -1);
  printf("%lld\n", dp(1, n, 1));
  return 0;
}

Measured memory_bytes: 35348
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;


const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m; assert(b>=0); for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int p, q, r, id, res;

int rec() {
	char c = s[id++];
	if (isdigit(c)) return c-'0';
	else if (c=='P') return p;
	else if (c=='Q') return q;
	else if (c=='R') return r;
	else if (c=='-') return 2-rec();
	else if (c=='(') {
		int a = rec();
		char d = s[id++];
		int b = rec();
		id++;
		if (d=='*') return min(a,b);
		else if (d=='+') return max(a,b);
	}
	return 0;
}

signed main() {
	while (1) {
		cin >> s;
		if (s==".") break;
		res = 0;
		rep(i,3) rep(j,3) rep(k,3) {
			id = 0, p = i, q = j, r = k;
			if (rec()==2) res++;
		}
		cout << res << ln;
	}
}


Measured memory_bytes: 3184
n, m = map(int, input().split())

accepted = set()
pena = 0
wa_cnt = [0]*(n+1)

for i in range(m):
    p, s = input().split()
    p = int(p)
    if p in accepted:
        continue
    if s == "AC":
        pena += wa_cnt[p]
        accepted.add(p)

    else:
        wa_cnt[p] += 1

print(len(accepted), pena)


Measured memory_bytes: 12652
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, H; cin >> N >> H;
  vector<int> a(N), b(N);
  FOR(i,0,N) {
    cin >> a[i] >> b[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  int p = 0;
  int ans = 0;
  int i = 0;
  while(p < H && i < N) {
    p += max(a[0], b[i]);
    i++;
    ans++;
  }
  if(p >= H) {
    cout << ans << endl;
  } else {
    cout << ans + (H - p + a[0] - 1) / a[0] << endl;
  }
  return 0;

}

Measured memory_bytes: 1024
using System;

namespace A___Ball_Distribution
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = read[0];
            var K = read[1];
            if(K!=1)Console.WriteLine(N-K);
            else Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main()
{
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if (x-r<0 || x+r>w ||y-r<0 || y+r>h){
		cout<<"No"<<endl;
	}
	else if(x-r>=0 && x+r<=w && y-r>=0 && y+r<=h){
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())
    X=list(map(int,input().split()))
    ans=0
    for i in range(n-1):
        ans+=min(b,a*(X[i+1]-X[i]))
    print(ans)
resolve()

Measured memory_bytes: 62704
/*
*
*   Bismillah Hir Rahman Nir Raheem
*   Name: Jaied Al Sabid
*
*/
#include <bits/stdc++.h>

using namespace std;

#define pf printf
#define sf scanf
#define elif else if
#define unint unsigned int
#define sint short int
#define lint long long int
#define Size 100000

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    char x;
    cin>>x;
    cout<<++x<<endl;
    return 0;
}


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

int main()
{
	int x,y; cin>>x>>y;
	if (x>=13)
	{
		cout<<y;
	}else if (x>=6 && x<= 12)
	{
		cout<<y/2;
	}else
	{
		cout<<'0';
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e5+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7


void solve(){
	int n; cin>>n;
	cout<<n*n*n<<ENDL;

}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define rep1(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    int a[120], b[120];
    ll ans = 0;
    cin >> n;
    rep(i, n-1)
        cin >> b[i];
    a[n-1] = b[n-2];
    ans += b[n-2];
    for (int i = n-2; i >= 0; --i) {
        if (i == 0) {
            a[i] = b[0];
        }
        else a[i] = min(b[i-1], b[i]);
        ans += a[i];
//        cout << i << " " << a[i] << '\n';
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=1e5+10;
int p[mx];
vector<int>g[mx];
bool vis[mx];
set<int>pos;
set<int>val;
void dfs(int u){
  pos.insert(u);
  val.insert(p[u]);
  vis[u]=true;
  for(int i=0;i<int(g[u].size());i++){
    int v=g[u][i];
    if(!vis[v]){
      dfs(v);
    }
  }
}
int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++){
    scanf("%d",p+i);
    --p[i];
  }
  for(int i=0;i<m;i++){
    int u,v;
    scanf("%d %d",&u,&v);
    g[--u].push_back(--v);
    g[v].push_back(u);
  }
  int ans=0;
  for(int i=0;i<n;i++)if(!vis[i]){
    pos.clear();
    val.clear();
    dfs(i);
    for(int x:pos)ans+=val.count(x);
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 18560
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    n = I()

    def rec(depth, p0_x, p0_y, p1_x, p1_y):
        if depth!=n:
            p2_x = p0_x*2/3 + p1_x*1/3
            p2_y = p0_y*2/3 + p1_y*1/3
            p4_x = p0_x*1/3 + p1_x*2/3
            p4_y = p0_y*1/3 + p1_y*2/3
            p3_x = (1/2)*(p4_x-p2_x)-(3**0.5/2)*(p4_y-p2_y)+p2_x
            p3_y = (3**0.5/2)*(p4_x-p2_x)+(1/2)*(p4_y-p2_y)+p2_y

            rec(depth+1, p0_x, p0_y, p2_x, p2_y)
            print(p2_x, p2_y)
            rec(depth+1, p2_x, p2_y, p3_x, p3_y)
            print(p3_x, p3_y)
            rec(depth+1, p3_x, p3_y, p4_x, p4_y)
            print(p4_x, p4_y)
            rec(depth+1, p4_x, p4_y, p1_x, p1_y)
    
    print(0, 0)
    rec(0, 0, 0, 100, 0)
    print(100, 0)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 5744
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A;
  for (int i = 0; i < 2; ++i) {
    vector<int> tmp(N);
    for (int j = 0; j < N; ++j) {
      cin >> tmp[j];
    }
    A.push_back(tmp);
  }

  int ans = 0;
  for (int ith_corner = 0; ith_corner < N; ++ith_corner) {
    int ith_ans = 0;
    for (int j = 0; j < N; ++j) {
      if (j <= ith_corner) {
        ith_ans += A[0][j];
      } else {
        ith_ans += A[1][j];
      }
    }
    ith_ans += A[1][ith_corner];
    ans = max(ans, ith_ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# 数が少ないので、総当たりでよい
n, m = gets.chomp.split.map(&:to_i)

students = []
points = []
n.times do |i|
  students.push gets.chomp.split.map(&:to_i)
end
m.times do |i|
  points.push gets.chomp.split.map(&:to_i)
end

def cal_m_distance s: [nil, nil], p: [nil, nil]
  (s[0] - p[0]).abs + (s[1] - p[1]).abs
end

students.each do |s|
  m_distances = points.map{|p| cal_m_distance(s: s, p: p)}
  min_d_idx = m_distances.index(m_distances.min)
  puts min_d_idx + 1
end

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

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    
        string s;
        cin >> s;
        bool flag=false;
        for(auto c: s){
            if(c == '7') flag=true;
        }
        if(flag) cout << "Yes";
        else cout << "No";
    

    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
int A[100000];
int main() {
	int N;
	cin >> N;
	rep(i, N) cin >> A[i];
	LL ans = 0;
	for (int i = 0; i < N; i++) {
		ans += A[i] / 2;
		A[i] %= 2;
		if (i + 1 < N && A[i]>0 && A[i+1]>0) {
			ans++;
			A[i]--;
			A[i + 1]--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }

    let mut ans = std::i32::MAX;
    for i in -100..101 {
        let current = a.iter().map(|&y| (i - y).pow(2)).sum::<i32>();
        ans = ans.min(current);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2068
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	if N == M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#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 repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl x(n), y;
    rep(i, 0, n) cin >> x[i];
    y = x;
    sort(ALL(y));
    ll l, r;
    l = y[(n-1)/2], r = y[n/2];
    rep(i, 0, n){
        if(x[i] <= l) co(r);
        else co(l);
    }

    return 0;
}


Measured memory_bytes: 6336
#include <stdio.h>



int main()
{
	int N, A, B;
	int i;
	int total = 0;

	scanf("%d %d %d", &N ,&A,&B);


	for (i = 0; i < N; i++) {
		total = A + total;
	}


	if (total > B) {
		printf("%d\n", B);
	}
	else {
		printf("%d\n", total);
	}

	return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int ex[100005];
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;cin>>N;
  set<int> S;
  FOR(i,1,N+1)S.insert(i);
  int a[N+1],b;
  FOR(i,1,N+1)cin>>a[i];
  FOR(i,1,N+1){
    cin>>b;
    S.erase(b);
  }
  if(S.empty()){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  FOR(i,0,N){
    if(i)cout<<" ";
    cout<<1;
  }
  cout<<endl;
  FOR(i,1,N+1){
    if(i-1)cout<<" ";
    if(S.count(a[i])){
      cout<<2;
    }else{
      cout<<1;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 8292
def main():
    k = int(input())
    a = [i for i in range(1,10)]
    x = 0
    while(1):
        if k <= len(a):
            print(a[k-1])
            return
        for i in range(-1,2):
            d = a[x]%10 +i
            if 0 <= d and d < 10:
                a.append(a[x]*10 + d)
        x+=1

if __name__ == "__main__":
    main()

Measured memory_bytes: 7320
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define P pair
// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    
    vector<P<ll, int>> v(n);
    int a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        v[i].X = a + b;
        v[i].Y = a;
    }
    vsort(v);
    vrev(v);
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            ans += v[i].Y;
        }else{
            ans -= v[i].X - v[i].Y;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	if n <= 2 {
		fmt.Println(1)
		return
	}

	l := make([]int, n)

	cnt := 0
	mode := 0 //0=neut  1=zouka 2=genshou
	l[0] = nextInt()
	l[1] = nextInt()
	if l[0] < l[1] {
		mode = 1
	} else if l[0] > l[1] {
		mode = 2
	}
	for i := 2; i < n; i++ {
		l[i] = nextInt()
		if mode == 0 {
			if l[i-1] < l[i] {
				mode = 1
			} else if l[i-1] > l[i] {
				mode = 2
			}
			continue
		}
		if mode == 1 {
			if l[i-1] > l[i] {
				cnt++
				mode = 0
			}
		}
		if mode == 2 {
			if l[i-1] < l[i] {
				cnt++
				mode = 0
			}
		}
	}

	fmt.Println(cnt + 1)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4408
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define INF 100000000
using namespace std;
typedef long long ll;

int N, M, C[16], X[20000];
ll dp[20001][256];

int main(void) {
  while(cin >> N >> M, N || M) {
    REP(i, 0, M) cin >> C[i];
    REP(i, 0, N) cin >> X[i];

    REP(i, 0, N + 1) REP(j, 0, 256) dp[i][j] = INF;
    dp[0][128] = 0;

    REP(i, 0, N) REP(j, 0, 256) if(dp[i][j] < INF) REP(k, 0, M) {
      ll y = max(0, min(255, j + C[k]));
      dp[i + 1][y] = min(dp[i + 1][y], dp[i][j] + (y - X[i]) * (y - X[i]));
    }

    ll ans = INF;
    REP(i, 0, 256) ans = min(ans, dp[N][i]);
    cout << ans << endl;
  }
}

Measured memory_bytes: 43080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

// void chmod(ll &M){
//     if(M >= mod) M %= mod;
//     else if(M < 0){
//         M += (abs(M)/mod + 1)*mod;
//         M %= mod;
//     }
// }

int main(void){
    int a, b, c, x, y; cin >> a >> b >> c >> x >> y;

    int ans = 0;
    if(a+b >= 2*c){
        ans += min(x, y)*2*c;
        int minv = min(x, y);
        x -= minv;
        y -= minv;

        if(x == y) cout << ans << endl;
        else if(x > 0) cout << ans + x*min(2*c, a) << endl;
        else cout << ans + y*min(2*c, b) << endl;
    }
    else{
        cout << a*x + b*y << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n, a[21], q, m[210];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    cin >> q;
    rep(i, q) cin >> m[i];

    vector<int> sum;
    for (int i = 0; i < 1 << n; i++) {
        int tmp = 0;
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                tmp += a[j];
            }
        }
        sum.emplace_back(tmp);
    }

    rep(i, q) {
        bool flg = false;
        for (const auto a: sum) {
            if (a == m[i]) flg = true;
        }
        if (flg) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



Measured memory_bytes: 7048
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int k = int.Parse(Console.ReadLine());
        int[] n = new int[k];
        for (int i = 0; i < k; i ++) n[i] = i+1;
        Console.WriteLine(n.Where(x=>x%2==1).Count() * n.Where(x=>x%2==0).Count());
    }
}

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

//#define rep(var,n)  for(int var=0;var<(n);++var)

int f(int d){
    int sc = 0;
    if (d > 0) { sc = d/2; d %= 2; }
    if (d > 0) return sc+2;
    return sc - d;
}
int solve(int a,int b,int c) {
    int best = INT_MAX;
    for (int t=-50; t<=100; ++t) {
        int score = f(t-a) + f(t-b) + f(t-c);
        best = min(best, score);
    }
    return best;
}

int main() {
    int a,b,c; cin>>a>>b>>c;
    cout << solve(a,b,c) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

    if (abs(a-b) % 2 == 1)
    {
        printf("Borys\n");
    }
    else
    {
        printf("Alice\n");
    }

    return 0;
}

Measured memory_bytes: 256