akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define ll long long int
#define endl "\n"
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector <int>
#define vl vector <long long>
#define pi pair <int, int>
#define sz(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define M 100005
#define mod 1000000007
using namespace std;

void solve()
{
	string s, t;
	cin>>s>>t;
	int n = s.size();
	if(t.substr(0, n) == s) cout<<"Yes\n";
	else cout<<"No";
}

int main()
{
    IOS
    int t = 1;
    //cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B,C; cin >> A >> B >> C;
    cout << min(B/A, C) << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include<iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   	ll n,cnt=0,temp=0,i=5,m;
   	cin >> n;
   	m=n/2;
   	while(m/i) {
   		temp+=(m/i);
   		i*=5;
   	}
   	if(!(n&1)) cout << temp;
   	else {
   		i=5;
   		while(n/i) {
   			cnt+=(n/i);
   			i*=5;
   		}
   		ll ans = cnt-m-temp;
   		if(ans>0) cout << ans;
   		else cout << 0; 
   	}
   	cout << "\n";
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int W=0,G=1,B=2;
int n,M[N][N],color[N],d[N],f[N],t;

void dfs_visit(int u){
  int v;
  color[u] = G;
  t++;
  d[u] = t;
  for(v=0;v<n;v++){
    if(M[u][v] == 0)continue;
    if(color[v] == W){
      dfs_visit(v);
    }
  }
  color[u] = B;
  f[u] = ++t;
}
void dfs(){
  int i,u;
  for(i=0;i<n;i++)color[i] = W;
  t = 0;
  for(u=0;u<n;u++){
    if(color[u] == W)dfs_visit(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}
main(){
  int u,k,v,i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j] = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v] = 1;
    }
  }
  dfs();

  return 0;
}



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


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
	int a, b ,m;

	cin >> a >> b >> m;

	int pa[a], pb[b];
	rep(i, a) {
		cin >> pa[i];
	}
	rep(i,b) {
		cin >> pb[i];
	}
	int p[m];
	rep(i,m) {
		int x, y, c;
		cin >> x >> y >> c;
		p[i] = pa[x - 1] + pb[y - 1] - c;
	}

	sort(&pa[0], &pa[a]);
	sort(&pb[0], &pb[b]);
	sort(&p[0], &p[m]);

	cout << min(pa[0] + pb[0], p[0]) << endl;




	return 0;

}

Measured memory_bytes: 1408
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int a1 = a + b;
        int a2 = a + c;
        int a3 = b + c;
        System.out.println(min(a1, min(a2, a3)));
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


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

int main()
{
	long long ret = 1;
	int n;
	cin >> n;
	const long long b = 1000000000000000000;
	for (int i = 0; i < n; ++i) {
		long long a;
		cin >> a;

		if (a == 0) {
			ret = 0;
		}

		if (ret <= 0) {
			continue;
		}

		long long c = b / ret;
		if (c < a) {
			ret = -1;
			continue;
		}

		ret *= a;
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
struct c{
  int a;
  string b;
  int m;
  
  bool operator<( const c& right ) const {
        return b == right.b ? a > right.a : b < right.b;
    }
  
};

int main(){
  int n,i;
  cin>>n;
  vector<c> d(n);
  for(i=0;i<n;i++){
    cin>>d[i].b>>d[i].a;
    d[i].m=i+1;
  }
  sort(d.begin(), d.end());
  for(i=0;i<n;i++){
    cout<<d[i].m<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
  int count = 0;
  int length = 0;
  length = str.size();

  for(int i = 0; i < (length / 2); i++){
  	if(str.at(i) == str.at(length - i - 1))
       continue;
    else
       count++;
  }  
  cout << count << endl;
}

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

public class Main {

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        long[] A = new long[N], B = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scanner.nextLong();
            B[i] = scanner.nextLong();
        }

        Arrays.sort(A);
        Arrays.sort(B);

        long medianA, medianB;
        if(N % 2 == 0){
            medianA = A[N/2-1] + A[N/2];
            medianB = B[N/2-1] + B[N/2];
        } else {
            medianA = A[(N+1)/2-1];
            medianB = B[(N+1)/2-1];
        }

        System.out.println(medianB-medianA+1);
    }

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


Measured memory_bytes: 62716
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons,std.numeric;
const dx = [1,0,-1,0], dy = [0,1,0,-1];
const readMixin = q{ auto line = readln().split();foreach(i,ref arg; args){ if (i >= line.length) return;arg = line[i].to!(typeof(arg));}};
void read(T...)  (auto ref T args){ mixin(readMixin);}
void readArray(T)(auto ref T args){ mixin(readMixin);}
void times(int n,void delegate() stmt){foreach(i;iota(n))stmt();}
void main(){
	int n;
	while(read(n),n){
		int [][] infos;
		(n+1).times({
			auto info = new int[n+1];
			readArray(info);
			infos ~= info[1..1+info[0]].sort;
		});
		auto leaked = infos[n];
		infos = infos[0..$-1];
		int commiter = -2;
		foreach(int i,info;infos){
			if (leaked.map!(a=>info.canFind(a)).all!"a"){
				if(commiter == -2) commiter = i;	
				else {commiter = -2;break;}
			}
		}
		(commiter+1).writeln;
	}
}

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

n3 = 0
n5 = 0
n15 = 0


for i in range(N // 3):
  n3 += 3 * (i+1)

for i in range(N // 5):
  n5 += 5 * (i+1)

for i in range(N // 15):
  n15 += 15 * (i+1)
  
print(N * (N + 1) // 2 - n3 - n5 + n15)

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

int main()
{
    long long int n , x , i;
    cin>>n;
    int a[n+1]={0};
    for( i = 1 ; i<=n-1 ; i++)
    {   
        cin>>x;
        a[x]++;
    }
    for( i = 1 ; i<n+1; i++ )
    {
        cout<<a[i]<<endl;
    }

}

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

int main(){
    int rect = 0;
    int dia = 0;
    int a, b, c;
    while(~scanf("%d,%d,%d", &a, &b, &c)){
        if(a*a + b*b == c*c) rect++;
        if(a == b) dia++;
    }
    cout << rect << endl;
    cout << dia << endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	double R;
	cin >> R;
	cout << 2*R*M_PI << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3808
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

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

ll n;
vll a;

void func() {
    cin >> n;
    a.resize(n);
    ll x = 0;
    for (ll i = 0, p = 1; i < n; i++) {
        cin >> a[i];
        x += p * a[i];
        p = -p;
    }
    cout << x << ' ';
    for (ll i = 1; i < n; i++) {
        x = 2 * a[i - 1] - x;
        cout << x << ' ';
    }
    cout << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


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

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

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

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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

vector<long long> toDivisor(ll num)
{
	vector<long long> d;
	for (ll i = 1; i*i <= num; ++i)
	{
		if (i*i == num)
		{
			d.push_back(i);
		}
		else if (num % i == 0)
		{
			d.push_back(i);
			d.push_back(num/i);
		}
	}
	return d;
}

vector<pair<long long , long long>> toDivisorP(ll num)
{
	vector<pair<long long, long long>> d;
	for (ll i = 1; i * i <= num; ++i)
	{
		if (i*i == num) d.push_back(pair<ll, ll>(i, i));
		else if (num % i == 0)
		{
			d.push_back(pair<ll, ll>(i, num/i));
		}
	}
	return d;
}


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N; cin >> N;
	vector<ll> d1 = toDivisor(N-1);
	vector<ll> d2 = toDivisor(N);

	ll res{d1.size()-1};

	for (auto e : d2)
	{
		if (e == 1) continue;

		ll nc = N;
		while (nc > 0)
		{
			if (nc % e != 0)
			{
				if (nc % e == 1)
				{
					++res;
				}
				break;
			}
			nc /= e;
		}
	}

	std::cout << res << std::endl; 
	
	return 0;
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

LL combi_dp[1000][1000];
bool combi_init = false;
// nCr
LL combi(int n, int r) {
    if(n < r)
        return 0;
    if(n == r || r == 0)
        return 1;
    if(!combi_init) {
        combi_init = true;
        REP(i, 1000) {
            fill(combi_dp[i], combi_dp[i] + 1000, 0);
        }
    }
    if(combi_dp[n][r]) {
        return combi_dp[n][r];
    }
    return combi_dp[n][r] = combi(n - 1, r) + combi(n - 1, r - 1);
}

int main() {
    LL N, A, B;
    cin >> N >> A >> B;
    LL v[N];
    REP(i, N) {
        cin >> v[i];
    }
    sort(v, v + N, greater<LL>());
    LL s = 0;
    REP(i, A) {
        s += v[i];
    }
    double ave = (double)s/A;
    cout << fixed;
    cout << ave << endl;

    if(v[0] == v[A - 1]) {
        LL X = count(v, v + N, v[0]);
        LL s = 0;
        for(LL i = A;i <= B;i++) {
            s += combi(X, i);
        }
        cout << s << endl;
    }else{
        LL X = count(v, v + N, v[A - 1]);
        LL Y = count(v, v + A, v[A - 1]);
        cout << combi(X, Y) << endl;
    }
    return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
const int N = 3e4+1;
signed main()
{
    fast;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = 0;
    for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
            for(int k =0;k<=9;k++)
            {
                int a = 0;
                int b = 0;
                string ss = to_string(i)+to_string(j)+to_string(k);
                while(b<n && a<3)
                {
                    if(s[b] == ss[a])
                        a++,b++;
                    else b++;
                }
                if(a == 3)
                    ans++;
            }
    cout<<ans;
}

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

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

int main(){
    int n;
    cin >> n;
    n%=1000;
    if(n==0) n=1000;
    cout << 1000-n << endl;
    
}

Measured memory_bytes: 3628
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
 
int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
      cout<<"A"<<endl;
  }
  else{
      cout<<"B"<<endl;
  }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll ans = 0;
    ll right = 0;
    ll sum = 0;
    for(i = 0;i < n;++i){
        while(right < n && (sum ^ a.at(right)) == (sum + a.at(right))){
            sum += a.at(right);
            ++right;
        }
        ans += right-i;
        if(i == right){
            ++right;
        }else{
            sum -= a.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,w;
    cin>>n>>w;
    ll a,b,c;
    vector<vector<ll> > v(4);
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(i==0)c=a;
        v[a-c].pb(b);
    }
    vector<vector<ll> > g(4);
    for(int i=0;i<4;i++){
        g[i].pb(0LL);
        sort(be(v[i]));
        reverse(be(v[i]));
    }
    for(int i=0;i<4;i++){
        ll maki=v[i].size();
        for(int j=0;j<maki;j++){
            g[i].pb((g[i].back())+v[i][j]);
        }
    }
    ll ans=0,num;
    int d[4];
    for(int i=0;i<4;i++){
        d[i]=g[i].size();
    }
    for(int i=0;i<d[0];i++){
        for(int j=0;j<d[1];j++){
            for(int k=0;k<d[2];k++){
                for(int m=0;m<d[3];m++){
                    num=c*i+(c+1)*j+(c+2)*k+(c+3)*m;
                    if(num>w){
                        continue;
                    }
                    num=(g[0][i]-g[0][0]);
                    num+=(g[1][j]-g[1][0]);
                    num+=(g[2][k]-g[2][0]);
                    num+=(g[3][m]-g[3][0]);
                    ans=max(ans,num);
                }
            }
        }
    }
    cout << ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
D = int(input())
C = np.array(list(map(int, input().split())))
S = np.zeros((D,26),int)
for i in range(0,D):
    S[i] = list(map(int, input().split()))

N = (C/np.sum(C)*D)
MN = np.argmax(N)
# print(N)
N = np.floor(N)
N[MN] += D-np.sum(N)
# print(N)
# print(np.sum(N))

Plan = np.zeros(D,int)
num = np.arange(D).reshape(D,-1)
# print(num)
S = np.hstack((S,num)).T
# print(S)

test=list()
for i in range(26):
    for j in range(int(N[i])):
        test.append(int(i))
# print(len(test))
np.random.seed(seed=30)
np.random.shuffle(test)

# print(test)
for i in test:
    l = np.argmax(S[i])
    # print(S[26,l])
    Plan[S[26,l]] = i
    S = np.delete(S,l,1)
# print(Plan)

[print(i+1) for i in Plan]

Measured memory_bytes: 27540
object Main extends App {
	val Array(n, d) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val dp = Array.ofDim[Int](n, d)

	for(i<-0 until n){
		dp(i) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	var ans = 0

	for(i<-0 until n-1){
		for(j<-i+1 until n){
			val tp = math.sqrt(dp(i).zip(dp(j)).map{case (a, b) => (a - b) * (a - b)}.sum)

			if(tp - tp.toInt == 0.0){
				ans += 1
			}
		}
	}

	println(ans)
}

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

int main(void) {
	int N; cin >> N;
	bool ok = false;
	while (N > 0) {
		int tmp = N % 10;
		if (tmp == 7) {
			ok = true;
			break;
		}
		N /= 10;
	}

	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

int main() {
  long long n; cin>>n;
  if (n%2==1) cout<<0<<endl;
  else {
    long long cnt=0;
    for (long long i=10; i<=n; i*=5) {
      cnt+=n/i;
    }
    cout<<cnt<<endl;
  }
}

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

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

	vector<vector<vector<int>> > v(5, vector<vector<int>>(4, vector<int>(11, 0)));
	for (int i = 0; i < n; i++)
	{
		int a[3];
		int t;
		cin >> a[0] >> a[1] >> a[2];
		cin >> t;
		v[a[0]][a[1]][a[2]] += t;
	}
	for (int i = 1; i < 5; i++)
	{
		for (int j = 1; j < 4; j++)
		{
			cout << " ";
			for (int k = 1; k < 11; k++)
			{
				string s = (k == 11 - 1) ? "\n" : " ";

				cout << v[i][j][k] << s;
			}
		}
		if (i != 4)
		{
			cout << "####################" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//////////

bool can(pii p, vector<pii> &a){
	int cnt = 0;
	ll me = p.first;
	fi(0, sz(a)){
		if(a[i] == p) continue;
		if(a[i].first <= me * 2){
			me += a[i].first;
		}else{
			return false;
		}
	}
	return true;
}

void solve(){
	int n;
	scanf("%d",&n);
	vector<pii> a;
	fi(0, n){
		int v;
		scanf("%d",&v);
		a.pb(mp(v, i));
	}
	sort(a.begin(), a.end());
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(can(a[m], a)){
			r = m;
		}else{
			l = m;
		}
	}
	printf("%d\n",n-1-r+1);
}


int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 1400
#include<atcoder/all>
using namespace atcoder;

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
int main() {
    int n, m;
    cin >> n >> m;
    vector<string> s(n);
    rep(i, n)cin >> s[i];
    mf_graph<int> g(n*m+2);
    int a = n*m, b = n*m+1;
    rep(i, n)rep(j, m){
        int now = i*m + j;
     	if(s[i][j] == '#')continue;
        if((i+j) & 1)g.add_edge(now, b, 1);
        else {
          	g.add_edge(a, now, 1);
          	rep(k, 4){
            	int ni = i + dx[k], nj = j + dy[k];
            	if(ni < 0 || ni >= n || nj < 0 || nj >= m)continue;
              	if(s[ni][nj] == '#')continue;
            	int next = m * ni + nj;
            	g.add_edge(now, next, 1);
        	}
        }
    }
    cout << g.flow(a, b) << endl;
  	auto es = g.edges();
  	rep(i, es.size()){
   	  	auto e = es[i];
   	  	if(!e.flow)continue;
   	  	if(e.from == a || e.to == b)continue;
   	  	if(e.to/m == e.from/m){
   	      	s[e.to/m][e.to%m] = '>';
   	      	s[e.from/m][e.from%m] = '<';
   	      	if(e.to%m > e.from%m)swap(s[e.to/m][e.to%m], s[e.from/m][e.from%m]);
    		}else{
          	s[e.to/m][e.to%m] = 'v';
          	s[e.from/m][e.from%m] = '^';
          	if(e.to/m > e.from/m)swap(s[e.to/m][e.to%m], s[e.from/m][e.from%m]);         
       	}
   	}
  	rep(i, n)cout << s[i] << endl;
}


Measured memory_bytes: 5464
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
typedef pair<int, int> PII;
int vx[] = {0,1,0,-1};
int vy[] = {1,0,-1,0};
int dist[21][21];


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h,w;
	cin >> h >> w;
	char field[h+1][w+1];
	REP(i,h) REP(j,w) cin >> field[i][j];
	int ans = 0;
	REP(i,h){
		REP(j,w){
			if(field[i][j]=='#') continue;
			REP(i,h) REP(j,w) dist[i][j] = 1e9;
			queue<PII> q;
			q.emplace( i, j);
			dist[i][j] = 0;
			while( !q.empty() ){
				PII now = q.front();
				q.pop();

				REP( k, 4){
					int ny = now.first + vy[k], nx = now.second + vx[k];
		
					if( 0 <= ny && ny <= h && 0 <= nx && nx <= w && field[ny][nx] != '#' && dist[ny][nx] == 1e9 ){
						q.emplace( ny, nx );
						dist[ny][nx] = dist[now.first][now.second] + 1;
						ans = max(ans, dist[ny][nx]);
					}   
				}
			}
		}
	}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
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, K;
    cin >> N >> K;
    vector<ll> h(1000001);
    for (int i = 0; i < N; i++) cin >> h[i];
    vector<ll> dp(1000001);
    for (int i = 0; i < 1000001; i++) dp[i] = INF;
    dp[0] = 0;

    for (int i = 0; i < N; i++){
      for (int j = 1; j <= K; j++){
        chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
      }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 18832
program r20711b

implicit none
integer :: i, x, n
integer, allocatable :: a(:)

read *, n

allocate(a(1:n))

x = 0

read *, a(:)

do i = 1, n, 2
 if(mod(a(i),2)==1) then
 x = x + 1
 end if
end do

print *, x

end program r20711b

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    int n, k;
    cin >> n >> k;
    vl x = vl(n);
    for (int i = 0; i < n; ++i) cin >> x[i];

    ll ans = 1LL << 60;
    for (int le = 0; le <= n - k; le++) {
        int ri = le + k - 1;
        ll d;
        auto abs_le = abs(x[le]);
        if (x[ri] * x[le] > 0) {
            d = max(abs(x[ri]), abs_le);
        } else {
            if (x[ri] > abs(x[le])) {
                d = x[ri] + 2 * abs_le;
            } else {
                d = 2 * x[ri] + abs_le;
            }
        }
        ans = min(ans, d);

    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int x, y, a, b, c;
    scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
    lint p[a], q[b], r[c];
    rep(i, a) scanf("%lld", &p[i]);
    rep(i, b) scanf("%lld", &q[i]);
    rep(i, c) scanf("%lld", &r[i]);
    sort(p, p+a, greater<>());
    sort(q, q+b, greater<>());

    lint sum = 0;
    priority_queue<lint, vector<lint>, greater<>> pq;
    priority_queue<lint> que_r;
    rep(i, x){
        pq.push(p[i]); sum += p[i];
    }
    rep(i, y){
        pq.push(q[i]); sum += q[i];
    }
    rep(i, c) que_r.push(r[i]);
    lint ans = sum;

    while(!que_r.empty() && !pq.empty()){
        lint s = que_r.top(); que_r.pop();
        lint t = pq.top(); pq.pop();
        sum += s-t;
        chmax(ans, sum);
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 5744
import math
n,m = map(int,input().split())
mm = int(math.sqrt(m))
s = {}
for i in range(2,mm+2):
    if m%i != 0:
        continue
    while m%i == 0:
        m = m//i
        s[i] = s.get(i, 0) + 1
    if m == 1:
        break
if m>=2:
    s[1] = 1
ans = 1
mod = 10**9+7
for i in s.values():
    for j in range(1,i+1):
        ans = ans * (n+j-1)//(j)
    ans %=mod
print(ans)


Measured memory_bytes: 3188
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

char s[500001];
int main(){
	scanf("\n%s", s + 1);
	int l = strlen(s + 1);
	for (int i = 1; i <= l; i++)
		if (s[i] == '?') s[i] = 'D';
	for (int i = 1; i <= l; i++)
		printf("%c", s[i]);
	cout << endl;
	return 0;
}



Measured memory_bytes: 3836
H,W = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(H)]
lis = []
for i in range(H):
    for j in range(W):
        if not i == H-1:
            if (a[i][j]) % 2 == 1:
                a[i+1][j] = a[i+1][j]+1 
                lis.append((i,j,i+1,j))
        else:
            if not j == W-1:
                if (a[i][j]) % 2 == 1:
                    a[i][j+1] = a[i][j+1]+1
                    lis.append((i,j,i,j+1))
print(len(lis))
for i in lis:
    print(i[0]+1,i[1]+1,i[2]+1,i[3]+1)

            


Measured memory_bytes: 22792
import java.util.Scanner;

public class Main {
    public static void main(String ars[]){
        int n, tmp, ave;
        String line;
        int score[] = new int[100];
        Scanner sc = new Scanner(System.in);

        while(true){
            ave = 0;
            n = sc.nextInt();
            if(n == 0) break;
            for(int i = 0; i < n; i++) score[i] = sc.nextInt();
            for(int i = 0; i < n; i++) {
                for (int j = n-1; j > i; j--) {
                    if (score[j] < score[j-1]) {
                        tmp = score[j-1];
                        score[j-1] = score[j];
                        score[j] = tmp;
                    }
                }
            }
            for(int i = 1; i < n-1; i++) ave += score[i];
            ave /= n-2;
            System.out.println(ave);
        }
    }
}

Measured memory_bytes: 21044
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const ll INF = 1e18;
int A[N];
ll prefix[N];
int main() {
	int n;
	while(~scanf("%d", &n)) {
		double all = 0;
		for(int i = 1; i <= n; ++i) {
			scanf("%d", &A[i]);
		}
		prefix[0] = 0;
		for(int i = 1; i <= n; ++i) {
			prefix[i] = prefix[i-1] + A[i];
		}  
		ll ans = INF;
		for(int i = 3; i <= n - 1; ++i) {
			ll Min = INF; ll Max = -1;
			ll Lsum = prefix[i-1];
			int tt = lower_bound(prefix+1, prefix+i, Lsum/2.0) - prefix;
		//	printf("%d ", tt);
			ll part1 = prefix[tt - 1];
			ll part2 = Lsum - part1;
			if(abs(part1 - part2) > abs(Lsum - prefix[tt] * 2)) {
				part1 = prefix[tt];
				part2 = Lsum - part1;
			}
		//	printf("%lld %lld | ", part1, part2);
			Max = max(Max, part1); Max = max(Max, part2);
			Min = min(Min, part1); Min = min(Min, part2);

			ll Rsum = prefix[n] - prefix[i-1];
			tt = lower_bound(prefix+i, prefix+n+1, prefix[i-1] + Rsum/2.0) - prefix;
		//	printf("%d ", tt);
			ll part3 = prefix[tt - 1] - prefix[i-1];
			ll part4 = Rsum - part3;
			if(abs(part3 - part4) > abs(Rsum - prefix[tt] * 2 + prefix[i-1]*2)) {
				part3 = prefix[tt] - prefix[i-1];
				part4 = Rsum - part3;
			}
		//	printf("%lld %lld |\n", part3, part4);
			Max = max(Max, part3); Max = max(Max, part4);
			Min = min(Min, part3); Min = min(Min, part4);

			ans = min(ans, Max - Min);
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2560
n,m, x = map(int,input().split())
text=[]
buy=10**10
for i in range(n):
  text.append(list(map(int,input().split())))
for i in range(2**n):
  bag=[0]*(m+1)
  
  for j in range(n):#いれる過程
    if ((i>>j)&1):#j冊目のフラグがあれば
      for k in range(m+1):
        bag[k]+= text[j][k]#bagにいれる
  
  if min(bag[1:])>=x and bag[0]<buy:
    buy=bag[0]

if buy==10**10:
  buy=-1
print(buy)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
//#include <atcoder/fenwicktree>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
//#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
int main()
{
    string a, b;
    cin >> a >> b;
    cerr << a + a << endl;
    string a_f = a;
    string b_f = b;
    
    //stoiで文字列型を数値型に変換
    int a_l = stoi(a) - 1;
    int b_l = stoi(b) - 1;
    
    rep(i, b_l) {
        a += a_f;
    }
    rep(i, a_l) {
        b += b_f;
    }
   // デバッグ
    cerr << a << " " << b << "\n";
    if(a <= b) cout << a << "\n";
    else cout << b << "\n";
 }

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

ll check(set<P> &s){
    ll last = -INF * 2, res = INF;
    for(P p : s){
        if(p.se){
            chmin(res, p.fi - last);
        }else{
            last = p.fi;
        }
    }
    return res;
}

int main() {
    const ll t2 = 200000;
    typedef vector<vector<set<P> > > mats;
    map<char, int> ctoi = {{'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}};
    cin>>N;
    vec x(N), y(N), u(N);
    //0 : up
    mats memo(6, vector<set<P>>(400001));
    rep(i,N) {
        char c;
        cin>>x[i]>>y[i]>>c;
        u[i] = ctoi[c];
        if(u[i] < 2){
            memo[u[i]][u[i] ? y[i] : x[i]].emplace(u[i] ? x[i] : y[i], 0);
            memo[u[i] + 2][y[i] - x[i] + t2].emplace(y[i] + x[i], 0);
        }else{
            memo[u[i] - 2][u[i] - 2 ? y[i] : x[i]].emplace(u[i] - 2 ? x[i] : y[i], 1);
            memo[5 - u[i]][y[i] - x[i] + t2].emplace(y[i] + x[i], 1);
        }
        if(u[i] == 0){
            memo[4][y[i] + x[i]].emplace(y[i] - x[i], 0);
        }else if(u[i] == 1){
            memo[4][y[i] + x[i]].emplace(y[i] - x[i], 1);
        }else if(u[i] == 2){
            memo[5][y[i] + x[i]].emplace(y[i] - x[i], 1);
        }else{
            memo[5][y[i] + x[i]].emplace(y[i] - x[i], 0);
        }
    }
    ll res = INF;
    rep(i,6){
        rep(j, 400001){
            chmin(res, check(memo[i][j]));
        }
    }
    if(res == INF) cout<<"SAFE"<<endl;
    else cout<<res * 5<<endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;


int ANS[100100];
int main(){
    string S;
    cin >> S;
    int N = S.length();

    int cnt = 0;
    vector<int> right;
    vector<int> left;
    for(int i = 0; i < N; i++){
        char c = S[i];
        if(c == 'R'){
            cnt++;
        }
        else{
            if(cnt == 0) continue;
            right.push_back(cnt);
            cnt = 0;
        }
    }

    cnt = 0;
    for(int i = N-1; i >= 0; i--){
        char c = S[i];
        if(c == 'L'){
            cnt++;
        }
        else{
            if(cnt == 0) continue;
            left.push_back(cnt);
            cnt = 0;
        }
    }

    int idx = 0;
    int size = left.size();
    for(int i = 0; i < right.size(); i++){
        int r = right[i];
        REP(k,r-1){
            ANS[idx++] = 0;
        }
        ANS[idx] += (r+1)/2;
        ANS[idx+1] += r/2;
        idx++;

        int l = left[size-i-1];
        ANS[idx-1] += l/2;
        ANS[idx] += (l+1)/2;
        idx++;
        REP(k,l-1){
            ANS[idx++] = 0;
        }
        //cout << idx << endl;
    }

    REP(i,N){
        printf("%d ", ANS[i]);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1596
#include <cstdio> 
#include <ctime> 
#include <cmath>   
#include <cstring>
#include <cstdlib>               //a = clock(); b = clock(); time = a - b;
#include <iostream>                                      
#include <map>                   //map<Type, Type>::iterator it;
#include <queue>                 //priority_queue< Type >Name
#include <stack>                 
#include <vector>                //.push_back()
#include <string>  
#include <algorithm>  
#define e 2.718281828459045      //底数
#define pi 3.141592653589793239  //high precision Π

using namespace std;
int main(){
	long long a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long x,y,z,w;
	x=a*c;
	y=a*d;
	z=b*c;
	w=b*d;
	long long m=max(x,y);
	long long t=max(z,w);
	long long f=max(m,t);
	printf("%lld",f);
} 

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a,ans=0,neednum=1,flag=0;
    for(int i=0; i<N; i++){
        cin >> a;
        if(a==neednum){
            neednum++;
            flag=1;
        }else{
            ans++;
        }
    }
    if(flag) cout << ans;
    else cout << -1;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

g = [[] for _ in range(3*N)]
for _ in range(M):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    g[u].append((1,v+N))
    g[u+N].append((1,v+2*N))
    g[u+2*N].append((1,v))

from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist
S,T = map(int,input().split())
dij = dijkstra(g,3*N,S-1)
ans = dij[T-1]//3
if ans == float('inf') or ans!=ans:
    ans = -1
print(ans)

Measured memory_bytes: 110192
#include<stdio.h>
#include <algorithm>
using namespace std;

pair<int,int> h1[120000],h2[120000];
int n;
int a[120000];
int mxh1,mxh2;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	
	for(int i=1;i<=n;i+=2)
	{
		h1[a[i]].first++;
	}
	for(int i=2;i<=n;i+=2)
	{
		h2[a[i]].first++;
	}
	for(int i=1;i<=100000;i++)
	{
		h1[i].second=h2[i].second=i;
	}
	sort(h1+1,h1+100001);
	sort(h2+1,h2+100001);
	if(h1[100000].second!=h2[100000].second) printf("%d",n-h1[100000].first-h2[100000].first);
	else printf("%d",n-max(h1[99999].first+h2[100000].first,h1[100000].first+h2[99999].first));
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
string s="";
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n;
    cin>>n;
    while(n--){
        s=char(n%26+'a')+s;
        n/=26;
    }

    cout<<s;
}


Measured memory_bytes: 3596
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e7+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
int main(void){
	llint n,H,i,kru=0;cin>>n>>H;
	vector<llint>nag(n);
	for(i=0;i<n;i++){
		llint a,b;cin>>a>>b;
		nag[i]=b;
		maxeq(kru,a);
	}
	SO(nag);
	reverse(nag.begin(),nag.end());
	llint kai=0;
	for(i=0;i<n;i++){
		if(nag[i]<=kru){break;}
		kai++;
		H-=nag[i];
		if(H<=0){cout<<kai<<endl;RE;}
	}
	cout<<kai+(H+kru-1)/kru<<endl;
	RE;
}

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

int main () {
    int n;
    cin >> n;
    vector<int>vec(n);
    
    for (int t = 0; t < n; t++) {
        cin >> vec.at(t);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    
    int a = 0, b = 0;
    for (int t = 0; t < vec.size(); t++) {
        if (t == 0 || t%2 == 0) {
            a += vec.at(t);
        } else {
            b += vec.at(t);
        }
    }
    cout << a - b << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long hp = scan.nextLong();
        scan.close();
        long count = 2;
        int jyosu = 0; //hpは2の何乗か?

        if(hp == 1) System.out.println(count - 1);
        else{
            while(hp != 1){
                hp = hp / 2;
                jyosu++;
            }

            for(int i = 0;i < jyosu;i++) count = count * 2;
            System.out.println(count - 1);
        }
        /*
        ArrayList<Integer> h = new ArrayList<Integer>();
        h.add(scan.nextInt());
        int count = 0;
        scan.close();

        while(!h.isEmpty()){
            int hp = h.get(0);
            h.remove(0);
            if(hp != 1){
                hp = hp / 2;
                h.add(hp);
                h.add(hp);
            }
            count++;
        }
        System.out.println(count);
        */
    }


}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int a[101], sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  sum /= n;
  long long p = 0, q = 0;

  for(int i = 0; i < n; i++){
    p += abs(sum - a[i])*abs(sum -a[i]);
    q += abs(sum - a[i] + 1)* abs(sum - a[i] + 1);
  }

  
  cout << min(p, q) << endl;
}


Measured memory_bytes: 256
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M = lr()
    A = sorted(lr())[::-1]
    if A[M-1] < sum(A)/(4*M):
        print('No')
    else:
        print('Yes')
resolve()

Measured memory_bytes: 38256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>
#include <sstream>

using namespace std;

class arc090_c {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<vector<int>> A(2, vector<int>(N));
        for (int i = 0; i < 2; ++i) {
            for (int j = 0; j < N; ++j) {
                in >> A[i][j];
            }
        }
        A[1][0] += A[0][0];
        for (int j = 1; j < N; ++j) {
            A[0][j] += A[0][j - 1];
            A[1][j] += max(A[1][j - 1], A[0][j]);
        }
        out << A[1][N - 1] << "\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc090_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
import sys
INFTY=sys.maxsize

def readinput():
    n,x,y=list(map(int,input().split()))
    return n,x,y

def dijkstra(s,n,nList):
    '''優先度付きキューを使用したダイクストラ法

    パラメーター
    s: 始点
    n: 頂点の数
    nList: [ 
        [vertex1, cost1], [vertex2, cost2], ...
        [vertex1, cost1], [vertex2, cost2], ...
        ...
    ]

    返り値
    d: 始点sから各頂点vまでの最短経路上の辺の重みの総和d[v]のリスト
    '''

    WHITE=0
    GRAY=1
    BLACK=2
    color=[WHITE]*n
    d=[INFTY]*n

    HQ=[]

    d[s]=0
    heappush(HQ,(d[s],s))

    while(len(HQ)>0):
        #print(HQ)
        du,u=heappop(HQ)
        color[u]=BLACK

        if d[u]<du:
            continue

        for v in nList[u]:
            vw=1
            if color[v]!=BLACK:
                if d[u] + vw < d[v]:
                    d[v] = d[u] + vw
                    color[v]=GRAY
                    heappush(HQ, (d[v], v))
    return d

def main(n,x,y):
    nList=[]
    #nList.append([])
    nList.append([1])
    for i in range(1,n-1):
        nList.append([i-1,i+1])
    nList.append([n-2])
    nList[x-1].append(y-1)
    nList[y-1].append(x-1)
    #print(nList)

    dList=[]
    for i in range(n):
        dList.append(dijkstra(i,n,nList))
    #print(dList)
    
    hist=[0]*n
    for i in range(n-1):
        for j in range(i+1,n):
            hist[dList[i][j]]+=1
    
    for i in range(1,n):
        print(hist[i])


if __name__=='__main__':
    n,x,y=readinput()
    main(n,x,y)


Measured memory_bytes: 109528