akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    if (s <= "2019/04/30") cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}


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

int main() {
  int N, A;
  int ans = 1000000000;
  cin >> N;
 
  for(int i = 0; i < N ; i++){
    int min = 0;
    cin >> A;
    
    if(A % 2 != 0){
      ans = 0;
      break;
    }
    
    while (A % 2 == 0){
      A /= 2;
      min++;
    }

    if(ans > min)
      ans = min;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for(int i = 1; i <= n; ++i){
		double p = 1.0 / (double)(n);
		int j = i;
		while(j < k){
			p /= 2;
			j *= 2;
		}
		ans += p;
	}
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 3752
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define int long long

using namespace std;

long long MOD = 1e9 + 7;
long long n, m;
long long a[500000];
long long b[500000];
long long dp[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    fill(b, b + n, 1);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        b[a[i]] = 0;
    }
    dp[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        dp[i] = (dp[i - 1] * b[i - 1] + dp[i - 2] * b[i - 2]) % MOD;
    }
    cout << dp[n];
}


Measured memory_bytes: 9216
fun main(args: Array<String>) {

    val s = readLine()!!

    // 連続したRのカウンタ
    var rCount = 0

    // 連続したLのカウンタ
    var lCount = 0

    // 連続したLの中で先頭のLのインデックス
    var rEnd = 0

    val answer = Array(s.length) { 0 }

    for (i in 0 until s.length) {

        if (s[i] == 'R') rCount++

        if (s[i] == 'L') lCount++

        if (i == s.length - 1) {
            answer[rEnd] += lCount / 2
            answer[rEnd + 1] += lCount / 2 + lCount % 2
            break
        }

        if (s[i] == 'R' && s[i + 1] == 'L') {

            // R
            answer[i] += rCount / 2 + rCount % 2

            // L
            answer[i + 1] += rCount / 2

            rCount = 0

            rEnd = i
        }

        if (s[i] == 'L' && s[i + 1] == 'R') {

            // L
            answer[rEnd + 1] += lCount / 2 + lCount % 2

            // R
            answer[rEnd] += lCount / 2

            lCount = 0
        }
    }

    println(answer.joinToString(" "))
}

Measured memory_bytes: 39892
#include<stdio.h>
#include<string.h>
int main(){
  int i,len;
  char S[100000];
  scanf("%s", S);
  len = strlen(S);

  int N[len];
  int gather_mode, odd, even;
  int gather_R,gather_L;

  gather_mode = 0;
  odd = 0;
  even = 0;
  
  for(i=0; i<len; i++){
    N[i] = 0;
    
    if(gather_mode == 0){
      if(S[i] == 'L'){
        gather_R = i-1;
        gather_L = i;
        gather_mode = 1;
      }
   }
    else if(gather_mode == 1){
      if(S[i] == 'R'){
        if(gather_R%2 == 0){
          N[gather_R] = even;
          N[gather_L] = odd;
        }
        else{
          N[gather_R] = odd;
          N[gather_L] = even;
        }
        gather_mode = 0;
        odd = 0;
        even = 0;
      }
    }
    if(i%2 == 0) even++;
    else odd++;
  }
  
  if(gather_R%2 == 0){
    N[gather_R] = even;
    N[gather_L] = odd;
  }
  else{
    N[gather_R] = odd;
    N[gather_L] = even;
  }
  
  for(i=0; i<len-1; i++){
    printf("%d ",N[i]);
  }
  printf("%d\n",N[i]);
  
  return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (auto i = 0; i < (int)s.size(); i++) {
        if(s[i] != t[i]) ans++;
    }

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

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

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

const int oo = 1e9;

bool ok(vector<int> &a){
	for(int i = 0; i + 1 < (int)a.size(); i++)
		if(a[i] > a[i + 1])
			return false;
	return true;
}

int invs(vector<int> &a){
	int ans = 0;
	for(int i = 0; i < a.size(); i++)
		for(int j = i + 1; j < a.size(); j++)
			if(a[i] > a[j])
				ans++;
	return ans;
}

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	vector<int> a(n), b(n);
	
	for(int i = 0; i < n; i++)
		cin >> a[i];
	
	for(int i = 0; i < n; i++)
		cin >> b[i];
	
	int ans = oo;
	
	for(int mask = 0; mask < (1 << n); mask++){
		
		vector<pii> odd, even;
		
		for(int i = 0; i < n; i++){
			if(mask & (1 << i)){
				if(i % 2)
					odd.push_back({a[i], i});
				else
					even.push_back({a[i], i});
			}
			else{
				if(i % 2)
					even.push_back({b[i], i});
				else
					odd.push_back({b[i], i});
			}
		}
		
		sort(odd.begin(), odd.end());
		sort(even.begin(), even.end());
		
		if(odd.size() != n / 2)
			continue;
		
		if(even.size() != (n + 1) / 2)
			continue;
		
		int p1 = 0, p2 = 0;
		
		vector<int> v(n), vv(n);
		for(int i = 0; i < n; i++){
			if(i % 2){
				v[i] = odd[p1].second;
				vv[i] = odd[p1].first;
				p1++;
			}
			else{
				v[i] = even[p2].second;
				vv[i] = even[p2].first;
				p2++;
			}
		}
		
		if(ok(vv))
			ans = min(ans, invs(v));
		
	}
	
	
	if(ans == oo)
		ans = -1;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int a=gi();
	    int b=gi();
	    int c=gi();



        System.out.println(Math.min(Math.min(a+b, b+c), c+a));
//        if (b-a<=0) {
//        	System.out.print(Math.);
//        }else if (b-a>x){
//            System.out.print("dangerous");
//        } else {
//        	System.out.print("safe");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35768
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main() {
	long long int N, P;
	int max_gcd = 1;
	int start_num = 0;

	cin >> N >> P;

	if (N == 1) {
		cout << P << endl;
	} else {

		for (int i = 1;; i *= 10) {
			if (pow(i, N) > P) {
				start_num = i;
				break;
			}
		}

		for (long long int i = start_num; i != 1; i--) {
			if (P % (long long int) pow(i, N) == 0) {
				max_gcd = i;
				break;
			}
		}

		cout << max_gcd << endl;
	}
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

void solve()
{
  // ll n; cin >> n;
  // ll x, y, z; cin >> x >> y >> z;
  string s; cin >> s;
  string t; cin >> t;
  // vector<ll> a(n); REP(i, n) cin >> a[i];
  // ll ans = 0;
  bool ok = true;
  if(s.size()!=t.size()-1) {
    ok = false;
  } else {
    REP(i, s.size()) {
      if(s[i]!=t[i]) ok = false;
    }
  }
  // cout << ans << endl;
  cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 3624
import bisect
n, x = map(int, input().split())
L = list(map(int, input().split()))
D = [0]
ans = 1
for i in range(1, n+1):
  d = D[i-1] + L[i-1]
  D.append(d)
  if d <= x:
    ans += 1
  else:
    break
print(ans)

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

typedef long long int LLI;

LLI N;
LLI X;
LLI ans;

int main() {
  scanf("%lld%lld", &N, &X);
  ans = X;
  tie(N, X) = make_pair(X, N-X);
  while (N > 0 && X > 0) {
    //printf("%lld %lld %lld\n", N, X, ans);
    if (N >= X) {
      ans += 2 * (N/X) * X;
      tie(N, X) = make_pair(N%X, X);
    } else {
      ans += N+X;
      tie(N, X) = make_pair(X-N, N);
    }
  }
  printf("%lld\n", ans);
}


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

if A == 5:
    if B == 7:
        if C == 5:
            print('YES')
        else:
            print('NO')
    elif B == 5:
        if C == 7:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')
elif A == 7:
    if B == 5:
        if C == 5:
            print('YES')
        else:
            print('NO')
    else:
        print('NO')
else:
    print('NO')

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <typeinfo>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
using namespace std;

int main() {

	string s="", t="";

	cin >> s >> t;

	if (s.size() < 11 && 0 < s.size() && t.size() == (s.size() + 1)&&t.substr(0,s.size())==s)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3632
my $k = Int(get);
my $ans = 0;
my @loop = 1..$k;
for @loop -> $a {
    for @loop -> $b {
        my $tmp = infix:<gcd>($a, $b);
        for @loop -> $c {
            $ans += infix:<gcd>($tmp, $c);
        }
    }
}
print "$ans\n";

Measured memory_bytes: 96556
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const double time_limit = 1.9;
double start;

unsigned rando() {
	static unsigned y = 2463534242;
    y ^= y << 13;y ^= y >> 17;y ^= y << 5;
    return y;
}


double sec() {
	struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec + tv.tv_usec * 1e-6;
}

double pastTime() {
	return sec() - start;
}

int d;

int c[26];
int s[365][26];

int score(vector<int>& t) {
	int score = 0;
	vector<int> last(26,0);
	rep(i, d) {
		score += s[i][t[i]];
		last[t[i]] = (i + 1);

		rep(j,26) {
			score -= ((i + 1) - last[j]) * c[j];
		}
		//cout  << score << endl;

	} 


	return score;

}

void output(vector<int>& t) {
	rep(i, d) {
		cout << t[i] + 1 << endl;
	}
}


int main() {
	


	cin >> d;
	rep(i, 26) {
		cin >> c[i];
	} 
	rep(i, d) {
		rep(j,26) {
			cin >> s[i][j];
		}
	}
	start = sec();
	vector<int> t(d);

	rep(i, d) {
		t[i] = rando() % 26;
	}

	int cur = score(t);


	while(true) {
		double cur_time = pastTime();
		if (cur_time > time_limit) {
			break;
		}
		//vector<int> nt = t;
		int size = (int) (cur_time / time_limit * 2.0) + 1;
		
		for (int loop = 0; loop < 100; loop++) {
			stack<P> cd;
			rep(i ,size) {
				int cur_d = rando() % d;
				int cur_c = rando() % 26;
				cd.push(mkp(cur_d, t[cur_d]));
 
				t[cur_d] = cur_c;
			}
			int next = score(t);
			if (cur < next) {
				cur = next;
			} else {
				while(!cd.empty()) {
					auto cur = cd.top();
					t[cur.first] = cur.second;
					cd.pop();
				}
 
			}
	
		}
	}

	output(t);

	//cout << "score:" <<  << endl;

	return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll n, m, x;    cin >> n >> m >> x;
    ll *c = new ll[n];
    ll **a = new ll*[n];
    for (int i = 0; i < n; i++) {
        a[i] = new ll[m];
        cin >> c[i];
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    }

    ll ans = LLONG_MAX;

    for (int bit = 0; bit < (1<<n); bit++) {
        vector<int> s;
        for (int i = 0; i < n; i++) {
            if (bit & (1<<i))
                s.push_back(i);
        }

        ll tmp = 0;
        vector<ll> score(m, 0);
        bool flag = true;
        for (int i = 0; i < s.size(); i++) {
            int j = s[i];
            tmp += c[j];
            for (int k = 0; k < m; k++)
                score[k] += a[j][k];
        }

        for (int k = 0; k < m; k++) {
            if (score[k] < x)
                flag = false;
        }
        if (flag)
            ans = min(ans, tmp);
    }

    if (ans == LLONG_MAX)
        cout << -1 << endl;
    else 
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc164_a solver = new abc164_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc164_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(in.nextInt() <= in.nextInt() ? "unsafe" : "safe");
        }

    }
}



Measured memory_bytes: 35832
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,p;cin>>n;
  lvector Q(n,0),checked(n,0);
  rep(i,n) {cin>>p;Q[p-1]=i;}
  ll prev=-1,l=0,l_=0;
  rep(i,n) {
    if(prev>Q[i]) l_=0;
    l_++;
    prev=Q[i];
    l=max(l,l_); 
  }
  print(n-l);
  return 0;
}

Measured memory_bytes: 3456
//
//  main.cpp
//  minnimum_spanning_tree
//
//  Created by ???????????? on 2017/10/23.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>

#define n_max 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1<<21

using namespace std;

int n, M[n_max][n_max], color[n_max], d[n_max], p[n_max];

void init(){
    int i, j, id, num, node;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }
    
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &id, &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            scanf("%d", &M[id][node]);
        }
        color[i] = WHITE;
        d[i] = INFTY;
    }
}

void dijkstra(){
    //initializing
    d[0] = 0;
    p[0] = -1;
    
    int u;
    while(true){
        int mincost = INFTY;
        for(int i = 0; i < n; i++ ){
            if((color[i] != BLACK) && (d[i] < mincost)){
                mincost = d[i];
                u = i;
            }
        }
        
        if (mincost == INFTY) break;
        
        color[u] = BLACK;
        
        for(int v = 0; v < n; v++){
            if((color[v] != BLACK) && (M[u][v] != INFTY)){
                if((d[u] + M[u][v]) < d[v]){
                    d[v] = M[u][v] + d[u];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}

int main(int argc, const char * argv[]) {
    init();
    dijkstra();
    //    std::cout << "Hello, World!\n";
    return 0;
}

Measured memory_bytes: 3260
import sys

N, M = list(map(int, input().split()))
num = [-1] * N

if M == 0:
    if N == 1:
        print(0)
        sys.exit()
    else:
        print(int('1' + '0' * (N-1)))
        sys.exit()

for m in range(M):
    s, c = list(map(int, input().split()))
    if num[s-1] != -1 and num[s-1] != c:
        print(-1)
        sys.exit()
    num[s-1] = c

if len(num) != 1 and num[0] == 0:
    print(-1)
    sys.exit()

for i in range(N):
    if num[i] == -1:
        if i == 0:
            num[i] = 1
        else:
            num[i] = 0
print("".join(map(str, num)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) b.rbegin(),v.rend()
typedef long long ll;
//isPrime
//modpow modinv
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  rep(i,n){
    cin >> p[i];
  }
  rep(i,n){
    cin >> q[i];
  }
  vector<int> a(n);
  rep(i,n){
    a[i]=i+1;
  }
  map<vector<int>,int> mp;
  int i;
  do {
    mp[a]=i;
    i++;
  } while(next_permutation(ALL(a)));
  cout << abs(mp[p]-mp[q]) << endl;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
using namespace std;

int main() {
    ll x, y;
    cin >> x >> y;

    ll ans = 0;
    ll ai = x;
    while (ai <= y) {
        ai *= 2;
        ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define int long long

// #define DEBUG

// √a以上の最小の自然数
ll my_sqrt(ll a) {
	int ng = 0, ok = a;
	while (ok - ng > 1) {
		int mid = (ng + ok) / 2;
		if (mid * mid >= a) ok = mid;
		else ng = mid;
	}
	return ok;
}

bool solve() {
	int N, M; cin >> N >> M;
	if (N == 0 && M == 0)
		return false;
	// imosを用いて最初のM-1個による強度を計算
	ll* u2 = new ll[N]; // uの二乗の係数
	ll* u1 = new ll[N]; // uの係数
	ll* c = new ll[N]; // 定数項
	for (int i = 0; i < N; ++i)
		u2[i] = u1[i] = c[i] = 0LL;
	for (int i = 0; i < M - 1; ++i) {
		int a, x; cin >> a >> x; --x;
		ll c_add = (ll)a - (ll)x * x;
		ll u1_add = 2LL * x;
		ll u2_add = -1LL;
		ll sq_a = my_sqrt(a);
		ll l = x - sq_a, r = x + sq_a;
		if (sq_a * sq_a > a) ++l;
		else ++r;
		if (l < 0) l = 0;
		u2[l] += u2_add; if (r < N) u2[r] -= u2_add;
		u1[l] += u1_add; if (r < N) u1[r] -= u1_add;
		c[l] += c_add; if (r < N) c[r] -= c_add;
	}
	for (int i = 1; i < N; ++i) {
		u2[i] += u2[i - 1];
		u1[i] += u1[i - 1];
		c[i] += c[i - 1];
	}
	int a_M; cin >> a_M;
#ifdef DEBUG
	cout << "----first M-1 shields----" << endl;
#endif
	ll* tmp = new ll[N]; // 現状の強度
	for (int i = 0; i < N; ++i) {
		tmp[i] = c[i];
		tmp[i] += i * u1[i];
		tmp[i] += i * (ll)i * u2[i];
#ifdef DEBUG
		cout << tmp[i] << " ";
#endif
	}
#ifdef DEBUG
	cout << endl;
#endif
	// M個目を置いたあとのスコアで二部探索
	ll ok = *min_element(tmp, tmp + N);
	ll ng = a_M + *min_element(tmp, tmp + N) + 1;
	while (ng - ok > 1) {
		ll mid = ok + (ng - ok) / 2;
		ll* cnt = new ll[N];
		for (int i = 0; i < N; ++i) cnt[i] = 0;
		for (int i = 0; i < N; ++i) {
			if (tmp[i] >= mid) {
				++cnt[0];
				continue;
			}
			if (tmp[i] + a_M < mid) {
				ng = mid;
				goto END_LOOP;
			}
			ll sq = my_sqrt(tmp[i] + a_M - mid);
			ll l = i - sq, r = i + sq;
			if (sq * sq == tmp[i] + a_M - mid) {
				++r;
			}
			else {
				++l;
			}
			++cnt[max(l, 0LL)];
			if (r < N) --cnt[r];
		}
		if (cnt[0] >= N) {
			ok = mid;
			goto END_LOOP;
		}
		for (int i = 1; i < N; ++i) {
			cnt[i] += cnt[i - 1];
			if (cnt[i] >= N) {
				ok = mid;
				goto END_LOOP;
			}
		}
		ng = mid;
	END_LOOP:;
		delete[] cnt;
	}
#ifdef DEBUG
	cout << "----ans----" << endl;
#endif
	cout << ok << endl;
#ifdef DEBUG
	cout << "-----------" << endl;
#endif
	delete[] u2, u1, c, tmp;
	return true;
}

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


Measured memory_bytes: 129820
using System;
using System.Collections.Generic;

namespace abc173_c
{
    class Program
    {
        static void Main(string[] args)
        {
            var H = CIn.ReadInt();
            var W = CIn.ReadInt();
            var K = CIn.ReadInt();
            var c = CIn.ReadStringArray(H);
            
            var ans = 0;
            for(int bit = 0; bit < Math.Pow(2 ,H); bit++)
            {
                for (int bit2 = 0; bit2 < Math.Pow(2, W); bit2++)
                {
                    var x = 0;
                    for (int i = 0; i < H; i++)
                    {
                        for (int j = 0; j < W; j++)
                        {
                            if ((bit >> i & 1) == 0 && (bit2 >> j & 1) == 0 && c[i][j] == '#')
                            {
                                x += 1;
                            }
                        }
                    }
                    if (x == K)
                    {
                        ans += 1;
                    }
                }
            }
            Console.WriteLine(ans);
            
        }
    }
    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }

            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }

            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }

            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }

            return array;
        }
        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];

            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }

            return array;
        }
    }

}


Measured memory_bytes: 28236
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int n;
    string s;
    cin>>n;
    cin>>s;
    char c[4];
    c[3]='e';
    string sd;
    int ans=0;
    for(int i=0;i<1000;i++){
        if(i<100){
            c[0]='0';
            if(i<10){
                c[1]='0';
                sd=to_string(i);
                c[2]=sd[0];
            }
            else{
                sd=to_string(i);
                c[1]=sd[0];
                c[2]=sd[1];
            }
        }
        else{
            sd=to_string(i);
            c[0]=sd[0];
            c[1]=sd[1];
            c[2]=sd[2];
        }
        int d=0;
        for(int j=0;j<n;j++){
            if(s[j]==c[d]){d++;}
        }
        if(d==3){ans++;}
        d=0;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int h[10];
	int i, j;
	int M,idx;
	char buf[8];
	
	for(j=0;j<10; j++){
		fgets(buf, 8, stdin);
		h[j] = strtol(buf, NULL, 10);
	}
	for(i=0;i<3;i++){
		M=0;
		for(j=0;j<10;j++){
			if(h[j] > M){
				M=h[j];
				idx = j;
			}
		}
		printf("%d\n",M);
		h[idx] = 0;
	}
	return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;

    int cntA = 0;
    int cntB = 0;
    REP(i, n) {
        if (s[i] == 'a') {
            if (cntA + cntB < a + b) {
                cout << "Yes" << '\n';
                cntA++;
            } else cout << "No" << '\n';
        } else if (s[i] == 'b') {
            if (cntA + cntB < a + b) {
                if (cntB < b) {
                    cout << "Yes" << '\n';
                    cntB++;
                } else cout << "No" << '\n';
            } else cout << "No" << '\n';
        } else cout << "No" << '\n';
    }
    return 0;
}

Measured memory_bytes: 848
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define soja(i,a,n) for(ll i=a;i<=n;i++)
#define ulta(i,n,a) for(ll i=n;i>=a;i--)
#define pb push_back
int main()
{
    ll n,m,k,sum=1,t=1e9+7;
cin>>n>>m>>k;
if(m*k>=n)
cout<<"Yes"<<endl;
else 
cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#define N 150000
using namespace std;
int main(){
  int n,p,sosu[N],i,j,result,data[N],l,flag,temp;
  for(i=0;i<N;i++) sosu[i]=1;
  sosu[0]=0;
  sosu[1]=0;
  for(i=2;i<N/2;i++){
    if(sosu[i]==1){
      for(j=i*2;j<N;j+=i){
        sosu[j]=0;
      }
    }
  }
  while(1){
    flag=0;
    l=0;
    cin >> n >> p;
    if(n==-1&&p==-1) break;
    for(i=n+1;i<N;i++){
      if(sosu[i]==1){
    for(j=n+1;j<=i;j++){
          if(sosu[j]==1){
            data[l]=i+j;
        l++;
        if(l==p+300){
          flag=1;
          break;
        }
      }
    }
    if(flag==1) break;
      }
    }
    for(i=1;i<p+300;i++){
      for(j=1;j<p+300;j++){
    if(data[j]<=data[j-1]){
      temp=data[j];
      data[j]=data[j-1];
      data[j-1]=temp;
    }
      }
    }
    cout << data[p-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1752
#include<stdio.h>
#define MAX 10000001
#define INF 20000000

void search(int);

typedef struct{
    int next;//次に訪れる頂点
    int now;//今いる頂点
    int cost;//nowからnextまでにかかるコスト(重み)
}Dist;

int n;
int d[MAX];//それぞれの頂点の重み
Dist D[MAX];

//スタックかキュー構造で格納している？
int main(){
    int i, j;
    int u, k, cnt = 0;

    scanf("%d", &n);
    for(i = 0 ; i < n ; i++){
        d[i] = INF;
        scanf("%d%d", &u, &k);
        for(j = 0 ; j < k ; j++){
            D[cnt].now = u;
            scanf("%d%d", &D[cnt].next, &D[cnt].cost);
            cnt++;
        }
    }

    search(cnt);//頂点の数を送る

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

    return 0;
}

void search(int v){
    int i;
    int flag = 0;

    d[0] = 0;

    while(flag != 1){
        flag = 1;
        for(i = 0 ; i < v ; i++){
            if(D[i].cost + d[D[i].now] < d[D[i].next]){
                d[D[i].next] = D[i].cost + d[D[i].now];
                flag = 0;
            }
        }
    }
}



Measured memory_bytes: 7632
#include<bits/stdc++.h>
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long c,k;
    cin>>c;
    vector<long long>v;
    for(int i=0; i<c; i++)
    {
        cin>>k;
        v.push_back(k);

    }
    bool  A[c]= {false};
    long long  alice=0,bob=0;
    bool alc=true,bo=false;
    for(int j=0; j<c; j++)
    {
         long long mx=0;
         int h=0;
         //max
        for(int i=0; i<c; i++)
        {
             if(v[i]>mx&&(!A[i])){
                mx=v[i];
                h=i;
             }
        }
        A[h]=true;
        if(alc==true){
            alc=false;
            bo=true;
            alice+=mx;
        }
        else{
            alc=true;
            bo=false;
            bob+=mx;
        }

    }
    cout<<alice-bob;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(it,st,en) for(int it=(st);it<(int)(en);++it)
#define allof(c) (c).begin(), (c).end()
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define X first
#define Y second
typedef long long int ll; 
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
const int INF=(int)1e9; 
const double EPS=(ld)1e-7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    vector<int> cnt(30,0);
    rep(i,0,h){
        string s;
        cin>>s;
        for(char c:s) cnt[c-'a']++;
    }
    vector<char> c1;
    vector<char> c2;
    rep(i,0,30){
        if(cnt[i]%2 == 1) {
            c1.pb(i+'a');
            --cnt[i];
        }
        if(cnt[i]%4 == 2) {
            c2.pb(i+'a');
            cnt[i]-=2;
        }
    }
    if(h%2 == 0 && w%2 == 0){
        if(c1.size() || c2.size()){
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }
    if(h%2 == 0 && w%2 == 1){
        if(c1.size()){
            cout<<"No"<<endl;
            return 0;
        }
        if(c2.size() > h/2){
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }
    if(h%2 == 1 && w%2 == 0){
        if(c1.size()){
            cout<<"No"<<endl;
            return 0;
        }
        if(c2.size() > w/2){
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }
    if(h%2 == 1 && w%2 == 1){
        if(c1.size() > 1){
            cout<<"No"<<endl;
            return 0;
        }
        if(c2.size() > w/2 + h/2){
            cout<<"No"<<endl;
            return 0;
        }
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def solve():
    H, W, M = map(int, input().split())
    N = 3 * 10 ** 5
    cnth = [0] * N
    cntw = [0] * N
    st = set()
    for i in range(M):
        h, w = map(lambda x: int(x) - 1, input().split())
        cnth[h] += 1
        cntw[w] += 1
        st.add((h, w))
    mh = max(cnth)
    mw = max(cntw)
    Y = []
    X = []
    for i in range(H):
        if cnth[i] == mh:
            Y.append(i)
    for i in range(W):
        if cntw[i] == mw:
            X.append(i)
    for y in Y:
        for x in X:
            if not (y, x) in st:
                return mh + mw
    return mh + mw - 1

print(solve())


Measured memory_bytes: 177372
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	string s,t;cin>>s>>t;
	int slen=s.size(),tlen=t.size();

	int dp[slen+1][tlen+1];//dpはi,j文字目までの編集距離を示す
	rep(i,slen+1) dp[i][0]=i;
	rep(j,tlen+1) dp[0][j]=j;

	for(int i=0;i<slen;i++){
		for(int j=0;j<tlen;j++){
			if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j];
			else dp[i+1][j+1]=min(dp[i][j]+1,min(dp[i+1][j]+1,dp[i][j+1]+1));
		}
	}

	cout<<dp[slen][tlen]<<endl;
}


Measured memory_bytes: 7144
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAX = 1e5 + 47;
const LL MAXN = 2e5 + 47;

int s(int n)
{
	int r = 0;
	while (n)
	{
		r += (n % 10);
		n /= 10;
	}
	return r;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	LL n;
	cin >> n;
	if (n < 1000)
	{
		int ans = 0;
		FOR(i, 1, n + 1)
			ans = max(ans, s(i));
		cout << ans << endl;
		return 0;
	}

	LL x = n;
	int d = 0;
	LL f;
	bool ok = 1;
	while (x)
	{
		f = x;
		++d;
		if (x > 9 && (x % 10 != 9))
			ok = 0;
		x /= 10;
	}

	if (ok)
	{
		cout << 9 * d - (9 - f) << endl;
		return 0;
	}

	LL ans = 9 * (d - 1);
	ans += (f - 1);

	cout << ans;
	cin >> n;
	return 0;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0031&lang=jp

#include <algorithm>
#include <iostream>
#include <vector>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <math.h>
#include <iomanip>
#include <sstream>

using namespace std;

//テ」ツδ榲」ツつッテ」ツδュテ・ツョツ堙ァツセツゥ
#define ALL(v) (v).begin(),(v).end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,a,b) for(int i=(int)(a); i<(int)(b); ++i)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define SORT(x) sort(begin(x),end(x))
#define SELECT_SORT(x, n) sort(begin(x),begin(x)+n)
#define SWAP(type, a, b) do {type tmp = a; a = b; b = tmp;} while (0)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

//テ・ツョツ堙ヲツ閉ー
#define INF 2000000000000
#define MAX 10

//DEBUGテァツ板ィ
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

vector<int> weight;

void binary(int x)
{
	int y,i,ans;
	ans=0;
	i=0;
	bool first=true;
	while (x>0)
	{
		y=x%2;
		ans=ans+y*pow(10,i);
		if(y){
			if(first){
				cout << weight[i]; first=false;
			}else{
				cout << " " << weight[i];
			}
		}
		x=x/2;
		i=i+1;
	}
	return;
}

int main()
{
	weight.push_back(1);
	for(int i=1; i<10; ++i){
		weight.push_back(weight[i-1]*2);
	}
	
	int obj;
	
	while(cin >> obj)
	{
		
		binary(obj);
		cout << endl;
	}
	
}

Measured memory_bytes: 1208
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N, K;
vector<ll> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> K;
  A.resize(N);
  map<ll, ll> mp;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
  }

  int cnt = 0;
  priority_queue<ll> pq;
  for (auto &e : mp) {
    pq.push(e.second);
    cnt++;
  }

  int size = pq.size();
  int ans = 0;
  for (int i = 1; i <= size; i++) {
    int n = pq.top();
    pq.pop();
    if (i > K) {
      ans += n;
    }
  }

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

Measured memory_bytes: 16500
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    int n,k,d;
    cin>>n>>k;
    int arr[n+1]={0};
    while(k-->0){
        cin>>d;
        int a[d+1];
        for(int i=1;i<=d;i++)
        cin>>a[i];
        for(int i=1;i<=d;i++){
            arr[a[i]]++;
        }
    }
    int c=0;
    for(int i=1;i<=n;i++){
        if(arr[i]==0)
        c++;
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 3624
import sys
def input():
    return sys.stdin.readline()[:-1]
import time

N = int(input())
A = [[int(x)-1 for x in input().split()] for i in range(N)]
P = [0] * N
cnt = 0
ALL = N*(N-1)//2
s = time.time()
for day in range(ALL):
    if time.time()-s > 1.6:
        print(N*(N-1)//2)
        break
    used = [0] * N
    flag = 0
    for i, p in enumerate(P):
        if p != N-1 and used[i] == 0:
            x = A[i][p]
            if x < N and used[x] == 0 and A[x][P[x]] == i:
                P[i] += 1
                P[x] += 1
                used[i] = 1
                used[x] = 1
                flag = 1
                cnt += 1
    if cnt == ALL:
        print(day+1)
        break
    if flag == 0:
        print(-1)
        break


Measured memory_bytes: 55640
# coding: utf-8
K=int(input())

lun=[[] for i in range(10)]

for i in range(10):
    for j in range(10):
        if abs(i-j)<=1:
            lun[i].append(j)

lunlun=[[1,2,3,4,5,6,7,8,9]]

for i in range(9):
    lunlun.append([])

for i in range(9):
    for j in range(len(lunlun[i])):
        for k in range(len(lun[lunlun[i][j]%10])):
            lunlun[i+1].append(lunlun[i][j]*10+lun[lunlun[i][j]%10][k])
LUNLUN=[]

for i in range(10):
    LUNLUN.extend(lunlun[i])
LUNLUN.sort

print(LUNLUN[K-1])




Measured memory_bytes: 13500
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,o,u) for(int i = o;i <= u; i++)
using namespace std;
short a[2000000];
short b[2000000];
int main(){
	int n;
	int c[10001];
	rep(i,0,10000) c[i] = 0;
	cin >> n;
	rep(i,0,n-1){ cin >> a[i];c[a[i]]++; }
	rep(i,1,10000){ c[i] += c[i-1]; }
	rep(i,0,n-1){
		b[c[a[i]]] = a[i];
		c[a[i]]--;
	}
	rep(i,1,n){ cout << b[i] ;if(i != n) cout << " ";}
	cout << endl;
	return 0;
}

Measured memory_bytes: 10860
sx, sy, tx, ty = map(int, input().split())

res = ""
res += "U" * (ty - sy) + "R" * (tx - sx)
res += "D" * (ty - sy) + "L" * (tx - sx)
res += "L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "D"
res += "R" + "D" * (ty - sy + 1) + "L" * (tx - sx + 1) + "U"

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  if(d==25){
    cout<<"Christmas"<<endl;
  }else if(d==24){
    cout<<"Christmas Eve"<<endl;
  }else if(d==23){
    cout<<"Christmas Eve Eve"<<endl;
  }else{
    cout<<"Christmas Eve Eve Eve"<<endl;
  }
}


Measured memory_bytes: 256
/**
    Bismillahir Rahmanir Rahim
    Md. Rakibul Islam
    Dept. of CSE, CoU
    **/
#include<bits/stdc++.h>
#define ll              long long int
#define ull             unsigned long long int
#define sc              scanf
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define pf              printf
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    char st[4];
    int t, n, m, i, j, k, l;
    cin>>t;
    if(t<=999)
        cout<<"ABC"<<endl;
    else
        cout<<"ABD"<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final String BOMB = "#";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == b) {
            System.out.println(c);
            return;
        }
        if (a == c) {
            System.out.println(b);
            return;
        }
        System.out.println(a);
    }

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define N 100005
#define m_p make_pair
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int a[N];
set<int> s;
map<int, int> f;
int main(){
	int i, j, n, m, flag, s1, s2, s3, s4, m1, m2;
	n = read();
	for(i = 1; i <= n; i++) a[i] = read(), s.insert(a[i]);
	if(s.size() == 1){
		printf("%d", n / 2);
		return 0;
	}
	s1 = s2 = s3 = s4 = m1 = m2 = 0;
	for(i = 1; i <= n; i += 2){
		f[a[i]]++;
	}
	for(auto u: f){
		if(u.second > s1){
			s2 = s1;
			s1 = u.second;
			m1 = u.first;
		}
		else s2 = max(s2, u.second);
	}
	f.clear();
	for(i = 2; i <= n; i += 2){
		f[a[i]]++;
	}
	for(auto u: f){
		if(u.second > s3){
			s4 = s3;
			s3 = u.second;
			m2 = u.first;
		}
		else s4 = max(s4, u.second);
	}
	if(m1 != m2){
		printf("%d", n - s1 - s3);
	}
	else{
		printf("%d", min(n - s1 - s4, n - s2 - s3));
	}
	return 0;
}


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

struct Edge {
    int to, id;
    Edge(int _to, int _id) : to(_to), id(_id) {}
};

int main() {
    int N; cin >> N;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }
    int K = 0;
    for(int i = 0; i < N; ++i) {
        K = max(K, (int)G[i].size());
    }
    stack<tuple<int, int, int>> st;
    st.emplace(0, -1, 0);
    vector<int> ans(N - 1);
    while(!st.empty()) {
        int cur, pre, col;
        tie(cur, pre, col) = st.top();
        st.pop();
        for(auto &e : G[cur]) {
            if(e.to == pre) continue;
            if(++col > K) col = 1;
            ans[e.id] = col;
            st.emplace(e.to, cur, col);
        }
    }
    cout << K << '\n';
    for(int i = 0; i < N - 1; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}


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

int main() {
  
  string S;
  cin >> S;
  
  if(S.at(0)=='S' && S.at(1)=='S' && S.at(2)=='S'){
    cout << 0 << endl;
  }
  else if(S.at(0)=='S' && S.at(1)=='S' && S.at(2)=='R'){
    cout << 1 << endl;
  }
  else if(S.at(0)=='S' && S.at(1)=='R' && S.at(2)=='S'){
    cout << 1 << endl;
  }
  else if(S.at(0)=='R' && S.at(1)=='S' && S.at(2)=='S'){
    cout << 1 << endl;
  }
  else if(S.at(0)=='S' && S.at(1)=='R' && S.at(2)=='R'){
    cout << 2 << endl;
  }
  else if(S.at(0)=='R' && S.at(1)=='S' && S.at(2)=='R'){
    cout << 1 << endl;
  }
  else if(S.at(0)=='R' && S.at(1)=='R' && S.at(2)=='S'){
    cout << 2 << endl;
  }
  else if(S.at(0)=='R' && S.at(1)=='R' && S.at(2)=='R'){
    cout << 3 << endl;
  }
  
}

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

int main() {
    int n, k, mi=1;
    cin >> n >> k;
    REP(i,n){
        mi = min(mi*2, mi+k);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

string S;
int K, N;
int dp[110][2][4];

void dfs(vector<int>& v, int last, int rest){
    if(rest == 0){

    }
    for(int i = last; i < N; i++){

    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> S >> K;
    N = S.length();
    dp[0][1][0] = 1;
    for(int i = 0; i < N; i++){
        int num = S[i] - '0';
        if(num == 0){
            for(int j = 0; j <= K; j++){
                dp[i + 1][1][j] += dp[i][1][j];
            }
        }else{
            for(int j = 0; j < K; j++){
                dp[i + 1][1][j + 1] += dp[i][1][j];
            }
            for(int j = 0; j < K; j++){
                dp[i + 1][0][j + 1] += dp[i][1][j] * (num - 1);
            }
            for(int j = 0; j <= K; j++){
                dp[i + 1][0][j] += dp[i][1][j];
            }
        }
        for(int j = 0; j <= K; j++){
            dp[i + 1][0][j] += dp[i][0][j];
        }
        for(int j = 0; j < K; j++){
            dp[i + 1][0][j + 1] += dp[i][0][j] * 9;
        }
    }
    cout << dp[N][0][K] + dp[N][1][K] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable : 4996)
int main()
{
	int n = 0;
	int k = 0;
	int price[1000] = { 0 };
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &price[i]);
	}
	
	int swap = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n - i - 1; j++) {
			if (price[j] > price[j + 1]) {
				swap = price[j];
				price[j] = price[j + 1];
				price[j + 1] = swap;
			}
		}
	}

	int total = 0;
	for (int i = 0; i < k; i++) {
		total = total + price[i];
	}
	printf("%d\n", total);

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  for(int i = 0; i < 26; i++)if (s.find('a' + i) == string::npos){
    cout << (char)('a' + i) << endl;
    return 0;
  }
  cout << "None" << endl;
}

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

int main(){
  int n, y;
  cin >> n >> y;
  int tenk_max=y/10000;
  int ans=0;
  for(int i=tenk_max;i>=0;i--){
    int sum=i*10000;
    if (i > n || sum > y){
      continue;
    }
    if (i == n && sum == y){
      cout << i << " 0 0" << endl;
      return 0;
    }
    int five_max=(y-sum)/5000;
    for(int j=five_max;j>=0;j--){
      int sum2=sum+j*5000;
      if(j > n || sum2 > y){
        continue;
      }
      if (i+j == n && sum2 == y){
        cout << i << " " << j << " 0" << endl;
        return 0;
      }
      if ((y-sum2) % 1000 != 0){
        continue;
      }else{
        int tenk = (y-sum2)/1000;
        if (i+j+tenk == n && sum2+1000*tenk==y){
          cout << i << " " << j << " " << tenk << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n, a;


int main(){
	scanf("%d ", &n);
	map<int, int> m;
	FORI(0, n) {
		scanf("%d ", &a);
		m[a]++;
	}
	int ans = 0;
	for (map<int, int>::iterator p = m.begin(); p != m.end(); p++) {
		ans += p->second % 2;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 4992