akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

#define size 3000
long long fac[size],finv[size],inv[size];
void COMvec() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < size; 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;
  }
}

ll COM(ll n,ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    ll S; cin >> S;
    if(S<3){
        AA(0);
        return 0;
    }
    if(S==3){
      AA(1);
      return 0;
    }
    COMvec();
    S-=3;
    ll i=0;
    ll ans = 0;
    for(;S>0;S-=2){
        ans = (ans + COM(S,i))%MOD;
        i++;
    }
    AA(ans);
    return 0;
}

Measured memory_bytes: 3692
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using Graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n)
    {
        ll tmp;
        cin >> tmp;
        a[i] = tmp;
        b[i] = tmp;
    }

    rep(i, n)
    {
        if (i > 0)
        {
            if (b[i - 1] > a[i])
            {
                b[i] = b[i - 1];
            }
        }
    }

    ll sum = 0;
    rep(i, n)
    {
        sum += b[i] - a[i];
    }
    cout << sum << endl;
}

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

int main(){

  int red,green,blue,k;
  cin >> red >> green >> blue >> k;

  int last=k;
  while(1){
    if(green>red)break;
    if(last==0 && green<=red){
      cout << "No" << endl;
      return 0;
    }
    green*=2;
    last--;
  }

  while(1){
    if(blue>green){
      cout << "Yes" << endl;
      return 0;
    }
    if(last==0 && blue<=green){
      cout << "No" << endl;
      return 0;
    }
    blue*=2;
    last--;
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    int count(int u) {
        return -p[root(u)];
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

struct E {
    int a, b;
};

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

    int n, m;
    cin >> n >> m;

    vector<E> p(m);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        p[i] = { a, b };
    }

    UnionFind uf(n);
    vector<ll> r(m);
    ll s = 0;
    for (int i = m - 1; i >= 0; i--) {
        r[i] = s;
        if (uf.same(p[i].a, p[i].b)) continue;
        s += (ll)uf.count(p[i].a) * uf.count(p[i].b);
        uf.unite(p[i].a, p[i].b);
    }

    for (int i = 0; i < m; i++) {
        cout << s - r[i] << '\n';
    }
    cout << flush;

    return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 3005
#define ll long long
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, mod, fac[N], inv[N], S[N][N];
int Pow(int a, int k, int m)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2, m);
	if (k & 1)
		return (ll)p * p % m * a % m;
	return (ll)p * p % m;
}
int C(int n, int m)
{
	if (n < m)return 0;
	if (m < 0)return 0;
	return (ll)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
	Read(n), Read(mod);
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = (ll)fac[i - 1] * i % mod;
	inv[n] = Pow(fac[n], mod - 2, mod);
	for (int i = n; i >= 1; i--)
		inv[i - 1] = (ll)inv[i] * i % mod;
	S[0][0] = 1;
	for (int i = 1; i <= n + 1; i++)
		for (int j = 1; j <= i; j++)
			S[i][j] = (S[i - 1][j - 1] + (ll)j * S[i - 1][j]) % mod;
	int ans = 0;
	for (int i = 0; i <= n; i++)
	{
		int sum = 0;
		for (int x = 0; x <= i; x++)
			sum = (sum + (ll)Pow(Pow(2, n - i, mod), x, mod) * S[i + 1][x + 1] % mod) % mod;
		sum = (ll)sum * Pow(2, Pow(2, n - i, mod - 1), mod) % mod * C(n, i) % mod;
		if (i & 1)
			ans = (ans + mod - sum) % mod;
		else
			ans = (ans + sum) % mod;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 34176
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, long long M, vector<string> A, vector<string> B) {
  REP(y, N) REP(x, N) {
    bool flag = true;
    REP(ny, M) REP(nx, M) {
      if (!flag)
        break;

      if (y + ny >= N || x + nx >= N) {
        flag = false;
        continue;
      }
      flag = A[y + ny][x + nx] == B[ny][nx];
    }
    if (flag) {
      cout << "Yes" << endl;
      return;
    }
  }

  cout << "No" << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long M;
  long long N;
  cin >> N;
  vector<string> A(N - 1 + 1);
  cin >> M;
  vector<string> B(M - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> A[i];
  }
  for (int i = 0; i <= M - 1; i++) {
    cin >> B[i];
  }
  solve(N, M, A, B);
  return 0;
}


Measured memory_bytes: 256
#def main(S, b):
if __name__ == '__main__':
    # n, m = map(int, input().split())
    s = input()
    n = len(s)

    flug = 1
    for i in range((len(s) - 1) // 2):
        if (s[i] != s[n - 1 - i]):
            flug = 0
            break
    if (flug):
        t = s[:(n - 1) // 2]
        for i in range(len(t) // 2):
            if (t[i] != t[len(t) - 1 - i]):
                flug = 0
        u = s[(n + 3) // 2 - 1:]
        for i in range(len(u) // 2):
            if (u[i] != u[len(u) - 1 - i]):
                flug = 0
        # print(t)
        # print(u)
    if (flug == 1):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 18;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int D[100001] = {};
	rep(i, N) (*(D + getint()))++;
	int S = 0;
	int kotae = 0;
	for (int i = 100000; i > 0; i--) {
		S += *(D + i);
		if (S >= N / 2) {
			if (S == N / 2) {
				i--;
				kotae++;
				while (!D[i]) {
					kotae++;
					i--;
				}
			}
			break;
		}
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 896
n   = gets.to_i     #入力数
str = Array.new
n.times {
     str << gets.chomp.delete('\"').to_s #文字列を格納
}

# 1.group_by(&:itself):同じ要素でまとめる(この時点で連想配列になる)
    #p m = str.group_by(&:itself) 
# 2.map()ですべての要素に対して[key] [Value.count]で要素名と数にまとめて mm に格納
    mm = str.group_by(&:itself).map{ |k, v| [k, v.count] }
# 3.辞書順に並べ替え
    mm.sort!()
# 4.mmをvでカウントした最大値を入手→その[1]をmmmに格納
    mmm = mm.max_by{ |k,v| v }
mm.each { |k,v|
    if v == mmm[1] then
         print("#{k}\n")
    end
}

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

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    string tmp;
    cin >> tmp;
    cout << tmp << endl;
    cout << tmp << endl;
  }
}


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

int main() {
	int M1,D1,M2,D2;
	cin >> M1 >> D1 >> M2 >> D2;
  if(M1 != M2){
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	int N;
	cin>>N;
	if(N%10==9){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(N>=90){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
a,b = map(int, input().split())

ans = 0
for i in range(10000):
    x = int(i*0.08)
    y = int(i*0.10)
    if x == a and y == b:
        ans = i
        break
if ans == 0:
    print(-1)
    exit()
print(ans)


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

const int N = 2e5 + 50;
int n,k, a[N];



int main() {
    cin >> n  >> k ;
    for(int i=0;i<n;i++){
        int x;
         cin >> x;
         a[x]++;
    }
    int ans = 0;
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=k;i<=n;i++) ans += a[i];
    cout << ans;



}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main (){	
	int a,b,i,r[9];
	while(scanf("%d%d", &a, &b)!=EOF){
		for(i=0;i<=9;i++)
		{
			r[0]=a+b;
			r[i+1]=r[i]/10;		
			if (r[i]<1)
				break;		
		}
		printf("%d\n",i);
	}
		return 0;
}


Measured memory_bytes: 1976
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] num = {1,3,1,2,1,2,1,1,2,1,2,1};
        int x = sc.nextInt();
        int y = sc.nextInt();

        if(num[x-1] == num[y-1]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22100
fn read<T: std::str::FromStr>() -> T {
    let mut s  = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main(){
    let t : i32 = read();

    println!("{}:{}:{}", t / 3600, (t / 60) % 60, t % 60);
}




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

int main(){ 
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << endl;
  return 0;
} 

Measured memory_bytes: 3560
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	u32 sum{ 0 }, max{ 0 };
	while (n--) {
		u32 t;
		::std::cin >> t;
		sum += t;
		smaxi(max, t);
	}
	::std::cout << sum - max / 2 << ::std::endl;
	return 0;
}


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

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for(int x = 0; x <= k; x++) {
    for(int y = 0; y <= k; y++) {
      int z = s - x - y;
      if(0 <= z && z <= k) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    long long n,a,b,c;
    cin >> n >> a >> b >> c;
    bool flag=true;
    string s[n];
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    vector<string> vec;
    for(int i=0;i<n;i++){
        if(s[i]=="AB"){
            if(a==0&&b==0){
                flag=false;
                break;
            }
            else if(a>b){
                a--;
                b++;
                vec.push_back("B");
            }
            else if(b>a){
                b--;
                a++;
                vec.push_back("A");
            }
            else if(a==b&&i+1<=n-1&&s[i+1]=="BC"){
                a--;
                b++;
                vec.push_back("B");
            }
            else if(a==b&&i+1<=n-1&&s[i+1]=="AC"){
                a++;
                b--;
                vec.push_back("A");
            }
            else{
                a--;
                b++;
                vec.push_back("B");
            }
        }
        if(s[i]=="AC"){
            if(a==0&&c==0){
                flag=false;
                break;
            }
            else if(a>c){
                a--;
                c++;
                vec.push_back("C");
            }
            else if(c>a){
                c--;
                a++;
                vec.push_back("A");
            }
            else if(a==c&&i+1<=n-1&&s[i+1]=="BC"){
                a--;
                c++;
                vec.push_back("C");
            }
            else if(a==c&&i+1<=n-1&&s[i+1]=="AB"){
                a++;
                c--;
                vec.push_back("A");
            }
            else{
                a--;
                c++;
                vec.push_back("C");
            }
        }
        if(s[i]=="BC"){
            if(b==0&&c==0){
                flag=false;
                break;
            }
            else if(b>c){
                b--;
                c++;
                vec.push_back("C");
            }
            else if(c>b){
                c--;
                b++;
                vec.push_back("B");
            }
            else if(b==c&&i+1<=n-1&&s[i+1]=="AC"){
                b--;
                c++;
                vec.push_back("C");
            }
            else if(b==c&&i+1<=n-1&&s[i+1]=="AB"){
                b++;
                c--;
                vec.push_back("B");
            }
            else{
                b--;
                c++;
                vec.push_back("C");
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
        for(int i=0;i<n;i++){
            cout << vec.at(i) << endl;
        }
    }
    if(!flag) cout << "No" << endl;
}

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

int main()
{
	string s;
	int n;
	cin >> n >> s;
	string saves = s;
	int len = (int)s.size();
		
	bool flag = false;
	REP(i, len){
		if (s[i] == '('){
			FOR(j, i, len){
				if (s[j] == ')'){
					s.erase(s.begin()+j);
					flag = true;
					j--;
				}
			
				if (flag == true){
					s.erase(s.begin()+i);
					flag = false;
					i--;
					break;
				}

			len = (int)s.size();
			}
		len = (int)s.size(); 
		}
//		cout << endl;

	}
//	cout << s << endl;

	int count1 = 0;
	int count2 = 0;
	
	len = (int)s.size();
	REP(i, len){
		if (s[i] == '(') count1++;
		else count2++;
	}

	REP(i, count2) saves = '(' + saves;
	REP(i, count1) saves = saves + ')';

	cout << saves << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 2e5 + 5;
ii a[maxn];
int n;
multiset<int> s , b;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i].first >> a[i].second;
        if(a[i].first > a[i].second)swap(a[i].first ,a[i].second);
        s.insert(a[i].first);
        b.insert(a[i].second);
    }
    sort(a + 1 , a + n + 1);
    ll res = 1e18;
    for(int i = 1 ; i <= n ; ++i){
        res = min(res , (ll)(*s.rbegin() - *s.begin()) * (*b.rbegin() - *b.begin()));
        s.erase(s.find(a[i].first));s.insert(a[i].second);
        b.erase(b.find(a[i].second));b.insert(a[i].first);
    }
    cout << res;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

    // dp[i] := 長さが i+1 であるような増加部分列における最終要素の最小値
    vector<int> dp(n, 1e9);
    vector<vector<int>> g(n);
    for(int i=0; i<n; i++){
        g[lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin()].push_back(a[i]);
        *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
    }

    ll ans=0;
    int gmax=1e9;
    for(int i=n-1; i>=0; i--){
        if(g[i].size()){
            sort(g[i].begin(), g[i].end(), greater<int>());
            for(auto j:g[i]){
                if(j<gmax){
                    gmax=j;
                    ans+=j;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 9056
while True:
    n = int(input())
    if n == 0:
        quit()
    a = []
    for i in range(n):
        a.append(int(input()))
    mn = -100001
    for i in range(len(a)):
        temp = a[i]
        mn = max(mn, temp)
        for j in range(i+1, len(a)):
            temp += a[j]
            mn = max(mn, temp)
    print(mn)


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

template <unsigned long long mod> class modint {
  public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod - this->v); }
	modint& operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod) v -= mod;
		return *this;
	}
	modint& operator-=(const modint rhs) {
		if (v < rhs.v) v += mod;
		v -= rhs.v;
		return *this;
	}
	modint& operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) { ret *= a; }
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint& operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
	friend ostream& operator<<(ostream& os, modint& u) {
		os << u.v;
		return (os);
	}
	friend istream& operator>>(istream& is, modint& u) {
		is >> u.v;
		return (is);
	}
};

const int MOD = 998244353;
using mint = modint<MOD>;

const int MAX = 5005;
mint fac[MAX], invfac[MAX], inv[MAX];

void facinit() {
	fac[0] = fac[1] = 1;	
	invfac[0] = invfac[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i;
		inv[i] = - inv[MOD%i] * (MOD / i);
		invfac[i] = invfac[i - 1] * inv[i];
	}
}

mint nCr(int n, int r){
	if(r < 0 || n < r)return mint{0};
	return fac[n]*invfac[r]*invfac[n-r];
}

mint nHr(int n, int r){
	if(n == 0 && r == 0)return mint{1};
	return nCr(n+r-1, n);
}

class Solution {
public:
	void solve() {
		int k, n;
		cin >> k >> n;
		facinit();
		vector<vector<mint>> dp(k+1, vector<mint>(n+1, 0));
		dp[0][0] = 1;
		for(int i=0; i < k; i++){
			mint s = 0;
			for(int j=0; j<=n; j++){
				dp[i+1][j] += s.v + dp[i][j].v;
				s += dp[i][j] * 2;
			}
		}
		for(int i=2; i <= 2*k; i++){
			int x = min(i, (2 * k + 2) - i);
			mint ret = 0;
			for(int j=0; j <= n; j++){
				ret += dp[(x-1)/2][j] * nHr(n-j, k-x+1);
				if(x%2 == 0)ret += dp[(x-1)/2][j] * nHr(n-j-1, k-x+1);
			}
			cout << ret << "\n";
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 31744
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a,b;
    a=sc.nextInt();
    b=sc.nextInt();
    if(a>=13){
      System.out.println(b);
    }else if(a<=5){
      System.out.println(0);
    }else{
      System.out.println(b/2);
    }
  }
}


Measured memory_bytes: 21716
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

s = ins()
n = len(s)
a = ab = abc = 0
z = 1
for i in range(n):
    ss = s[i]
    if ss=='A':
        a += z
    elif ss=='B':
        ab = (ab+a)%R
    elif ss=='C':
        abc = (abc+ab)%R #+qb+aq+qq
    else:
        abc = (abc*3+ab)%R #+qb+aq+qq
        ab = (ab*3+a)%R
        a = (a*3+z)%R
        z = (z*3)%R
    #ddprint(f"{i=} {z=} {a=} {ab=} {abc=}")
print(abc)


Measured memory_bytes: 73172
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());

		String nn = Integer.toString(N, K);
		System.out.println(nn.length());

	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
using namespace std;
struct  Dice{
	int left;
	int right;
	int top;
	int bottom;
	int front;
	int behind;
	void e()
	{
		int t=this->front;
		this->front=this->left;
		this->left=this->behind;
		this->behind=this->right;
		this->right=t;
	}
	void w()
	{
		int t=this->front;
		this->front=this->right;
		this->right=this->behind;
		this->behind=this->left;
		this->left=t;
	}
	void s()
	{
		int t=this->front;
		this->front=this->top;
		this->top=this->behind;
		this->behind=this->bottom;
		this->bottom=t;
	}
	void n()
	{
		int t=this->front;
		this->front=this->bottom;
		this->bottom=this->behind;
		this->behind=this->top;
		this->top=t; 
	}
	void loop()
	{
		int t=this->right;
		this->right=this->bottom;
		this->bottom=this->left;
		this->left=this->top;
		this->top=t;
	}
};
int main() {
	Dice dice;
	int n,front,top;
	cin>>dice.front>>dice.bottom>>dice.right>>dice.left>>dice.top>>dice.behind; 
	cin>>n;
	while(n--)
	{
		cin>>top>>front;
		while(dice.right==top||dice.left==top) dice.loop(); 
		while(dice.top!=top) dice.n();
		while(dice.front!=front) dice.e();
		cout<<dice.right<<endl;
	}
	return 0;
}



Measured memory_bytes: 3116
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N = z()
A = zz()


def get_sadness(A, b):
    sad = 0
    for i, a in enumerate(A):
        sad += abs(a - (b))
    return sad


for i in range(N):
    A[i] -= (i+1)
A = sorted(A)
# print(A)
if(N % 2 == 0):
    b = (A[N//2] + A[N//2 - 1])//2
else:
    b = A[N//2]
# print(b)

print(get_sadness(A, b))


Measured memory_bytes: 49352
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn f(
    state: usize,
    dp: &mut [Option<usize>],
    av: &[usize],
    cvv: &[Vec<usize>],
    n: usize,
    inf: usize,
) -> usize {
    if let Some(res) = dp[state] {
        return res;
    }
    if state == (1 << n) - 1 {
        let res = 0;
        dp[state] = Some(res);
        return res;
    }
    let mut res = inf;
    for i in 0..av.len() {
        let a = av[i];
        let mut bits = 0;
        for &c in &cvv[i] {
            bits |= 1 << c;
        }
        let new_state = state | bits;
        if new_state != state {
            let cost = a + f(new_state, dp, av, cvv, n, inf);
            res = res.min(cost);
        }
    }
    dp[state] = Some(res);
    res
}

fn solve() {
    input! {
        n: usize, m: usize
    };

    let mut av = Vec::new();
    let mut cvv = Vec::new();
    for _ in 0..m {
        input! {
            a: usize, b: usize,
            cv: [Usize1; b]
        };
        av.push(a);
        cvv.push(cv);
    }
    let max = (1 << n) - 1;
    let inf = 1 << 60;
    let mut dp = vec![None; max + 1];
    let cost = f(0, &mut dp, &av, &cvv, n, inf);
    let res = if cost == inf { -1 } else { cost as isize };
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2364
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int INF=1e9+7;
	int n;
	cin>>n;
	int k;
	cin>>k;
	long long h[n];
	for(int i=0;i<n;i++)cin>>h[i];
	long long dp[n+1];
	dp[0]=0;
	dp[1]=0;
	for(int i=2;i<=n;i++)dp[i]=INF;
	for(int i=1;i<n;i++){
		for(int j=1;j<=k && i+j<=n;j++){
			dp[i+j]=min(dp[i+j],dp[i]+abs(h[i-1]-h[i+j-1]));
		}
		
	}
	cout<<dp[n];
	return 0;
	
}


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

int main()
{
    int A,B,C,m,cnt=0;
    cin >> A >> B >> C;
    if(A == B && B == C){
        cout << 0 << endl;
        return 0;
    }
    int x = A+B+C;
    m = max(max(A,B),C);
    while(1){
        x += 2;
        cnt++;
        if(x%3 == 0){
            if(x/3 >= m){
                cout << cnt << endl;
                return 0;
            }
        }
    }
}


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

typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
const ll N=2e5 + 5;
const ll mod=1e9 + 7;
vector<ll> adj[N];
vector<ll> add(N,0);
vector<bool>visited(N,false);

void dfs(ll src,ll parent,ll val)
{
    visited[src]=true;
    add[src] = add[src] + val;
    for(ll i=0;i<adj[src].size();i++)
    {
        ll v=adj[src][i];
        if(v==parent)
            continue;
        dfs(v,src,add[src]);
    }
}
int main()
{
    fast();
    ll n,q;
    cin>>n>>q;

    for(ll i=0;i<n-1;i++)
    {
        ll u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    while(q-->0)
    {
        ll v,val;
        cin>>v>>val;
        v--;
        add[v]+=val;
    }


    dfs(0,-1,0);
    for(ll i=0;i<n;i++)
        cout<<add[i]<<" ";
}


Measured memory_bytes: 27392
n,m=map(int,input().split())
h=list(map(int,input().split()))
g=[1]*n
for _ in range(m):
  a,b=map(int,input().split())
  if g[a-1]:
    if h[a-1]<=h[b-1]:
      g[a-1]=0
  if g[b-1]:
    if h[b-1]<=h[a-1]:
      g[b-1]=0
print(g.count(1))

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

/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define II pair<int, int>
#define LL pair<ll, ll>
#define VI vector<int>
#define VB vector<bool>
#define VL vector<ll>
#define VII vector<II>
#define VLL vector<LL>
#define PB push_back
#define B begin()
#define E end()
#define F first
#define S second
#define SZ size()
#define P complex <ll> 
#define X real()
#define Y imag()
const int oo = 1e9;
const ll mod = 1e7;
/* * * *   * * *   	* * * */

/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, i; cin>>n>>i;
	cout<<n-i+1;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

int main()
{
	ll n, c;
	cin >> n >> c;
	
	vector<ll> x(n), y(n), v(n);
	REP (i, n)
	{
		cin >> x[i] >> v[i];
		y[i] = c - x[i];
	}
	
	ll res = 0;
	{
		vector<ll> mx(n);
		ll tmx = 0, cc = 0;
		REP (i, n)
		{
			cc += v[n - i - 1];
			mx[n - i - 1] = tmx;
			tmx = max(tmx, cc - y[n - i - 1] * 2);
		}
		cc = 0;
		REP (i, n)
		{
			cc += v[i];
			res = max(res, cc - x[i] + mx[i]);
		}
	}
	{
		vector<ll> mx(n);
		ll tmx = 0, cc = 0;
		REP (i, n)
		{
			cc += v[i];
			mx[i] = tmx;
			tmx = max(tmx, cc - x[i] * 2);
		}
		cc = 0;
		REP (i, n)
		{
			cc += v[n - i - 1];
			res = max(res, cc - y[n - i - 1] + mx[n - i - 1]);
		}
	}
	
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3440
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace atcoder;
using namespace std;
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;
}
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) {
            os << ',';
        }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    int N, Q;
    cin >> N >> Q;
    dsu uf(N);
    for(int _ = 0; _ < Q; _++) {
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0) {
            uf.merge(u, v);
        } else {
            cout << uf.same(u, v) << "\n";
        }
    }
}

Measured memory_bytes: 3856
import scala.annotation.tailrec

/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0011&lang=jp
  * Drawing Lots
  */
object Main {
  def main(args: Array[String]): Unit = {
    val w = io.StdIn.readInt()
    val n = io.StdIn.readInt()
    val hLines = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(n)
      .map(_.split(",").map(_.toInt)).map { case Array(a, b) => (a, b) }
      .toList
    val vLines = 1 to w
    val playedVLines = playAmida(vLines, hLines)
    playedVLines.foreach(println)
  }

  @tailrec
  def playAmida(vLines: Seq[Int], hLines: Seq[(Int, Int)]): Seq[Int] = {
    hLines match {
      case Nil => vLines
      case hHead :: hTail =>
        val newVLines = vLines.zipWithIndex
          .map {
            case (_, i) if i == hHead._1 - 1 => vLines(hHead._2 - 1)
            case (_, i) if i == hHead._2 - 1 => vLines(hHead._1 - 1)
            case (e, _) => e
          }
        playAmida(newVLines, hTail)
    }
  }

}

Measured memory_bytes: 43848
import sys
sys.setrecursionlimit(10 ** 8)
N = int(input())
graph = [[] * N for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])
    
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

depth = [0] * N
def dfs(v, p, d):
    depth[v] = d
    for new_v_list in graph[v]:
        new_v = new_v_list[0]
        if new_v == p:
            continue
        dfs(new_v, v, d + new_v_list[1])

dfs(K-1, -1, 0)
for i in range(Q):
    print(depth[xy[i][0] - 1] + depth[xy[i][1] - 1])

Measured memory_bytes: 162316
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int A = Integer.parseInt(tokens[1]);
		int B = Integer.parseInt(tokens[2]);

		int resultA = N * A;
		if (resultA < B) {
			System.out.println(resultA);
		} else {
			System.out.println(B);
		}
		in.close();
	}
}

Measured memory_bytes: 23124
// header file section
#include <iostream>
#include <cstdio>
#include <cfloat>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <algorithm>

using namespace std;
using llong = long long;

// library section
// ===

int main() {
    llong n, m;
    llong a[55];
    llong b[55];
    llong c[55];
    llong d[55];

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

    for (int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }

    for (int i = 0; i < n; i++) {
        llong minv = 1ll << 60ll;
        llong pos = -1;
        for (int j = 0; j < m; j++) {
            if (minv > llabs(a[i] - c[j]) + llabs(b[i] - d[j])) {
                minv = llabs(a[i] - c[j]) + llabs(b[i] - d[j]);
                pos = j;
            }
        }

        cout << pos + 1 << endl;
    }

    return 0;
};



Measured memory_bytes: 256
N = int(input())

def decompose(n):
    prime_exp = [0] * (n+1)
    for i in range(2, n+1):
        exponent = 0
        while(n % i == 0):
            n /= i
            exponent += 1
        if exponent != 0:
            prime_exp[i] = exponent
    return prime_exp

def decompose_fact(n):
    prime_exp = [0] * (n+1)
    for i in range(2, n+1):
        for j, k in enumerate(decompose(i)):
            prime_exp[j] += k
    return prime_exp

def solve(n):
    ans = 0
    dec_f = decompose_fact(n)
    for i in range(n+1):
        if dec_f[i] >= 74:
            ans += 1

    for i in range(n+1):
        for j in range(n+1):
            if i != j and (dec_f[i] >= 2 and dec_f[j] >= 24):
                ans += 1

    for i in range(n+1):
        for j in range(n+1):
            if i != j and (dec_f[i] >= 4 and dec_f[j] >= 14):
                ans += 1

    for i in range(n+1):
        for j in range(n+1):
            for k in range(n+1):
                if i != j and i != k and j != k and j < k and (dec_f[i] >= 2 and dec_f[j] >= 4 and dec_f[k] >= 4):
                    ans += 1
    return ans

print(solve(N))

Measured memory_bytes: 3064
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
	lst = [p[i-1], p[i], p[i+1]]
	lst.pop(lst.index(max(lst)))
	lst.pop(lst.index(min(lst)))
	if lst[0] == p[i]:
		cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vl u, v;

int main(){
	int n; scanf("%d", &n);
	REP(i, n){
		ll a, b; scanf("%lld%lld", &a, &b);
		u.EB(a);
		v.EB(b);
	}
	sort(ALL(u));
	sort(ALL(v));
	ll ans;
	if(n%2){
		ans = v[n/2] - u[n/2] + 1;
	} else {
		ans = (v[n/2] + v[n/2-1]) - (u[n/2] + u[n/2-1]) + 1;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 6568
def main():
    S = input()
    a = S[0:2]
    b = S[2:4]

    if 1 <= int(a) <= 12:
        if 1 <= int(b) <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if 1 <= int(b) <= 12:
            print("YYMM")
        else:
            print("NA")


if __name__ == "__main__":
    main()

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

const int maxn=2e5+5;
#define ll long long

int a[maxn];

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

    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll last=a[1],sum=0;
    for(int i=2;i<=n;i++)
    {
        if(a[i]<=last) sum+=last-a[i];
        else last=a[i];
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 4356
import java.util.*;


public class Main {
    public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
           
            int n = sc.nextInt();
            int c = 0;
            while (n != 0) {
                if (n % 10 == 2) {
                    c++;
                }
                n = n/10;
            }
            System.out.println(c);
            sc.close();
        }
    
}



Measured memory_bytes: 23764
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> v(N);
  vector<pair<ll, ll>> m_o(100001, {0, 0}), m_e(100001, {0, 0});
  for (int i = 0; i < N; i++) {
    cin >> v[i];
    if (i % 2 == 0) {
      m_o[v[i]].first++;
      m_o[v[i]].second = v[i];
    } else {
      m_e[v[i]].first++;
      m_e[v[i]].second = v[i];
    }
  }
  sort(m_o.rbegin(), m_o.rend());
  sort(m_e.rbegin(), m_e.rend());
  ll ans = 0;
  ll o_first = m_o[0].second;
  ll e_first = m_e[0].second;
  ll o_second = (m_o[1].first != 0) ? m_o[1].second : o_first;
  ll e_second = (m_e[1].first != 0) ? m_e[1].second : e_first;
  if (o_first == o_second && o_first == e_first && e_first == e_second) {
    ans = N / 2;
  } else if (o_first != e_first) {
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0 && v[i] != o_first) {
        ans++;
      }
      if (i % 2 == 1 && v[i] != e_first) {
        ans++;
      }
    }
  } else {
    ll cand1 = 0, cand2 = 0;
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0 && v[i] != o_first) {
        cand1++;
      }
      if (i % 2 == 1 && v[i] != e_second) {
        cand1++;
      }
    }
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0 && v[i] != o_second) {
        cand2++;
      }
      if (i % 2 == 1 && v[i] != e_first) {
        cand2++;
      }
    }
    ans = min(cand1, cand2);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int N=0;
    cin >> N;
    vector<int>dp(N);
    vector<int>a(N);
    for (int i=0; i<N; i++){
        cin >> a.at(i);
    }
    dp.at(0)=0;

    for(int i=1;i<N;i++){
        if(i-2>=0){
            dp.at(i) = min(dp.at(i-2) + abs(a.at(i)-a.at(i-2)), dp.at(i-1) + abs(a.at(i)-a.at(i-1)));
        }else{
            dp.at(i) = dp.at(i-1) + abs(a.at(i-1) - a.at(i));
        }
    }
    cout << dp.at(N-1) << endl;
} 

Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main() {
  int n, z, w;
  cin >> n >> z >> w;
  
  int a[2000];
  for(int i = 0; i < n; i++) {
   	cin >> a[i]; 
  }
  
  cout << (n == 1 ? abs(a[0] - w) : max(abs(a[n - 1] - w), abs(a[n - 1] - a[n - 2]))) << endl;
}

Measured memory_bytes: 512
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N,= map(int, sys.stdin.readline().rstrip().split(" "))
s = sys.stdin.readline().rstrip()
r = sum(ss == "R" for ss in s)
b = len(s) - r
print("Yes" if (r > b) else "No")

exit(0)


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    //freopen("Inp.txt","r", stdin);
    //freopen("Out.txt","w", stdout);

    int n; cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector <int> b(n);
    b[0]=0;
    b[1]=abs(a[1]-a[0]);
    for (int i = 2; i < n; i++)
        b[i] = min(b[i-1] + abs(a[i]-a[i-1]), b[i-2]+abs(a[i]-a[i-2]));
    cout << b[n-1];
    return 0;
}


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

int main()
{
	int a, b  = 0;
	cin >> a >> b;
	int ans = max(a, b);
	if (a < b)
	{
		b--;
	}
	else
	{
		a--;
	}

	ans += max(a, b);

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
 void swap (long *x, long *y) {
  long temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
long partition (long array[], long left, long right) {
  long i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (long array[], long left, long right) {
  long pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}

int main()
{
    long  N,K;
   long  Hsum=0;
    long  H[200000];
 
    scanf("%ld %ld", &N, &K);
 
    // printf("H=%ld N=%ld\n", N, K);
  if (N <= K) printf("0");
    else
    {
 
   
 
    //入力
    for (long  i=0; i < N; i++)
    {
      long  h;
        scanf("%ld", &(H[i]));
        // printf("H[%ld] = %ld\n",i, H[i]);
        Hsum += H[i];
    }
  
      //ソート
    // long  i, j;
    // long  tmp;
    // for (i=0; i<N; ++i)
    // {
    //     for (j=i+1; j<N; ++j)
    //     {
    //         if (H[i] > H[j])
    //         {
    //             tmp =  H[i];
    //             H[i] = H[j];
    //             H[j] = tmp;
    //         }
    //     }
    // }
 
 quick_sort(H, 0, N-1);
 
    for (long i=0; i<K; ++i)
    {
        Hsum -= H[N-1-i];
    }
 
 
    printf("%ld", Hsum);
    }
 
    return 0;
}

Measured memory_bytes: 1792