akhauriyash/Code-Regression huggingface dataset:
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#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<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i]-'0');
	}
	return d;
}
string S;
int main()
{
	cin >> S;
	int N = S.size();
	string T = S;
	reverse(T.begin(), T.end());
	rep(i, N) {
		if (T[i] != S[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	rep(i, (N - 1) / 2) {
		if (S[i] != S[(N - 1) / 2 - i-1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	rep(i, N) {
		if (S[i + (N + 3) / 2-1] != S[N - i-1]) {
			cout << "No" << endl;
			return 0;
		}
		if ((N + 3) / 2 - 1 == N - i - 1)break;
	}
	cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    string a;
    cin>>a;
    int t=0;
    if(a[0]=='o')
        t++;
    if(a[1]=='o')
        t++;
    if(a[2]=='o')
        t++;
    t+=7;
    t*=100;
    cout<<t;

}


Measured memory_bytes: 256
//PCK2015予選4
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
   int Q;
   cin>>Q;
   for(int i=0;i<Q;++i){
       int c,a,n;
       cin>>c>>a>>n;
       int t=0;
       while(c&&a&&n)--c,--a,--n,++t;
       while(c>1&&a) c-=2,--a,++t;
       while(c>2) c-=3,++t;
       cout<<t<<endl;
   }
}



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


bool lamp_check(bitset<10> s,int n,int m,vector<vector<int>> &array,vector<int> &p){
    //cout << s << endl;
    for(int i=0;i<m;i++){
        //cout << i << endl;
        int count = 0;
        for(int j=0;j<(int)array.at(i).size();j++){
            int num = array.at(i).at(j);
            if(s.test(num)){
                count++;
            }
        }
        if(count % 2 != p.at(i)) return false;
    }
    return true;
}


int main(){
 int n,m;
 cin >> n >> m;
 vector<vector<int>> switch_array(m);
 vector<int> p(m);
 for(int i=0;i<m;i++){
     int k;
     cin >> k;
     for(int j=0;j<k;j++){
         int l;
         cin >> l;
         switch_array.at(i).push_back(l-1);
     }
 }
 
 for(int i=0;i<m;i++) cin >> p.at(i);
 int c = 0;
 for(int tmp=0; tmp < (1 << n); tmp++){
     bitset<10> s(tmp);
     if(lamp_check(s,n,m,switch_array,p)){
         c++;
     }
 }
 cout << c << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>

using namespace std;

using ll = long long;

struct store {
    ll val;
    ll stock;
};

int main(void) {
    ll n, m;
    cin >> n >> m;

    // ll* a;
    // ll* b;

    // a = new ll[n];
    // b = new ll[n];

    store* s = new store[n];

    for ( int ni = 0; ni < n; ++ni) {
        // cin >> a[ni] >> b[ni];
        cin >> s[ni].val >> s[ni].stock;
    }

    sort(s,s+n,[](const store& a, const store& b){return a.val < b.val;});

    // for(int i = 0; i < n; ++i ) {
    //     cout << s[i].val << "-" << s[i].stock << endl;
    // }

    ll basket = 0;
    ll total_price = 0;
    ll ix = 0;

    while(true) {

            if (s[ix].stock + basket  > m) {
                total_price += s[ix].val * (m - basket);
                break;

            } else {
                total_price += s[ix].val * s[ix].stock;
                basket += s[ix].stock;
            }

            ix++;
            // cout << ix << ":" << "price:" << total_price << endl;
        // }
    }

    cout << total_price << endl;

    return 0;
}

Measured memory_bytes: 1792
H, W, K = gets.split.map(&:to_i)

dp = Array.new(H + 1) { Array.new(W + 1, 0) }
dp[0][0] = 1

line_patterns = []

(1..(W / 2)).each do |n|
  if n == 1
    line_patterns << (W - 1).times.map { |i| [i] }
  else
    line_patterns << [*0..(W - 2)].combination(n).select { |l| l.each_cons(2).all? { |a, b| b - a >= 2 } }
  end
end

line_patterns.flatten!(1)
line_patterns << []

H.times do |i|
  line_patterns.each do |pattern|
    W.times do |j|
      if pattern.include?(j)
        dp[i + 1][j + 1] += dp[i][j]
        dp[i + 1][j] += dp[i][j + 1]
      elsif !pattern.include?(j - 1)
        dp[i + 1][j] += dp[i][j]
      end
    end
  end
end

MOD = 10 ** 9 + 7
puts dp[H][K - 1] % MOD


Measured memory_bytes: 2812
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd); FUNC(printde);
#endif

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N; cin >> N;
    for(ll n = 1; n <= 3500; n++){
        for(ll h = 1; h <= 3500; h++){
            if(4 * n * h - N * n - N * h == 0){ continue; }
            ll w = N * h * n / (4 * n * h - N * n - N * h);
            if(w > 0 && w * (4 * n * h - N * n - N * h) == N * h * n){
                cout << n << ' ' << h << ' ' << w << '\n';
                return 0;
            }
        }
    }
}


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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }
    int n,m,q;
    int a[50],b[50],c[50],d[50];
    int ans=0;
    vector<int>v;

    int check(){
        int val=0;
        for(int i=0;i<q;i++){
            if(v[b[i]]-v[a[i]] ==c[i])
                val+=d[i];
        }
        return val;
    }

    void dfs(int i, int cur){
        if(i>=n){
            ans=max(ans,check());
            return;
        }
        for(int j=cur;j<=m;j++){
            v.push_back(j);
            dfs(i+1,j);
            v.pop_back();
        }
    }
    int main(){
        cin>>n>>m>>q;
        for(int i=0;i<q;i++){
            cin>>a[i]>>b[i]>>c[i]>>d[i];
            a[i]--;
            b[i]--;
        }
        dfs(0,1);
        cout<<ans<<"\n";
        return 0;
    }


Measured memory_bytes: 3572
#include<cstdio>
using namespace std;

int n, x, minn,sum=1;

int main()
{
	scanf("%d%d", &n, &minn);
	for (int i = 2; i <= n; i++) {
		scanf("%d", &x);
		if (x < minn) {
			sum++;
			minn = x;
		}
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
// Problem : A - Expired?
// Contest : AtCoder - AtCoder Beginner Contest 065
// URL : https://atcoder.jp/contests/abc065/tasks/abc065_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int x,a,b;cin>>x>>a>>b;
int y=-a+b;
if(y<=0)
cout<<"delicious";
else if(y<=x)
cout<<"safe";
else
cout<<"dangerous";
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3656
n,m = map(int,input().split())
ab = [0]*n
V = [[] for i in range(m+1)]
for i in range(n):
    a,b = map(int,input().split())
    if a <= m:
        V[a].append(-b)

import heapq
q = []
ans = 0
heapq.heapify(q)
for i in range(1,m+1):
    for v in V[i]:
        heapq.heappush(q,v)

    if len(q) == 0:
        pass
    else:
        ans -= heapq.heappop(q)
print(ans)

Measured memory_bytes: 22940
import java.util.Scanner;

public class Main {
	
	private static final String YES = "YES";
	private static final String NO = "NO";

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N1 = sc.nextInt();
		final int N2 = sc.nextInt();
		final int N3 = sc.nextInt();
		final int N4 = sc.nextInt();
		
		boolean [] b = new boolean[10];
		
		b[N1] = true;
		b[N2] = true;
		b[N3] = true;
		b[N4] = true;
		
		if(b[1] && b[9] && b[7] && b[4]) {
			System.out.println(YES);
		}else {
			System.out.println(NO);
		}
		
		sc.close();
	}


}


Measured memory_bytes: 23124
a=1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
K=int(input())
print(a[K-1])

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  
  if(sy < ty)
    for(int i = 0; i < ty-sy; i++) cout << "U";
  else if(sy > ty)
    for(int i = 0; i < sy-ty; i++) cout << "D";
  if(sx < tx)
    for(int i = 0; i < tx-sx; i++) cout << "R";
  else if(sx > tx)
    for(int i = 0; i < sx-tx; i++) cout << "L";
  
  if(sy < ty)
    for(int i = 0; i < ty-sy; i++) cout << "D";
  else if(sy > ty)
    for(int i = 0; i < sy-ty; i++) cout << "U";
  if(sx < tx)
    for(int i = 0; i < tx-sx; i++) cout << "L";
  else if(sx > tx)
    for(int i = 0; i < sx-tx; i++) cout << "R";
  
  if(sx < tx){
    cout << "L";
    if(sy < ty)
      for(int i = 0; i < ty-sy+1; i++) cout << "U";
    else if(sy > ty)
      for(int i = 0; i < sy-ty+1; i++) cout << "D";
    for(int i = 0; i < tx-sx+1; i++) cout << "R";
    if(sy < ty) cout << "D";
    else if(sy > ty) cout << "U";
  }
  else if(sx < tx){
    cout << "R";
    if(sy < ty)
      for(int i = 0; i < ty-sy+1; i++) cout << "U";
    else if(sy > ty)
      for(int i = 0; i < sy-ty+1; i++) cout << "D";
    for(int i = 0; i < tx-sx+1; i++) cout << "L";
    if(sy < ty) cout << "D";
    else if(sy > ty) cout << "U";
  }
  
  if(sx < tx){
    cout << "R";
    if(sy < ty)
      for(int i = 0; i < ty-sy+1; i++) cout << "D";
    else if(sy > ty)
      for(int i = 0; i < sy-ty+1; i++) cout << "U";
    for(int i = 0; i < tx-sx+1; i++) cout << "L";
    if(sy < ty) cout << "U";
    else if(sy > ty) cout << "D";
  }
  else if(sx < tx){
    cout << "L";
    if(sy < ty)
      for(int i = 0; i < ty-sy+1; i++) cout << "D";
    else if(sy > ty)
      for(int i = 0; i < sy-ty+1; i++) cout << "U";
    for(int i = 0; i < tx-sx+1; i++) cout << "R";
    if(sy < ty) cout << "U";
    else if(sy > ty) cout << "D";
  }
  
  cout << endl;
  return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

long long A[401], D[401][401];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int N;
	cin>>N;
	for(int i=1;i<=N;i++) cin>>A[i], A[i]+=A[i-1];
	for(int i=1;i<N;i++) {
		for(int j=1;j+i<=N;j++) {
			D[j][j+i]=0x7fffffffffffffffLL;
			for(int k=0;k<i;k++) {
				D[j][j+i]=min(D[j][j+i],D[j][j+k]+D[j+k+1][j+i]+A[j+i]-A[j-1]);
			}
		}
	}
	cout<<D[1][N]<<'\n';
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int taro_point=0, hanako_point=0;
    for (int i=0; i<n; i++)
    {
        string taro, hanako;
        cin >> taro >> hanako;
        int short_len = min(taro.size(), hanako.size());
        int j=0;
        while(true)
        {
            if (j==short_len)
            {
                if (taro.size()>hanako.size())
                {
                    taro_point+=3;
                    break;
                }
                else if (taro.size()<hanako.size())
                {
                    hanako_point+=3;
                    break;
                }
                else
                {
                    taro_point+=1;
                    hanako_point+=1;
                    break;
                }
                
            }
            if (taro.at(j)-hanako.at(j)>0)
            {
                taro_point+=3;
                break;
            }
            else if (taro.at(j)-hanako.at(j)<0)
            {
                hanako_point+=3;
                break;
            }
            else
            {
                j++;
            }
        }
    }
    cout << taro_point << " " << hanako_point << endl;
}


Measured memory_bytes: 3172
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		long A=sc.nextLong();
		long P=sc.nextLong();
		pw.println((A*3+P)/2);
		pw.close();
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int INF=2e9;

int main(){
	int N;
	cin >> N;
	bool F[110][5][2];
	rep(i,N){
		rep(j,5){
			rep(k,2) cin >> F[i][j][k];
		}
	}
	int P[110][15];
	rep(i,N){
		rep(j,11) cin >> P[i][j];
	}
	int ans=-1*INF;
	for(int bit=1; bit<(1<<10); bit++){
		int pro=0;
		rep(i,N){
			int c=0;
			rep(j,10){
				if(!(bit&(1<<j))) continue; 
				int day=j%5, time=j%2;
				if(F[i][day][time]) c++;
			}
			pro+=P[i][c];
		}
		ans=max(ans,pro);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void program(); int main() {cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); program();}
#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>

#define N 100007
#define MOD 1000000007

vector<int> gra[N];
int w[N], b[N];
int n,u,v;

void dfs(int x, int p){
    w[x] = b[x] = 1;
    for(int nxt: gra[x]) if(nxt != p){
        dfs(nxt,x);
        w[x] = (w[x] * (w[nxt] + b[nxt]))%MOD; 
        b[x] = (b[x] * w[nxt])%MOD;
    }
}

void program(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>u>>v;
        u--;v--;
        gra[u].pb(v);
        gra[v].pb(u);
    }
    dfs(0,-1);
    cout<<(w[0]+b[0])%MOD<<endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-different perspective?
-bruteforce?
-greedy?
-reduce dimensionality with problem contraints?
*/


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

using namespace std;
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int inf = 1000000007;
const ll linf  = 1ll * inf * inf;
const int N = 50 + 7;
const int M = 31;
const int multipleTest = 0;


string s;

void solve() {
    cin >> s;
    int n = sz(s);
    int i = 0, j = n - 1;
    int res = 0;
    while (i <= j) {
        if (s[i] == s[j]) {
            ++i; --j;
        } else {
            if (s[i] == 'x') {
                ++i;
                ++res;
            } else if (s[j] == 'x') {
                --j; ++res;
            } else {
                cout << -1;
                return;
            }
        }
    }
    cout << res;
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
//        printf("Case #%d: ", i + 1);
        solve();
    }
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC <<endl;
#endif
}


Measured memory_bytes: 512
from collections import deque
N=int(input())
H=list(map(int,input().split()))
h=deque(H)
h.appendleft(0)
s=0
i=1
while i<=N-1:
    while h[i]<=h[i+1]:
        i+=1
        if i==N:
            s+=h[N]
            break
    if i==N:
            break
    s+=h[i]
    while h[i]>=h[i+1]:
        i+=1
        if i==N:
            break
    if i==N:
            break
    s-=h[i]
if N==1:
    s+=h[1]
print(s)    

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;


int main() {
    
    int n;
    cin>>n;
    vi v(n);
    mii m,p;
    rep(i,n){
        cin>>v[i];
        if(i%2)p[v[i]]++;
        else m[v[i]]++;
    }
    vpii mM(2),pM(2);
    irep(i,m){
        if(i->second>mM[1].se){
            mM[1].fi=i->fi;
            mM[1].se=i->se;
            if(mM[0].se<mM[1].se)swap(mM[0],mM[1]);
        }
    }
    irep(i,p){
        if(i->second>pM[1].se){
            pM[1].fi=i->fi;
            pM[1].se=i->se;
            if(pM[0].se<pM[1].se)swap(pM[0],pM[1]);
        }
    }
    int ans=INF;
    if(mM[0].fi!=pM[0].fi)chmin(ans,n-mM[0].se-pM[0].se);
    if(mM[1].fi!=pM[0].fi)chmin(ans,n-mM[1].se-pM[0].se);
    if(mM[0].fi!=pM[1].fi)chmin(ans,n-mM[0].se-pM[1].se);
    if(mM[1].fi!=pM[1].fi)chmin(ans,n-mM[1].se-pM[1].se);
    fin(ans);
}








Measured memory_bytes: 5376
#include<stdio.h>
  int main(){
  int i,N,K,sum;
  scanf("%d",&N);
  scanf("%d",&K);
  sum=K;
  for(i=0; i<N-1; i++){
    sum=sum*(K-1);
  }
  printf("%d\n",sum);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=200005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n,a[max_n];
int k;
int main(){
    scanf("%d%d",&k,&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    int ans=0;
    for(int i=0;i+1<n;i++)ans=max(ans,a[i+1]-a[i]);
    ans=max(ans,a[0]+k-a[n-1]);
    printf("%d\n",k-ans);
    return 0;
}

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

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

    if ((c[0] == 'a') || (c[0]=='i')||(c[0]=='u')||(c[0]=='e')||(c[0]=='o')){
        cout << "vowel";
        return 0;
    }

    else{
        cout << "consonant";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, M, cnt;
bool used[100010];
bool flag = true;
vector<int> G[100010];

void dfs(int s, int t){
    if(G[t].size() == 4) {
        cnt++;
        return;
    }
    used[t] = true;
    for(auto u : G[t]){
        if(!used[u]){
            dfs(s, u);
        }
    }
}

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int s = 0, f = 0;
    for(int i = 1; i <= N; i++){
        int si = G[i].size();
        if(si % 2 == 1) flag = false;
        if(si >= 6) s++;
        if(si == 4) f++;
    }
    if(s <= 0 && f <= 1) flag = false;
    if(s <= 0 && f == 2) {
        flag = false;
        for(int i = 0; i < N; i++){
            if(G[i].size() == 4){
                used[i] = true;
                for(auto u : G[i]){
                    dfs(i, u);
                }
                if(cnt < 4) flag = true;
                break;
            }
        }
    }
    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 5e5 + 9, M = 1e6 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;
const ll INF = 2e18;
using namespace std;

ll mul(ll x, ll y) {
	return (1ll * x * y) % MOD;
}

ll add(ll x, ll y) {
	x += y;
	while(x >= MOD) x -= MOD;
	while(x < 0) x += MOD;
	return x;
}

ll sub(ll x, ll y) {
	return (x - y + MOD) % MOD;
}

ll fastpow(ll x,ll pw) {
	if(pw == 0) return 1ll;
	int ret = fastpow(x, pw / 2);
	ret = mul(ret, ret);
	if(pw & 1)
		ret = mul(ret, x);
	return ret;
}

ll ans[N];

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	ll n, k;
	cin >> k >> n;
	for (int i = n; i >= 1; --i) {
		ll x = n / i;
		ans[i] = fastpow(x, k);
	}
	for (int i = n; i >= 1; --i) {
		ll sum = 0;
		for (int j = i + i; j <= n; j += i)
			sum = add(sum, ans[j]);
		ans[i] = sub(ans[i], sum);
	}
	ll total = 0;
	for (int i = 1; i <= n; ++i)
		total = add(total, mul(i, ans[i]));
	cout << total;
	return 0;
}


Measured memory_bytes: 4424
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int N; 
cin >> N; 
int A[123]; 
for (int i = 1; i <= N; i++){
cin >> A[i]; 
}
int slime = 0; 
for (int i = 1; i <= N; i++){
for (int j = 0; j <= N-i+1; j++){
if(A[i-1] != A[i] && A[i] != A[i+j]){
slime += j/2; 
break; 
}
}
}
cout << slime << endl; 
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextLong();
		long m = sc.nextLong();
		
		if(n*2 >= m) {
			System.out.println(m/2);
		}
		else {
			long result = n;
			m -= 2*n;
			
			result += m/4;
			
			System.out.println(result);
		}
	}

}


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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;
	vector<ll> ar(n);
	for(ll &it : ar){
		cin >> it;
	} 
	ar.push_back(0);
	ll now = 1000, stock = 0;
	for(int i=0;i<n;i++){
		if(ar[i] >= ar[i+1]){
			now += stock*ar[i];
			stock = 0;
		}else{
			ll add = now/ar[i];
			stock += add;
			now -= add*ar[i];
		}
	}
	cout << now << '\n';

	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



ll power(ll a, ll b) {
    ll ans = 1;
    ll t = a;
    while (b) {
        if (b % 2) {
            ans = (ans * t) % 998244353;
        }

        t = (t * t) % 998244353;
        b /= 2;
    }

    return ans;
}



int main() {
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);



    int r;
    cin >> r;
    cout << r * r;

}


Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
  	int	H;
  	int	A;
  	int	num;
  	int	i;
  
  	num = scanf("%d %d", &H, &A);
  	if (num != 2)
      	return (0);
  
  	i = 0;
  	while (H > 0)
    {
      	H = H - A;
      	i++;
    }
  	printf("%d", i);
  	return (0);
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<limits>
using namespace std;
int main(){
  string S;
  cin >> S;
  int mn = numeric_limits<int>::max();
  for(int m=0; m<2; m++){
    int s=0;
    for(int i=0; i<S.size(); i++) s+= (S[i]-'0'+m+i)%2;
    mn = min(mn, s);
  }
  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 512
import numpy as np
from collections import Counter
ans=[]
N=int(input())
a=Counter([input() for _ in range(N)])
M=int(input())
b=Counter([input() for _ in range(M)])
for k, v in a.items():
  if k in b.keys():
    ans.append(v-b[k])
  else:
    ans.append(v)
print(max(0, *ans))

Measured memory_bytes: 12436
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		sc.close();

		long d = a;
//		a = a-c;
		a = Math.max(0,a-c);
//		if(a<0) { a = 0; }
		c = c-d;
		if(c>0) { b = b-c; }
		if(b<0) { b = 0; }
		System.out.println(a+" "+b);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(void) {
    int n; cin >> n;
    vector<int> x(n);
    int avg = 0;
    rep(i, n) {
        cin >> x[i];
        avg += x[i];
    }avg /= n;
    int c1 = avg;
    int c2 = c1 + 1;
    int ans1=0, ans2=0;
    rep(i, n) {
        ans1 += (x[i] - c1)*(x[i] - c1);
        ans2 += (x[i] - c2)*(x[i] - c2);
    }
    if(ans1 < ans2) cout << ans1;
    else cout << ans2;
}



Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
dp=[0]*N
dp[0]=0
dp[1]=abs(H[0]-H[1])
for i in range(1,int(N)-1,1):
    dp[i+1] +=min(dp[i]+abs(H[i]-H[i+1]),dp[i-1]+abs(H[i-1]-H[i+1]))
print(dp[N-1])

Measured memory_bytes: 13980
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

// vector set 等
#include <map>
#include <set>
#include <vector>

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto& i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000  // 10^12:∞
#define MOD 1000000007     // 10^9+7:合同式の法
#define MAXR 100000        // 10^5:配列の最大のrange
//略記
#define PB push_back  //挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素

// 負の数にも対応した % 演算
ll mod(ll x) {
  ll res = x % MOD;
  if (res < 0) x += MOD;
  return res;
}

ll mpow(ll x, ll n) {
  ll res = 1;
  while (n != 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return res;
}

// a^{-1} mod を計算する
ll minv(ll a) { return mpow(a, MOD - 2); }

signed main() {
  //入力の高速化用のコード
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll x, k, d, temp, temp2;
  cin >> x >> k >> d;

  if (x < 0) {
    x = -x;
  }

  temp = x % d;

  if (temp < 0) {
    temp = temp + d;
  }
  if ((x - temp) < 0) {
    if (k % 2 == 0) {
      cout << x << endl;
    } else {
      cout << d - x << endl;
    }
    return 0;
  }
  temp2 = (x - temp) / d;

  if (temp2 >= k) {
    cout << x - k * d << endl;
    return 0;
  } else {
    ll temp3;
    temp3 = k - temp2;
    if (temp3 % 2 == 0) {
      cout << temp << endl;
    } else {
      temp = temp - d;
      if (temp < 0) temp = -temp;
      cout << temp << endl;
    }
    return 0;
  }
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

    LL a, b;
    cin >> a >> b;

    if(a * b <= 0){
        cout << "Zero" << endl;
    }else if(a > 0){
        cout << "Positive" << endl;
    }else if(a < 0){
        cout << (abs(a - b + 1) & 1 ? "Negative" : "Positive") << endl;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int q;
  cin >> q;
  auto eval = [] (long long num, long long a, long long b) {
    long long lim = a * b - 1;
    long long st = max(1LL, num / 2 - 100);
    long long en = min(num, num / 2 + 100);
    for (long long i = st; i <= en; i++) {
      long long x = i;
      long long y = num - i + 1;
      if (x == a || y == b || x == b || y == b) continue;
      if (x * y > lim) {
        //cerr << num << " " << lim << " " << x * y << endl;
        return false;
      }
    }
    //cerr << num << " " << lim << " ok" << endl;
    return true;
  };
  while (q--) {
    long long a, b;
    cin >> a >> b;
    if (a == b) {
      cout << a * 2 - 2 << '\n';
      continue;
    }
    if (a > b) swap(a, b);
    long long lo = 0, hi = a + b + 10;
    while (hi - lo > 1) {
      long long mid = (hi + lo) >> 1;
      if (eval(mid, a, b)) lo = mid;
      else hi = mid;
    }
    cout << lo - 1 - (b - a == 1) << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int t,data[100],s[100],c[100],sum=0,indeks=0,indeks_c=0;
bool p=0;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	for(int i=0;i<t;i++)
      cin >> data[i];
  	for(int i=0;i<t;i++)
      cin >> s[i];
  	for(int i=0;i<t;i++)
      cin >> c[i];
  	for(int i=0;i<t;i++)
    {
     if(i==0)
     {
       sum+=s[data[i]-1];
     }else
     {
      	if((data[i-1])+1==data[i])
          sum+=c[data[i-1]-1]+s[data[i]-1];
         else
           sum+=s[data[i]-1];
     }
        
    }
  cout << sum <<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] +abs(h[i]-h[i-2]))
print(dp[-1])

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

void change_cookie(ll A, ll B, ll C, ll &count, bool &end) {
  if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
    return;
  }
  else if (A == B && B == C) {
    end = false;
    return;
  }
  
  else {
    ll a = A / 2;
    ll b = B / 2;
    ll c = C / 2;
    count++;
    end = true;
    change_cookie(b+c, a+c, a+b, count, end);
  }
}

  

int main() {
  ll A, B, C;
  cin >> A >> B >> C;
  ll count = 0;
  bool end = true;
  change_cookie(A, B, C, count, end);
  
  if (end) {
    cout << count << endl;
  }
  else {
    cout << -1 << endl;
  }
}

  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    ll n; 
    cin >> n;
    
    ll ans = LINF;

    for(ll x = 1; x * x <= n; x++) {
        if(n%x == 0) {
            ll y = n / x; 
            chmin(ans, (x-1LL)+(y-1LL));
        }
    }
    cout << ans << endl;

    return 0;
} /*atcoder*/



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct BigNum {
	ULL A[2] = {};
	void operator+=(ULL r) {
		A[0] += r;
		A[1] += A[0] / 1000000000000000000;
		A[0] %= 1000000000000000000;
	}
	void print() {
		if (A[1] == 0) printf("%llu", A[0]);
		else {
			printf("%llu%18llu", A[1], A[0]);
		}
	}
};

struct Problem {
public:

	UL N;
	ULL A[100005];
	ULL M[100005] = {};

	void Solve() {
		scanf("%u", &N);
		rep(i, N + 1) scanf("%llu", A + i);
		if (N == 0) {
			if (A[0] == 1) printf("1\n");
			else printf("-1\n");
			return;
		}
		A[N + 1] = 0;
		if (A[0] != 0) { printf("-1\n"); return; }
		for (UL i = N; i > 0; i--) {
			M[i] = M[i + 1] + A[i];
		}
		BigNum ans;
		ans += 1;
		ULL B = 1;
		for (UL i = 1; i <= N; i++) {
			B *= 2;
			if (B >= M[i]) B = M[i];
			if (A[i] > B) { printf("-1\n"); return; }
			ans += B;
			B -= A[i];
		}
		ans.print();
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 4660
import java.util.Scanner;

public interface Main {
	static int a = 1;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a =new int[n];
		long sum;
		int i, min, max;
		for(i=0; i<n; i++) {
			a[i]= sc.nextInt();
		}
		
		sum = 0;
		min = a[0];
		max = a[0];
		for(i=0; i<n; i++) {
			if(a[i]<min)	min=a[i];
			else if(a[i]>max)	max=a[i];
			sum += a[i];
		}
		System.out.printf("%d %d %d\n", min,max,sum);
	}
}


Measured memory_bytes: 41496
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int dp[200100];
vector<int> gr[200100];
int main()
{
	int n,m,a,b;
	cin>>n>>m;
	rep(i,m){
		cin>>a>>b;gr[a].pb(b);gr[b].pb(a);
	}
	rep(i,200100) dp[i]=200100;dp[1]=0;
	rep(i,gr[1].size()) dp[gr[1][i]]=1;
	REP(i,1,n) rep(j,gr[i].size()){
		int v=gr[i][j];
		if(dp[i]==1) dp[v]=min(dp[v],2);
	}
	if(dp[n]<3) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 12784
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 2e5 + 3;
const int M = 2e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 3e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9;
const double PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long a; cin >> a;
    cout << a + a * a + a * a * a;

    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int n; cin >> n;
	vector<int> v(n);
	for (auto &i : v)
		cin >> i;
	sort(rbegin(v), rend(v));
	multiset<array<int, 2>> s = {{v[1], v[0]}, {v[1], v[0]}};
	// set<array<int, 2>> s = {{v[1], v[0]}};
	long long ans = v[0];
	for (int i = 2; i < n; ++i) {
		auto [l, r] = *s.rbegin();
		s.erase(s.find({l, r}));
		ans += l;
		s.insert({v[i], l});
		s.insert({v[i], r});
	}
	cout << ans << '\n';
}

Measured memory_bytes: 13532
import java.util.Scanner;

class Main
{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int tmp;
    if(a>b){tmp = a; a = b; b = tmp;}
    if(a>c){tmp = a; a = c; c = tmp;}
    if(b>c){tmp = b; b = c; c = tmp;}
    System.out.println(a +" "+ b +" "+ c);
  }
}

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

int main() {
  int a,b,k;
  cin>>a>>b>>k;

  int ans = 1;
  for (int i = min(a,b); i > 0; i--) {
    if (a%i==0 && b%i==0) k--;
    if (k==0) {
      cout << i << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <algorithm>
#include <limits>
#include <ios>
#include <iomanip>
using namespace std;

#define rep(i,N) for(int i=0; i<N; i++)
#define revrep(i,N) for(int i=N-1; i>=0; i--)

typedef long long ll;

int main(void)
{
    int N,M,C;
    cin >> N >> M >> C;
    
    int B[M];
    rep(i,M){cin >> B[i];}

    int A[N][M];
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
        }
    }
    int ret = 0;
    rep(i,N){
        ll ans = 0;
        rep(j,M){
            ans += A[i][j] * B[j];
        }
        if (ans+C > 0) ret++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
ll dp[maxn];
ll n,W;
ll v[maxn];
ll w[maxn];
int main()
{
    memset(dp,0x3f,sizeof(dp));
    gbtb;
    cin>>n>>W;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    ll ans=0ll;
    dp[0]=0;
    repd(i,1,n)
    {
        for(int j=1e5;j>=v[i];--j)
        {
            {
                dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
                if(dp[j]<=W)
                    ans=max(ans,(ll)(j));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define eb emplace_back
#define PI 3.14159265
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(it, a, b) \
    for (ll it = (a); it < (b); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double ld;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k, s = 0;
    cin >> k;
    fr(i, 1, k + 1)
    {
        fr(j, 1, k + 1)
        {
            fr(l, 1, k + 1)
            {
                ll x = hcf(i, j);
                s += hcf(x, l);
            }
        }
    }
    cout << s << "\n";
    return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
const int MAXN=2e5+10;
const LL INF=0x3f3f3f3f;
vector<pii> bck[MAXN];
int n,m;
LL sum;

struct Segment_tree{
	#define lson (nod<<1)
	#define rson ((nod<<1)|1)
	#define mid ((tree[nod].lef+tree[nod].rig)>>1)
	
	struct Pt{
		int lef,rig;
		LL mn,vl;
	}tree[MAXN<<2];
	
	void build(int nod,int l,int r){
		tree[nod].lef=l;
		tree[nod].rig=r;
		if(l==r) return; 
		build(lson,l,mid);
		build(rson,mid+1,r);
	}
	
	void plus(int nod,int l,int r,LL val){
		if(l<=tree[nod].lef&&tree[nod].rig<=r){
			tree[nod].mn+=val;
			tree[nod].vl+=val;
			return;
		}
		pushdown(nod);
		if(l<=mid) plus(lson,l,r,val);
		if(r>mid) plus(rson,l,r,val);
		update(nod);
	}
	
	void pushdown(int nod){
		tree[lson].mn+=tree[nod].vl;
		tree[rson].mn+=tree[nod].vl;
		tree[lson].vl+=tree[nod].vl;
		tree[rson].vl+=tree[nod].vl;
		tree[nod].vl=0;
	}
	
	void update(int nod){
		tree[nod].mn=min(tree[lson].mn,tree[rson].mn);
	}
	
	LL query(int nod,int l,int r){
		if(l<=tree[nod].lef&&tree[nod].rig<=r){
			return tree[nod].mn;
		}
		pushdown(nod);
		LL ret=INF;
		if(l<=mid) ret=min(ret,query(lson,l,r));
		if(r>mid) ret=min(ret,query(rson,l,r));
		return ret;
	}
	
	void change(int nod,int x,LL val){
		if(tree[nod].lef==x&&tree[nod].rig==x){
			tree[nod].mn=val;
			tree[nod].vl=val;
			return;
		}
		pushdown(nod);
		if(x<=mid) change(lson,x,val);
		else change(rson,x,val);
		update(nod);
	}
	
	#undef lson
	#undef rson
	#undef mid
} tree;

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		bck[b].push_back(make_pair(a,c));
		sum+=c;
	}
	
	tree.build(1,0,n);
	
	for(int i=1;i<=n;i++){
		LL d=tree.query(1,0,i-1);
		tree.change(1,i,d);
		pii t;
		int len=bck[i].size();
		for(int j=0;j<len;j++){
			t=bck[i][j];
			tree.plus(1,0,t.first-1,t.second);
		}
	}
	
	cout<<sum-tree.query(1,0,n)<<endl;
	
	return 0;
}
 

Measured memory_bytes: 25856