akhauriyash/Code-Regression huggingface dataset:
use std::collections::HashSet;
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let nums: Vec<i64> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect();
    let x = nums[0];
    let n = nums[1];
    input.clear();

    io::stdin().read_line(&mut input)?;
    let mut ps: HashSet<i64> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect();

    if !ps.contains(&x) || n == 0 {
        println!("{}", x);
        return Ok(());
    }

    let mut all = Vec::new();
    for i in 0..=101 {
        if !ps.contains(&i) || i == x {
            all.push(i);
        }
    }
    let index = match all.binary_search(&x) {
        Ok(index) => index,
        _ => panic!(""),
    };
    if all[index + 1] - x >= x - all[index - 1] {
        println!("{}", all[index - 1]);
    } else {
        println!("{}", all[index + 1]);
    }
    Ok(())
}


Measured memory_bytes: 2188
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main()
{
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        if(a+b>=c&&c>=a)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
a, b, c = [int(i) for i in input().split()]

a, b, c = sorted([a, b, c])

cnt = 0
while a < c-1:
    a += 2
    cnt += 1

while b < c-1:
    b += 2
    cnt += 1

if a == c and b == c:
    print(cnt)
elif a == c or b == c:
    print(cnt+2)
else:
    print(cnt+1)

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

int main(){
    int N;
    cin >> N;
    map<int, int64_t> mp;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
        mp[A[i]]++;
    }
    int64_t ans = 0;
    for(auto& p : mp) ans += p.second*(p.second-1)/2;

    for(int a : A){
        int64_t val = mp[a];
        int64_t res = ans - val*(val-1)/2 + (val-1)*(val-2)/2;
        cout << res << endl;
    }
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int L = A + B , R = C + D;
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
X, Y, Z, K = [int(x) for x in input().split()]
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
C = [int(c) for c in input().split()]
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
ABC = []
for a in range(len(A)):
    if a+1 > K:
        break
    for b in range(len(B)):
        if b+1 > K:
            break
        elif (a+1)*(b+1) > K:
            break
        for c in range(len(C)):
            if (a+1)*(c+1) > K:
                break
            elif (b+1)*(c+1) > K:
                break
            elif (a+1)*(b+1)*(c+1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])
ABC = sorted(ABC, reverse=True)
for i in range(K):
    print(ABC[i])

Measured memory_bytes: 9564
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int n;
  cin >> n;
  vector<int> res(n);
  rep(i,n) {
    int a;
    cin >> a;
    res[a-1] = i+1;
  }
  print_array(res);
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int N;
	cin >> N;
	int a1[110];
	int a2[110];
	for (int i = 0; i < N; i++) {
		cin >> a1[i] ;
	}
	for (int i = 0; i < N; i++) {
		cin >> a2[i];
	}
	int max = 0;

	for (int i = 0; i < N; i++) {
		int temp = 0;
		for (int j = 0; j <= i; j++) temp += a1[j];
		for (int k = i; k < N; k++) temp += a2[k];
		if (max < temp) max = temp;
	}
	cout << max << endl;
		
	
	return 0;
	}














Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> x(n, 0);
  for (int i = 0; i < k; ++i) {
    int d;
    cin >> d;
    for (int j = 0; j < d; ++j) {
      int a;
      cin >> a;
      x.at(a-1)++;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (x.at(i) == 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#define index 100
int main(int argc, char const *argv[]) {
    
    int data[index];
    int N=0;
    std::cin>>N;
    for (int i=0; i<N; ++i) {
        std::cin>>data[i];
    }
    
    for (int i = 0; i<N; ++i) {
        int v = data[i];
        int j = i-1;
        while (0<=j && v<data[j]) {
            data[j+1]=data[j];
            j--;
        }
        data[j+1] = v;
        
        for (int i = 0; i<N; ++i) {
            std::cout<<data[i];
            if (!(i==N-1)) {
                std::cout<<" ";
            }else{
                std::cout<<std::endl;;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <string.h>

int main(void)
{
    int t, h;
    int n;
    char s1[128], s2[128];
    int c;

    scanf("%d", &n);
    t = h = 0;
    while (n--){
        scanf("%s %s", s1, s2);
        c = strcmp(s1, s2);
        if (c > 0) t += 3;
        else if (c < 0) h += 3;
        else ++t, ++h;
    }
    printf("%d %d\n", t, h);

    return 0;
}



Measured memory_bytes: 2056
// ABC 119

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;

class Program
{
    static void Main()
    {
        int[] s = Console.ReadLine().Split('/').Select(int.Parse).ToArray();
        if (s[0] < 2019)
        {
            Console.WriteLine("Heisei");
            return;
        }
        if (s[0] == 2019 && s[1] < 5)
        {
            Console.WriteLine("Heisei");
            return;
        }
        Console.WriteLine("TBD");
    }
}

Measured memory_bytes: 11348
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n, i, ans, sum = 0, tmp = 0;
    scanf("%d", &n);
    int w[n];
    for(i = 0; i < n; ++i){
        scanf("%d", &w[i]);
        sum += w[i];
    }
    for(i = 0; i < n; ++i){
        tmp += w[i];
        if(sum - tmp*2 <= 0){ans = abs(sum - tmp*2); break;}
    }
    if( (tmp = abs(sum - (tmp-w[i])*2)) < ans){ans = tmp;}
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<vector<bool>> map1(N, vector<bool>(N, false));
    for(int i = 0;i < N;i++) {
        for(int j = 0;j < N;j++) {
            if (s[i] == s[j]) {
                map1[i][j] = true;
            }
        }
    }
    int ans = 0;
    for(int i = 1;i < N ;i++) {
        for(int j = 0;i+j < N;j++) {
            int cj = j;
            if(map1[j][i+j]) {
                for(;i+j < N && map1[j][i+j] && j-cj < i;j++) {}
                ans = max(ans, j-cj);
            }
        }
    }
    for(int i = 1;i < N;i++) {
        for(int j = 0;i+j < N;j++) {
            int cj = j;
            if(map1[i+j][j]) {
                for(;i+j < N && map1[i+j][j] && j-cj < i;j++) {}
                ans = max(ans, j-cj);
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3584
#include <iostream>

using namespace std;

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

    int taro = 0;
    int hanako = 0;

    for (int i = 0; i < n; i++) {
        string t,h;
        cin >> t >> h;
        int comp = t.compare(h);
        if (comp > 0) {
            taro += 3;
        } else if (comp < 0) {
            hanako += 3;
        } else {
            taro += 1;
            hanako += 1;
        }
    }
    cout << taro << " " << hanako << endl;
    return 0;
}

Measured memory_bytes: 1212
using System;
using System.Collections.Generic;
using System.Text;

namespace codeTester.contest190616
{
    class ProblemA
    {
        static List<int> values = new List<int>();
        static int answer = 0;

        public static void Main(string[] args)
        {
            Input();
            Logic();
            Output();
        }

        static void Input()
        {
            values = IOUtilities.ReadSpaceSeparatedValues();
        }

        static void Logic()
        {
            if (values[0] < values[1])
            {
                answer = 0;
            } else
            {
                answer = 10;
            }
        }

        static void Output()
        {
            Console.WriteLine(answer.ToString());
        }
    }
}
    class IOUtilities
    {
        public static List<int> ReadSpaceSeparatedValues()
        {
            List<int> values = new List<int>();
            string[] inputs = Console.ReadLine().Split(' ');
            foreach (string input in inputs)
            {
                values.Add(int.Parse(input));
            }

            return values;
        }

        public static List<int> ReadIndentationSeparatedValues(int num)
        {
            List<int> values = new List<int>();
            for (int i = 0; i < num; i++)
            {
                string input = Console.ReadLine();
                values.Add(int.Parse(input));
            }

            return values;
        }

        public static List<List<int>> ReadIndentationSeparatedLists(int num)
        {
            List<List<int>> Lists = new List<List<int>>();
            for (int i = 0; i < num; i++)
            {
                Lists.Add(ReadSpaceSeparatedValues());
            }
            return Lists;
        }
    }

Measured memory_bytes: 11092
#include<iostream>
#include<cmath>

using namespace std;
class Dice{
public:
    int face[7],n;
    Dice(){}
    void role_E(){
        role(1,3,6,4);
    };
    void role_N(){
        role(1,5,6,2);
    };
    void role_S(){
        role(1,2,6,5);
    };
    void role_W(){
        role(1,4,6,3);
    };
    void role_z(){
        role(2,3,5,4);
    }
    
    void role(int i, int j, int k, int l){
        n = face[l],face[l] = face[k], face[k] = face[j], face[j] = face[i], face[i] = n;
        
    }

};
bool sam(Dice C1, Dice C2){
    for (int i = 1; i < 7; i++){
        if (C1.face[i] != C2.face[i]) return false;
        
    }return true;
}
bool same(Dice C1, Dice C2){
    for (int i = 0; i < 6; i++){
        for(int j = 0; j < 4; j++){
            if(sam(C1,C2)) return true;
            C1.role_z();
        }
        if(i % 2 == 0) C1.role_W();
        else C1.role_N();
    }return false;
}
Dice dice[100]; int n;
bool ch(){
     for(int i = 0; i<n-1; i++){
        for(int j = i+1; j<n; j++){
            if(same(dice[i],dice[j])) return false;
        }
    }return true;
 
}
int main(){
    cin >>n;
    for(int i = 0; i<n; i++){
        for (int j = 1; j<7; j++){
            cin >>dice[i].face[j];
        }
    }
    
    if(ch()) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
 return 0;
}



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

int par[100000];
int ran[100000];
int num[100000];

void init(int n){
  rep(i,0,n){
    par[i]=i;
    ran[i]=0;
    num[i]=1;
  }
}

int find(int x){
  if(par[x]==x) return x;
  return par[x]=find(par[x]);
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(ran[x]<ran[y]){
    par[x]=y;
    num[y]+=num[x];
  }
  else{
    par[y]=x;
    num[x]+=num[y];
    if(ran[x]==ran[y]) ran[x]++;
  }
}

int size(int x){
  return num[find(x)];
}

bool same(int x,int y){
  return find(x)==find(y);
}

int main(){
  ll n,m;
  cin>>n>>m;
  init(n);
  int a[m];
  int b[m];
  rep(i,0,m){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
  }
  ll ans[m+1];
  ans[0]=0;
  rep(i,0,m){
    if(same(a[m-1-i],b[m-1-i])){
      ans[i+1]=ans[i];
    }
    else{
      ans[i+1]=ans[i]+size(a[m-1-i])*size(b[m-1-i]);
      unite(a[m-1-i],b[m-1-i]);
    }
  }
  rep(i,0,m){
    cout<<n*(n-1)/2-ans[m-1-i]<<endl;
  }
}

Measured memory_bytes: 4096
import java.io.*;
import java.util.*;

public class Main{


	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int A=sc.nextInt(),B=sc.nextInt(),Q=sc.nextInt();
		TreeSet<Long>S=new TreeSet(),T=new TreeSet();
		long INF=(long)1e13;
		S.add(INF);
		S.add(-INF);
		T.add(INF);
		T.add(-INF);
		while(A-->0)
			S.add(sc.nextLong());
		while(B-->0)
			T.add(sc.nextLong());
		while(Q-->0) {
			long x=sc.nextLong();
			long s1=S.lower(x),s2=S.higher(x),t1=T.lower(x),t2=T.higher(x);
			long d1=x-s1,d2=t2-x;
			long op=2*Math.min(d1,d2)+Math.max(d1, d2);
			d1=x-t1;
			d2=s2-x;
			op=Math.min(op, 2*Math.min(d1,d2)+Math.max(d1, d2));
			out.println(Math.min(x-Math.min(s1,t1),Math.min(Math.max(s2, t2)-x,op)));
		}
		
		out.close();
	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

int main() {
  int H, N;
  cin >> H >> N;
  int total = 0;
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    total += a;
  }
  if(total >= H) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long 
    #define pb push_baack 
    using namespace  std ;
    vector<int>vc;
    vector<int>cv;
    vector<int>gh;
    int main(){
     
    int a, b ;
    cin>>a>>b;
    if(a>0 && a<=9 && b>0 && b <= 9){
    	cout<<a*b<<endl;
    	return 0;
    }
    else {
    	cout<<-1<<endl;
    	return 0;
    }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
int main() {
  int H , W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H)cin >> S[i];
  
  rep(i,H)rep(j,W){
    if(S[i][j] == '.'){
      S[i][j] = '0';
      for(int dx = -1;dx <= 1;dx++){
        for(int dy = -1;dy <= 1;dy++){
          int x = i + dx,y = j + dy;
          if(0 <= x&& x < H && 0 <= y && y < W){
            if(S[x][y] == '#'){
              S[i][j] ++;
            }
          }
        }
      }
    }
  }
  rep(i,H)cout << S[i] << endl;
}

Measured memory_bytes: 256
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout<<endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x ; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		string ans = "";
		while (n != 0) {
			n--;
			ll rem = n % 26;
			ans = char(97 + rem) + ans;
			n /= 26;
		}

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



Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N, A, B; cin >> N >> A >> B;
  vector<ll> h(N);
  rep(i, N) cin >> h[i];
  sort(all(h));

  ll low = 1;
  ll high = 1e9;
  ll ans;
  while (true) {
    ans = (low + high) / 2;
    if (high == low) break;

    ll cnt = 0;
    rep(i, N) {
      ll a = h[i] - ans * B;
      ll b = A - B;
      if (a <= 0) continue;
      cnt += (a + (b - 1)) / b;
    }

    if (cnt < ans) {
      high = ans;
    } else if (cnt > ans) {
      low = ans + 1;
    }

    if (cnt == ans) break;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int K, X;
	cin >> K >> X;
	if(500*K >= X) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#define N 100005
using namespace std;
typedef long long ll;
int n, a, b;
int h[N];
int main() {
	cin>>n>>a>>b;
	for (int i = 1; i <= n; ++i) {
		cin>>h[i];
	}
	int l = 0, r = 1000000000;
	int c = a-b;
	while(l < r) {
		int mid = (l+r)/2;
		ll cnt=0;
		for (int i =1; i <= n; ++i) {
			ll det = h[i] - (ll)mid * (ll)b;
			if (det > 0) {
				cnt += (det + c-1) /c;
			}
		}
		if (cnt <= mid) {
			r = mid;
		} else {
			l = mid+1;
		}
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int D = N / 999;
    if(N % 999 == 0) {
      D--;
    }
      if(D == 0) {
        System.out.println("ABC");
      }
      
      else if(D == 1) {
        System.out.println("ABD");
      }
  }
}
 

Measured memory_bytes: 21588
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); i++)
#define rep1(i,n) for(int (i) = 1; (i) <= (int)(n); i++)
#define INF 1000000
#define MOD 998244353



int main()
{
    ll H,W;
    cin >> H >> W;
    
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (ll) (H * W + 1 )/ 2 << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

while len(a) > 1:
    min_ = a[-1]
    new = []
    for i in a:
        if i % min_ :
            new.append(i%min_)
    new.append(min_)
    new.sort(reverse=True)
    a = new
print(a[0])

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const ll mod = 998244353;
const int DEG = 30;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
static auto faster_iostream = []() {
    std::ios::sync_with_stdio(false);  // turn off sync
    std::cin.tie(nullptr);             // untie in/out streams
    return 0;
}();
int main(){
	ll a, b;
	cin >> a >> b;
	if(a >= 13) cout << b << endl;
	else if(a >= 6) cout << b / 2 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}

/*
<url:https://arc079.contest.atcoder.jp/tasks/arc079_b>
問題文============================================================
 長さ N の非負整数列 ai に対し、数列の最大値が N−1 以下になるまで以下の操作を繰り返し行うことを考えます。
 
 数列のうち最も大きい要素を求める、複数ある場合はどれか 1 つ選ぶ。
 この要素の値を N 減らす。これ以外の要素の値を 1 増やす。
 なお、この操作を行い続けると、いつかは数列の最大値が N−1 以下になることが証明できます。
 
 ここで、整数 K が与えられるので、
 この操作を行う回数がちょうど K 回になるような数列 ai を 1 つ求めてください。
 なお、この問題の入出力の制約下では、かならず 1 つは条件を満たすような数列が存在することが示せます。
=================================================================

解説=============================================================
 
 問題を逆から考える
 
 全ての数列がN-1以下であるものから
 要素を一つ選択して、値をN増やす。それ以外を1減らすという
 という条件でK回行うと考える
 
 ここで,
 
 0,1,2,...,N-1
 という数列を考え
 左から順番に要素を選択していけば N 回の施行において 全ての数列の値は +1 される
 
 よって、K/N加算された数列を K%N 回シュミレーションをすればいい
 
================================================================
*/
void solve(){
    ll K; cin >> K;
    const ll N = 50;
    vector<ll> a(N,0);
    iota(a.begin(),a.end(),0);
    for(int i = 0; i < N;i++) a[i] += K/N;
    K %= N;
    for(int i = 0; i < K;i++){
        a[i] += (N+1);
        for(int j = 0; j < N;j++) a[j]--;
    }
    cout << N << endl;
    for(int i = 0; i< N;i++){
        cout << a[i] << " ";
    }
    cout << endl;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    solve();
	return 0;
}


Measured memory_bytes: 384
n,a,b = map(int, input().split())
mod = 10**9+7

def cmb(n,k):
    x,y = 1,1
    for i in range(k):
        x = x * (n-i) % mod
        y = y * (i+1) % mod
    res = x * pow(y,mod-2,mod) % mod
    return res

ans = pow(2,n,mod) - 1 - cmb(n,a) - cmb(n,b)
ans %= mod
print(ans)

Measured memory_bytes: 38640
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

ans = 0
for i in range(N):
    ans = ans + B[i]

for i in range(N-1):
    if A[i+1] == A[i] + 1:
        ans = ans + C[A[i]-1]
        
print(ans)        

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

int main() {
    int32_t n, k;
    cin >> n >> k;
    set<int> d;
    for (int32_t i = 0; i < k; i++) {
        int32_t v;
        cin >> v;
        d.insert(v);
    }
    while(1) {
        bool f = true;
        for (int32_t m = n; m > 0; m /= 10) {
            int32_t l = m % 10;
            if (d.find(l) != d.end()) {
                f = false;
                break;
            }
        }
        if (f) {
            cout << n << endl;
            return 0;
        }
        n++;
    }
}


Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
s=input()
l=len(s)
count=0
#print(l)


if l%2==0:
    for i in range(0,int(l/2)):
        if s[i]!=s[(l-1)-i]:
            #print(i)
            #print("このときl-1は")
           # print(l-1)
            #print(s[i]+","+s[l-1])
            count+=1
        else:
            #print("こちらは")
            #print(i)
            #print("このときl-1は")
            #print(l-1)
            #print(s[i]+","+s[l-1])
            pass
            
else:
    N=Decimal(str(l/2)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    for i in range(0,int(N)):
        if s[i]!=s[(l-1)-i]:
            #print(i)
            #print("このときl-1は")
            #print(l-1)
            #print(s[i]+","+s[(l-1)-i])
            count+=1
            
        else:
            #print(i)
            #print("下の方でこのときl-1は")
            #print(l-1)
            #print(s[i]+","+s[(l-1)-i])
            pass

#print("count is")

print(count)

Measured memory_bytes: 5076
#include<stdio.h>
#include<string.h>
int main(){
    int a,b,n;
    int answer=0;
    scanf("%d %d %d %d",&n,&a,&b);
    for(int i=1;i<=n;i++){
        int num = i;
        int total=num%10;
        num/=10;
        while(num!=0){
            int buf = num%10;
            total+=buf;
            num/=10;
        }
        if(a<=total&&total<=b){
          answer+=i;
        }
    }
    printf("%d\n",answer);
    return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, N) FOR(i, 0, N)
#define SZ(x) ((int)(x).size())

const int MAXN = 200007, INF = 100000007;

int main()
{	
	int N, M, a, b, d[MAXN];
	vector <int> G[MAXN];
	queue <int> Q;
	scanf("%d%d", &N, &M);
	REP(i, M){
		scanf("%d%d", &a, &b);
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	d[0] = 0;
	Q.push(0);
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		if (d[v] < 2) REP(i, SZ(G[v])){
			int to = G[v][i];
			if (to != 0) Q.push(to);
			d[to] = d[v] + 1;
		}
	}
	if (d[N - 1] != 2) printf("IM");
	printf("POSSIBLE");
	//cout << endl; system("pause");//please
	return 0;
}//don't forget about const, please
/*
4
0 3 1 1
6 0 400 1
2 4 0 1
1 1 1 0
4 1 2 3
fictive
*/

Measured memory_bytes: 13168
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
using namespace std;



int main(){
  ll A,P;
  ll kakera,ans;
  cin>>A>>P;
  kakera=A*3+P;
  ans=kakera/2;
  cout<<ans<<endl;

  return 0;
}



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


public class Test
{	
    public static void Main()
	{
	    int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        if(nums[0] * nums[1] < nums[2]) Console.WriteLine(nums[0] * nums[1]);
        else Console.WriteLine(nums[2]);

	}
}

Measured memory_bytes: 13268
//abc137_b.cpp
//Sat Aug 10 20:49:42 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=max(-1000000,x-(k-1));i<=min(1000000,x+(k-1));i++){
		cout << i << " ";
	}
	printf("\n");
}

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

int main() {
  int64_t N, K;
  cin >> N >> K;

  if(N > K){
    N = N % K + K;
  }

  int64_t D = abs(N - K);
  //if(D < 0){cout << "error" << endl;}

  while(D < N){
      N = D;
      D = abs(N - K);
      if(D < 0){cout << "error" << endl;}
      if(D == 0){break;}
  }

  cout << N << endl;
}


Measured memory_bytes: 256
m=24*60*60
while True:
	n=int(raw_input())
	if n==0:break
	dp=[0]*(m+1)
	for _ in range(n):
		a,d=raw_input().split()
		a,b,c=map(int,a.split(':'));
		d,e,f=map(int,d.split(':'));
		dp[a*3600+b*60+c]+=1
		dp[d*3600+e*60+f]-=1
	for i in range(m):
		dp[i+1]+=dp[i]
	print(max(dp))

Measured memory_bytes: 11712
#include <stdio.h>

int main () {
	
	char x[4];
	int count = 0;
	
	for(int k = 0; k < 4; k++){
		scanf("%c", &x[k]);
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = i+1; j < 4; j++){
			if(x[i] == x[j]){
				count++;
			}
		}
	}
	
	if(count == 2){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	
	
	
	
	
	
	
	return 0;
}

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

bool dp[81][81][2*81*81];
int main(){
   int h,w; cin>>h>>w;
   vector<vector<int>> A(h,vector<int>(w));
   vector<vector<int>> B(h,vector<int>(w));
   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++) cin>>A[i][j];
   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++) cin>>B[i][j];
   
   dp[0][0][abs(A[0][0]-B[0][0])] = true;

   for(int i = 0; i < h; i++)for(int j = 0; j < w; j++)for(int k = 0;  k < (2*81*81); k++){
       if(!dp[i][j][k]) continue;
       if(i<h-1){
           int c = abs(A[i+1][j] - B[i+1][j]);
           dp[i+1][j][abs(k+c)] = true;
           dp[i+1][j][abs(k-c)] = true;
       }
       if(j<w-1){
         int c = abs(A[i][j+1] - B[i][j+1]);
        dp[i][j+1][abs(k+c)] = true;
        dp[i][j+1][abs(k-c)] = true;
       }
   }
   int ans = 1e9;
   for(int i = 0; i < 2*81*81; i++){
       if(dp[h-1][w-1][i]) ans = min(ans,i);
   }
  cout<<ans;
}


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

using namespace std;
using ll = long long;

const int nmax = 500;
int C[nmax], S[nmax], F[nmax];

int func(int v,int N);

int main() {
        int N;
        cin >> N;
        for (int i = 1; i < N; i++) {
                cin >> C[i] >> S[i] >> F[i];
        }

        for (int i = 1; i < N; i++) {
                cout << func(i, N) << endl;
        }

        cout << 0 << endl;

        return 0;
}


int func(int v,int N) {
        int ret = C[v] + S[v];

        for (int i = v+1; i < N; i++) {
                if(ret > S[i]) {
                        if (ret % F[i] == 0) {
                                ret += C[i];
                        }
                        else {
                                ret += F[i] - (ret % F[i]) + C[i];
                        }
                }
                else {
                        ret = S[i] + C[i];
                }
        }

        return ret;
}

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

int main(int argc, char* argv[]) {
    int x, y;
    cin >> x >> y;
    if (x > y){
        int tmp = x;
        x = y;
        y = tmp;
    }
    // x <= y
    while (1){
        if (y%x != 0){
            int tmp = y % x;
            y = x;
            x = tmp;
        }else{
            cout << x << "\n";
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 3088
process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!

function main(input) {
    var ans = 0;
    var arg = input.split('');
    for(var i = 0, l = arg.length; i < l; i++){
        if(arg[i] == '1') {ans++;}
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7752
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

template <typename T>
string join(const vector<T>& v, const char* delim = 0) {
  string s;
  if (!v.empty()) {
    s += v[0];
    for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
      if (delim) s += delim;
      s += v[i];
    }
  }
  return s;
}

template <typename T>
vector<vector<T>> transpose(vector<vector<T>>& v) {
  int row = v.size();
  int col = v[0].size();
  vector<vector<T>> trans(col, vector<T>(row));
  for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++) {
      trans[j][i] = v[i][j];
    }
  }
  return trans;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  string row_string = string(W, '.');
  vector<int> row_to_delete(0);
  string joined_string;
  // row
  for (int i = 0; i < H; i++) {
    vector<char> row = a[i];
    joined_string = join(row);
    if (joined_string == row_string) {
      row_to_delete.push_back(i);
    }
  }
  int size_row_to_delete = row_to_delete.size();
  for (int i = 0; i < size_row_to_delete; i++) {
    a.erase(a.begin() + row_to_delete[i]);
    int n = 0;
    for_each(row_to_delete.begin(), row_to_delete.end(),
             [n](int& x) mutable { x -= 1; });
  }
  // col
  string col_string = string(a.size(), '.');
  vector<vector<char>> transposed = transpose(a);
  vector<int> col_to_delete(0);
  for (int i = 0; i < W; i++) {
    vector<char> col = transposed[i];
    joined_string = join(col);
    if (joined_string == col_string) {
      col_to_delete.push_back(i);
    }
  }
  int size_col_to_delete = col_to_delete.size();
  for (int i = 0; i < size_col_to_delete; i++) {
    transposed.erase(transposed.begin() + col_to_delete[i]);
    int n = 0;
    for_each(col_to_delete.begin(), col_to_delete.end(),
             [n](int& x) mutable { x -= 1; });
  }
  vector<vector<char>> output = transpose(transposed);
  for (vector<char> row : output) {
    cout << join(row) << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;

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

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

int main(){

    ll A, B, C, ans;

    cin >> A >> B >> C;

    if(A == B)
        ans = C;
    if(B == C)
        ans = A;
    if(C == A)
        ans = B;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 924844033
#define N 4010
using namespace std;
int n, k, jc[N], inv[N], L[N], f[N], g[N], m, top, x, ans;
inline int C(int n, int m){return (ll)jc[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	scanf("%d%d", &n, &k); m=k*2;
	jc[0]=1; for(int i=1; i<=n; i++)jc[i]=(ll)jc[i-1]*i%mod;
	inv[0]=inv[1]=1; for(int i=2; i<=n; i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1; i<=n; i++)inv[i]=(ll)inv[i-1]*inv[i]%mod;
	for(int i=1; i<=k; i++)L[i*2-1]=L[i*2]=(n-i)/k;
	memset(f, 0, sizeof(f)); f[0]=1; top=0;
	for(int i=1; i<=m; i++){
		memcpy(g, f, sizeof(g)); memset(f, 0, sizeof(f));
		for(int j=0; j<=(L[i]+1)/2; j++){
			x=C(L[i]-j+1, j);
			for(int ii=0; ii<=top; ii++)f[ii+j]=(f[ii+j]+(ll)g[ii]*x%mod)%mod;
		}
		top+=(L[i]+1)/2;
	}
	ans=0;
	for(int i=0; i<=n; i++)
		if(i&1)ans=(ans-(ll)f[i]*jc[n-i]%mod+mod)%mod;
		else ans=(ans+(ll)f[i]*jc[n-i]%mod)%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7

N = int(input())

memo = {0:1, 1:2}
def f(n):
    if n not in memo:
        memo[n] = (f(n // 2) + f((n - 1) // 2) + f((n - 2) // 2)) % mod
    return memo[n]

print(f(N))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int m[3][3], n[3][3];
int T[3][3];

int main() {
	rep(i, 3) {
		rep(j, 3) cin >> m[i][j];
		rep(j, 3) cin >> n[i][j];
	}

	rep(i, 3) {
		rep(j, 3) {
			if (n[i][j] - m[i][j] >= 0) {
				T[i][j] = n[i][j] - m[i][j];
			}
			else {
				T[i][j] = 60 + n[i][j] - m[i][j];
				T[i][j - 1] -= 1;
				if (T[i][j - 1] < 0) {
					T[i][j - 1] += 60;
					T[i][j - 2] -= 1;
				}
			}
		}

	}

	rep(i, 3) {
		rep(j, 3) {
			if (j < 2) {
				cout << T[i][j] << ' ';
			}
			else cout << T[i][j] << endl;
		}
	}


	return 0;
}



Measured memory_bytes: 3096
x = int(input())
a = []
b = []
for i in range(-200,200):
    a.append([i, i**5])
    b.append([i, i**5])

n = len(a)

for i in range(n):
    for j in range(n):
        if a[i][1] - b[j][1] == x:
            print(str(a[i][0]) + " " + str(b[j][0]))
            exit()
        if b[j][1] - a[i][1] == x:
            print(str(b[j][0]) + " " + str(a[i][0]))
            exit()
        if a[j][1] - b[i][1] == x:
            print(str(a[j][0]) + " " + str(b[i][0]))
            exit()
        if b[i][1] - a[j][1] == x:
            print(str(b[i][0]) + " " + str(a[j][0]))
            exit()

Measured memory_bytes: 65136
// https://atcoder.jp/contests/arc062/tasks/arc062_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a1 = 1, a2 = 1;
    cin >> n;
    REP(i, n) {
        ll b1, b2;
        cin >> b1 >> b2;
        // ll m1 = a1 / b1 + (a1 % b1 ? 1 : 0);
        // ll m2 = a2 / b2 + (a2 % b2 ? 1 : 0);
        ll m1 = ceil((long double)a1 / b1);
        ll m2 = ceil((long double)a2 / b2);
        a1 = b1 * max(m1, m2);
        a2 = b2 * max(m1, m2);
    }
    cout << a1 + a2 << endl;

    return 0;
}


Measured memory_bytes: 256
use proconio::input;

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

    let mut sorted = a.clone();
    sorted.sort();
    let max = sorted[n-1];
    let secondary_max = sorted[n-2];
    for i in a {
        if i == max { println!("{}", secondary_max) }
        else { println!("{}", max) }
    }
}


Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double N,M,sum=0; cin >> N >> M;
  vector<int> A(N);
  bool ans = true;
  
  for(int i=0; i<N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  double judge = sum / (4*M);

  for(int i=0; i<M; i++) {
    if(A.at(i) < judge ) ans = false;
  }

  if(ans==true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define li long long int
using namespace std;

int main() {
	li n;
	cin>>n;
	vector<long long int >a(n),b(n);
	 for(li i = 0; i < n; i++ )
	 {
	 	cin>>a[i];
	 	b[i] = a[i];
	 }
	 sort(a.begin(),a.end());
	 for(li i = 0 ; i < n ; i++){
	 	if(b[i]==a[n-1])
	 	cout<<a[n-2]<<endl;
	 	else 
	 	cout<<a[n-1]<<endl;
	 }
	return 0;
}

Measured memory_bytes: 4736
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();

      int[] seqA = new int[n/2];
      int[] seqB = new int[n/2];

      List<Integer> listA = new ArrayList<>();
      List<Integer> listB = new ArrayList<>();
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      int offset=0,next=0;
      char regx = ' ';
      for(int i=0, j=0; i<n; i++, j= i >> 1) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        Integer num = Integer.valueOf(line.substring(offset, next));
        offset = ++next;

        if((i & 1) == 0) {
          seqA[j] = num;
          if(mapA.containsKey(num)) {
            mapA.replace(num, mapA.get(num) + 1);
          } else {
            mapA.put(num, 1);
            listA.add(num);
          }
        }
        else {
          seqB[j] = num;
          if(mapB.containsKey(num)) {
            mapB.replace(num, mapB.get(num) + 1);
          } else {
            mapB.put(num, 1);
            listB.add(num);
          }
        }
      }

      int vma,vmb,xa,xb;
      vma = vmb = xa = xb =0;
      for (Integer var : listA) {
        int ma = mapA.get(var);
        if(vma < ma) {
          vma = ma;
          xa = var;
        }
      }
      for (Integer var : listB) {
        int mb = mapB.get(var);
        if(vmb < mb) {
          vmb = mb;
          xb = var;
        }
      }

      int cca,ccb;
      cca = ccb = 0;
      for (int i : seqA) {
        if(i != xa) cca++;
      }
      for (int i : seqB) {
        if(i != xb) ccb++;
      }

      int vma2,vmb2,xa2,xb2;
      vma2 = vmb2= xa2 = xb2 =0;
      int cca2,ccb2;
      cca2 = ccb2 = 0;
      int ans = 0;
      if(xa == xb) {
        for (Integer var : listA) {
          int ma = mapA.get(var);
          if(var != xa && vma2 < ma) {
            vma2 = ma;
            xa2 = var;
          }
        }
        for (Integer var : listB) {
          int mb = mapB.get(var);
          if(var != xb && vmb2 < mb) {
            vmb2 = mb;
            xb2 = var;
          }
        }
      
        for (int i : seqA) {
          if(i != xa2) cca2++;
        }
        for (int i : seqB) {
          if(i != xb2) ccb2++;
        }

        ans = cca2 > ccb2 ? cca + ccb2 : cca2 + ccb;
      }
      else {
        ans = cca + ccb;
      }

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 46840
import resource
import sys
sys.setrecursionlimit(20000)
f = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
n, m = map(int, input().split())
a = list(map(int, input().split()))

memo = ["-1"] * 10100


def MAX(x, y):
    if y[0] != '#' and (x == "#" or len(x) < len(y) or (len(x) == len(y) and x < y)):
        return y
    else:
        return x


def dp(i):
    # i本のマッチを使って作れる最大の整数
    if i < 0:
        return "#"

    if memo[i] != "-1":
        return memo[i]

    if i == 0:
        return ""

    ret = "#"
    for x in a:
        ret = MAX(ret, dp(i - f[x]) + str(x))
    memo[i] = ret
    return ret


print(dp(n))


Measured memory_bytes: 30140
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

N,M,K = inputlist()
uf = UnionFind(N+1)
graph = [[] for _ in range(N+1)]
for i in range(M):
    a,b = inputlist()
    uf.union(a,b)
    graph[a].append(b)
    graph[b].append(a)
brogra = [[] for _ in range(N+1)]
li = [0]*N
for i in range(K):
    c,d = inputlist()
    if uf.same(c,d):
        brogra[c].append(d)
        brogra[d].append(c)
for i in range(1,N+1):
    li[i-1] = uf.size(i) - len(graph[i]) - len(brogra[i]) -1
print(*li)

Measured memory_bytes: 47120
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;
int main() {
ll N, a, b;cin >> N;
vector<ll> A(N);
vector<ll> B(N);

rep(i, 0, N){
cin >> A[i];
}

B = A;
sort(ALL(A));

a = A[N/2 - 1];b = A[N/2];

rep(i, 0, N){
if(B[i] <= a){cout << b << endl;continue;}
if(B[i] >= b)cout << a << endl;
}

}

Measured memory_bytes: 6440
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
 
#define endl '\n'
#define loop(i, m, n) for (ll i = m; i < n; i++)
#define loope(i, m, n) for (ll i = m; i <= n; i++)
#define epool(i, m, n) for (ll i = m; i >= n; i--)
#define mod 1000000007
#define mod2 998244353
#define vi vector<ll>
#define fi first
#define se second
#define pb push_back
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x,0;
#define all(v) v.begin(),v.end()
const ll INF=1e18;
const double PI=4*atan(1);

#define SpeedForce                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;

ll mpow(ll base,ll exp);
void solve();
ll POW(ll base,ll exp);
ll gcd(ll a,ll b);

ll modInverse(ll n) { 
    return mpow(n, mod-2); 
}
 
ll nCr(ll n, ll r){ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = (fac[i-1]*i)%mod; 
    return ((fac[r]%mod)*(fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod)*(fac[n]* modInverse(fac[r]) % mod * 
            modInverse(fac[n-r]) % mod) % mod)%mod; 
}

int32_t main(){
    SpeedForce
    ll i = 0,j = 0;

    int t;
    t=1;
    //cin >> t;
    while (t--){
        //cout << fixed << setprecision(10);
        solve();
    }
}



void solve(){
    ll n;
    cin >> n;
    ll a[n];
    ll x=0;
    loop(i,0,n){
        cin >> a[i];
        x=x^a[i];
    }

    loop(i,0,n){
        cout << (x^a[i]) << " ";
    }
    cout << endl;

}

ll POW(ll base,ll exp){
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base);
        base = ((ll)base * base);
        exp >>= 1;
    }
    return result;
}

ll mpow(ll base, ll exp){
    base %= mod;
    ll result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

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

Measured memory_bytes: 5164