akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

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

	int ans = 0;
	for (; a % 2 == 0 && b % 2 == 0 && c % 2 == 0; ++ans) {
		const int x = a / 2, y = b / 2, z = c / 2;

		if (a == b && b == c) {
			std::cout << -1 << std::endl;
			return 0;
		}

		a = y + z;
		b = z + x;
		c = x + y;
	}

	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import os, sys, re, math

N = int(input())
H = [int(n) for n in input().split()]

def get_count(heights):
    count = 0
    while not 0 in heights:
        count += min(heights)
        heights = [n - min(heights) for n in heights]
    group = []
    groups = [group]
    for h in heights:
        if h != 0:
            group.append(h)
        else:
            group = []
            groups.append(group)
    for group in groups:
        if group:
            count += get_count(group)
    return count

print (get_count(H))


Measured memory_bytes: 3316
#include<cstdio>
typedef long long ll;
int main()
{
    ll q,h,s,d,n;
    scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
    if(s>4*q) s=4*q;
    if(s>2*h) s=2*h;
    if(d>2*s) d=2*s;
    ll ans=n/2*d+(n&1?s:0);
    printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    x = a[0]
    for v in a:
        if v % x == 0:
            continue
        x = v % x
    f = False
    for v in a:
        if k <= v and (v-k)%x == 0:
            f = True
    if f:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);
    
    int p,q,r; cin >> p >> q >> r;

    cout << min(p+q,min(p+r,r+q)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Graph vector<vector<ll>>
#define INF (1ll<<60)
#define mod 1000000007
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(){
    ll n;cin>>n;
    vector<ll> a(n);
    priority_queue<ll> que;
    
    rep(i,n){
        cin>>a[i];
        que.push(a[i]);
    }
    sort(a.begin(),a.end(),greater<ll>());

    ll ans=que.top();
    que.pop();
    ll num=1;
    while(num!=n-1){
        ll now=que.top();
        que.pop();

        ans+=now;
        num++;
        if(num==n-1) break;

        ans+=now;
        num++;
    }

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


Measured memory_bytes: 6928
import heapq
import math
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = list(map(lambda x: x*(-1), A))
heapq.heapify(A)
ans = 0
while M > 0:
    max_price = heapq.heappop(A)

    max_price = math.ceil(max_price/2)
    M -= 1
    heapq.heappush(A, max_price)


A = list(map(lambda x: x*(-1), A))

for a in A:
    ans += a

print(ans)

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

void prians(bool answer) {
  if(answer)
    cout << "B" << endl;
  else
    cout << "A" << endl;
}
int x, a, b;

int main() {
  cin >> x >> a >> b;
  prians(max(a - x, x - a) > max(b - x, x - b));
  return 0;
}

Measured memory_bytes: 256
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// #define int            	long long
#define tree            ped
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)		for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {

    om_shree_ganeshaya_namah();

    in(n);
    cout<<(n^1);
}

Measured memory_bytes: 3604
s = gets.chomp.split("")
K = gets.to_i

used_alphabets = s.uniq.sort
dict = []

used_alphabets.each do |alphabet|
  indices = s.map.with_index { |char, index| char == alphabet ? index : nil }.compact
  part_dict = []
  indices.each do |start_index|
    K.times do |k|
      part_dict << s[start_index, k + 1].join("")
    end
  end # of indices.each
  dict += part_dict.uniq.sort
  break if dict.length >= K
end # of used_alphabets.each

puts dict[K-1]


Measured memory_bytes: 7420
def sqsum(a, x):
    s = 0
    for i in range(len(a)):
        s += (a[i]-x)**2
    return s
    
n = int(input())
a = [int(i) for i in input().strip().split()]
s = sum(a)
sq = []
for x in range(-100, 101):
    sq.append(sqsum(a, x))
print(min(sq))    

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
void ABC70(void);
void ABC71(void);
void ABC72(void);
void ABC73(void);
void ABC75(void);
void ABC77(void);
void ABC78(void);
void ABC79(void);

int main(void){
    ABC72();
}

void ABC72(void){
    int x,t;
    cin>>x>>t;
    if(x<t)cout<<0<<endl;
    else cout<<x-t<<endl;
}

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

#define LL long long

LL h,w;
vector<pair<LL,LL>> heap;
unsigned long long ans=0;
LL oper[2];
int main()
{
    cin>>w>>h;
    oper[0]=w+1;
    oper[1]=h+1;
    for (int i=0;i<w;i++)
    {
     LL temp;
     cin>>temp;
     heap.push_back(make_pair(temp,0));
    }
    for (int i=0;i<h;i++)
    {
     LL temp;
     cin>>temp;
     heap.push_back(make_pair(temp,1));
    }
    //while (!heap.empty())
    sort(heap.begin(),heap.end());
    for (auto f:heap)
    {
    // auto f=heap.top();
     //heap.pop();
     ans+=oper[1-f.second]*f.first;
     //cout<<f.first<<' '<<oper[1-f.second]<<' '<<oper[f.second]<<' '<<f.second<<' '<<ans<<endl;
     oper[f.second]--;
    // cout<<f.first<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main()
{
    long long n,k;
    cin >> n >> k;
    //double min1 = max(n,k);
/*    if (n == 1 || k == 1 || fmod(n, k) == 0)
    {
        cout << 0 << endl;
        return 0;
    }*/
    cout << min(n%k,abs(k - n%k)) << endl;
    /*while (min >= tmp)
    {
        tmp = abs(n - k);
        if (min >= tmp)
        {
            min = tmp;
            n = tmp;
        }
        else
        {
            cout << min << endl;
            return 0;
        }
    }*/
    return 0;
}


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

const int geta = 3000;

signed main(){
	int N,A;
	cin>>N>>A;
	vector<int> x(N);
	for(int i=0;i<N;i++){
		cin >>x[i];
		x[i]-=A;
	}
	
	int dp[51][6000] ;
	for(int i=0;i<50;i++){
		for(int j=0;j<6000;j++){
			dp[i][j]=0;
		}
	}
	
	for(int i=0;i<N;i++){
		dp[i+1][x[i]+geta]++;
		for(int k=0;k<6000;k++){
			dp[i+1][k]+=dp[i][k];
			dp[i+1][k+x[i]]+=dp[i][k];
		}
	}
	
	cout<< dp[N][geta]<<endl;	
}



Measured memory_bytes: 2688
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd

using namespace std;

int main() {

	int A, B;
	cin >> A >> B;

	if (A > 9 || B > 9) {
		cout << -1 << endl;
		return 0;
	}

	cout << A * B << endl;

	return 0;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (ll)(1e18)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//ctrl + command + e -> 変数一括変更




int n, e, r;
const int lim = 100001;
ll table[lim];
vector<vector<pii> > edge(lim);
void bell(int r) {
    fill_n(table, n, inf); //rからの距離
    table[r] = 0;
    
    
    
    int cnt = 0;
    while (1) {
        int update = 0;
        rep(from, n) {
            if (table[from] == inf) continue;
            rep(j, SZ(edge[from])) {
                int to = edge[from][j].F;
                int cost = edge[from][j].S;
                
                if (table[to] > table[from] + cost) {
                    update = 1;
                    table[to] = table[from] + cost;
                }
            }
        }
        if (update == 0) break;
        cnt++;
        if (cnt == n) {
            //out("NEGATIVE CYCLE");
            return;
        }
    }
    
    
}


int main() {
    
    cin >> n >> e >> r;
    
    
    int s[e], t[e], d[e];
    rep(i, e) {
        cin >> s[i] >> t[i] >> d[i];
        
        edge[s[i]].eb(t[i], d[i]);
    }
    
    bell(r);
    
    
    
    rep(i, n) {
        if (table[i] == inf) out("INF");
        else out(table[i]);
    }
}




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

typedef vector<int> vi;
typedef pair<int, int> pi;

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, b, e) for (int i = (b); i <= (int)(e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl


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

    int ans = K == 1 ? 0 : N - K;
    cout << ans << endl;

    return 0;
}


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

const long long mod=(1e9)+7;
long long a, b, c, d;
long long res;

void _input(){
    cin>>a>>b>>c>>d;
}

void _solve(){
    res=0;
    if(d>a){
        res+=a;
        d-=a;
    }
    else{
        res=d;
        return;
    }

    if(d>b)
        d-=b;
    else
        return;

    res-=d;
}

void _output(){
    cout<<res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    _input();
    _solve();
    _output();

    return 0;
}


Measured memory_bytes: 3652
from functools import lru_cache

@lru_cache(None)
def rec(n):
    if n == 1:return 1
    if n == 0:return 0
    
    return 1 + 2*rec(n//2)
    
    

def main():
    h = int(input())
    print(rec(h))
    
    
    
    
    
    
    
main()

Measured memory_bytes: 3812
h, w = map(int, input().split())
a0 = '.' * w
r0 = list(range(w))
for i in range(h):
  a = input()
  r = [i]
  for x, y, z, u in zip(a0, '.' + a, a, r0):
    r.append(min(u + (x + z == '.#'), r[-1] + (y + z == '.#')))
  a0 = a
  r0 = r[1:]
print(r[-1])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
	fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
	ll n, m, l, r, x = 0, y = 1e11, ans;
	cin>>n>>m;
	vplli v;
	forn(i, 0, m){
		cin>>l>>r;
		x = max(l, x);
		y = min(r, y);
	}
	ans = y-x+1;
	if(ans>=1){
		cout<<ans<<endl;
	} else {
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3660
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
#print(ab)
money = 0
buy = 0

for i in range(n):
    if buy < m:
        money += ab[i][0]*min(ab[i][1], m-buy)
        buy += min(ab[i][1], m-buy)
    if buy == m:
        break
print(money)

Measured memory_bytes: 64728
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

int answer(std::vector<std::string>const& field, int H, int W)
{
	boost::multi_array<bool, 2> count(boost::extents[H - 1][W - 1]);
	for (int i : boost::irange(0, H - 1))
	{
		for (int j : boost::irange(0, W - 1))
		{
			for (int a : {i, i + 1})
			{
				for (int b : {j, j + 1})
				{
					count[i][j] ^= field[a][b] == '#';
				}
			}
		}
	}
	boost::multi_array<int, 2> dp0(boost::extents[H][W]);
	boost::multi_array<int, 2> dp1(boost::extents[H][W]);
	for (int i : boost::irange(0, H))
	{
		dp0[i][W - 1] = dp1[i][W - 1] = 1;
		for (int k : boost::irange(0, W - 1) | adaptor::reversed)
		{
			dp0[i][k] = ((i != 0 && count[i - 1][k]) ? 0 : dp0[i][k + 1]) + 1;
			dp1[i][k] = ((i != H - 1 && count[i][k]) ? 0 : dp1[i][k + 1]) + 1;
		}
	}

	int max = 0;
	for (int k : boost::irange(0, W))
	{
		int local = dp0[0][k];
		std::stack<std::pair<int, int>> stack;
		std::vector<std::pair<int, int>>for_debug;
		auto emplace = [&](int i, int j)
		{
			stack.emplace(i, j);
			for_debug.emplace_back(i, j);
		};
		emplace(0, dp1[0][k]);
		for (int i : boost::irange(1, H))
		{
			auto left = stack.top().first;
			auto height = stack.top().second;
			local = std::max(local, (left - i + 1) * std::min(height, dp0[0][k]));
			if (height < dp1[i][k])
			{
				emplace(i, dp1[i][k]);
			}
			else if (dp1[i][k] < stack.top().second)
			{
				int last = left;
				while (stack.size() && dp1[i][k] < stack.top().second)
				{
					auto left = stack.top().first;
					auto height = stack.top().second;
					last = left;
					local = std::max(local, (i - left + 1) * height);
					stack.pop();
				}
				emplace(last, std::min(dp1[i][k], dp0[i][k]));
			}
		}
		while(stack.size())
		{
			auto left = stack.top().first;
			auto height = stack.top().second;
			local = std::max(local, (H - left) * std::min(height, dp1[H - 1][k]));
			stack.pop();
		}
		max = std::max(max, local);
	}
	return max;
}

void Main()
{
	int H, W;
	std::cin >> H >> W;
	std::vector<std::string> field(H);
	for (auto& str : field)
	{
		std::cin >> str;
	}
	std::cout << answer(field, H, W) << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 39680
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<utility>
#include<memory>
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
 
typedef long long ll;

using namespace std;

const int mod=1e9+7;
const int INF=1<<25;

void solve(int n){
  int dp[11][11];
  fill(dp[0],dp[10],INF);
  rep(i,9) dp[i][i]=0;
  int a,b,c;
  int first=10,last=0;
  int ans1;
  ll ans2=INF,temp;
  rep(i,n){
    cin >> a >> b >> c;
    first=min(first,min(a,b));
    last=max(last,max(a,b));
    dp[a][b]=dp[b][a]=c;
  }
  REP(k,first,last+1) REP(i,first,last+1) REP(j,first,last+1){
    dp[j][i]=dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
  }
  REP(i,first,last+1){
    temp=0;
    REP(j,first,last+1){
      temp+=dp[i][j];
    }
    if(temp<ans2){
      ans2=temp;
      ans1=i;
    }
  }
  cout << ans1 << " " << ans2 << endl;

  return ;
}
int main(){
  int n;
  while(true){
    cin >> n;
    if(!n)  break;
    solve(n);
  }
  return 0;
}

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

using namespace std;

int main()
{
   ios_base::sync_with_stdio(false);
   int n, k;
   cin >> n >> k;
   vector<int> nums(n);
   for (int i = 0; i < n; ++i)
   {
      cin >> nums[i];
   }
   for (int i = k, j = 0; i < n; ++i, ++j)
   {
      if (nums[i] > nums[j])
         cout << "Yes\n";
      else
         cout << "No\n";
   }
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0; i<(int) (x); i++)
#define PI 3.14159265359
using namespace std;

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

	if(s*t >= d)
		cout << "Yes\n";
	else
		cout << "No\n";

	//////////////////////////////////
	//--------end--------
	//
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;
string s1, s2;


int main()
{
    ios::sync_with_stdio(false);
    cin >> s1 >> s2;
    int flag = 1;
    if(s1.length() != s2.length()) flag = 0;
    else
    {
        for(int i = 0; i < s1.length(); i ++)
        {
            if(s1[i] != s2[s1.length() - i - 1])
            {
                flag = 0;
                break;
            }
        }
    }
    if(flag == 0) cout <<"NO" << endl;
    else cout << "YES" << endl;


}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<cstdio>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll a,b;
 cin>>a>>b;
 ans=1;
 ll m=gcd(a,b);
 ll tmp=m;
 for(i=2;i*i<=m;++i){
  if(tmp%i==0){
 // cout<<i<<" "<<tmp<<" "<<ans<<endl;
   ans++;
  }
  while(tmp%i==0)tmp/=i;
  if(tmp==1)break;
 }
 if(tmp!=1)ans++;
 pr(ans);
return 0;}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int search(int b,int e,vll& s){
    int MIN = b + 1;
    int MAX = e - 1;
    if (MIN==MAX)
        return MIN;
    while (1){
        if (MIN+1==MAX)
            break;
        int m = (MIN + MAX) / 2;
        if (s[m]-s[b]==s[e]-s[m]){
            return m;
        }
        else if (s[m]-s[b]<s[e]-s[m]){
            MIN = m;
        }
        else{
            MAX = m;
        }
    }
    return MIN;
}

int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll s(n + 1,0);
    rep(i, n) s[i + 1] = s[i] + a[i];
    ll ans = infl;
    repf(i,2,n-1){
        int idx = search(0, i, s);
        ll x0 = (s[i] - s[idx]) ,x1= (s[idx] - s[0]);
        ll x2 = -infl, x3 = infl;
        idx++;
        if (idx<i){
            x2 = (s[i] - s[idx]) ,x3= (s[idx] - s[0]);
        }
        ll xx0, xx1;
        if (abs(x0-x1)>=abs(x2-x3)){
            xx0 = min(x2,x3);
            xx1 = max(x2,x3);
        }
        else{
            xx0 = min(x0, x1);
            xx1 = max(x0, x1);
        }
/*
        cout << "start : " << i << endl;
        cout << "x idx : " << idx-1 << endl;
        cout << x0 << " " << x1 << " " << x2 << " " << x3 << endl;
        cout << xx0 << " " << xx1 << endl;
 */

        idx = search(i, n, s);
        ll y0 = (s[n] - s[idx]) ,y1= (s[idx] - s[i]);
        ll y2 = -infl, y3 = infl;
        idx++;
        if (idx<n){
            y2 = (s[n] - s[idx]) ,y3 = (s[idx] - s[i]);
        }
        ll yy0, yy1;
        if (abs(y0-y1)>=abs(y2-y3)){
            yy0 = min(y2, y3);
            yy1 = max(y2, y3);
        }
        else{
            yy0 = min(y0, y1);
            yy1 = max(y0, y1);
        }

/*
        cout << "y idx : " << idx-1 << endl;
        cout << y0 << " " << y1 << " " << y2 << " " << y3 << endl;
        cout << yy0 << " " << yy1 << endl;
 */
        ans = min(ans, max(xx1, yy1) - min(xx0, yy0));
    }
    cout << ans << endl;
}   


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

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> tmp(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
        tmp[i] = x[i];
    }

    sort(tmp.begin(), tmp.end());

    int a = n/2;
    a = a-1;

    for(int i = 0; i < n; i++){
        if(x[i] > tmp[a]) {
            cout << tmp[a] << endl;
        }
        else{
            cout << tmp[a+1] << endl;
        }
    }

    return 0;
    
}






Measured memory_bytes: 3712
#include <stdio.h>
typedef struct {
    int x;
    int y;
} data_t;
typedef struct {
    int head;
    int tail;
    data_t data[200000];
} queue_t;
queue_t queue;
void init_queue() { queue.head = queue.tail = 0; }
void enqueue(data_t data) { queue.data[queue.tail++] = data; }
data_t dequeue() { return queue.data[queue.head++]; }
int dist[100][100];
int h, w;
char s[100][100];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(data_t start, data_t end) {
    init_queue();
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dist[i][j] = -1;
        }
    }
    dist[start.y][start.x] = 0;
    enqueue(start);
    while (queue.tail != queue.head) {
        data_t now = dequeue();
        for (int i = 0; i < 4; i++) {
            data_t move;
            move.x = now.x + dx[i];
            move.y = now.y + dy[i];
            if (move.x < 0 || move.x >= w || move.y >= h || move.y < 0) {
                continue;
            }
            if (s[move.y][move.x] == '#' || dist[move.y][move.x] != -1) {
                continue;
            }

            enqueue(move);
            dist[move.y][move.x] = dist[now.y][now.x] + 1;
        }
        if (dist[end.y][end.x] != -1) {
            return dist[end.y][end.x];
        }
    }
    return -1;
}
int main(void) {
    scanf("%d %d", &h, &w);
    int max = 0;
    for (int i = 0; i < h; i++) {
        scanf("%s", s[i]);
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int ii = 0; ii < h; ii++) {
                for (int jj = 0; jj < w; jj++) {
                    if (s[i][j] == '#') {
                        continue;
                    }
                    if (s[ii][jj] == '#') {
                        continue;
                    }
                    data_t start, end;
                    start.y = i;
                    start.x = j;
                    end.y = ii;
                    end.x = jj;
                    if (max < bfs(start, end)) {
                        max = bfs(start, end);
                    }
                }
            }
        }
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: a,b
    read*, a,b
    if (mod(a,2) == 1 .and. mod(b,2) == 1) then
        print'(a)', 'Yes'
    else
        print'(a)', 'No'
    end if
end program main

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

int main() {
	int A, B;
	cin >> A >> B;

	int ans;
	if (A < 10 && B < 10) ans = A * B;
	else ans = -1;
	cout << ans << endl;
}


Measured memory_bytes: 256
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=1000000007;
long long n,a,b;
int main()
{
	cin>>n>>a>>b;
	if(a>b||a>n+1||b-a<=2)
	{
		//cout<<"!"<<a<<n+1;
		cout<<n+1;
	}
	else
	{
		cout<<((n-(a-1))/2)*(b-a)+1+n-(n-(a-1))/2*2;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
using namespace std;
int a,b,c,d,n,m,num;
int t [2000];
bool flg=false;
void compute(int x){
  if(num!=a){
    for(int i=x;i<n;i++){
      if(num+t[i]<=a){
	num+=t[i];
	if(num==a)flg=true;
	if(i+1<n)compute(i+1);
	num-=t[i];
      }
    }
  }
  
}


int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>t[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    flg=false;
    cin>>a;
    num=0;
    compute(0);
    if(flg)cout<<"yes"<<endl;
    if(!flg)cout<<"no"<<endl;
  }
}

Measured memory_bytes: 1156
import java.util.Scanner;

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

        for (int i = 0; i <= N; i++) {
            int sumDigits = calcSumOfDigits(i);
            if (A <= sumDigits && sumDigits <= B) {
                res += i;
            }
        }
        System.out.println(res);
    }

    private static int calcSumOfDigits(int i) {
        int tmp = i;
        int sumDigits = 0;
        while (tmp > 0) {
            sumDigits += tmp % 10;
            tmp /= 10;
        }
        return sumDigits;
    }
}


Measured memory_bytes: 35608
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for l in range(K+1):
        for r in range(K-l+1):
            if l+r > N or l+r>K:
                continue
            now = []
            val = 0
            for i in range(l):
                now.append(V[i])
                val += V[i]
            for j in range(r):
                now.append(V[-j-1])
                val += V[-j-1]

            d = K-l-r
            now.sort()
            for i in range(d):
                if i >= len(now):
                    break
                if now[i] > 0:
                    break
                val -= now[i]
            ans=max(ans,val)

    print(ans)

resolve()

Measured memory_bytes: 41456
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr ll INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld PI = acos(-1);
constexpr ld EPS = 1e-11;

int main(void){
	ll n;
	cin >> n;
	ll ans = 0;
	ll t = n / 500;
	ans += t * 1000;
	n -= 500 * t;
	ans += n / 5 * 5;
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    
    a = (a + 11) % 13;
    b = (b + 11) % 13;
    
    if(a == b){
        cout << "Draw" << endl;
    }else if(a > b){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
constexpr int64_t INF = 1e6 + 1;

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

  int64_t X, K, D;
  cin >> X >> K >> D;
  if (X < 0) X = -X;
  int64_t N = X / D;
  int64_t res = 0;
  if (K <= N) {
    res = X - K * D;
  } else {
    int64_t A = X - N * D;
    if ((K - N) % 2 == 0) {
      res = A;
    } else {
      res = D - A;
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

int main() {
  ll n;
  cin >> n;
  vector<ll> c(n);
  for(ll i=0;i<n;i++) {
    c[i]=i+1;
  }
  vector<ll> a(n);
  vector<ll> b(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  for(ll i=0;i<n;i++) {
    cin >> b[i];
  }
  ll na,nb;
  ll count=0;
  do {
    bool flag=true;
    for(ll i=0;i<n;i++) {
      if(a[i]!=c[i]) {
        flag=false;
        break;
      }
    }
    if(flag) {
      na=count;
    }
    flag=true;
    for(ll i=0;i<n;i++) {
      if(b[i]!=c[i]) {
        flag=false;
        break;
      }
    }
    if(flag) {
      nb=count;
    }
    count++;
  } while(next_permutation(c.begin(),c.end()));
  cout << abs(na-nb) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    
    public static void main(String[] args) {
        new Main().solve();
    }
    
    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] s = S.toCharArray();
        int l = 0;
        for (int i = 1; i < S.length(); i++) {
            if (s[i - 1] != s[i]) {
                l++;
            }
        }
        int r = 0;
        for (int i = S.length() - 2; i >= 0; i--) {
            if (s[i + 1] != s[i]) {
                r++;
            }
        }
        System.out.println(Math.min(l, r));
    }
}


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

// input
string N;


void input() {
    cin >> N;
}


int main() {
    input();
    bool a = N[0] == N[1] && N[1] == N[2];
    bool b = N[1] == N[2] && N[2] == N[3];
    string ans;
    if (a || b) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3604
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ???????????£???????????? '''

from collections import deque

functions = {"insert": lambda obj, x: obj.insert(x),
             "delete": lambda obj, x: obj.delete(x),
             "deleteFirst": lambda obj: obj.deleteFirst(),
             "deleteLast": lambda obj: obj.deleteLast()}


class DoublyLinkedList(object):
    """ Doubly Linked List """

    def __init__(self):
        # self.list = []
        self.list = deque()

    def insert(self, x):
        """ ???????????????x?????????????´?????????\ """
        # self.list = [x] + self.list
        self.list.appendleft(x)

    def delete(self, x):
        """ ??????x??????????????????????´?????????? """
        # for i in range(len(self.list)):
        #     if self.list[i] == x:
        #         self.list.pop(i)
        #         break
        if x in self.list:
            self.list.remove(x)

    def deleteFirst(self):
        """ ?????????????????????????´?????????? """
        # self.list.pop(0)
        self.list.popleft()

    def deleteLast(self):
        """ ????????????????°????????´?????????? """
        self.list.pop()


if __name__ == '__main__':
    N = int(input())

    q = deque()
    for i in range(N):
        command = input().split()
        if command[0] == 'insert':
            q.appendleft(command[1])
        elif command[0] == 'delete':
            if command[1] in q:
                q.remove(command[1])
        elif command[0] == 'deleteFirst':
            q.popleft()
        elif command[0] == 'deleteLast':
            q.pop()

    print(' '.join(map(str, q)))

    # dll = DoublyLinkedList()
    # for i in range(N):
    #     command = input().split()
    #     if len(command) == 1:
    #         functions[command[0]](dll)
    #     elif len(command) == 2:
    #         functions[command[0]](dll, int(command[1]))
    # print(' '.join(map(str, dll.list)))

Measured memory_bytes: 71908
import math

class Watch():
    """
    This is a class to calculate angle and distance between two hands.
    
    Attributes:
        length_of_hour_hand(int): Length of the hour hand.
        length_of_minute_hand(int): Length of the minute hand.
        hours(int): Hours.
        minutes(int): Minutes.
    """

    def __init__(self, length_of_hour_hand, length_of_minute_hand,
                 hours, minutes):
        """
        The constructor for Watch class.

        Attributes:
            length_of_hour_hand(int): Length of the hour hand.
            length_of_minute_hand(int): Length of the minute hand.
            hours(int): Hours.
            minutes(int): Minutes.
            angle_between_two_hands(float): 
                Angle between the hour hand and the minute one.
            distance_between_two_hands(float): 
                Distance between the tip of hour hand and 
                that of minute one.
        """
        self.length_of_hour_hand = length_of_hour_hand
        self.length_of_minute_hand = length_of_minute_hand
        self.hours = hours
        self.minutes = minutes
        self.angle_between_two_hands = None
        self.distance_between_two_hands = None

    def calculate_angle_between_two_hands(self):
        """
        Calculate angle between the hour hand and the minute one.
        """

        #degrees_of_hour_hand: float, radian
        degrees_of_hour_hand = (((self.hours + self.minutes/60.)/12.)
                               *2.*math.pi)
        #degrees_of_minute_hand: float, radian
        degrees_of_minute_hand = (self.minutes/60.)*2.*math.pi
        
        #angle_between_two_hands: float, radian
        angle_between_two_hands = (degrees_of_hour_hand
                                   - degrees_of_minute_hand)
        
        self.angle_between_two_hands = angle_between_two_hands
    
    def calculate_distance_between_two_hands(self):
        """
        Calculate distance between the tip of hour hand and 
        that of minute hand.
        """                          

        self.distance_between_two_hands = math.sqrt(
            self.length_of_hour_hand**2 + self.length_of_minute_hand**2
            - 2*self.length_of_hour_hand*self.length_of_minute_hand
            *math.cos(self.angle_between_two_hands))

#A, B, H, M: ints, A: the length of the hour hand, 
#B: the length of the minute hand, H: hours, M: minutes
A, B, H, M = [int(s) for s in input().split(" ")] 

watch = Watch(A, B, H, M)
watch.calculate_angle_between_two_hands()
watch.calculate_distance_between_two_hands()
print(watch.distance_between_two_hands)

Measured memory_bytes: 9516
h,w = map(int,input().split())
d = [list(map(int,input().split())) for _ in range(10)]
aa =  [list(map(int,input().split())) for _ in range(h)]

def warshall_floyd():
  for k in range(10):
    for i in range(10):
      for j in range(10):
        d[i][j] = min(d[i][j], d[i][k]+d[k][j])

warshall_floyd()

ans = 0
for i in range(h):
  for j in range(w):
    if abs(aa[i][j]) != 1:
      ans += d[aa[i][j]][1]      
    
print(ans)    

Measured memory_bytes: 3444
#include <stdio.h>
#include <ctype.h>

int main(int argc, char *args[])
{
	int i;
	char mojiretsu_in[1201];
	char mojiretsu_out[1201];

	gets(mojiretsu_in);

	for( i=0; i<1201; i++ ) {
		if( islower(mojiretsu_in[i]) ) {
			mojiretsu_out[i] = toupper(mojiretsu_in[i]);
		}
		else if( isupper(mojiretsu_in[i]) ) {
			mojiretsu_out[i] = tolower(mojiretsu_in[i]);
		}
		else {
			mojiretsu_out[i] = mojiretsu_in[i];
		}

		if( mojiretsu_in[i] == 0 ) {
			break;
		}
	}

	printf("%s\n",mojiretsu_out);


	return 0;

}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

vector<pair<int,int>> f(const vector<int> v) {
  map<int, int> count;
  for (int x : v) count[x]++;
  vector< pair<int,int> > res;
  for (auto it = count.begin(); it != count.end(); ++it) {
    res.push_back({it->second, it->first});
  }
  res.push_back({0, -1});
  sort(ALL(res));
  reverse(ALL(res));
  res.resize(2);
  return res;
}

int main2() {
  int N = nextInt();

  vector<int> v0, v1;
  REP(i, N) {
    int x = nextInt();
    if (i % 2 == 0) v0.push_back(x);
    else v1.push_back(x);
  }
  sort(ALL(v0));
  sort(ALL(v1));
  if (v0[0] == v1[0] && v0[0] == v0.back() && v1[0] == v1.back()) {
    cout << v0.size() << endl;
    return 0;
  }
  auto res0 = f(v0);
  auto res1 = f(v1);

  int ans = 0;
  if (res0[0].second != res1[0].second) {
    ans = N - (res0[0].first + res1[0].first);
  } else {
    ans = N - max(
      res0[1].first + res1[0].first,
      res0[0].first + res1[1].first
    );
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 4364
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int x[] = new int[n];
		int y[] = new int[n];
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		
		double l=0,r = 5000;
		while(r-l >= 1e-7){
			double m = (l+r)/2;
			
			boolean ok = false;
			
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					double d = dis(x[i], y[i], x[j], y[j]);
					if(!isZero(d-2*m) && d > 2*m){
						break;
					}
					
					double h = Math.sqrt(m*m - d*d/4);
					double mx = (double)(x[i] + x[j])/2;
					double my = (double)(y[i] + y[j])/2;
					
					double[] vec = pv(h, -y[j] + y[i], x[j] - x[i]);
					
					double itx = mx + vec[0];
					double ity = my + vec[1];
					
					boolean ins1 = true, ins2 = true;
					for(int k=0;k<n;k++){
						if(i==k || j==k)
							continue;
						
						double dt = dis(itx, ity, x[k], y[k]);
			
						if(!isZero(dt-m) && dt > m){
							ins1 = false;
							break;
						}
					}
					itx = mx - vec[0];
					ity = my - vec[1];
					for(int k=0;k<n;k++){
						if(i==k || j==k)
							continue;
						double dt = dis(itx, ity, x[k], y[k]);
						
						if(!isZero(dt-m) && dt > m){
							ins2 = false;
							break;
						}
					}
					
					if(ins1 || ins2){
						ok = true;
						break;
					}
				}
				
				if(ok)
					break;
			}
			
			if(ok){
				r = m;
			}
			else{
				l = m;
			}
		}
		System.out.println((l+r)/2);
		
	}
	
	static boolean isZero(double d){
		return  Math.abs(d)<1e-8;
	}
	static double[] pv(double len, double x, double y){
		double plen = dis(x, y, 0,0);
		return new double[]{x * len / plen, y * len / plen};
	}
	static double dis(double x1, double y1, double x2, double y2){
		return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
	}
}


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

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

        sort(a, a + n);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i] * (n - i);
        }
        cout << sum << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 200010;
int N;
LL A[MC],B[MC];

int main(){
	cin >> N;
	LL S = 0 , T = 12345678901234;
	bool b = 1;
	repp(i,0,N){
		cin >> A[i] >> B[i];
		S += A[i];
		if(A[i] != B[i]) b = 0;
		if(A[i] > B[i]) T = min(T,B[i]);
	}
	if(b) return cout << 0 << endl , 0;
	cout << S-T << endl;
	return 0;
}


Measured memory_bytes: 512
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int ans;
map<char,int>m;

int32_t main(){_
    //freopen("input","r",stdin);
	string s;
	cin >> s;
	for(auto it : s) m[it]++;
	for(auto it : m) ans += 1LL * it.second * (it.second - 1);
	rc(max(1LL,((1LL * sz(s) * (sz(s) - 1) - ans)) / 2LL + 1LL));
}


Measured memory_bytes: 720
import java.util.Scanner;
import java.util.stream.Collectors;

class Main {

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

    void compute() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        if(S.length()<4){
            System.out.println("No");
            return;
        }
        if(S.substring(0,4).equals("YAKI")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764