akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    
    int n;
    cin>>n;
    int sum = 0;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)sum+=a[i];
    int dif = 1e9;
    for(int i=0;i<n;i++)chmin(dif,abs(sum-n*a[i]));
    for(int i=0;i<n;i++){
        if(abs(sum-n*a[i]) == dif){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <cfloat>

using namespace std;

//start of 0uts1de's library

int cin_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}


int cout_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}


int max_int_arr(std::vector<int>& arr){    //data mode
    int maxVal = INT_MIN;       //min of int
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
        }
    }
    return maxVal;
}

int max_int_arr(std::vector<int>& arr, int mode){    //overload index mode
    int maxVal = INT_MIN;       //min of int
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
            maxIndex = i;
        }
    }
    return maxIndex;
}

double max_double_arr(std::vector<double>& arr){    //data mode
    double maxVal = -DBL_MAX;       //min of double
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
        }
    }
    return maxVal;
}

int max_double_arr(std::vector<double>& arr, int mode){    //overload index mode
    double maxVal = -DBL_MAX;       //min of double
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
            maxIndex = i;
        }
    }
    return maxIndex;
}

//end of 0uts1de's library

int main(){
    int n, m, tmp;
    cin >> n >> m;
    vector<int> k(n), ans(m);
    vector<vector<int>> a(n);
    for (int i = 0; i < n; ++i){
        cin >> k.at(i);
        for (int j = 0; j < k.at(i); ++j){
            cin >> tmp;
            a.at(i).push_back(tmp);
        }
    }
    for (int i = 0; i < n; ++i){
        for (int j = 0; j < m; ++j){
            ans.at(j) += count(a.at(i).begin(), a.at(i).end(), j + 1);
        }
    }
    int answer = 0;
    for (int i = 0; i < m; ++i){
        if (ans.at(i) == n){
            ++answer;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static String INPUT = "";

    public static void main(String[] args) {
        InputStream is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());

        Scanner scanner = new Scanner(is);

        final int fiveHundred = scanner.nextInt();
        final int hundred = scanner.nextInt();
        final int fifty = scanner.nextInt();
        final int x = scanner.nextInt();
        List<Pair> keys = new ArrayList<>();
        keys.add(new Pair(500, fiveHundred));
        keys.add(new Pair(100, hundred));
        keys.add(new Pair(50, fifty));
        final List<List<Pair>> result = solve(keys, 0, x, new ArrayList<>());
        System.out.println(result.size());
    }

    static class Pair {
        int val;
        int count;

        public Pair(int val, int count) {
            this.val = val;
            this.count = count;
        }
    }

    static List<List<Pair>> solve(List<Pair> keys, int position, int remaining, List<Pair> acc) {
        List<List<Pair>> result = new ArrayList<>();
        if (position == keys.size()) {

            if (remaining == 0) {
                result.add(new ArrayList<>(acc));
            }
            return result;
        }

        final Pair currentPair = keys.get(position);

        for (int i = 0; i <= remaining / currentPair.val && i <= currentPair.count; i++) {
            acc.add(new Pair(currentPair.val, i));
            result.addAll(solve(keys, position + 1, remaining - currentPair.val * i, acc));
            acc.remove(acc.size() - 1);
        }
        return result;
    }

}


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

int main(){
	int N;
	cin>>N;
	int ** kazu=new int*[N];
	for(int i=0;i<N;i++)
		kazu[i]=new int[3];
	int *saidai=new int[N];
	bool *hantei=new bool[N];
	fill(hantei,hantei+N,false);

	for(int j=0;j<N;j++){
		cin>>kazu[j][0]>>kazu[j][1]>>kazu[j][2];
		if(kazu[j][0]<kazu[j][1]){
			swap(kazu[j][0],kazu[j][1]);
			if(kazu[j][0]<kazu[j][2])
				swap(kazu[j][0],kazu[j][2]);
		}
		else if(kazu[j][0]<kazu[j][2]){
			swap(kazu[j][0],kazu[j][2]);
			if(kazu[j][0]<kazu[j][1])
				swap(kazu[j][0],kazu[j][1]);
		}
		
		if((kazu[j][0]*kazu[j][0])==(kazu[j][1]*kazu[j][1]+kazu[j][2]*kazu[j][2]))
			hantei[j]=true;
	}
	for(int k=0;k<N;k++)
		cout<<((hantei[k])?"YES":"NO")<<endl;

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// using cd = complex<double>;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 

typedef long long int ll;
typedef long double ld;
const ll N = 2e5 + 9;
const ll mod = 1e9 + 7;
const ll inf= 1e14;

const double PI = acos(-1);
#define x first
#define y second
#define pb push_back
#define mp make_pair    
#define pii pair<ll,ll>
#define pld pair<ld,ld>
ll powm(ll a, ll b,ll mod) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }

int main() {    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    ll T = 1;
    // cin>>t;
    while(T--){
        ll n;cin>>n;
        ll a[n];
        ll su = 0;
        for(int i = 0;i<n;i++){
            cin>>a[i];
            su+=a[i];
            su%=mod;
        }
        // cout<<su<<'\n';
        ll sub = 0,ans = 0;
        for(int i = 0;i<n;i++){
            sub+=a[i];
            sub%=mod;
            ans+=((su-sub +mod)%mod)*a[i];
            ans%=mod;

        }
        cout<<ans<<'\n';

    }
}

Measured memory_bytes: 5156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
int main(){
	int R;
	cin >> R;
	if(R < 1200) cout << "ABC" << endl;
	else if(R < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 10000000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int main(){
IOS;
lli n,i,j,k;
cin>>n;
lli a[n];
for(i=0;i<n;i++){
    cin>>a[i];
}
lli dp[n][n],value[n+1];
for(i=0;i<n;i++){
    for(j=0;j<n;j++){
        dp[i][j]=inf;
    }
}
for(i=0;i<n;i++){
    dp[i][i]=0;
}
value[0]=0;
for(i=0;i<n;i++){
    value[i+1]=value[i]+a[i];
}
for(i=n-1;i>=0;i--){
    for(j=i+1;j<n;j++){
            lli mini=inf;
        for(k=i;k<j;k++){
            mini=min(mini,(dp[i][k]+dp[k+1][j])+value[j+1]-value[i]);
            //cout<<i<<" "<<k<<" "<<j<<" "<<dp[i][k]+dp[k+1][j]<<" "<<value[j+1]-value[i]<<endl;
        }
        dp[i][j]=mini;
    }
}
cout<<dp[0][n-1]<<endl;
}



Measured memory_bytes: 1536
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入


int main(){
    string s;
    cin>>s;
    int N=s.size();
    REP2(i,1,N){
        if(s[i]==s[i-1]){
            cout << i <<" "<<i+1<<endl;
            return 0;
        }else if(i!=1&&s[i-2]==s[i]){
            cout << i-1 << " " << i+1<<endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 <<endl;   
}

Measured memory_bytes: 512
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

vector<char> vt;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        ll n;
        int val=97;
        cin>>n;
        while(n) {
                n--;
            ll mod=n%26ll;
            n/=26ll;
            //if(mod==0ll)mod=26;
            vt.pb(val+mod);
            //if(n==1)break;
        }
        int len=(int)vt.size();
        for(int i=1; i<=len; ++i) {
            cout<<vt.back();
            vt.pop_back();
        }
    }
    return 0;
}



Measured memory_bytes: 3620
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split;
	auto X = data[0].to!int, Y = data[1].to!int;
	writeln(X + Y/2);
}


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

void call(int n){
	for(int i=1;i<=n;++i){
		int x=i;
		if(x%3==0){
			cout<<" "s<<i;
		}else if(x%10==3){
			cout<<" "s<<i;
		}else{
			while(x&&x%10!=3)x/=10;
			if(x&&x%10==3)cout<<" "s<<i;
		}
	}
	cout<<"\n"s;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	call(n);
}


Measured memory_bytes: 3232
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		int [] a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		Map <Integer,Integer> hm = new HashMap <Integer,Integer>();
		
		for(int i = 0 ; i < n ; i+=2) {
			if(hm.containsKey(a[i])) {
				hm.put(a[i], hm.get(a[i])+1);
			}
			else {
				hm.put(a[i],1);
			}
		}
		int fnum = 0;
		int first = 0;
		int second = 0;
		
		for(int num : hm.keySet()) {
			if(first < hm.get(num)) {
				fnum = num;
				second = first;
				first = hm.get(num);
				}
			else if(second < hm.get(num)) {
				second = hm.get(num);
			}
		}
		
		hm = new HashMap<Integer, Integer>();
		
		for(int i = 1 ; i < n ;i+=2) {
			if(hm.containsKey(a[i])) {
				hm.put(a[i], hm.get(a[i])+1);
			}
			else {
				hm.put(a[i],1);
			}
		}
		
		int first1 = 0;
		int second1 = 0;
		int fnum1 = 0;
		
		for(int num : hm.keySet()) {
			if(first1 < hm.get(num)) {
				fnum1 = num;
				second1 = first1;
				first1 = hm.get(num);
			}
			else if(second1 < hm.get(num)) {
				second1 = hm.get(num);
			}
		}
		
		if(fnum != fnum1) {
			int ans = n - first - first1;
			System.out.println(ans);
		}
		else {
			if(second > second1) {
				int ans = n - first1 - second;
				System.out.println(ans);
			}
			else {
				int ans = n - first - second1;
				System.out.println(ans);
			}
		}

	}

}


Measured memory_bytes: 50312
#直径が答えになるわけではない

N = int(input())
S = [list(map(int, input())) for _ in range(N)]

# for s in S:
#     print (s)

lst = [0] * N
lst[0] = 1

stack = [0]
flag = True
while len(stack) != 0:
    tmp = stack.pop()
    for index, x in enumerate(S[tmp]):
        if x == 0:
            continue
        if lst[index] == 0:
            lst[index] = -lst[tmp]
            stack.append(index)
        else:
            if lst[tmp] == -lst[index]:
                pass
            else:
                flag = False
                break
    if not flag:
        print (-1)
        exit()

INF = 10 ** 9
for i in range(N):
    for j in range(N):
        if S[i][j] == 0 and i != j:
            S[i][j] = INF

for k in range(N):
    for i in range(N):
        for j in range(N):
            S[i][j] = min(S[i][j], S[i][k] + S[k][j])
            
ans = 0
for i in range(N):
    for j in range(N):
        ans = max(S[i][j], ans)

print (ans + 1)

Measured memory_bytes: 44396
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
// #define int long long

signed main(){
  int h,w,n;
  cin >> h >> w >> n;
  cout << min((w+n-1)/w, (h+n-1)/h) << endl;
}


Measured memory_bytes: 256
(let* ((l (concatenate 'list (read-line)))
       (check-c-list (reverse (cdr (reverse (cddr l)))))
       (check-lowercase-list (remove #\C check-c-list)))
  (format t "~A~%"
          (if (and (= (count #\C check-c-list) 1)
                   (every #'lower-case-p check-lowercase-list)
                   (char= (car l) #\A)
                   (lower-case-p (cadr l))
                   (lower-case-p (car (last l))))
            'ac
            'wa)))


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

#define st first
#define nd second
#define mp make_pair
#define space << " " <<
#define END << endl
#define pb push_back
#define fo(i, n) for(int i = 0; i < int(n); i ++)
#define ff(i, n) for(int i = 1; i < int(n); i ++)

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pi;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl;
typedef vector<pil>vil;
typedef long double ld;

const int N = 1e5 + 100;

int bit[N];

void update(int u , int v)
{
    while(u < N)
    {
        bit[u] += v;
        u += (u & (-u));
    }
}

int get(int u)
{
    int ans = 0;
    while(u)
    {
        ans += bit[u];
        u -=(u&(-u));
    }
    return ans;
}

int place[N];
int a[N],b[N],c[N];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,m; cin >> n >> m; ff(i,m+1) cin >> place[i];
    ff(i,n) cin >> a[i] >> b[i] >> c[i];
    ff(i,m) { int u = place[i]; int v = place[i+1]; if(u > v) swap(u,v); update(u,1); update(v,-1); }
    ll ans = 0;
    ff(i,n) { int u = get(i); ans += min(1LL * a[i] * u , 1LL * c[i] + 1LL * b[i] * u ); } cout << ans << endl;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll n, m, q;
vector<ll> a, b, c, d;
ll ans = 0;

void dfs(vector<ll> v){
    if(v.size() == n+1){
        ll now = 0;
        REP(i, q){
            if(v[b[i]] - v[a[i]] == c[i]){
                now += d[i];
            }
        }
        ans = max(ans, now);
        cout << endl;
        return;
    }

    v.push_back(v.back());
    while (v.back() <= m){
        dfs(v);
        v.back()++;
    }
}

int main()
{	
    cin >> n >> m >> q;
    a = b = c = d = vector<ll>(q);
    REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    //長さが1で要素が1の配列
    dfs(vector<ll>(1, 1));
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
#include<math.h>

#define MAX 256

int main(void){

	int a, b;
	char op;

	int c[MAX], i = 0;

	while (op != '?'){
		scanf("%d %c %d", &a, &op, &b);

		switch(op){
		case '+': c[i] = a + b; break;
		case '-': c[i] = a - b; break;
		case '*': c[i] = a * b; break;
		case '/': c[i] = a / b; break;
		}
		i++;
	}

	for (int j = 0; j < i - 1; j++){
		printf("%d\n", c[j]);
	}

	return 0;
}

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

int main() {
  int N, K;
  int res = 0;
  cin >> N >> K;
  vector<int> arr(N);
  
  for(int i = 0; i < N; ++i)
  {
    cin >> arr[i];
  }
  sort(arr.begin(), arr.end());
  for(int i = 0; i < K; ++i)
  {
    res += arr[i];
  }
  
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define forin(x,y) for(int i=x;i<y;i++)
#define vii vector<long>
#define pii  pair<long,long>
using namespace std;

vii v;
vii lookup;
ll minCost( ll n)
{
    if(n<=0) return 0;
    if(n == 1)  return abs(v[1]-v[0]);
    else
    {
        if(lookup[n] != -1)     return lookup[n];
        else
        {
            lookup[n] = min( (minCost(n-1) + abs(v[n] - v[n-1])), (minCost(n-2)    + abs(v[n] - v[n-2])));
            return lookup[n];
        }
        
    }
    
}


int main()
{
    ios::sync_with_stdio(false);    cin.tie(0);     cout.tie(0);
    //int t;    cin>>t;     forin(0,t)  evaluate();
    ll n;   cin>>n;     v.assign(n,0);      lookup.assign(n,-1);
    forin(0,n){     cin>>v[i];}
    ll ans = minCost(n-1);
    cout<<ans<<endl;
}




Measured memory_bytes: 4224
#include<stdio.h>
#define N 8
void putq(int i,int row[],int col[],int dpos[],int dneg[]);
void printQ(int row[]);
char A[N][N];
int memo[N]={10};
int main()
{
  int k,i,j,r,c;
  int col[N]={10},dpos[15]={10},dneg[15]={10},row[N]={10};
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&r);
    scanf("%d",&c);
    row[r]=c;
    memo[r]=r;
    col[c]=dpos[r+c]=dneg[r-c+N-1]=-1;
    }
  putq(0,row,col,dpos,dneg);
  return 0;
}
void putq(int i,int row[],int col[],int dpos[],int dneg[])
{
  int j=-1;
  if(i==N){
    printQ(row);
  return ;
  }
  if(memo[i]==i)putq(i+1,row,col,dpos,dneg);
  for(j=0;j<N;j++){
    if(memo[i]==i)break;
    if(col[j]==-1 || dpos[i+j]==-1 || dneg[i-j+N-1]==-1)continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=-1;
    putq(i+1,row,col,dpos,dneg);
    col[j]=dpos[i+j]=dneg[i-j+N-1]=1;
  }
}
void printQ(int row[])
{
  int i,j,k;
  for(i=0;i<N;i++)A[i][row[i]]='Q';
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]=='Q')printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}


Measured memory_bytes: 2112
var table: [String: Int] = [:]

let N = Int(readLine()!)!
for _ in 0..<N {
  let res = readLine()!
  table[res, default: 0] += 1
}
for key in ["AC", "WA", "TLE", "RE"] {
  print("\(key) x \(table[key, default: 0])")
}

Measured memory_bytes: 8068
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
const int maxn = 1e5 + 5;
int main()
{
    ios::sync_with_stdio(false);
    int n; cin >> n;
    cout << !n << endl;
    return 0;
}


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

int n, a, x[55];
long long ans, dp[55][3000];

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

	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j >= 0; j--) {
			for (int k = 0; k <= 2500; k++) {
				if (dp[j][k]) {
					dp[j + 1][k + x[i]] += dp[j][k];
				}
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		ans += dp[i][a * i];
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

typedef struct
{
	int h;
	int w;
	int num;
	int height;
	int weight;
	double closeness;
} STATUS;

void CalculateCloseness(STATUS* status);

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int i;
		STATUS nearest;
		
		scanf("%d %d %d", &nearest.num, &nearest.h, &nearest.w);
		CalculateCloseness(&nearest);
		for (i = 1; i < n; i++){
			STATUS tmp;
			
			scanf("%d %d %d", &tmp.num, &tmp.h, &tmp.w);
			CalculateCloseness(&tmp);
			if (nearest.closeness > tmp.closeness){
				nearest = tmp;
			}
		}
		printf("%d\n", nearest.num);
	}
	
	return 0;
}

void CalculateCloseness(STATUS* status)
{
	double height = status->h / 100.0;
	double bmi = status->w / height / height;
	status->closeness = 22 > bmi ? 22 - bmi : bmi - 22;
}

Measured memory_bytes: 600
/*{{{*/
#include<bits/stdc++.h>

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=b-1;i>=a;i--)

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll n;
  cin >> n;
  ll otherNim = 0;
  ll a1,a2;
  cin >> a1 >> a2;
  REP(i,n-2){
    ll a;
    cin >> a;
    otherNim ^= a;
  }
  if((a1+a2-otherNim)%2 > 0){
    //cout << "common is negative" << endl;
    cout << -1 << endl;
    return 0;
  }
  ll common = (a1+a2-otherNim)/2;
  if(common < 0){
    //cout << "common is negative" << endl;
    cout << -1 << endl;
    return 0;
  }
  if((common&otherNim) != 0){
    //cout << "exists common bit bw common and otherNim" << endl;
    cout << -1 << endl;
    return 0;
  }
  if(common > a1){
    //cout << "common larger than a1" << endl;
    cout << -1 << endl;
    return 0;
  }
  vl bitlist;
  ll t = 1;
  while(t<=4e12){
    if((t&otherNim)>0) bitlist.push_back(t);
    t *= 2;
  }
  reverse(bitlist.begin(),bitlist.end());
  ll newA1 = common;
  REP(i,bitlist.size()){
    newA1 += bitlist[i];
    if(newA1 > a1){
      newA1 -= bitlist[i];
    }
  }
  if(newA1 <= 0){
    //cout << "a1 becomes 0" << endl;
    cout << -1 << endl;
    return 0;
  }

  cout << a1 - newA1 << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

int main(){
  int N;
  cin >> N;
  
  cout << "Christmas";
  FOR(i, N, 25) cout << " " << "Eve";
  
    
}

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

#define rep(i, n)     for (int (i) = 0; (i) < (n); (i)++)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long ll;

const int MAXN = 2000100;
const int MAXK = 10100;

int A[MAXN], B[MAXN], C[MAXK];

void countingSort(int n) {
   rep(i, MAXK) C[i] = 0;
   rep1(i, n) C[A[i]]++;
   for (int i = 1; i < MAXK; i++) {
      C[i] += C[i - 1];
   }
   for (int i = n; i > 0; i--) {
      B[C[A[i]]] = A[i];
      C[A[i]]--;
   }
}

int main() {
   int n;

   cin >> n;
   for (int i = 1; i <= n; i++) {
      scanf("%d", &A[i]);
   }
   countingSort(n);
   for (int i = 1; i <= n; i++) {
      if (i != 1) printf(" ");
      printf("%d", B[i]);
   }
   printf("\n");
   return(0);
}



Measured memory_bytes: 18756
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  string s; cin >> s;
  V<> cd(n + 1), cm(n + 1), cc(n + 1);
  for (int i = 0; i < n; ++i) {
    cd[i + 1] = cd[i] + (s[i] == 'D');
    cm[i + 1] = cm[i] + (s[i] == 'M');
    cc[i + 1] = cc[i] + (s[i] == 'C');
  }
  int q; cin >> q;
  for (int iq = 0; iq < q; ++iq) {
    int k; cin >> k;
    lint res = 0, t = s.substr(0, 2) == "DM";
    for (int i = 2; i < n; ++i) {
      if (s[i] == 'C') res += t;
      else if (s[i] == 'M') {
        t += cd[i] - cd[max(i - k + 2, 0)];
      }
      if (i - k + 1 >= 0 and s[i - k + 1] == 'D') {
        t -= cm[i] - cm[i - k + 2];
      }
    }
    cout << res << '\n';
  }
}

Measured memory_bytes: 15132
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
#include<iostream>  
#include<string>  
#include<vector>  
#include<stack>  
#include<bitset>  
#include<cstdlib>  
#include<cmath>  
#include<set>  
#include<list>  
#include<deque>  
#include<map>  
#include<queue>  
#include<sstream>  
using namespace std;  
typedef long long LL;  
const int INF = 0x3f3f3f3f;  
  
  
int main()  
{  
 int a,b,c,d;  
 cin >> a >>b >> c >>d;  
 int num1 = ceil(a * 1.0/ d);  
 int num2 = ceil(c * 1.0 / b);  
 if(num1 >= num2)  
  cout << "Yes" <<endl;  
 else  
  cout << "No" << endl;   
  
 return 0;  
}  

Measured memory_bytes: 3632
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
template <typename T> T add(T& a, T b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T mul(T& a, T b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T up_self(T& a, T b){a = up(a,b);}
template <typename T> T min_self(T& a, T b){a = min(a,b);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
int main()
{
	int n,k; cin>>n>>k;
	vector<int> stones(n);
	for(int i = 0 ; i < n; i++)
		cin>>stones[i];
	vector<bool> at(k+1);
	for(int i = 0 ; i < k+1; i++)
		for(int j : stones)
			if(i-j>=0&&at[i-j]==false)
				at[i] = true;
	if(at[k])
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
  	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define vi vector<int>

int main() {
    int n;
    cin >> n;
    vi d(n);
    rep (i, n){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int x;
    x = d[n/2] - d[n/2-1];
    cout << x << endl;

    return 0;
}

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

typedef long long ll;

const int kN = 1e5 + 5;

int a[kN]; ll ans = 0;

int main() {
	int n, lst = 0; scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		int x; scanf("%d", &x);
		if(lst && x) lst = 0, --x, ++ans;
		lst = x % 2; ans += x / 2;
	}
	printf("%lld", ans);
	return 0;
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    string s; cin >> s;
    vector<ll> w, r;

    rep(i, n){
        if (s[i] == 'W'){
            w.PB(i);
        }
        else{
            r.PB(i);
        }
    }
    ll ans = 0, cnt_w = 0, cnt_r = 0, cnt = 0, lim = r.size();


    if (w.size() == n || lim == n){
        cout << 0;
        return 0;
    }

    while(true){
        if(cnt_r+cnt == lim) break;

        if(r[cnt_r] < w[cnt_w]) cnt_r++;
        else{
            cnt_w++; cnt++; ans++;
        }

    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5824
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e5+10;
int main(void) {
    ll n, k;
    while(~scanf("%lld%lld", &n, &k)) {
        ll st = 1;
        while(n--) {
            if (st <= k) st <<= 1;
            else st += k;
        }
        printf("%lld\n", st);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

void dfs(int cur, vector<vector<int>> &g, vector<int> &color, int curColor, bool &ok) {

  color[cur] = curColor;
  int nxtColor = curColor + 1;
  if (nxtColor == 3) nxtColor = 1;

  for (auto nxt : g[cur]) {
    if (color[nxt] == 0) { // 未訪問の場合
      dfs(nxt, g, color, nxtColor, ok);
    } else { // 訪問済みの場合
      if (curColor == color[nxt]) {
        ok = false;
      }
    }
  }
}



bool solve() {

  int n, m; cin >> n >> m;
  if (n == 0 and m == 0) {
    return false;
  }

  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<int> color(n, 0);
  bool ok = true;
  dfs(0, g, color, 1, ok);
  if (!ok) {
    cout << 0 << endl;
    return true;
  }

  int cnt1 = 0;
  int cnt2 = 0;

  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (color[i] == 1) cnt1++;
    else if (color[i] == 2) cnt2++;
    else assert(false);
  }

  if (cnt1 % 2 == 0) ans.push_back(cnt1 / 2);
  if (cnt2 % 2 == 0) ans.push_back(cnt2 / 2);

  set<int> anss;
  for (auto i : ans) anss.insert(i);

  cout << anss.size() << endl;

  for (auto i : anss) cout << i << endl;


  return true;
}

int main() {
  
  while (solve()) {
  }
  return 0;
}



Measured memory_bytes: 3220
using System;

namespace Myatcoder
{
    public class Program
    {
        public static void Main()
        {
            int x = int.Parse(Console.ReadLine());
            int gcd = GCD(x);
            Console.WriteLine(x * 2 / gcd);
        }

        public static int GCD(int x)
        {
            int y = 2;
            while (true)
            {
                if (x % y == 0) break;
                int tmp = y;
                y = x % y;
                x = tmp;
            }
            return y;
        }
    }
}

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

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    rep(i, N)
        cin >> p.at(i);

    int sum = 0;
    int swap_cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        int minj = i;
        for (int j = i + 1; j < N; j++) {
            if (p.at(minj) > p.at(j))
                minj = j;
        }

        if (i != minj) {
            int tmp;
            tmp = p.at(i);p.at(i) = p.at(minj); p.at(minj) = tmp;
            swap_cnt++;
        }
        if (swap_cnt > 1)
            break;
    }

    cout << (swap_cnt > 1 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, p[10], q[10];
	cin >> n;
	rep(i, 1, n){
		cin >> p[i];
	}
	rep(i, 1, n){
		cin >> q[i];
	}
	
	
	ll use[10];
	memset(use, 0, sizeof(use));
	ll a = 0;
	rep(i, 1, n){
		ll unuse = 0;
		//cout << p[i] << endl;
		zep(j, 1, p[i]){
			//print(use[j])
			if(!use[j]){
				unuse++;
			}
		}
		
		ll ex = 1;
		rep(k, 1, n-i){
			ex *= k;
		}
		a += unuse*ex;
		use[p[i]] = true;
		//cout << unuse << " " << ex << " " << a << endl;
	}
	//print(a)
	
	memset(use, 0, sizeof(use));
	ll b = 0;
	rep(i, 1, n){
		ll unuse = 0;
		zep(j, 1, q[i]){
			if(!use[j]){
				unuse++;
			}
		}
		
		ll ex = 1;
		rep(k, 1, n-i){
			ex *= k;
		}
		b += unuse*ex;
		use[q[i]] = true;
	}
	print(abs(a-b))
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,k;
	cin>>n>>k;

	int a2[101]={};
	rep(i,k){
		int d;
		cin>>d;
		rep(j,d){
			int a;
			cin>>a;
			a2[a]++;
		}
	}
	int t=0;
	rep(i,n){
		if(a2[i+1]==0)t++;
	}
	cout<<t<<endl;

	return 0;
}


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

//~ const int MOD=1000000007;
const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[300000],b[300000];

int main(){
	int n;cin>>n;
	vector<int>va,vb;
	rep(i,n){
		scanf("%d%d",&a[i],&b[i]);
		va.push_back(a[i]);
		vb.push_back(b[i]);
	}
	sort(va.begin(),va.end());
	sort(vb.begin(),vb.end());
	if(n%2==0){
		int A=(va[n/2-1]+va[n/2]);
		int B=(vb[n/2-1]+vb[n/2]);
		cout<<B-A+1<<endl;
	}
	else{
		int A=va[n/2],B=vb[n/2];
		cout<<B-A+1<<endl;
	}
}

Measured memory_bytes: 6668
#include <iostream>
#include <vector>

int main(){
    uint32_t N;
    std::cin >> N;
    uint32_t sum = 0;

    std::vector<uint32_t> leng(N, 0);
    for(uint32_t i = 0; i < N; i++){
        std::cin >> leng[i];
    }

    for(int k = 0; k < N; k++){
        for(int l = 0; l < k; l++){
            for(int m = 0; m < l; m++){
                if(((leng[m] + leng[l]) > leng[k]) && ((leng[l] + leng[k]) > leng[m]) && ((leng[k] + leng[m]) > leng[l])){
                    //std::cout << leng[m] << leng[l] << leng[k] << std::endl;
                    sum += 1;
                    }
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

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

 using namespace std;

 int main() {
   int Mx, x, N, i;
   string S;
   cin >> N >> S;

   Mx = 0;
   x = 0;
   for (i = 0; i < N; i++) {
     if (S.at(i) == 'I') x++;
     else x--;
     Mx = max(Mx, x);
   }

   cout << Mx << endl;
 }


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

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

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

	vector<int> d_arr(N);

	REP(i,N){
		cin>>d_arr[i];
	}

	sort(d_arr.begin(),d_arr.end());
	
	int center_num = d_arr[N/2];
		
	cout<<(d_arr[N/2] - d_arr[N/2 - 1])<<endl;

	return 0;
}



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

bool a[101] = {0};

int main(){
    int n, k;
    cin >> n >> k;

    while(k--){
        int d; cin >> d;
        for(int i=0; i<d; i++){
            int ai; cin >> ai;
            a[ai] = 1;
        }
    }

    int res = 0;
    for(int i=1; i<=n; i++) 
        if (a[i] == 0) res++;

    cout << res << endl;
}




Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>

using namespace std;

int N;
int occurences[105];
int diameter;
bool isPossible = true;

int main()
{
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
    {
        int a; scanf("%d", &a);
        occurences[a]++;
        diameter = max(diameter, a);
    }
    for (int i = (diameter + 1) / 2; i <= diameter && isPossible; i++)
    {
        if (i == (diameter + 1) / 2)
        {
            if ((diameter % 2 == 0 && occurences[i] != 1) || (diameter % 2 == 1 && occurences[i] != 2)) isPossible = false;
        }
        else if (occurences[i] < 2) isPossible = false;
    }
    for (int i = 0; i < (diameter + 1) / 2 && isPossible; i++)
    {
        if (occurences[i] != 0) isPossible = false;
    }
    if (isPossible) printf("Possible\n");
    else printf("Impossible\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int len;
	string s;
	cin>>len;	cin>>s;
	if (len%2) cout<<"No";
	else{
		for (int i=0;i<len/2;i++)
			if (s[i]!=s[i+len/2]){
				cout<<"No";
				return 0;
			}
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#define N 2005
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
int n,m,Q;
char mp[N][N];
int l[N][N];
int u[N][N];
int dp[N][N];
int e1[N][N];
int e2[N][N];
void Init()
{
	scanf("%d %d %d\n",&n,&m,&Q);
	rep(i,1,n+1)
		scanf("%s",mp[i]+1);
	rep(i,1,n+1)
		rep(j,1,m+1)
			dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+(mp[i][j]=='1');
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			l[i][j]=l[i][j-1];
			if(mp[i][j]=='1' && mp[i][j-1]=='1')++l[i][j];
		}
	}
	rep(i,1,n+1)
		rep(j,1,m+1)
			l[i][j]+=l[i-1][j];
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			u[i][j]=u[i-1][j];
			if(mp[i][j]=='1' && mp[i-1][j]=='1')++u[i][j];
		}
	}
	rep(i,1,n+1)
		rep(j,1,m+1)
			u[i][j]+=u[i][j-1];
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			e1[i][j]=e1[i][j-1];
			if(mp[i][j]=='1' && mp[i][j-1]=='1')e1[i][j]++;
		}
	}
	rep(i,1,n+1)
		rep(j,1,m+1)
			e1[i][j]+=e1[i-1][j];
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			e2[i][j]=e2[i-1][j];
			if(mp[i][j]=='1' && mp[i-1][j]=='1')e2[i][j]++;
		}
	}
	rep(i,1,n+1)
		rep(j,1,m+1)
			e2[i][j]+=e2[i][j-1];
}
void Solve()
{
	while(Q--)
	{
		int x1,y1,x2,y2;
		int point_count;
		int edge_count=0;
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		point_count=dp[x2][y2]-dp[x1-1][y2]-dp[x2][y1-1]+dp[x1-1][y1-1];
		edge_count+=l[x2][y2]-l[x1-1][y2]-l[x2][y1-1]+l[x1-1][y1-1];
		edge_count+=u[x2][y2]-u[x1-1][y2]-u[x2][y1-1]+u[x1-1][y1-1];
		int more=0;
		more+=e1[x2][y1]-e1[x1-1][y1]-e1[x2][y1-1]+e1[x1-1][y1-1];
		more+=e2[x1][y2]-e2[x1][y1-1]-e2[x1-1][y2]+e2[x1-1][y1-1];
		edge_count-=more;
		printf("%d\n",point_count-edge_count);
	}
}
int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 84096
import sys
sys.setrecursionlimit(10 ** 7)

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

N, Q = lr()
edges = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b = lr()
    edges[a].append(b)
    edges[b].append(a)

counter = [0] * (N+1)
for _ in range(Q):
    p, x = lr()
    counter[p] += x

parents = [0] * (N+1)

def bfs(x):
    for y in edges[x]:
        if y == parents[x]:
            continue
        counter[y] += counter[x]
        parents[y] = x
        bfs(y)

bfs(1)
print(*counter[1:])
# 09

Measured memory_bytes: 238996
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  ll a;
  ll sum = 0;
  bool four = false;
  REP(i, N) {
    cin >> a;
    if (a % 4 == 0) {
      sum += 2;
      four = true;
    } else if (a % 2 == 0) {
      sum++;
    }
  }
  if (four = true && N % 2 != 0) {
    sum++;
  }
  if (sum >= N) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int MaxN = 50;
const LL INF =  5e17;
LL a[MaxN + 5], cnt[MaxN + 5];
LL k;
bool flag = false;

int main(){
	while(~scanf("%lld", &k)){
		int n = 50;
		LL temp = k / n;
		for(int i = 1; i <= n; i++) a[i] = n - 1;
		for(int i = 1; i <= n; i++){
			a[i] += temp * n;
			for(int j = 1; j <= n; j++){
				if(j == i) continue;
				a[j] -= temp;
			}
		}
		for(int i = 1; i <= k % n; i++){
			a[i] += n;
			for(int j = 1; j <= n; j++){
				if(i == j) continue;
				a[j]--;
			}
		}
		LL Min = a[1];
		for(int i = 2; i <= n; i++) Min = min(a[i], Min);
		if(Min < 0){
			for(int i = 1; i <= n; i++)  a[i] += abs(Min);
		}
		printf("50\n");
		for(int i = 1; i <= n; i++) printf("%lld ", a[i]);
	}
	return 0;
}

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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()

#define EPS 1e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

int main() {

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

	int bingo[3][3], n;

	for(int k = 0; k < 3; ++k)
		for(int i = 0; i < 3; ++i)
			cin >> bingo[k][i];

	cin >> n;

	while(n--) {

		int x;

		cin >> x;

		for(int k = 0; k < 3; ++k) {
			for(int i = 0; i < 3; ++i) {
				if(bingo[k][i] == x) {
					bingo[k][i] = -1;
				}
			}
		}
	}

	bool marked = false;

	for(int k = 0; k < 3; ++k) {

		if(bingo[k][0] == -1 && bingo[k][1] == -1 && bingo[k][2] == -1)
			marked = true;

		if(bingo[0][k] == -1 && bingo[1][k] == -1 && bingo[2][k] == -1)
			marked = true;
	}

	if(bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1)
		marked = true;

	if(bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1)
		marked = true;

	if(marked) cout << "Yes\n";
	else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; i < 10; i++) {
		c = (c*a) - b;
		cout << c << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long a, b, k;
    scanf ( "%lld%lld%lld", &a, &b, &k );

    if ( a >= k ) {
        long long tmp = a-k;
        printf ( "%lld %lld", tmp, b );
    }

    else if ( a + b <= k ) {
        printf ( "0 0" );
    }

    else {
        printf ( "0 %lld", a+b-k );
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    int N,ans,cnt=0;
    cin>>N;
    REP(i,N){
        int k=i;
        int cntt=0;
        for(;;){
            if(k%2==0){
                cntt++;
                k/=2;
            } else {
                break;
            }
        }
        if(cnt<cntt){
            cnt=cntt;
            ans=i;
        }
    }
    cout<<(N==1?1:ans)<<endl;
}

Measured memory_bytes: 256