akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
void solve(){
    int n, m, s, c;
    cin >> n >> m;
    vector<int> A(n, -1);
    for(int i=0; i<m; i++){
        cin >> s >> c;
        if(A[s-1]!=-1){
            if(A[s-1] == c){
                A[s-1] = c;
            }else{
                cout << -1 << endl;
                exit(0);
            }
        }else{
            A[s-1] = c;
        }
    }
    for(int i=0; i<n; i++){
        if(n!=1){
            if(A[0] == -1){
                A[0] = 1;
            }
            if(A[i] == -1){
                A[i] = 0;
            }
        }else{
            if(A[0] == -1){
                A[0] = 0;
            }
        }
    }
    if(n!=1){
        if(A[0] == 0){
            cout << -1 << endl;
        }else{
            for(int i=0; i<n; i++){
                cout << A[i];
                if(i == n-1){
                    cout << endl;
                }
            }
        }
    }else{
        cout << A[0] << endl;
    }
    

}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

signed main() {
	int n;
	string s;
	cin >> n >> s;

	//vector<int> l(m);
	//vector<int> r(m);
	int red = 0;
	int blue = 0;
	for (size_t i = 0; i < n; ++i)
	{
		if (s[i] == 'R') red++;
		if (s[i] == 'B') blue++;
	}

	if (red > blue) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	
}




Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long int gcd(long long int a, long long int b){
    if(b==0){
        return a;
    }else{
        return gcd(b, a % b);
    }
}
long long int lcm(long long int a, long long int b){
    long long int cur = gcd(a,b);
    return (a/cur)*b;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vector<long long int> vals(N);
    for(int i = 0; i < N; i++){
        cin >> vals[i];
    }
    long long int ans = vals[0];
    for(int i = 1; i < vals.size(); i++){
       ans = lcm(ans, vals[i]);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if (a!=b && a!=c)
        cout<<a<<endl;
    else if (b!=a && b!=c)
        cout<<b<<endl;
    else
        cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    vector<ll>A(N),B(M);
    vector<ll> SA(N+1),SB(M+1);
    rep(i,N){
        cin >> A[i];
        SA[i+1]=SA[i]+A[i];
    }
    rep(i,M){
        cin >> B[i];
        SB[i+1]=SB[i]+B[i];
    }
    ll ans = 0;
    for(int i=0;i<=N;i++){
        if(SA[i]>K) break;
        ll tm = K-SA[i];
        auto itr = upper_bound(SB.begin(),SB.end(),tm);
        ll tmp = i+(itr-SB.begin()-1);
        ans = max(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9528
#include <iostream>
#include<cstdio>
#include<cctype>
#include<string.h>
#include<stdio.h>
using namespace std;

int main()
{
    char a[1300];
    cin.getline(a,sizeof(a));
    char c[strlen(a)];
    strcpy(c,a);
    

        
    
    for(int i=0;i<strlen(c);i++){
        
          if(islower(c[i])){
              putchar(toupper(c[i]));
          }else if(isupper(c[i])){
              putchar(tolower(c[i]));
          }/*else if(c[i]==','){
              cout<<",";
          }else if(c[i]=='.'){
              cout<<".";
          }else if(isspace(c)){
              cout<<" ";
          }*/else{
              cout<<c[i];
          }
          
       
            
        
    }

    cout<<endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MX_N = 1e5+5;

int N;
vector<int> al[MX_N];

int dfs(int u) {
    vector<int> vec;
    for (int& v : al[u]) {
        vec.push_back(dfs(v));
    }
    sort(ALL(vec));
    int ret = 0;
    FOR(i,0,SZ(vec)-1){
        ret = max(ret, vec[i]+SZ(vec)-i);
    }
    return ret;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    FOR(i,2,N){
        int P; cin >> P;
        al[P].push_back(i);
    }

    cout << dfs(1);
}



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

int main() {
  string str;
  cin >> str;

  int q;
  cin >> q;
  rep(i, q) {
    string com, p;
    int a, b;
    cin >> com >> a >> b;
    ++b;

    if (com == "print") {
      cout << str.substr(a, b - a) << endl;
    }

    if (com == "reverse") {
      reverse(str.begin() + a, str.begin() + b);
    }

    if (com == "replace") {
      cin >> p;
      str.replace(str.begin() + a, str.begin() + b, p);
    }
  }
}


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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

const int MOD = (int)1e9 + 7;
int F[100010], iF[100010];
int exp(int a, int b){
    if (b == 0) return 1;
    if (b & 1) {
        return (ll)a * exp(a, b-1) % MOD;
    }
    int tmp = exp(a, b/2);
    return (ll)tmp * tmp % MOD;
}

int binom(int n, int k){
    if (k > n || n <= 0) return 0;
    int res = (ll)F[n] * iF[k] % MOD * iF[n-k] % MOD;
    return res;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    F[0] = iF[0] = 1;
    for (int i = 1; i < 100010; i++){
        F[i] = (ll)F[i-1] * i % MOD;
        iF[i] = exp(F[i], MOD-2);
    }
    int n; cin >> n;
    vi indx(n + 1, -1);
    int L, R, K;
    for (int i = 0; i <= n; i++) {
        int t; cin >> t;
        if (indx[t] == -1) indx[t] = i;
        else {
            L = indx[t];
            R = i;
            K = R-L-1;
            break;
        }
    }
    cout << n << "\n";
    for (int i = 2; i <= n; i++){
        // choose 2
        ll res = binom(n-1, i-2);
        // exclude 2nd
        res += binom(n, i);
        // choose 2nd
        res += binom(n-1, i-1) - binom(n-1-K, i-1);
        res = (res % MOD);
        if (res < 0) res += MOD;
        cout << res << '\n';
    }
    cout << 1 << "\n";
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,n,a[100000],i;
    cin >> h >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        h=h-a[i];
    }
    if(h<=0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    

    return 0;

}


Measured memory_bytes: 4040
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll> town(n+1);
    vector<ll> baster(n);
    REP(i,0,n+1){
        cin >> town[i];
    }
    REP(i,0,n){
        cin >> baster[i];
    }
    ll sum=0;
    REP(i,0,n){
        if(town[i]-baster[i]>=0){
            sum+=baster[i];
        }else{
            sum+=town[i];
            if(town[i+1]-(baster[i]-town[i])>=0){
                sum+=baster[i]-town[i];
                town[i+1]=town[i+1]-(baster[i]-town[i]);
            }else{
                sum+=town[i+1];
                town[i+1]=0;
            }
        }
    }
    P(sum);
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0,1,0,-1 };
const ll dy[4] = { -1, 0, 1,0 };
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

//書いてある数が最大のボールを一つ考える
//それをi番目のボールとするこの時i番目のボールのペアとなるボールｊがあるとしたら
//Ai<Ai+Aj<=2*AiよりAi+Ajの値は一意に定まる
//よってAi＋Ajが２べきとなるようなjがあるとしたらi番目のボールとj番目のボールをペアにしてよい

int mypow(int b, int n) {
	if (n == 0)return 1;
	if (n == 1)return b;
	if (n % 2 == 0) {
		return mypow(b*b, n / 2);
	}
	else {
		return mypow(n, n - 1)*b;
	}
}
//n<2^kなる最小の2^kを返す
int minbeki(int n) {
	int ret = 1;
	while (n >= ret) {
		ret *= 2;
	}
	return ret;
}
int main() {
	int N; cin >> N;
	map<int, int>cnt;
	//key=書かれた整数,value=ボールの個数
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		if (cnt.find(a) == cnt.end())cnt[a] = 0;
		++cnt[a];
	}
	int ans = 0;
	for (auto itr = cnt.rbegin(); itr != cnt.rend(); ++itr) {
		int b = itr->first;
		if (cnt[b] == 0)continue;
		int a = minbeki(b) - b;
		if (a == b) {
			//bと書かれたボール同士でペアを作る
			ans += cnt[b] / 2;
		}
		else {
			if (cnt.find(a) == cnt.end())continue;
			//aと書かれたボールが存在しなければ次へ
			//少ないほうに合わせてペアを作る
			ans += min(cnt[a], cnt[b]);
			cnt[a] -= min(cnt[a], cnt[b]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define vv(type)		vector<vector<type>>
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define db(x) 			cout<<x<<" "
#define db1(x) 			cout<<x<<'\n'
#define db2(x,y) 		cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) 		cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) 		for(int i=0;i<(n);++i)
#define repA(i,a,n) 	for(int i=a;i<=(n);++i)
#define repD(i,a,n) 	for(int i=a;i>=(n);--i)
#define so(a) 			sort(a.begin(),a.end())
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
// to find all local maximaa and minima in O(n)
//	 for (int i=1;i<=n;i++)
//        {
//            if (i==1 || i==n || (p[i-1]<p[i])!=(p[i]<p[i+1]))
//           ans.push_back(p[i]);
//        }
int dx[] = { -1, 1, -1, 0, 0, -1, 1, 1 };
int dy[] = { -1, -1, 1, -1, 1, 0, 0, 1 };
int gcd(int a, int b)
{
	if (!b)
		return a;
	return gcd(b, a % b);
}
int modular_expo(int x, int y, int m)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans % m * x % m) % m;
		x = (x % m * x % m) % m;
		y /= 2;
	}
	return ans % m ;
}
int power(int x, int y)
{
	int ans = 1;
	while (y)
	{
		if (y & 1)
			ans = (ans * x);
		x *= x;
		y /= 2;
	}
	return ans;
}
unordered_map<int, int>mp;
vi dp;
vector<vector<int>>adj;
int maxlength(int u)
{
	if (dp[u] != -1)
		return dp[u];
	dp[u] = 0;
	for (int i = 0; i < adj[u].size(); i++)
		dp[u] = max(dp[u], 1 + maxlength(adj[u][i]));
	return dp[u];
}

void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, m, x, y;
	cin >> n >> m;
	adj.resize(n + 1);
	dp.resize(n + 1);
	for (int i = 0; i < m; i++)
	{
		cin >> x >> y;
		adj[x].pb(y);
	}
	rep(i, n + 1)
	dp[i] = -1;
	int ans = 0;
	repA(i, 1, n)
	{
		if (dp[i] == -1)
			dp[i] = maxlength(i);
		ans = max(ans, dp[i]);
	}
	db(ans);
}

int32_t main()
{
	solve();
	return 0;
}


Measured memory_bytes: 11600
using System;

namespace q1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] arr = str.Split(' ');
            int K = int.Parse(arr[0]);
            int X = int.Parse(arr[1]);
            if (K * 500 >= X) {
                Console.WriteLine("Yes");
            }
            else {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(){
	int a,b;cin>>a>>b;
	cout<<((a%3==0 || b%3==0 || (a+b)%3==0) ? "Possible":"Impossible")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>



using namespace std;

int main() {

    int H[100],W[100];
    int count = 0;


    while (1) {
        cin >> H[count] >> W[count];
        if (H[count] == 0 && W[count] == 0) {
            break;
        }
        count++;
    }


     
    for (int k = 0; k < count; k++) {
        for (int i = 2; i < H[k] + 2; i++) {
            for (int j = 2; j < W[k] + 2; j++) {
                if (j % 2 == 0 && i % 2 == 0) {
                    cout << '#';
                }
                else if(j % 2 != 0 && i % 2 == 0){
                    cout << '.';
                }else if (j % 2 == 0 && i % 2 != 0) {
                    cout << '.';
                }
                else if (j % 2 != 0 && i % 2 != 0) {
                    cout << '#';
                }
                
            }
            cout << endl;
        }
        cout << endl;
        ;
    }
        
    

    
}


Measured memory_bytes: 3104
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

template <uint_fast64_t MOD> class ModInt {
    using u64 = uint_fast64_t;

  public:
    u64 val;

    ModInt(const u64 x = 0) : val((x + MOD) % MOD) {}
    constexpr u64 &value() { return val; }
    constexpr ModInt operator-() { return val ? MOD - val : 0; }
    constexpr ModInt operator+(const ModInt &rhs) const {
        return ModInt(*this) += rhs;
    }
    constexpr ModInt operator-(const ModInt &rhs) const {
        return ModInt(*this) -= rhs;
    }
    constexpr ModInt operator*(const ModInt &rhs) const {
        return ModInt(*this) *= rhs;
    }
    constexpr ModInt operator/(const ModInt &rhs) const {
        return ModInt(*this) /= rhs;
    }
    constexpr ModInt &operator+=(const ModInt &rhs) {
        val += rhs.val;
        if(val >= MOD) {
            val -= MOD;
        }
        return *this;
    }
    constexpr ModInt &operator-=(const ModInt &rhs) {
        if(val < rhs.val) {
            val += MOD;
        }
        val -= rhs.val;
        return *this;
    }
    constexpr ModInt &operator*=(const ModInt &rhs) {
        val = val * rhs.val % MOD;
        return *this;
    }

    constexpr ModInt &operator/=(const ModInt &rhs) {
        *this *= rhs.inv();
        return *this;
    }

    constexpr bool operator==(const ModInt &rhs) { return this->a == rhs.a; }
    constexpr bool operator!=(const ModInt &rhs) { return this->a != rhs.a; }
    friend constexpr ostream &operator<<(ostream &os, const ModInt<MOD> &x) {
        return os << x.val;
    }
    friend constexpr istream &operator>>(istream &is, ModInt<MOD> &x) {
        return is >> x.val;
    }

    constexpr ModInt inv() const { return ModInt(*this).pow(MOD - 2); }

    constexpr ModInt pow(ll e) const {
        u64 x = 1, p = val;
        while(e > 0) {
            if(e % 2 == 0) {
                p = (p * p) % MOD;
                e /= 2;
            } else {
                x = (x * p) % MOD;
                e--;
            }
        }
        return ModInt(x);
    }
};

int main() {
    int N, K;
    cin >> N >> K;
    using mint = ModInt<MOD>;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<mint>> dp(N + 1, vector<mint>(K + 1));
    // dp[i][j]:=i-1番目まで見て、j個配り終えたときの通り数
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        vector<mint> sum(K + 2);
        for(int j = 0; j <= K; j++) {
            sum[j + 1] = dp[i][j] + sum[j];
        }
        for(int j = 0; j <= K; j++) {
            dp[i + 1][j] += sum[j + 1] - sum[max(0LL, j - A[i])];
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}

Measured memory_bytes: 83088
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return x * y / tmp;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	string y = "Yay!";
	string n = ":(";
	
	


	int X;
	cin >> X;

	int syou = X / 100;
	int amari = X % 100;

	vector<int> v;
	for (int i = 5; i > 0; i--)
	{
		v.push_back(i);
	}


	int ans = 0;
	for (int i = 0; i < v.size(); i++)
	{
		ans += amari / v[i];
		amari -= v[i] * (amari / v[i]);
	}

	//cout << amari << " " << ans << endl;

	if (ans <= syou) {
		cout << "1" << endl;
	}
	else
	{
		cout << "0" << endl;
	}



	return 0;
}


Measured memory_bytes: 256
//be name khoda :)

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

#define sz(x) ((int)x.size())
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define pb emplace_back
#define IINF 0x3f3f3f3f //1061109567
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;

inline int in() {int x, y; y = scanf("%d", &x); return x;}

const int N = 101;

string s[N];
int d[N][N], dx[2] = {0, 1}, dy[2] = {1, 0};

struct MyComp { 
    bool operator()(pair <int, pii> const &a, pair <int, pii> const &b) 
    { 
        if(a.first < b.first)
			return false;
		if(a.first > b.first)
			return true;
		return s[a.second.first][a.second.second] == '.';
    } 
}; 

int main() {
	random_device rd; mt19937_64 eng(rd()); uniform_int_distribution<long long> distr; // distr(eng)
	ios_base::sync_with_stdio(0), cin.tie(0);
	int h, w;
	cin >> h >> w;
	rep(i, h)
		cin >> s[i];
	priority_queue <pair<int, pii>, vector<pair<int, pii>>, MyComp> q;
	memset(d, -1, sizeof(d));
	d[0][0] = (s[0][0] == '#');
	q.push({0, {0, 0}});
	while(!q.empty()) {
		auto p = q.top().second;
		int x = p.first, y = p.second;
		q.pop();
		rep(i, 2) {
			int tx = x + dx[i];
			int ty = y + dy[i];
			if(tx < h and ty < w and d[tx][ty] == -1) {
				d[tx][ty] = d[x][y] + (s[x][y] == '.' and s[tx][ty] == '#');
				q.push({d[tx][ty], {tx, ty}});
			}
		}
	}
	// rep(i, h)
	// 	rep(j, w)
	// 		cerr << d[i][j] << " \n"[j == w - 1];
	cout << d[h - 1][w - 1] << endl;
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
int up;//??????
bool b[1000][1000];
	int c=-1;
	int i2;
	int itizi;
	int i;	
	int con;//?¶??????????
	int saisyo[1000];
	for(i=0;c==-1;i++){
		scanf("%d",&up);
		if(up==0){c=i;break;}
		scanf("%d",&itizi);
		saisyo[i]=itizi;
		b[i][itizi]=true;	
		for(i2=1;i2<up;i2++){
			scanf("%d",&itizi);
			b[i][itizi]=true;
		}
	}
	
	for(i=0;i<c;i++){
		con=-1;
		for(i2=1;i2<=1000;i2++){
			if(con==-1&&b[i][i2]==true){
				con=i2;
			}
			else if(b[i][i2]==true){}
			else if(con!=-1&&b[i][i2]!=true){
				if(con==saisyo[i]){
					if(con==i2-1){printf("%d",con);}
					else {printf("%d-%d",con,i2-1);}
			    }
				else {
					if(con==i2-1){printf(" %d",con);}
				    else {printf(" %d-%d",con,i2-1);}
				}
				con=-1;
			}
		}
		printf("\n");
	}
return 0;
}

Measured memory_bytes: 1128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    public class B_Triple_Dots
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int k = int.Parse(Console.ReadLine());
            // 文字列の入力
            string s = Console.ReadLine();


            //// 文字列配列の入力
            //string[] inputStrArray = Console.ReadLine().Split(' ');

            //// 整数配列の入力
            //var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            string result = "";
            if(s.Length<=k)
            {
                result = s;
            }
            else
            {
                result = Global.Left(s, k) + "...";
            }


            //string result = "";

            Console.WriteLine(result);

            Console.Out.Flush();
        }

        public class Global
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public Global(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
            public static string Right(string str, int len) { return ((str != null && str.Length >= len && str.Length >= 0) ? str.Substring(str.Length - len) : ""); }
            public static string Left(string str, int len) { return ((str != null && str.Length >= len && str.Length >= 0) ? str.Substring(0, len) : ""); }



        }
    }
}


Measured memory_bytes: 27500
import bisect

A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
"""
def bsr(a, v, lo=0, hi=None):
	if None == hi:
		hi = len(a) - 1
	while lo <= hi:
		mi = (lo + hi) // 2
		if a[mi] <= v:
			lo = mi + 1
		else:
			hi = mi - 1
	return lo
"""
bsr = bisect.bisect_right

INF = 10 ** 18
s = [-INF] + S + [INF]
t = [-INF] + T + [INF]

for x in X:
	sp = bsr(s, x)
	tp = bsr(t, x)
	cost = []
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(s[sp - 0] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(s[sp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 0] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 0] - t[tp - 1])]
	cost += [abs(t[tp - 0] - x) + abs(s[sp - 1] - t[tp - 0])]
	cost += [abs(t[tp - 1] - x) + abs(s[sp - 1] - t[tp - 1])]
	print(min(cost))


Measured memory_bytes: 105560
import itertools

n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

# generate permunations from Node 2 to Node n
p = itertools.permutations(range(2, n + 1), n - 1)

cnt = 0
for v in p:
    if [1, v[0]] not in ab and [v[0], 1] not in ab:
        continue
    else:
        if all([n0, n1] in ab or [n1, n0] in ab for n0, n1 in zip(v, v[1:])):
            cnt += 1
print(cnt)

Measured memory_bytes: 9096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int i = 1;
        while( x != 0){
            System.out.printf("Case %d: %d\n", i, x);
            x = sc.nextInt();
            i++;
        }
    }
}


Measured memory_bytes: 67512
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int alice=0, bob=0;
    for(int i = 0; i < n; i++)
    {
        if (i%2 == 0) {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout << alice-bob << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (r, g, b, n) = readLine()!!.split(" ").map { it.toInt() }

    var count = 0

    for (i in 0 until n / r + 1) {
        for (j in 0 until n / g + 1) {
            val rest = (n - (r * i + g * j))
            if (rest >= 0 && rest % b == 0) {
                count += 1
            }
        }
    }
    print(count)
}

Measured memory_bytes: 36076
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, k, r, s, p, res = 0;
    string t, piece[111111];
    cin>>n>>k>>r>>s>>p>>t;
    rep(i, n) {
        piece[i % k].push_back(t[i]);
    }
    rep(i, k) {
        rep(j, piece[i].size()) {
            if(piece[i][j] == 'r') res += p;
            else if(piece[i][j] == 's') res += r;
            else res += s;

            if(piece[i][j + 1] == piece[i][j]) j++;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 5328
N = gets.chomp.to_i
x = []
y = []
h = []

N.times do
  a,b,c = gets.chomp.split.map(&:to_i)
  x << a
  y << b
  h << c
end


# h[i] == 0でないのが1つしかないとき
if h.count(0) == N-1
  N.times do |i|
    if h[i] != 0
      puts [x[i], y[i], h[i]].join(' ')
      exit
    end
  end
end

0.upto(100) do |c_x|
  0.upto(100) do |c_y|
    flag = true
    h_tmp = -1

    N.times do |i|
      next if h[i] == 0

      if h_tmp == -1
        # 登録されていなかったら登録する
        h_tmp = h[i] + (x[i]-c_x).abs + (y[i]-c_y).abs
        next
      end

      if h_tmp != h[i] + (x[i]-c_x).abs + (y[i]-c_y).abs
        flag = false
        break
      end
    end

    if flag
      puts [c_x, c_y, h_tmp].join(' ')
      exit
    end
  end
end


Measured memory_bytes: 1788
#include <stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    if(a!=1)
    {

        if(b!=1)
        {
            if(a>b)
            {
                printf("Alice\n");
            }

            else if(a<b)
            {
                printf("Bob\n");
            }
            else
            {
                printf("Draw\n");
            }
        }
        else
        {
            if(b==1)
            {
                printf("Bob\n");
            }
            else
            {
                if(a>b)
                {
                    printf("Alice\n");
                }
                else if(a<b)
                {
                    printf("Bob\n");
                }
                else
                {
                    printf("Draw\n");
                }
            }

        }
    }
    else if(a==b)
    {
        printf("Draw\n");
    }
    else
    {
        if(a==1)
        {
            printf("Alice\n");
        }
        else
        {
            if(b==1)
            {
                printf("Bob\n");
            }
            else
            {
                if(a>b)
                {
                    printf("Alice\n");
                }
                else if(a<b)
                {
                    printf("Bob\n");
                }
                else
                {
                    printf("Draw\n");
                }
            }

        }
    }
    return 0;
}


Measured memory_bytes: 128
n = int(input())
s = input()

ans = 0
lenS = 1
for i in range(n):
	tempS = s[i:i+lenS]
	while (tempS in s[i+lenS:]):
		lenS += 1
		tempS = s[i:i+lenS]
		ans += 1
	if (i + 2*lenS>= n):
		break
print(ans)

Measured memory_bytes: 3064
// Contest: AtCoder Beginner Contest 179 (https://atcoder.jp/contests/abc179)
// Problem: F: Simplified Reversi (https://atcoder.jp/contests/abc179/tasks/abc179_f)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    int n, q; cin >> n >> q;
    ll rem = (n - 2) * (ll)(n - 2);
    map<int, int> h, w;
    h[n-1] = n - 2;
    w[n-1] = n - 2;

    while (q--) {
        int t, x; cin >> t >> x; --x;
        if (t == 1) {
            auto it = h.upper_bound(x);
            rem -= it->second;
            if (it == begin(h))
                begin(w)->second = x - 1;
            h[x] = it->second;
        } else {
            auto it = w.upper_bound(x);
            rem -= it->second;
            if (it == begin(w))
                begin(h)->second = x - 1;
            w[x] = it->second;
        }
    }

    cout << rem << '\n';
    return 0;
}


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

#define int long long

signed main() {
    int h, w;
    cin >> h >> w;
    for(int i=0; i<h; ++i) {
        for(int j=0; j<w; ++j) {
            string s;
            cin >> s;
            if(s=="snuke") {
                cout << (char)('A'+j) << i+1 << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
//Coalbert Ramirez
//AtCoder Begginer Contest 159D - Banned K
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5+1;
long long a[maxN], n;
  
int main(){
  cin >> n;
  long long f[n]{0};
  for(int i = 0; i < n; ++i){
		cin >> a[i];
  	f[a[i]-1]++;
	}
	long long ways[n]{0};
	long long total = 0;
	for(int i=0; i < n; ++i){
		if (f[i]){
			ways[i] = f[i]*(f[i]-1)/2;
			total += ways[i];
		}
	}
	
  for(int i = 0; i < n; ++i){
  	long long number = a[i];
  	cout << total - ways[number-1] + (f[number-1]-1)*(f[number-1]-2)/2 << "\n";
	}
  return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N,K; cin >> N >> K;
    vector<int> P(N);
    vector<int> C(N);
    ll outt=-LNF;
    for(int i=0;i<N;i++){
        cin >> P[i]; P[i]--;
    }
    for(int i=0;i<N;i++){
        cin >> C[i];
    }
    for(int i=0;i<N;i++){
        ll tmp=0;
        int x=P[i];
        for(int j=0;j<min(K,N);j++){
            tmp += C[x];
            outt = max(tmp,outt);
            x = P[x];
        }
    }
    if(K<=N){
        cout << outt << endl;
        return 0;
    }
    ll out=-LNF;
    for(int i=0;i<N;i++){
        vector<int> lp;
        int x=i;
        ll tmp=0;
        for(int j=0;j<=N;j++){
            x = P[x];
            lp.push_back(x);
            tmp += C[x];
            if(i==x){
                break;
            }
        }
        int l=lp.size();
        ll t=0;
        for(int j=0;j<l;j++){
            t += C[lp[j]];
            //if(j+1>K) break;
            ll now=t;
            if(tmp>0){ //１周した結果が正
                ll e = (K-(j+1))/l;
                now += tmp*e;
            }
            out = max(out,now);
        }
    }
    cout << max(out,outt) << endl;
    return 0;
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9
int n;
vector<int> A;
vector<bool> ans(2003, false);
void solve(){
  REP(b, 1 << n){
    int sum = 0;
    REP(i, n){
      if((b >> i) & 1){
        sum += A[i];
      }
    }
    ans[sum] = true;
  }
}
int main(){
  cin >> n;
  A.resize(n);
  REP(i, n){
    scanf("%d", &A[i]);
  }
  int q;
  cin >> q;
  vector<int> m(q);
  REP(i, q){
    cin >> m[i];
  }
  solve();
  REP(i, q){
    if(ans[m[i]]){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }
  }
  return 0;
}



Measured memory_bytes: 3156
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

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

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 220000;

int n;
ll a[MAXN];
ll dpr[MAXN];
ll dpl[MAXN];
ll go[MAXN];

void solve(ll *a, int n, ll *dp) {
	for (int i = 0; i + 1 < n; ++i) {
		if (a[i] <= a[i + 1]) {
			int cnt = 0;
			ll cur = a[i];
			while (cur * 4 <= a[i + 1])
				++cnt, cur *= 4;
			go[i] = cnt * 2;
		}
		else {
			int cnt = 0;
			ll cur = a[i + 1];
			while (cur < a[i])
				cur *= 4, --cnt;
			go[i] = cnt * 2;
		}
		go[i] = -go[i];
	}
	dp[n - 1] = 0;
	vector<tuple<int, ll, ll>> vv;
	for (int i = n - 2; i >= 0; --i) {
		ll d = go[i];
		if (d <= 0) {
			vv.emplace_back(i + 1, d, d * (n - 1 - i));
			dp[i] = dp[i + 1];
		}
		else {
			ll sum = d * (n - 1 - i);
			ll cur = d;
			int fl = 0;
			while (!vv.empty()) {
				int r; ll s, dd;
				tie(r, dd, s) = vv.back();
				vv.pop_back();
				if (cur + dd <= 0) {
					fl = 1;
					vv.emplace_back(r, cur + dd, sum + s);
					dp[i] = dp[r] + (sum + s) - (cur + dd) * (n - r);
					break;
				}
				else {
					sum += s;
					cur += dd;
				}
			}
			if (!fl) {
				vv.emplace_back(n - 1, cur, sum);
				dp[i] = sum;
			}
		}
	}
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	solve(a, n, dpr);
	reverse(a, a + n);
	solve(a, n, dpl);
	reverse(a, a + n);
	reverse(dpl, dpl + n);
	ll ans = 1e18;
	ans = min(dpr[0], dpl[n - 1] + n);
	for (int i = 0; i + 1 < n; ++i) {
		ans = min(ans, i + 1 + dpl[i] + dpr[i + 1]);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 13296
from collections import Counter
def main():
    N = int(input())
    V = [int(a) for a in input().split()]
    
    even = list()
    odd = list()

    for i in range(N):
        if (i + 1) % 2 == 0:
            odd.append(V[i])
        else:
            even.append(V[i])

    even_counter = Counter(even).most_common()
    odd_counter = Counter(odd).most_common()

    ans = 0
    if even_counter[0][0] != odd_counter[0][0]:
        if len(even_counter) >= 2:
            ans += len(even) - even_counter[0][1]

        if len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[0][1]

    else:
        if len(even_counter) == 1 and len(odd_counter) == 1:
            ans += even_counter[0][1]

        elif len(even_counter) == 1 and len(odd_counter) >= 2:
            ans += len(odd) - odd_counter[1][1]

        elif len(even_counter) >= 2  and len(odd_counter) == 1:
            ans += len(even) - even_counter[1][1]

        elif len(even_counter) >= 2 and len(odd_counter) >= 2:
            cost_even = len(even) - even_counter[0][1] + len(odd)  - odd_counter[1][1]
            cost_odd  = len(odd)  - odd_counter[0][1]  + len(even) - even_counter[1][1]

            ans += min(cost_even, cost_odd)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    if(n==1) cout<<"Hello World"<<endl;
    else{
        ll a,b; cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size],ara[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	//int ara[n_size],ara2[n_size];

	cin>>n;

	vi vec;

	f(i,1,n)
	{
	    cin>>ara[i];
	}

    if(n & 1)
    {
        for(i=n;i>=1;i-=2) cout<<ara[i]<<" ";
        for(i=2;i<=n-1;i+=2) cout<<ara[i]<<" ";
        cout<<endl;
    }
    else{
        for(i=n;i>=1;i-=2) cout<<ara[i]<<" ";
        for(i=1;i<=n-1;i+=2) cout<<ara[i]<<" ";
        cout<<endl;
    }

}


Measured memory_bytes: 2944
package main

import "fmt"

func main() {
	var A, B int

	fmt.Scan(&A, &B)

	if B%2 == 0 {
		if A >= 13 {
			fmt.Print(B)
		} else if A >= 6 && A <= 12 {
			fmt.Print(B / 2)
		} else if A <= 5 {
			fmt.Print("0")
		}
	}
}


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

int main(){
  int cnt[4]={0,0,0,0};
  for(int i=0;i<3;i++){
    int a,b; cin>>a >>b;
    a--; b--;
    cnt[a]++; cnt[b]++;
  }
  
  for(int i=0;i<4;i++){
    if(cnt[i]>2){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;



int main()
{
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    if(x>=y){
        ans = 2*y*c+(x-y)*a;
    }
    else{
        ans = 2*x*c+(y-x)*b;
    }
    ans = min(ans,a*x+b*y);
    ans = min(ans,2*c*max(x,y));
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

static const double PI=acos(-1);

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  double ans;
  if(x>a*a*b/2) {
    ans=atan((a*a*b-x)*2/a/a/a)*180/PI;
    
  }else {
    ans=atan(a*b*b/x/2)*180/PI;
  }
  
  printf("%.10f\n", ans);
  
  
  
  
}



Measured memory_bytes: 384