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

using namespace std;

typedef long long ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, n) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = min((a), (b))

struct Info {
  ll A, B;
};

bool operator<(const Info &left, const Info &right) { return left.A < right.A; }

int main() {
  int N, M;
  cin >> N >> M;
  vector<Info> shops(N);

  REP(i, N) { cin >> shops[i].A >> shops[i].B; }
  sort(shops.begin(), shops.end());

  ll count = M;
  ll total = 0;
  REP(i, N) {
    if (shops[i].B < count) {
      total += shops[i].B * shops[i].A;
      count -= shops[i].B;
    } else {
      total += shops[i].A * count;
      break;
    }
  }
  cout << total;

  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = GettingStarted.Rectangle();
            System.Diagnostics.Trace.WriteLine(result);
            Console.WriteLine(result);
        }
    }

    public static class GettingStarted
    {
        public static string Rectangle()
        {
            var input = Console.ReadLine();
            var lines = input.Split(' ').Select(i => int.Parse(i)).ToArray();
            return string.Format("{0} {1}", lines[0] * lines[1], (lines[0] + lines[1]) * 2);
        }

        public static string XCubic()
        {
            var input = Console.ReadLine();
            return Math.Pow(double.Parse(input), 3).ToString("#");
        }

        public static string HelloWorld()
        {
            return "Hello World";
        }
    }
}

Measured memory_bytes: 5940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	if(x<0)putchar('-'),x=-x;
	int y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
ll n,a[100005],dp[100005];
int main(){
	n=read();
	for(int i=0;i<n;i++)
		a[i]=read();
	dp[0]=0,dp[1]=abs(a[1]-a[0]);
	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	print(dp[n-1]);
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 9223372036854775807;

//x座標の組み合わせで左右の長さが決まる
//y座標の組み合わせで上下の長さ決まる
//たかだかそのへんの組み合わせ分だけの長方形を考えると良さそう
//それらの組み合わせの中に内包されている座標はいくつ？
//5重ループ！！くそ

//入力
ll N, K;
vector<ll > X;
vector<ll > Y;
ll check(ll x1, ll x2, ll y1, ll y2){
    ll cn = 0;
    for(ll k = 0; k < N; k++){
        ll xk = X[k];
        ll yk = Y[k];
        if(xk >= x1 && xk <= x2 && yk >= y1 && yk <= y2){
            cn++;
        }        
    }
    return cn;
}

int main(){

    cin >> N >> K;

    for(ll i = 0; i < N; i++){
        ll a, b; cin >> a >> b;
        X.push_back(a);
        Y.push_back(b);
    }
    //sort(X.begin(), X.end());
    //sort(Y.begin(), Y.end());


    ll ans = INF;
    for(ll x1 = 0; x1 < N; x1++){
        for(ll x2 = x1 + 1; x2 < N; x2++){
            for(ll y1 = 0; y1 < N; y1++){
                for(ll y2 = y1 + 1; y2 < N; y2++){
                    //長方形作れない例外（必要ない)
                    ll tx1 = X[x1];
                    ll tx2 = X[x2];
                    ll ty1 = Y[y1];
                    ll ty2 = Y[y2];

                    if(tx1 > tx2) swap(tx1, tx2); 
                    if(ty1 > ty2) swap(ty1, ty2); 
                    
                    ll cn = check(tx1, tx2, ty1, ty2);
                    if(cn >= K) ans = min(ans, (tx2-tx1)*(ty2-ty1));
                }
            }
        }
    }

    cout << ans << endl;

}

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

#define ll long long
const int mod = 1e9 + 7;
ll int INF = 1e17;


int cost[200005];
int harr[200005];
ll int dp[200005];
ll int seg[800005];


void update(int node, int start, int end, int l, int r, ll int val)
{
  if(end < l || start > r)
    return;

  if(start == end)
    seg[node] = val;
  else
  {
    int mid = (start + end) / 2;
    update(node*2, start, mid, l, r, val);
    update(node*2 + 1, mid+1, end, l, r, val);
    seg[node] = max(seg[node*2], seg[node*2+1]);
  }
  return;
}

ll int query(int node, int start, int end, int l, int r)
{
  if(end < l || start > r)
    return 0;

  if(l <= start && end <= r)
    return seg[node];

  ll int q1, q2;
  int mid = (start + end) / 2;
  q1 = query(node*2, start, mid, l, r);
  q2 = query(node*2+1, mid+1, end, l, r);

  return max(q1, q2);
}

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

  int n;
  ll int y;
  cin>>n;
  for(int i=0;i<n;i++)
    cin>>harr[i];
  for(int i=0;i<n;i++)
    cin>>cost[i];

  for(int i=0;i<n;i++)
  {
    y = query(1, 0, n, 0, harr[i]);
    dp[harr[i]] = y + cost[i];
    update(1, 0, n, harr[i], harr[i], dp[harr[i]]);
  }

  for(int i=0;i<=n;i++)
    y = max(y, dp[i]);
  cout<<y<<endl;

  return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>

double zc(double n){
        if(-0.000000001<n&&n<=0) return 0;
        else return n;
}

signed main(){
        double a,b,c,d,e,f;
        while( scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF ){
                double x = 1/(a*e-b*d)*(c*e-b*f);
                double y = 1/(a*e-b*d)*(a*f-c*d);
                printf("%.3f %.3f\n",zc(x),zc(y));
        }
        return 0;
}

Measured memory_bytes: 3148
<?php
    $cnt = 0;
    $num = explode(" ",trim(fgets(STDIN)));
    $a = $num[0];
    $b = $num[1];
    $c = $num[2];
    while($a <= $b){
        if(($c % $a)==0){
            $cnt++;
        }
        $a++;
    }
    echo $cnt.PHP_EOL;
?>


Measured memory_bytes: 9208
import java.util.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = (a+b) % 2 == 0 ? (a+b)/2 : (a+b)/2 +1;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <deque>
using namespace std;

int main(){
    deque<char> dq;
    string S;
    bool x = true;
    int Q;
    cin >> S >> Q;
    for (int i = 0; i < (int)S.size();i++)
        dq.emplace_back((char)S[i]);
    
    for (int i = 0; i < Q; i++)
        {
            int q;
            cin >> q;
            if (q - 1)
            {
                int f;
                char s;
                cin >> f >> s;
                if (f - 1)
                {
                    if (x)
                        dq.emplace_back(s);
                    else
                        dq.emplace_front(s);
                }
                else
                {
                    if (x)
                        dq.emplace_front(s);
                    else
                        dq.emplace_back(s);
                }
            }
            else
            {
                if (x)
                    x = false;
                else
                    x = true;
            }
        }

        if (x)
        {
            while (!dq.empty())
            {
                cout << dq.front();
                dq.pop_front();
            }
    }else{
        while (!dq.empty())
        {
            cout << dq.back();
            dq.pop_back();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> l(Q),r(Q),R(N+1);
    R[0] = 0;
    for(int i = 0; i < Q; i++) cin >> l[i] >> r[i];
    for(int i = 1; i <= N+1; i++){
        if(S[i] == 'C' && S[i-1] == 'A'){
            R[i+1]++;
        }
        R[i] += R[i-1]; 
        //cout << R[i] << endl;
    }
    for(int i = 0; i < Q; i++){
        cout << R[r[i]] - R[l[i]] << endl;
    }
    
}


Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    N,M = LI()
    s = [0]*M
    c = [0]*M
    n = [0]*3
    for i in range(M):
        Sn,Cn = LI()
        s[i] = Sn
        c[i] = Cn

    if N == 1:
        ans = [0]
    elif N == 2:
        ans = [1, 0]
    elif N == 3:
        ans = [1, 0, 0]

    for k in range(0, M):
        if ans[s[k]-1] != c[k]:
            n[s[k]-1] += 1
        ans[s[k]-1] = c[k]


    if (ans[0] == 0 and N != 1) or  n[0]>=2 or n[1]>=2 or n[2]>=2:
        print(-1)
    else:
        ans = map(str,ans)
        print(''.join(ans))




if __name__ == "__main__":
	main()

Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1e9+7;

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

//********************************template END****************************************//

void solve(void){

	ll N, K;
	cin >> N >> K;

	ll tmp = (N/K);

	ll ans = pow(tmp, 3);

	if (K % 2 == 0)
	{
		if (N % K >= K/2)
		{
			tmp++;
			ans += pow(tmp, 3);
		}
		else
		{
			ans *= 2;
		}
	}

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
w=list(map(int,input().split()))

dist =10**18
for i in range(1,n):
    a= w[:i]
    b= w[i:]

    a_sum = sum(a)
    b_sum = sum(b)

    dist = min (dist , abs(a_sum - b_sum))


print(dist)

Measured memory_bytes: 3060
from collections import deque

div = 10 ** 9 + 7

n, k = map(int, input().split())
A = deque(sorted([int(x) for x in input().split()]))
maxA = A[-1]
ans = 1
for i in range(k // 2):
    l1 = A[0]
    l2 = A[1]
    r1 = A[-1]
    r2 = A[-2]
    l = l1 * l2
    r = r1 * r2
    if k % 2 == 1 and maxA < 0:
        ans *= r
        ans %= div
        A.pop()
        A.pop()
    else:
        if l < r:
            ans *= r
            ans %= div
            A.pop()
            A.pop()
        else:
            ans *= l
            ans %= div
            A.popleft()
            A.popleft()
if k % 2 == 1:
    ans *= A[-1]
    ans %= div
print(ans)


Measured memory_bytes: 32144
q=int(input())
ans=[0]*q
for i in range(q):
    a,b=map(int,input().split())
    n=a*b
    if a==b:
        ans[i]=2*(a-1)
    elif n==int(n**.5)**2:
        ans[i]=(int(n**.5)-1)*2-1
    elif n<=int(n**.5)*(int(n**.5)+1):
        ans[i]=(int(n**.5)-1)*2
    else:
        ans[i]=(int(n**.5)-1)*2+1
print(*ans,sep='\n')

Measured memory_bytes: 3064
from collections import defaultdict
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
AB = [[int(x) for x in input().split()] for i in range(M)]

g = defaultdict(set)
for a, b in AB:
    g[a].add(b)
    g[b].add(a)

good = 0
for obs, h in enumerate(H, 1):
    highest = 0
    for other in g[obs]:
        highest = max(highest, H[other - 1])
    if highest < h:
        good += 1
print(good)

Measured memory_bytes: 123920
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

vector<int> edge[108000];
Int dp[108000][2];
Int n, x, y;
Int solve(int x, int last = -1){
  dp[x][0] = 1;
  dp[x][1] = 1;
  for(int i = 0;i < edge[x].size();i++){
    int to = edge[x][i];
    if(to == last)continue;
    dp[x][0] *= solve(to, x);dp[x][0] %= MOD;
    dp[x][1] *= dp[to][0];dp[x][1] %= MOD;
  }
  return (dp[x][0] + dp[x][1]) % MOD;
}

int main(){
  cin >> n;
  for(int i = 0;i < n-1;i++){
    cin >> x >> y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }

  cout << solve(1) << endl;
  
  return 0;
}

Measured memory_bytes: 14464
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define inf (1ll<<60)
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;

int main() {
    
    
    fast();
    ll t,n,k,p,q,x,y,z,ans=0;
    cin>>n>>k;
   
     
     for(ll i=k-1;i<=n;i++)
     {
         p=i*(i+1)/2;
         t=n-(i+1);
         q=(n*(n+1)/2)-(t*(t+1)/2);
         
         ans=(ans%mod)+((abs(q-p))%mod)+(1%mod);
        // cout<<ans<<" ";
     }
     
   cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
pair<ll,ll> a[200010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].second>>a[i].first;
	}
	sort(a,a+n);
	bool flag=0;
	ll last=0;
	for(int i=0;i<n;i++){
		last+=a[i].second;
		if(last>a[i].first)flag=1;
	}
	if(flag)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define l first
#define r second
typedef pair <int,int> pii;
int N;
pii problem[100005];
int leftRegion[100005];
int rightRegion[100005];
int main() {
    scanf("%d", &N);
    int largeL = INT_MIN, smallR = INT_MAX;
    int idxSmall = 0, idxLarge = 0;
    for (int i=0; i<N; i++){
        scanf("%d %d", &problem[i].l, &problem[i].r);
        problem[i].r++;
        if (problem[i].l > largeL){
            largeL = problem[i].l;
            idxLarge = i;
        }
        if (problem[i].r < smallR) {
            smallR = problem[i].r;
            idxSmall = i;
        }
    }
    int ans = 0;
    for (int i=0; i<N; i++){
        if (i != idxLarge && i != idxSmall)
            ans = max(ans, max(0, smallR-largeL) + problem[i].r - problem[i].l);
    }
    int l1 = problem[idxSmall].l, r1 = problem[idxSmall].r;
    int l2 = problem[idxLarge].l, r2 = problem[idxLarge].r;
    sort(problem, problem+N);
    for (int i=0; i<N; i++){
        l1 = max(l1, problem[i].l);
        r1 = min(r1, problem[i].r);
        leftRegion[i] = max(0, r1-l1);
    }
    for (int i=N-1; i>=0; i--){
        l2 = max(l2, problem[i].l);
        r2 = min(r2, problem[i].r);
        rightRegion[i] = max(0, r2-l2);
    }
    for (int i=0; i<N-1; i++){
        ans = max(ans, leftRegion[i]+rightRegion[i+1]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
int A, B, K, y;
  cin >> K >> A >> B;
  y = A / K;
  if(K * (y + 1) <= B || K * y == A){
  cout << "OK" << endl;
  }
  else
    cout << "NG" << endl;
}

Measured memory_bytes: 3624
import scala.io.StdIn._

object Main extends App {
  val n = 5
  val a = (1 to n).map(_ => readLine.toInt).toArray
  val k = readLine.toInt
  var msg = "Yay!"
  for (i <- (4 to 1 by -1)) {
    if (a(i) - a(0) > k) {
      msg = ":("
    }
  }
  println(msg)
}

Measured memory_bytes: 25540
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  for(int i = 2;i<n;++i){
    if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C') cnt++;
  }
    cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
#define max_limit 1000005
using namespace std;


int main() {

    ll n;
    ll k;
    cin>>n>>k;

    ll p[n];
    for(ll i = 0; i < n; i++) {
        cin>>p[i];
    }

    double avg[1001];
    avg[0] = 0.0;
    ll sum = 0;
    for(ll num = 1; num <= 1000; num++) {
        sum += num;
        avg[num] = double(sum)/num;
    }

    queue<ll> q;
    double cur_average = 0;
    for(ll i = 0; i < k; i++) {
        q.push(p[i]);
        cur_average += avg[p[i]];
    }

    double max_average{cur_average};

    ll last_index = k;
    while(last_index < n) {
        ll startNumber = q.front();
        cur_average -= avg[startNumber];
        cur_average += avg[p[last_index]];
        q.pop();
        q.push(p[last_index]);

        if(cur_average > max_average) {
            max_average = cur_average;
        }

        last_index++;
    }

    cout<<setprecision(8)<<max_average<<'\n';
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int n, k, tab[N], res[N], i, j;

int main() {
scanf("%d %d", &n, &k);
for (i=0;i<n;i++) scanf("%d", &tab[i]);
res[0] = 0;
for (i=1;i<n;i++) {
	res[i] = INF;
	for (j=1;j<=k;j++) if (i - j >= 0) res[i] = min(res[i], res[i - j] + abs(tab[i] - tab[i - j]));
}
printf("%d\n", res[n - 1]);
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

ll a[300000];

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}
bool isOK(int index) {
    int k = 0;
    REP(i, N) {
        if (a[i] > index)
            k += a[i] / index;
    }
    dump(k, index);
    if (K >= k)
        return true;
    else
        return false;
}
int binary_search(int key) {
    int ng = 0;      //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)X; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (isOK(mid))
            ok = mid;
        else
            ng = mid;
    }
    return ok;
}

signed main() {
    cin >> N >> K;
    REP(i, N)
    cin >> a[i];
    X = 0;
    REP(i, N)
    X = max(a[i], X);
    X++;
    cout << binary_search(K) << endl;
}

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

int main() {
  long long n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  long long m=min({a,b,c,d,e});
  long long q;
  if(n%m==0){q=n/m;}
  else{q=n/m+1;}
  cout << q+5-1 << endl;
}

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

using namespace std;
using ll = long long;

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

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

  vector<int> id(m, -1);
  vector<ll> s;
  int len = 0;
  while (id[x] == -1) {
    id[x] = len++;
    s.push_back(x);
    x = x * x % m;
  }

  int d = len - id[x];
  ll ans = 0;
  if (n <= d) {
    rep(i, n) ans += s[i];
  } else {
    rep(i, id[x]) ans += s[i];
    n -= id[x];
    ll sum = 0;
    rep(i, d) sum += s[id[x] + i];
    ans += sum * (n / d);
    n %= d;
    rep(i, n) ans += s[id[x] + i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4264
use proconio::input;
use proconio::marker::Usize1;
use std::collections::BTreeSet;

fn main() {
    input! {
        h: usize,
        w: usize,
        m: usize,
        bomb: [(Usize1,Usize1); m]
    }

    let ans = {
        let mut tate = vec![0; h];
        let mut yoko = vec![0; w];
        let mut set = BTreeSet::new();
        for &(y,x) in &bomb {
            tate[y] += 1;
            yoko[x] += 1;
            set.insert((y,x));
        }

        let tate_max = {
            let mut mm = tate[0];
            for i in 0..h {
                if mm < tate[i] {
                    mm = tate[i];
                }
            }
            let mut tate_max = Vec::new();
            for i in 0..h {
                if mm == tate[i] {
                    tate_max.push(i);
                }
            }
            tate_max
        };
        let yoko_max = {
            let mut mm = yoko[0];
            for i in 0..w {
                if mm < yoko[i] {
                    mm = yoko[i];
                }
            }
            let mut yoko_max = Vec::new();
            for i in 0..w {
                if mm == yoko[i] {
                    yoko_max.push(i);
                }
            }
            yoko_max
        };
        
        let mut ans = 0;
        let mut flag = false;
        for &y in &tate_max {
            if flag {
                break;
            }
            for &x in &yoko_max {
                let mm = if set.contains(&(y,x)) {1} else {0};
                if ans < tate[y]+yoko[x]-mm {
                    ans = tate[y]+yoko[x]-mm;
                }
                if mm == 0 {
                    flag = true;
                    break;
                }
            }
        }
        ans
    };


    println!("{}",ans)
}


Measured memory_bytes: 26556
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,x;
    cin>>n;
    map<ll,ll>mp;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        sum+=x;
        mp[x]++;
    }
    int m;
    cin>>m;
    while(m--)
    {
        ll a,b;
        cin>>a>>b;

        if(mp[a]==0)
        {
            cout<<sum<<endl;
        }
        else{
            sum-=(mp[a]*a);
            sum+=(mp[a]*b);
            mp[b]+=(mp[a]);
            cout<<sum<<endl;
            mp[a]=0;
        }
    }
}


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

#define N_MAX 100

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

    long yyyy = stoi(S.substr(0, 4));
    long mm = stoi(S.substr(5, 2));
    long dd = stoi(S.substr(8, 2));

    if (yyyy <= 2019 && mm <= 4) {
        cout << "Heisei" << endl;
    }
    else {
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	int Y;
	int x, y,z;
	
	scanf("%d%d", &N, &Y);

	for (x = N; x >=0; x--){
		for (y = N-x; y >=0; y--){
			z = N- x - y;
			int sum;
			sum = 10000 * x + 5000 * y + 1000*z;

			if (sum == Y){
				printf("%d %d %d\n", x, y, z);
				return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#define sq(a)(a)*(a)
using namespace std;
int n,m;
double l[99],a[99],b[99];
double d(int i,int j)
{
	return sq(l[i]-l[j])+sq(a[i]-a[j])+sq(b[i]-b[j]);
}
main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>l[i]>>a[i]>>b[i];
	double ans=0;
	for(int i=0;i<1<<n;i++)
	{
		if(__builtin_popcount(i)!=m)continue;
		double now=0;
		for(int j=0;j<n;j++)
		{
			if(!(i&(1<<j)))continue;
			for(int k=j+1;k<n;k++)
			{
				if(!(i&(1<<k)))continue;
				now+=d(j,k);
			}
		}
		ans=ans<now?now:ans;
	}
	cout<<fixed<<setprecision(9)<<ans<<endl;
}



Measured memory_bytes: 3272
n = int(input())

taro = 0
hanako = 0

for i in range(n):
    taro_card,hanako_card = input().split(' ')
    if taro_card > hanako_card:
        taro += 3
    elif hanako_card > taro_card:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print(taro , hanako)



Measured memory_bytes: 5600
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val s = sc.next()
    val odd = Seq('R', 'U', 'D')
    val even = Seq('L', 'U', 'D')
    for (i <- 0 until s.length) {
      if (i % 2 == 0) {
        if (odd.indexOf(s(i)) == -1) {
          println("No")
          return
        }
      } else {
        if (even.indexOf(s(i)) == -1) {
          println("No")
          return
        }
      }
    }
    println("Yes")
  }
}

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

long read_long() {
	long ret=0;char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9') {
		ret=ret*10+c-'0';
		c=getchar();
	}		return ret;
}

int main() {
	long a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n=sc.nextInt(),d=2*sc.nextInt()+1;
		out.println((n+d-1)/d);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000

int A[MAX], n;

int Partition(int p, int r)
{
    int i, j, x, t;
    i = p - 1;
    x = A[r];
    for ( j = p; j < r; ++j) {
        if (A[j] <= x) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i+1;
}

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

    int ans = Partition(0, n-1);

    for (int i=0; i<n; ++i) {
        if ( i ) cout << " ";
        if (i == ans) cout << "[";
        cout << A[i];
        if (i == ans) cout << "]";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3468
import sys
import math

while True:
	n = int(input())
	if n == 0:
		break
	data = [list(map(int,input().split())) for i in range(n)]
	data.append([0 for i in range(n+1)])

	for i in range(n+1):
		if i != n:
			data[i].append(sum(data[i]))
		for j in range(n):
			data[n][i] = data[n][i]+data[j][i]
	for i in range(n+1):
		for j in range(n+1):
			if j != n:
				string = str('{:>5}'.format(data[i][j]))
				sys.stdout.write(string)
			else:
				print('{:>5}'.format(data[i][j]))

Measured memory_bytes: 7748
n = int(input())
name = []
eng = 'abcdefghijklmnopqrstuvwxyz'
while n:
  name.append(eng[n % 26-1])
  if n % 26 == 0:
    n = n // 26 - 1
  else:
    n //= 26
print(''.join(reversed(name)))

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

int main(){
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	if(s[0] == '0' || s[n - 1] == '1'){
		cout << "-1\n";
		return 0;
	}
	for(int i = 0; i < n - 1; ++i){
		if(s[i] != s[n - 2 - i]){
			cout << "-1\n";
			return 0;
		}
	}

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


Measured memory_bytes: 1616
#include<iostream>
#include<queue>
using namespace std;
int G[1005][1005], dist[1005][1005], H, W, K, sx[11], sy[11];
int solve(int ax, int ay, int bx, int by) {
	for (int i = 0; i < 1005 * 1005; i++)dist[i / 1005][i % 1005] = 1000000000;
	queue<pair<int, int>>Q; Q.push(make_pair(ax, ay)); dist[ax][ay] = 0;
	while (!Q.empty()) {
		int a1 = Q.front().first, a2 = Q.front().second; Q.pop();
		int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
		for (int i = 0; i < 4; i++) {
			if (G[a1 + dx[i]][a2 + dy[i]] == 0 && dist[a1 + dx[i]][a2 + dy[i]] > dist[a1][a2] + 1) {
				dist[a1 + dx[i]][a2 + dy[i]] = dist[a1][a2] + 1;
				Q.push(make_pair(a1 + dx[i], a2 + dy[i]));
			}
		}
	}
	return dist[bx][by];
}
int main() {
	cin >> H >> W >> K;
	for (int i = 0; i <= H + 1; i++) {
		for (int j = 0; j <= W + 1; j++) {
			if (i == 0 || i == H + 1 || j == 0 || j == W + 1)G[i][j] = 1;
		}
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			char p; cin >> p;
			if (p == 'S') { sx[0] = i; sy[0] = j; }
			if (p >= '0' && p <= '9') { sx[p - '0'] = i; sy[p - '0'] = j; }
			if (p == 'X')G[i][j] = 1;
		}
	}
	int cnt = 0;
	for (int i = 0; i < K; i++) {
		cnt += solve(sx[i], sy[i], sx[i + 1], sy[i + 1]);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 10896
n=int(input())

X=list(map(int,input().split()))
X=sorted(X,reverse=True)
if n==1:
  print(0)
  exit()

A=[]
for i in range(1,100):
  ans=0
  for j  in range(n):
    ans += abs(i-X[j])**2
  A.append(ans)
A = sorted(A)
print(A[0])


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll N;
vll A;
bool flag = false;
map<ll, ll> mp;

void solve(){
    rep(i,N){
        mp[A[i]]++;
    }

    if(2*mp[0] + 1 >= N) {
        flag = true;
    } else {
        N -= 2*mp[0];

        if(mp[2] == N || mp[2] == N + 1) flag = true;
    }

    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main(){
    cin >> N;
    A.resize(N);

    rep(i, N) cin >> A[i];

    rep(i, N) A[i] %= 4;

    solve();
}


Measured memory_bytes: 4028
#include<stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))

int main(){
	int i,j,h,w;
	char s[2000][2001];
	scanf("%d%d",&h,&w);
	for(i=0;i<h;i++)scanf("%s",s[i]);
	int hsc[2000][2000];
	int wsc[2000][2000];
	for(i=0;i<h;i++){
		int tmp=0,hu=0;
		for(j=0;j<w;j++){
			if(s[i][j]=='.')tmp++;
			if(s[i][j]!='.'){
				for(int k=hu;k<j;k++)hsc[i][k]=tmp;
				tmp=0;
				hu=j;
			}
		}for(int k=hu;k<j;k++)hsc[i][k]=tmp;
	}
	for(i=0;i<w;i++){
		int tmp=0,hu=0;
		for(j=0;j<h;j++){
			if(s[j][i]=='.')tmp++;
			if(s[j][i]!='.'){
				for(int k=hu;k<j;k++)wsc[k][i]=tmp;
				tmp=0;
				hu=j;
			}
		}				for(int k=hu;k<j;k++)wsc[k][i]=tmp;

	}
/*  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      printf("%d,",hsc[i][j]);
    }puts("");
  }*/
	int ans=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i][j]!='#'){
				ans=max(ans,hsc[i][j]+wsc[i][j]-1);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35328
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b,c,x;
    while(scanf("%d%d%d%d",&a,&b,&c,&x)==4){
        int sum=0;
        int ans=0;
        for(int i=0;i<=a;i++){
            for(int j=0;j<=b;j++){
                for(int k=0;k<=c;k++){
                    sum=i*500+j*100+k*50;
                    if(sum==x) ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;
 
typedef long long ll;
 
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
 
// const int C ;
// const int M = 1000000007;
 
int H, W;
string A[8];
bool F[8][8];
int S;
 
int main () {
  cin >> H >> W;
  for (auto i = 0; i < H; i++) {
    cin >> A[i];
  }
  for (auto i = 0; i < H; i++) {
    for (auto j = 0; j < W; j++) {
      F[i][j] = (A[i][j] == '#');
    }
  }
  S = H+W-1;
  int cnt = 0;
  for (auto i = 0; i < H; i++) {
    for (auto j = 0; j < W; j++) {
      if (F[i][j]) cnt++;
    }
  }
  cout << ((S == cnt) ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*
import kotlin.comparisons.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val n = readInt() 
    val count = (0 until n).map {
        val (l, r) = readListOfInt()
        r - l + 1
    }.sum()
    println(count)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 38180
int main()
{
  long long a, b, c, d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  long long e[7];
  e[0] = a * c;
  e[1] = b * d;
  e[2] = a * d;
  e[3] = b * c;
  long long ans = e[0];
  int i = 1;
  if ((a <= 0 && b >= 0) || (c <= 0 && d >= 0))
  {
    e[4] = 0;
    while (i < 5)
    {
      if (ans < e[i])
        ans = e[i];
      i++;
    }
  }
  else
  {
    while (i < 4)
    {
      if (ans < e[i])
        ans = e[i];
      i++;
    }
  }
  printf("%lld", ans);
}

Measured memory_bytes: 1724
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  cout << (a[n-1]-a[0]) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

const int Max = 1e6;
int n, p[Max];

int main() {
    cin >> n;
    int m = inf;
    rep(i, n) cin >> p[i];
    int ans = 0;
    rep(i, n) {
        chmin(m, p[i]);
        if(m >= p[i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;


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

	int n,limit;
	int arr[100];
	cin >> n >> limit;

	rep(i , n)
		cin >> arr[i];

	int prev = 0;
	int ans = 1;
	rep(i , n)
	{
		int current = prev + arr[i];
		if(current <= limit)	ans++;
		prev = current;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

X,A = Is()
lis = [0] + Is()
t = 0
for i in range(X+1):
    t += lis[i]
    if t > A:
        print(i)
        exit()
    elif i == X:
        print(X+1)
        exit()

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

 
int n;
int v[110000];
// 奇遇それぞれの最頻値を算出
vector<pair<int,int> > cntEven(110000);
vector<pair<int,int> > cntOdd(110000);
int main(){
    cin >> n;
    REP(i,n) cin >> v[i];

    // v[i]という数字の頻度をカウント　：　pair<頻度,数>
    // 頻度数でソートするために頻度をfirstに
    REP(i,100001){
        cntEven[i] = make_pair(0,i);
        cntOdd[i] = make_pair(0,i);
    }
    REP(i,n/2){
        ++cntEven[v[i*2]].first;
        ++cntOdd[v[i*2+1]].first;
    }
    sort(cntEven.begin(),cntEven.end(),greater<pair<int,int> >());
    sort(cntOdd.begin(),cntOdd.end(),greater<pair<int,int> >());
    int modeEven = cntEven[0].second;
    int modeOdd = cntOdd[0].second;
    if(modeEven==modeOdd){
        cout << n - max(cntEven[1].first + cntOdd[0].first, cntEven[0].first + cntOdd[1].first) << endl;
    } else {
        cout << n - cntEven[0].first - cntOdd[0].first << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
A,B = map(int,input().split())
def prime_number_set(n):
  N = n
  result = set()
  while (n%2) == 0:
    n //= 2
    result.add(2)

  for i in range(3,int(N**0.5)+2,2):
    while (n%i) == 0:
      n //= i
      result.add(i)
  if n > 1:
    result.add(n)
  return result

arrayA = prime_number_set(A)
arrayB = prime_number_set(B)
array = arrayA & arrayB
print(len(array)+1)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))
import copy
from operator import mul
from functools import reduce

def cmb(n,r):
    if n >= r:
        r = min(n-r,r)
        if r == 0: return 1
        over = reduce(mul, range(n, n - r, -1))
        under = reduce(mul, range(1,r + 1))
        return over // under
    else:
        return 0


s = [0 for i in range(N)]
for i in range(N):
    s[A[i]-1] += 1
    
s1 = copy.copy(s)
for i in range(N):
    if s[i] == 0:
        s1[i] = 0
    else:
        s1[i] -= 1

amount = 0
for i in range(N):
    a = cmb(s[i],2)
    amount += a

for i in range(N):
    print(amount-s1[A[i]-1])

Measured memory_bytes: 26140
N, L = map(int, input().split())
apple = [ L + int(_) - 1 for _ in range(1, N + 1)]
sumA = sum(apple)
ans = float("INF")
for i in range(N):
    l = sum(apple[0:i])
    r = sum(apple[i + 1:N])
    ans = min(abs(sumA - (l + r)), ans)

if sumA < 0:
    print(sumA + ans)
else:
    print(sumA - ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;


struct UnionFind
{
    vector<int> par;

    void init(int N) { par.assign(N, -1); }

    int root(int x)
    {
        if (par[x] < 0) { return x; }              // x が根
        else { return par[x] = root(par[x]); }     // 経路短縮
    }

    bool same(int x, int y) { return (root(x) == root(y)); }

    void unite(int x, int y)
    {
        int xx = root(x);
        int yy = root(y);

        if (xx == yy) { return; }

        if (par[xx] < par[yy])
        {
            par[xx] += par[yy];
            par[yy] = xx;
        }
        else
        {
            par[yy] += par[xx];
            par[xx] = yy;
        }
    }

};


int main()
{
    int N, M;
    vector<int> A, B;

    cin >> N >> M;

    UnionFind uf;
    uf.init(N);

    for (int i = 0; i < M; ++i) 
    { 
        int a, b;
        cin >> a >> b;
        uf.unite(a-1, b-1);
    }

    int num = 0;
    for (size_t i = 0; i < uf.par.size(); ++i)
    {
        if (uf.par[i] < 0)
        {
            ++num;
        }
    }

    cout << num - 1 << endl;


    return 0;
}


Measured memory_bytes: 3740
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll N,i;
	cin>>N;
	for(i=0;i*i<=N;i++);
	cout<<(i-1)*(i-1)<<endl;
}


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

using namespace std;

typedef long long ll;

const ll Mod = 1000000007LL;
const int Maxn = 1e6 + 10;

ll mul(ll a, ll b){
	return (a * b) % Mod;
}

ll dp[Maxn], f[Maxn];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	ll n, h, d;
	cin >> n >> h >> d;
	
	ll sm = 0;
	f[0] = 1;
	for(int i = 1; i <= n; i++) f[i] = mul(f[i - 1], i), sm += f[i];
	sm %= Mod;
	dp[0] = f[n];
	ll s = dp[0];
	for(int i = 1; i < h; i++){
		dp[i] = mul(s, sm);
		s += dp[i];
		if(i >= d) s -= dp[i - d];
		s %= Mod;
	}
	cout << (s + Mod) % Mod;
	return 0;
}
/*
1
5 1
20 21 22 23 24

1
4 2 
1 2 3 4

2 4 1 3

*/


Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, b; char op; cin >> a >> op >> b;
  if (op == '+') cout << a + b << endl;
  else cout << a - b << endl;
  return 0;
}


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

int main() {
  string str;
  getline(cin, str);
  for(int i = 0; i < str.length(); i++) {
    if(isalpha(str[i])) {
      str[i] = toupper(str[i]);
    }
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
    int n,m,count,number;
    number=0;
    cin>>n>>m;
    int k[30];
    int a[30][30];
    for (int i=0;i<n;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            cin>>a[i][j];
        }
    }
    for (int l=0;l<m;l++){
        count=0;
        for (int i=0;i<n;i++){
            for(int j=0;j<k[i];j++){
                if(a[i][j]==l+1){
                    count++;
                }
            }
        }
        if(count==n){
            number++;
        }
    }
    cout<<number<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;

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

    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    ll ans = 0;
    if (p == 2 || p == 5) {
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % p == 0) {
                ans += i + 1;
            }
        }
    } else {
        int ss[n+1];
        ss[n] = 0;
        for (int i = n - 1, q = 1; i >= 0; i--, q = q * 10 % p) {
            ss[i] = (ss[i+1] + q * (s[i] - '0')) % p;
        }

        int cp[p];
        fill(cp, cp+p, 0);
        for (int i = n; i >= 0; i--) {
            ans += cp[ss[i]];
            cp[ss[i]]++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

    int a, n[4] = {};
    char pm[5];
    bool shiki(int i, int k)
    {
        if (i == 4)
        {
            if (k == 7)
            {
                return true;
            }
            else
                return false;
        }
        if (shiki(i + 1, k + n[i]))
        {
            pm[i] = '+';
            return true;
        }
        else if(shiki(i+1,k-n[i])){
            pm[i] = '-';
            return true;
        }
        else
            return false;
}

int main(){
    cin >> a;
    n[3] = a % 10;
    n[2] = (a / 10) % 10;
    n[1] = (a / 100) % 10;
    n[0] = (a / 1000) % 10;
    if(shiki(1,n[0])){
        cout << n[0] << pm[1] << n[1] << pm[2] << n[2] << pm[3] << n[3] << "=7" << endl;
    }
    return 0;
}

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

const int MX = 100001;

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

  ll ans = 1000000005;
  rep(i,n){
    ll a;
    cin >> a;
    ll n2 = 0;
    while(a%2==0){
      a /= 2;
      n2++;
    }
    if(n2<ans) ans = n2;
  }

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

Measured memory_bytes: 3640