akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const int INF = 1e9 + 5;

void solve(){
    int n; cin>>n;
    int ans=0;
    for(int i=1;i<=min(9,n);i++) ans++;
    for(int i=100;i<=min(999,n);i++) ans++;
    for(int i=10000;i<=min(99999,n);i++) ans++;
    cout<<ans;
}
int main(){
    int T=1;        //! COMMENT IF THERE IS NO TEST CASES
    //cin>>T;             
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[35000];
int main()
{
	int n,k,i,j,s=0;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=n;i++)
	for(j=1;j<=n-1;j++)
	if(a[j]<a[j+1])
	swap(a[j],a[j+1]);
	for(i=1;i<=k;i++)
	s+=a[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
bool check(vector<int>a){
  bool r = true;
  rep(i,a.size())if(a[i] != 0)r = false;
  return r;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n + 1);
  int ans = 0;
  rep(i,n){
    cin >> v[i];
  }
  v[n] = 0;
  while(!(check(v))){
    int j = 0;
    while(v[j] == 0)j++;
    int k = j;
    while(v[k] != 0){
      v[k]--;
      k++;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 256
ret_sub :: Integer -> Integer -> Integer -> Integer -> Integer
ret_sub num id n k =
    if (id > n) then
        num
    else
        if (mod (((mod (-id) k) + k)*2) k == 0) then
            let a = div n k + if (mod n k >= mod (-id) k && mod (-id) k /= 0) then 1 else 0 in
            ret_sub (num + a*a) (id + 1) n k
        else
            ret_sub num (id + 1) n k


ret :: Integer -> Integer -> Integer
ret n k = ret_sub 0 1 n k


main = do
    hoge <- getLine
    let [n, k] = map read $ words hoge
    putStrLn $ show $ ret n k

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

public class Main {
    static int k;
    static String s;

    public static void main(String[] args) throws IOException {
        BufferedReader input =
            new BufferedReader(new InputStreamReader(System.in));

        s = input.readLine();
        k = Integer.parseInt(input.readLine());
        SortedMap a = new SortedMap(k);
        int len = s.length();

        for (int i=0; i<len; i++) {
            for (int j=1; j<=k && i+j<=len; j++) {
                String ss = s.substring(i, i+j);
                if (a.getBiggest().compareTo(ss) > 0) {
                    a.put(ss);
                    //System.out.println(ss + a);
                }
            }
        }
        System.out.println(a.getBiggest());
    }
}

class SortedMap {
    int maxSize;
    ArrayList<String> list;
    SortedMap(int maxSize) {
        list = new ArrayList<String>();
        this.maxSize = maxSize;
        list.add("zzzzzzzzzzz");
    }
    
    public String getBiggest() {
        return list.get(list.size()-1);
    }
    public void put(String s) {
        for (int i=0; i<list.size(); i++) {
            String t = list.get(i);
            if (s.equals(t)) return;
            if (s.compareTo(t) < 0) {
                list.add(i, s);
                break;
            }
        }
        if (list.size() > maxSize) list.remove(maxSize);
    }
    public String toString() {
        String s = "";
        for (int i=0; i<list.size(); i++) {
            s += ":" + list.get(i);
        }
        return s;
    }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    int n;
    cin >> n;
    for(int i = n; i <= 1111; i++){
        int first = i / 100;
        int second = i % 100 / 10;
        int third = i % 10;
        if(first == second && second == third){
            cout << 100 * first + 10 * second + third << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;

int main(void){
    IOS;
    int n; cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            for (int k = 1; k <= n; ++k){
                ans += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
// vim: set fdm=marker:
// {{{
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>

using namespace std ;

typedef long long ll ;

// }}}

int N, M;

vector<pair<int, ll>> to[1111111];

bool vis[1111111];
ll loc[1111111];

bool ans = true;

void dfs(int i, ll l) {
    vis[i] = true;
    loc[i] = l;
    for(auto p: to[i]) {
        if(vis[p.first]) {
            if(loc[p.first] != l + p.second) {
                //printf("vis[%d] != %d + %d\n", p.first, l, p.second);
                ans = false;
            }
        }
        else {
            dfs(p.first, l + p.second);
        }
    }
}

int main()
{
    cin >> N >> M;
    for(int i = 0 ; i != M ; i++) {
        int L, R, D;
        scanf("%d%d%d", &L, &R, &D);
        to[L].push_back({R, D});
        to[R].push_back({L, -D});
    }
    for(int i = 1 ; i <= N ; i++) {
        if(vis[i])
            continue;
        dfs(i, 0);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 40832
def inpl():
    return list(map(int, input().split()))


N = int(input())
ans = 0.0
for _ in range(N):
    x, u = input().split()
    x = float(x)
    if u == 'JPY':
        ans += x
    else:
        ans += 380000 * x
# print(ans)
print("{:.10f}".format(ans))


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, c, k, t[100010];
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++) cin >> t[i];

    sort(t, t + n);

    t[n] = 2000000010;
    int ans = 0, tt = t[0], cc = 0;
    for (int i = 0; i < n; i++) {
        cc++;
        if (cc == c or t[i + 1] > tt + k) {
            cc = 0;
            tt = t[i + 1];
            ans++;
        }
        cerr << tt << " " << cc << " " << ans << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }

    // n (n - 1) / 2 - (n - 1)
    val m = (n - 1) * (n - 2) / 2

    if (k > m) {
        println(-1)
        return
    }

    val ans = mutableListOf<Pair<Int, Int>>()

    // star
    for (i in (2 .. n)) {
        ans.add(Pair(1, i))
    }

    var v1 = 2
    var v2 = 3

    repeat(m - k) {
        ans.add(Pair(v1, v2))
        if (v2 < n) {
            v2++
        } else {
            v1++
            v2 = v1 + 1
        }
    }

    println(ans.size)
    ans.forEach { println("${it.first} ${it.second}") }
}

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

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

vector<ll> enum_divisor(ll x){
	ll tmp = x;
	vector<ll> res;
	for(ll i=1; i*i<=x; i++){
		if(tmp%i == 0){
			res.push_back(i);
			if(i*i != tmp) res.push_back(tmp/i);//iが√tmpのときは重複して数えないようにする
		} 
	}
	return res;
}

int main(void) {
	ll N;
	cin >> N;

	ll ans = 0;
	
	//操作1ができる場合
	vector<ll> n_divisor = enum_divisor(N);//Nの約数
	//cout << " n_divisor: ";print_vec(n_divisor);
	for(ll K : n_divisor){
		if(K==1) continue;//K=1だと永遠と操作1ができてしまう
		ll tmp = N;
		while(tmp >= K){//操作1をやれるだけ，やる.
		if(tmp % K == 0) tmp = tmp / K;
		else break;
		}
		if(tmp%K == 1) ans++;//操作2で1になるならインクリメント
		//if(tmp%K == 1) cout << " K: " << K << endl;
	}///↑上のifのところは　操作1に戻ることはないので，これで十分


	//操作1ができない場合(　N%i==1　⇒　(N-1)%i==0)
	// 操作2で1になるのは (N-1)の約数の個数だね
	vector<ll> n1_divisor = enum_divisor(N-1);//(N-1)の約数
	//cout << " n1_divisor: ";print_vec(n1_divisor);
	ans += n1_divisor.size() - 1;//-1は約数1の分(K=1は答えには，あてはまらない)

	cout << ans << endl;
}


Measured memory_bytes: 384
n = int(input())
ans = [0 for _ in range(4)]
for _ in range(n):
    a = input()
    if a == 'AC': ans[0] += 1
    elif a == 'WA': ans[1] += 1
    elif a == 'TLE': ans[2] += 1
    else: ans[3] += 1

for i, j in enumerate(['AC', 'WA', 'TLE', 'RE']):
    print(j+' x %d' % ans[i])


Measured memory_bytes: 9196
#include <stdio.h>
#define abs(a) ((a) < 0 ? - (a) : (a))

int main(void){
    int n;
    int k;
    int x[100];
    int total;
    int i;
    total = 0;

    scanf("%d", &n);
    scanf("%d", &k);
    for (i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }

    for (i = 0; i < n; i++){
        if (x[i]  < abs(x[i] - k)){
            total += x[i];
        }else{
            total += abs(x[i] - k);
        }
    }

    printf("%d", total*2);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int cyc(string &s) {
  size_t S = s.size();
  for (size_t i = 0; i < S / 2; i++) {
    bool flag = true;
    s.pop_back();
    s.pop_back();
    for (size_t j = 0; j < s.size() / 2; j++) {
      if (s[j] != s[s.size() / 2 + j]) {
        flag = false;
      }
    }
    if (flag) {
      return s.size();
    }
  }
}

string s;
int main(int argc, char const *argv[]) {
  cin >> s;
  int ans = 0;
  ans = cyc(s);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef pair<ld,ld> mp;
ld inf = 1e9;

ld dis(mp a,mp b){
	return sqrt( (a.first-b.first)*(a.first-b.first) + (a.second-b.second) * (a.second - b.second) );
}

int main(){
	int n;
	cin>>n;
	vector<mp> a(n);
	for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;
	vector<vector<ld> > dp(n,vector<ld>(n,inf) );
	sort(a.begin(),a.end());
	dp[0][0] = 0;
	for(int i=0;i<n-1;i++){
		for(int j=0;j<n-1;j++){
			int t = max(i,j) + 1;
			dp[t][j] = min( dp[t][j], dp[i][j] + dis( a[i] , a[t] ) );
			dp[i][t] = min( dp[i][t], dp[i][j] + dis( a[j] , a[t] ) );
		}
	}
	ld res = inf ;
	for(int i=0;i<n-1;i++) res = min( res,  dp[n-1][i]  + dis( a[i] , a[n-1] ) );
	cout<<fixed<<setprecision(10)<<res<<endl;
	return 0;
}



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

#define N 1000000007

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(m);
    for(int i = 0; i < m; i++) {
        cin >> v[i];
    }

    vector<long long int> dp(n+2, 0);
    dp[1] = 1;
    dp[2] = 2;
    for(int i = 0; i < m; i++) {
        dp[v[i]] = -1;
    }
    if(dp[1] == -1 && dp[2] == -1) {
        cout << 0 << endl;
        return 0;
    }
    
    if(dp[1] == -1) {
        dp[2] = 1;
    }


    for(int i = 3; i <= n+1; i++) {
        //cout << "i: " << i << " " << dp[i] << endl;
        if(dp[i] == -1) {
            //
            continue;
        }
        else {
            if(dp[i-1] != -1) {
                dp[i]+=dp[i-1];
            }
            if(dp[i-2] != -1) {
                dp[i]+=dp[i-2];
            }
        }
        dp[i]%=N;
    }
    
    if(dp[n] == -1) {
        cout << 0 << endl;
    }
    else {
        cout << dp[n] % N << endl;
    }

    return 0;

}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector <int> vec(N);
	for (int i = 0; i < N; i++)
	{
		cin >> vec.at(i);
	}
	int A = 0, B = 0;
	 sort (vec.begin(), vec.end());
	 reverse(vec.begin(), vec.end());
	 for (int i = 0; i < N; i++)
	 {
		 if (i == 0 || (i % 2) == 0)
			 A += vec.at(i);
		 else if (i == 1 || (i % 2) == 1)
		 {
			 B += vec.at(i);
		 }
	 }
	 cout << A - B << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>
int main(){
  int n,x,m,s=1e9,r=0,i;
  scanf("%d%d",&n,&x);
  for(i=0;i<n;i++){
    scanf("%d",&m);
    if(s>m)s=m;
    r+=m;
  }
  printf("%d",n+(x-r)/s);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
using namespace std;
typedef pair<int,int>P;
typedef vector<P>VP;
typedef priority_queue<P,VP>PQ;
int  box[1000001];
int main(void){
	int n,q;
	int i;
	int x,y;
	PQ que;
	P pp;
	cin>>n>>q;
	for(i=1;i<=n;i++)	box[i]=0;
	for(i=0;i<q;i++){
		cin>>x>>y;
		box[x]+=y;
		que.push(MP(box[x],-1*x));
		while(1){
			pp=que.top();
			que.pop();
			if(pp.F==box[-1*pp.S])	break;
		}
		cout<<-1*pp.S<<" "<<pp.F<<endl;
		que.push(pp);
	}
	return 0;
}
		
		
		


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

int main() {
  int N, X;
  cin >> N >> X;
  int A[N];
  for(int i = 0; i < N; i++) cin >> A[i];
  int ans = 1;
  int sum = 0;
  for(int i = 0; i < N; i++) {
    sum += A[i];
    if (X >= sum) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
m, n = gets.split.map(&:to_i)
if m < 2
  gg = 0
elsif m == 2
  gg = 1
elsif m == 3
  gg = 3
else
  gg = m * (m - 1) / 2
end

if n < 2
  kk = 0
elsif n == 2
  kk = 1
elsif n == 3
  kk = 3
else
  kk = n * (n - 1) / 2
end
puts gg + kk


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll n,t[100005],ans;
int main(){
	cin>>n;
	rep(i,n)cin>>t[i];
	sort(t,t+n);
	int ok = 0;
	rep(i,n){
		if(i>0) t[i]+=t[i-1];
		if(i!=n-1 && t[i]*2 < t[i+1]){
			ok = i+1;
		}
	}
	cout<<n-ok<<endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var s string
	var a, z int
	fmt.Scan(&s)
	for i:=0; i<len(s); i++ {
		if s[i:i+1] == "A" {
			a = i
			break
		}
	}

	for i:=len(s)-1; i>-1; i-- {
		if s[i:i+1] == "Z" {
			z = i
			break
		}
	}

	fmt.Println(z-a+1)
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>

int main(){
	int N;
	scanf("%d", &N);
	char S[N + 1];
	scanf("%s", S);
	
	if (N % 2 ==1){
		puts("No");
	} else {
		int count = 0;
	for(int i = 0; i < strlen(S); i++){
		if (S[i] == S[i + strlen(S) / 2]){
			count++;
		} 
	}	if (count == strlen(S) / 2){
		puts("Yes");
	} else {
		puts("No");
	}
	}
		
	

	
	return 0;
}

Measured memory_bytes: 1588
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N; cin >> N;
    vector<int> As(N);
    map<int, LLONG> int2NumMap;
    for (int i = 0; i < N; ++i)
    {
        int Ai; cin >> Ai;
        As[i] = Ai;
        ++int2NumMap[Ai];
    }
    map<int, pair<LLONG, LLONG>> int2PairNumMap;
    LLONG maxPairNum  = 0LL;
    for (const auto &kvp : int2NumMap)
    {
        LLONG num = kvp.second;
        int2PairNumMap[kvp.first] = {
            num * (num - 1) / 2,
            max(0LL, (num - 1) * (num - 2) / 2)
        };
        maxPairNum += num * (num - 1) / 2;
    }
    for (int i = 0; i < N; ++i)
    {
        int Ai = As[i];
        auto kvp = int2PairNumMap[Ai];
        cout << maxPairNum - kvp.first + kvp.second << '\n';
    }
}


Measured memory_bytes: 18176
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end(), greater<int>());
	long long int Alice = 0, Bob = 0;
 	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			Alice += A.at(i);
		}
		else {
			Bob += A.at(i);
		}
	}
	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n,m,x; cin >>n >>m >>x;
      vector<int> b(n+1);
      for (int i=0; i<m; i++){
        int buf; cin >>buf;
        b.at(buf) = 1;
      }
      
      int cost1=0, cost2=0;
      for (int i=0; i<=n; i++){
        if (i<=x) cost1 += b.at(i);
        else cost2 += b.at(i);
      }
      cout <<min(cost1,cost2) <<endl;
    }


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

int fac(int k) {
	int sum = 1;
	for (int i = 1; i <= k; i++) {
		sum *= i;
	}
	return sum;
}

int main(void) {
	int n; cin >> n;
	vector<int> P(n), Q(n);
	rep(i, n) cin >> P[i];
	rep(i, n) cin >> Q[i];

	int a = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (P[i] != 1) {
			a += (P[i] - 1) * fac(n - i - 1);
		}
		if (Q[i] != 1) {
			b += (Q[i] - 1) * fac(n - i - 1);
		}
		for (int j = i + 1; j < n; j++) {
			if (P[i] < P[j]) {
				P[j]--;
			}
			if (Q[i] < Q[j]) {
				Q[j]--;
			}
		}
	}

	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set;
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef vector<string> VS;
typedef pair<int, int> PII;

void output (int* v1, int* v2) {
   if (v1[0] - v2[0] > 0) {
    cout << "10 " << v1[0] - v2[0] << endl; 
   }
   if (v1[1] - v2[1] > 0) {
    cout << "50 " << v1[1] - v2[1] << endl; 
   }
   if (v1[2] - v2[2] > 0) {
    cout << "100 " << v1[2] - v2[2] << endl; 
   }
   if (v1[3] - v2[3] > 0) {
    cout << "500 " << v1[3] - v2[3] << endl; 
   }
   return;
}

int main(void) {
    int money;
    int sum;
    int notpay;
    cin >> money;
    int have[4];
    int notpay_num[4];
    int cost[4] = {1, 5, 10, 50};
    while (1) {
        money /= 10;
        for (int i = 0; i < 4; i++) {
            cin >> have[i];
        }
        sum = have[0] + 5 * have[1] + 10 * have[2] + 50 * have[3];
        notpay = sum - money;
        //cout << sum << " " << notpay << endl;
        for (int i = 3; i >= 0; i--) {
        //cout << "NOTPAY = " << notpay << endl;
           notpay_num[i] = notpay / cost[i];
           //cout << notpay_num[i] << endl;
           notpay -= cost[i] * notpay_num[i];
        }
        //cout << "HERE" << endl;
        output(have, notpay_num);

        cin >> money;
        if (money == 0) {
            break;
        }
        cout << endl;
    }
    return 0;
}

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

int main(){
    int N;cin>>N;
    int X[N];
    int ans[N];
    for(int i=0;i<N;i++){
        cin>>X[i];
        ans[i]=X[i];
    }
    sort(ans,ans+N);
    for(int i=0;i<N;i++){
        if(X[i]<ans[N/2])cout<<ans[N/2]<<endl;
        else cout<<ans[N/2-1]<<endl;
    }
}

Measured memory_bytes: 3712
fn main() {
    proconio::input! {
        n: usize,
        k: u64,
        a: [u64;n],
    }
    let mut l=0;
    let mut r=*a.iter().max().unwrap();
    while l+1<r {
        let m=(l+r)/2;
        let mut c=0;
        for &a in &a {
            c+=(a-1)/m;
        }
        if c>k {
            l=m;
        }
        else {
            r=m;
        }
    }
    println!("{}",r);
}

Measured memory_bytes: 5408
#include<stdio.h>
#include<math.h>

int main () {
   int n,i,j, count,sq;
   int a[10000] = {0};


   scanf("%d", &n);

   for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
   }


   count = n;

   for (i = 0; i < n; i++) {
      if (a[i] == 2) {
      } else if (a[i] % 2 == 0) {
         count--;
      } else {

         sq = sqrt(a[i]);

         for (j = 3; j <= sq; j = j + 2) {
            if (a[i] % j == 0) {
               count--;
               break;
            }
         }
      }
   }
 
   printf("%d\n", count);

   return 0;

}

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

//#include "atcoder.hpp"

long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    int k,  abcde[5];
    
    cin >> abcde[0] >> abcde[1] >> abcde[2] >> abcde[3] >> abcde[4];
    int least = 10, sum10 = 0;

    for (int i : abcde) {
        sum10 += (int)ceil((double)i / 10.0);
        if (i %10) least = min(least, i % 10);
    };
    
    sum10 *= 10;
    if (least != 10) sum10 = sum10 - 10 + least;
    
    cout << sum10 << endl;

    return 0;
}



Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 4003
#define mod 1000000007
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) cout<<"Case #"<<i<<": "
#define pf(a) printf("%lld\n",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define pfff(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pffff(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb;
ll n,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,maxi;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
vector<ll>power;
int main()
{
    vector<char>vc;
    string s,t;
    cin>>n>>s;
    FOR(i,n/2)
    {
        t+=s[i];
    }
    t+=t;
    if(t!=s or n%2==1) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}
/*
5
4
3
2
3
4
4
3
3
4
2
3
*/


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

int main(){
  int N;
  cin >> N;
  for(int i=0; i<9; i++){
    for(int j=0; j<9; j++){
      if((i+1)*(j+1) == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

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

    int ans = 0;
    for (int i=1; i<n; i++){
        if (a[i]-a[i-1]>=0) continue;
        else{
            ans += abs(a[i]-a[i-1]);
            a[i] = a[i-1];
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 5220
a = input("").split(" ")
a = [int(aa) for aa in a]
b = input("").split(" ")
b = [int(ab) for ab in b]
c = input("").split(" ")
c = [int(ac) for ac in c]
n = int(input(""))
hav = a + b + c
val = []
for d in range(n):
    temp = int(input(""))
    val.append(temp)
tf = [0,0,0,0,0,0,0,0,0]
i = 0
for e in hav:
    if (e in val) == True:
        tf[i] = 1
    i += 1
tr = [1,1,1]
if tf[0:3] == tr:
    print("Yes")
elif tf[3:6] == tr:
    print("Yes")
elif tf[6:9] == tr:
    print("Yes")
elif (tf[0]+tf[3]+tf[6]) == 3:
    print("Yes")
elif (tf[1]+tf[4]+tf[7]) == 3:
    print("Yes")
elif (tf[2]+tf[5]+tf[8]) == 3:
    print("Yes")
elif (tf[0]+tf[4]+tf[8]) == 3:
    print("Yes")
elif (tf[2]+tf[4]+tf[6]) == 3:
    print("Yes")
else:
    print("No") 

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

int main() {
  int N; cin >> N;
  double sum = 0;
  rep(i, N) {
    double A; cin >> A;
    sum += 1 / A;
  }
  cout << setprecision(10) << 1 / sum << endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		int n = 0;
		String s = null;
		int result = 0;
		try {
			sc = new Scanner(System.in);
			while (sc.hasNextBigDecimal()) {

				BigDecimal a = sc.nextBigDecimal();
				BigDecimal b = sc.nextBigDecimal();
				n = sc.nextInt();

				s = String.valueOf(a.divide(b, n, RoundingMode.DOWN));
				String[] str = s.substring(s.indexOf(".") + 1,s.indexOf(".") + ( 1+ n)).split("(?<=.)");

				for (String sum : str) {

					result += Integer.parseInt(sum);

				}

				System.out.println(result);
				result = 0;

			}

		} finally {
			sc.close();
		}

	}

}

Measured memory_bytes: 20676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int cl[200010];
vector<int> s[31],t[31];
int main(){
    int n,c,si,ti,ci;
    cin>>n>>c;
    rep(i,n){
        cin>>si>>ti>>ci;
        --ci;
        s[ci].pb(2*(si));
        t[ci].pb(2*(ti+1));
    }
    rep(i,c){
        sort(s[i].begin(),s[i].end());
        sort(t[i].begin(),t[i].end());
    }
    rep(i,c){
        if(!s[i].empty()) ++cl[s[i][0]];
        FOR(j,1,s[i].size()){
            if(s[i][j]>t[i][j-1]){
                ++cl[s[i][j]];
                --cl[t[i][j-1]];
            }
        }
        if(!t[i].empty()) --cl[t[i][t[i].size()-1]];
    }
    int cnt=0,mx=0;
    rep(i,200003){
        cnt+=cl[i];
        mx=max(cnt,mx);
    }
    cout<<mx<<endl;
    return 0;
}

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

#define PI 3.14159265358979323846264338327950L

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    unordered_set<int> sets;
    for (int i = 1; i <= k; i++) {
        int number;
        cin >> number;
        for (int j = 0; j < number; j++) {
            int comparison;
            cin >> comparison;
            if (sets.find(comparison) == sets.end()) {
                sets.insert(comparison);
            }
        }
    }

    cout << n - sets.size() << "\n";

}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n)cin >> a[i] >> b[i] >> c[i];
    int INF = 1001001;
    vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(401, vector<int>(401, INF)));
    rep(i, n + 1)dp[i][0][0] = 0;
    rep(i, n)rep(j, 401)rep(k, 401){
        if(j >= a[i] && k >= b[i]){
            dp[i+1][j][k] = min(dp[i][j][k], dp[i][j-a[i]][k-b[i]] + c[i]);
        }else dp[i+1][j][k] = dp[i][j][k];
    }
    int ans = INF;
    rep(i, 401)rep(j, 401){
        if(i * j == 0)continue;
        if(j * ma == i * mb)ans = min(ans, dp[n][i][j]);
    }
    cout << ((ans == INF) ? -1 : ans) << endl;
}

Measured memory_bytes: 27264
package main

import "fmt"

func main() {
	c := make([][]int, 3)
	for i := range c {
		c[i] = make([]int, 3)
		for j := range c[i] {
			fmt.Scan(&c[i][j])
		}
	}

	a := make([]int, 3)

	for i := 0; i <= 100; i++ {
		a[0] = i
		for j := 0; j <= 100; j++ {
			a[1] = j
			for k := 0; k <= 100; k++ {
				a[2] = k
				b00 := c[0][0] - a[0]
				b01 := c[0][1] - a[0]
				b02 := c[0][2] - a[0]
				b10 := c[1][0] - a[1]
				b11 := c[1][1] - a[1]
				b12 := c[1][2] - a[1]
				b20 := c[2][0] - a[2]
				b21 := c[2][1] - a[2]
				b22 := c[2][2] - a[2]
				if b00 == b10 && b00 == b20 && b10 == b20 {
					if b01 == b11 && b01 == b21 && b11 == b21 {
						if b02 == b12 && b02 == b22 && b12 == b22 {
							fmt.Println("Yes")
							return
						}
					}
				}
			}
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 512
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	int n;
	cin>>n;
	fo(i,n+1)
	{
		if((int)(i*1.08)==n)
		{
			cout<<i<<'\n';
			return 0;
		}
	}
	cout<<":(\n";
	printclock;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define lb lower_bound
using namespace std;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int h,w;
	cin>>h>>w;
	if(h == 1 || w == 1){
		cout<<1;
		return 0;
	}
	int ans = (h*w + (int)1)/(int)2;
	cout<<ans;
}

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

using namespace std;
typedef long long ll;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

char buffer[111];

int main () {
    int i, j;
    const int n = getint(), l = getint();
    vector<string> strings;
    for (i = 0; i < n; ++i) {
        getstr(buffer);
        strings.emplace_back(buffer);
    }
    sort(begin(strings), end(strings));
    for (const auto& s: strings) cout << s;
    puts("");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

void solve() {
    ll a, b;
    cin >> a >> b;
    cout << a*b - a - b + 1 << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 256
import numpy as np

class Node:
    def __init__(self, id):
        self.id = id
        self.nexts = []
        self.visited = False

    def add_next(self, node):
        self.nexts.append(node)

def saiki(node, count, judge):
    node.visited = True
    judge[node.id] = True
    if(all(judge)):
        count[0]+=1

    for next in node.nexts:
        if(not next.visited):
            saiki(next, count, judge)
    node.visited = False
    judge[node.id] = False

if __name__=="__main__":
    inputs = lambda : input().replace("\n", "").split(" ")
    N, M = [int(number) for number in inputs()]

    nodes = [Node(i) for i in range(N)]
    for i in range(M):
        x, y = [int(number)-1 for number in inputs()]
        nodes[x].add_next(nodes[y])
        nodes[y].add_next(nodes[x])

    judge = [False]*N
    count = [0]
    saiki(nodes[0], count , judge)
    print(count[0])


Measured memory_bytes: 18160
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i,n;
    n=s.length()-1;
    if(s[n]=='2'||s[n]=='4'||s[n]=='5'||s[n]=='7'||s[n]=='9')
        cout<<"hon";
    else if(s[n]=='0'||s[n]=='1'||s[n]=='6'||s[n]=='8')
        cout<<"pon";
    else
        cout<<"bon";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[3001][3001];

ll solve(int i,int j,vector<ll> &v,int turn)
{
    if(i>j)
    {
        return 0;
    }
    if(dp[i][j]!=-1)
    {
        return dp[i][j];
    }
    if(turn)
    {
        return dp[i][j]=max(v.at(i)+solve(i+1,j,v,0),v.at(j)+solve(i,j-1,v,0));
    }
    else
    {
        return dp[i][j]=min(solve(i+1,j,v,1),solve(i,j-1,v,1));
    }
}

int main()
{
    int n;
    cin>>n;
    vector<ll> v(n+1);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        cin>>v.at(i);
        sum+=v.at(i);
    }
    memset(dp,-1,sizeof(dp));
    ll score_x=solve(1,n,v,1);
    // this solve function will return the optimal value of x when vector from 1 to n is traversed and
    // the game is started by the first player......
    ll score_y=sum-score_x;
    cout<<(score_x-score_y);

    return 0;
}

Measured memory_bytes: 70784
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int[] items = new int[n];
		for(int i=0; i<n; i++){
			items[i] = sc.nextInt();
			ans += items[i];
		}
		
		int max = 0;
		for(int i=0; i<n; i++){
			if(items[i] > max){
				max = items[i];
			}
		}
		
		ans -= max / 2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll 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; }




void solve(){
    ll h,a;
    cin>>h>>a;
    cout<<h/a+(h%a!=0)<<endl;

}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    
     

    solve(); 


    return 0;
}


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

int main() {
  int N;
  int A[100005], B[100005];
  int cnt[200001] = {};

  int sum = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    sum += A;
    if (sum >= 86400) sum %= 86400;
    cnt[sum]++;
    sum += B;
    if (sum >= 86400) sum %= 86400;
  }
  for (int i = 86400; i < 200001; i++) {
    cnt[i] = cnt[i-86400];
  }
  int maxv = 0;
  int now = 0;
  for (int i = 0; i < 10801; i++) {
    maxv += cnt[i];
  }
  now = maxv;
  for (int i = 10801; i < 200001; i++) {
    now -= cnt[i-10801];
    now += cnt[i];
    maxv = max(maxv, now);
  }
  cout << maxv << endl;
  return (0);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  vector<vector<lint>> dp((1 << n), vector<lint> (51, INF));
  dp[0][0] = 0LL;
  
  for(int bit = 0; bit < (1 << n); bit++) {
    for(int v = 0; v <= 50; v++) {
      if(dp[bit][v] == INF) continue;
      
      lint cost = 0;
      int i = __builtin_popcount(bit);
      for(int j = 0; j < n; j++) {
        if(bit & (1 << j)) continue;
        lint val = a[j];
        if((int)abs(i - j) % 2 == 1) val = b[j];
        if(val >= v) {
          dp[bit | (1 << j)][val] = min(dp[bit | (1 << j)][val], dp[bit][v] + cost);
        }
        cost++;
      }
    }
  }

  lint ans = INF;
  for(int j = 0; j < 51; j++) ans = min(ans, dp[(1 << n) - 1][j]);
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 112896
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n;
ll p[300000];
ll q[300000];
int main(){
	cin >> n;
	REP(i,n) {
		cin >> p[i];
		p[i]--;
	}
	REP(i,n) {
		q[p[i]] = i;
	}


	ll l = 0,r = 0;

	ll maxi = 0;

	while(l < n) {
		maxi = max(maxi,r - l + 1);
		if(r + 1 < n && q[r] < q[r + 1]) {
			r++;
		}else {
			l = r + 1;
			r++;
		}
	}

	cout << n - maxi << endl;
	return 0;
}


Measured memory_bytes: 3840
#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>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int d[n];
    rep(i,n){
        cin>>d[i];
    }
    int ans=0;
    rep(i,n){
        for(int j=i;j<n;j++){
            ans=ans+d[i]*d[j];
        }
    }
    rep(i,n){
        ans=ans-d[i]*d[i];
    }
    cout<<ans<<endl;

    return 0;
}

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

int main() {
  int k,s;
  cin>>k>>s;
  int ans = 0;
  rep(i,k+1) rep(j,k+1){
    if(i+j<=s && s-k<=i+j) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
// AtCoder140150b.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>


using namespace std;


void func140b (){
	int n, a[20], b[20], c[20];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++)cin >> b[i];
	c[0] = 0;
	for (int i = 1; i < n; i++)cin >> c[i];

	int sum = b[a[0]-1];
	for (int i = 1; i < n; i++) {
		sum += b[a[i]-1];
		if (a[i] - a[i - 1] == 1)sum += c[a[i]-1];
	}
	cout << sum;
}



int main()
{
	func140b();
	return 0;	
}



Measured memory_bytes: 256
N,K,C=map(int,input().split())
S=input()

def check0(S0):
    count=0
    index=0
    out=[0]*K
    while count<K and index<N:
        if S0[index]=='o':
            out[count]=index
            count+=1
            index+=(C+1)
        else:
            index+=1
    if count==K:
        return 1,out
    return 0,out

def checkend(S0):
    count=0
    index=N-1
    out=[0]*K
    while count<K and index>=0:
        if S0[index]=='o':
            out[K-1-count]=index
            count+=1
            index-=(C+1)
        else:
            index-=1
    if count==K:
        return 1,out
    return 0,out



flag0,out0=check0(S)
flagend,outend=checkend(S)
if flag0==1:
    for i in range(K):
        if out0[i]==outend[i]:
            print(out0[i]+1)

Measured memory_bytes: 20572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int D;
  cin >> D;
  vector<int64_t> down(26);
  for(int i=0; i<26; i++){
    cin >> down[i];
  }
  vector<vector<int64_t>> contest(D,vector<int64_t>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> contest[i][j];
    }
  }
  
  vector<int64_t> last(26,-1);
  
  int64_t ans = 0;
  
  for(int i=0; i<D; i++){
    int c;
    cin >> c;
    c--;
    for(int j=0; j<26; j++){
      if(j == c){
        ans += contest[i][j];
        last[c] = i;
      }
      else{
        ans -= down[j]*(i - last[j]);
      }
    }
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{int m,d,i=2,j=2,count=0;
 cin>>m>>d;
 while(i*10+j<=d)
 {
   if(i*10+j<=d && i*j<=m &&i>=2 &&j<=9)
   {
     //cout<<i*10+j<<" ";
     count++;j++;
   }
   else
   {
     i++;j=2;
   }
 }
 //cout<<endl;
 cout<<count<<endl;
  return 0;
}
//2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2

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);
  //a
  string s;
  cin >> s;
  int ans = 0;
  int c = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') c++;
    else c = 0;
    ans = max(ans, c);
  }
  ans = max(ans, c);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3648
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ');
  buildMaxHeap(arr);
  console.log(' ' + arr.join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    if (left < n && Number(arr[left]) > Number(arr[largest])) largest = left;
    if (right < n && Number(arr[right]) > Number(arr[largest])) largest = right;
    if (largest != i) {
        arr[largest] = arr[i] + (arr[i] = arr[largest], "");
      maxHeapify(largest);
    }
  };
  for (let i = Math.floor(n / 2 - 1); i >= 0; i--) maxHeapify(i);
}



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

int main()
{
  int64_t n, d, a, ans = 0;
  cin >> n >> d >> a;
  vector<pair<int64_t, int64_t>> xh(n);
  for (int i = 0; i < n; i++)
  {
    cin >> xh[i].first >> xh[i].second;
  }
  sort(xh.begin(), xh.end());
  int64_t add = 0;
  queue<pair<int64_t, int64_t>> Q;
  for (int i = 0; i < n; i++)
  {
    int64_t x, h;
    tie(x, h) = xh.at(i);
    if (Q.size())
    {
      while (Q.size() && Q.front().first < x)
      {
        add -= Q.front().second;
        Q.pop();
      }
    }
    h -= add;
    if (h <= 0)
    {
      continue;
    }
    int64_t cnt = (h + a - 1) / a;
    ans += cnt;
    add += a * cnt;
    Q.emplace(x + 2 * d, a * cnt);
  }
  cout << ans << endl;
}

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, M;
int A[110000], B[110000];
vint G[110000];
bool visited[110000], color[110000];
bool dfs(int idx, bool c) {
    if (visited[idx]) { return color[idx] == c; }
    visited[idx] = true;
    color[idx] = c;
    bool ret = true;
    rep(i, G[idx].size()) { ret &= dfs(G[idx][i], !c); }
    return ret;
}
signed main() {
    cin >> N >> M;
    rep(i, M) {
        cin >> A[i] >> B[i];
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    if (dfs(1, 0)) {
        int h = 0;
        reps(i, N) { h += color[i]; }
        cout << h * (N - h) - M << endl;
    } else { cout << N * (N - 1) / 2 - M << endl; }

}

Measured memory_bytes: 9344