akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		int v = 1000 - n;
		int ret = 0;
		int c[] = {500,100,50,10,5,1};
		for(int i=0;i<6;i++){
			ret += v / c[i];
			v -= (v/c[i])*c[i];
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#include <set>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 5e18+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll n, k; cin >> n >> k;
  vector<int> p(n); rep (i, n) { cin >> p[i]; p[i]--; }
  vector<int> c(n); rep (i, n) cin >> c[i];



  vector<vector<int>> cycles(n, vector<int>());
  vector<ll> scores(n);
  for (int i = 0; i < n; i++) {
    vector<bool> seen(n+1);
    int curr = i;
    while (true) {
      if (seen[curr]) break;
      seen[curr] = true;
      cycles[i].push_back(curr);
      scores[i] += c[curr];
      curr = p[curr];
    }
  }


  ll ans = -inf;
  for (int i = 0; i < n; i++) {

    int next = p[i];
    for (auto cyc_count : {0LL, k / (ll)cycles[next].size() - 1, k / (ll)cycles[next].size()}) {
      if (cyc_count < 0) continue;
      ll curr_score = 0;
      curr_score += cyc_count * scores[next];
      if (cyc_count != 0) ans = max(ans, curr_score);
      int curr = next;
      if (cyc_count != 0) ans = max(ans, curr_score);
      int last_block = cyc_count == k / (ll)cycles[next].size() ? k % cycles[next].size() : cycles[next].size();
      for (int j = 0; j < last_block && j < k; j++) {
        curr_score += c[curr];
        curr = p[curr];
        ans = max(ans, curr_score);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 120948
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func joinInts(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func divUp(x, y int64) int64 {
	return (x + y - 1) / y
}

func main() {
	solve()
	writer.Flush()
}

func solve() {
	N := nextInt()
	T, A := make([]int64, N), make([]int64, N)
	for i := 0; i < int(N); i++ {
		T[i], A[i] = nextInt(), nextInt()
	}
	t, a := T[0], A[0]
	for i := 1; i < int(N); i++ {
		r := max(divUp(t, T[i]), divUp(a, A[i]))
		t, a = T[i]*r, A[i]*r
	}
	out(t + a)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi   = vec<int>;
using vvi  = vec<vi>;
using vvvi = vec<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n; cin>>n;
  vi a(n);
  int amax = 0;
  rep(i,n) { cin>>a[i]; if(amax<a[i]) amax = a[i]; }
  sort(all(a));
  dump(a, amax);
  vector<bool> dp(amax+1, false);

  unordered_map<int,int> count;
  rep(i,n){
    count[a[i]]++;
    int k = a[i];
    if(dp[k]) continue;
    int j = 2;
    while(j*k<=amax){
      dp[j*k] = true;
      j++;
    }
  }

  int ans = 0;
  rep(i,n){
    if(count[a[i]]>1) continue;
    if(dp[a[i]]==false) ans++;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 12140
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

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

  int all = 0;
  vector<int> v(n);
  forn(i,n){
    cin >> v[i];
    all ^= v[i];
  }

  forn(i,n) cout << (v[i] ^ all) << " \n"[i==n-1];
}


Measured memory_bytes: 3948
while True:
    try:
        a, b, c, d, e, f = map(int, input().split())
        tb, tc = d*b, d*c
        te, tf = a*e, a*f
        y = (tc-tf)/(tb-te)
        x = (c-(y*b))/a
        print("{0:.3f} {1:.3f}".format(x, y))

    except:
        break

Measured memory_bytes: 7568
A, B, C = map(int, input().split())
K = int(input())
cnt = 0

while cnt <= K + 1:
  if B <= A:
    B *= 2
    cnt += 1
  elif C <= B:
    C *= 2
    cnt += 1
  else:
    break

if cnt <= K:
  print("Yes")
else:
  print("No")

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

using namespace std;

typedef long long ll;

int main()
{
  int n = 0;
  scanf("%d", &n);
  vector<pair<int, int> > a;
  for (int i = 0; i < n; ++i) {
    int val = 0;
    scanf("%d", &val);
    // (value, index)
    a.push_back(make_pair(val, i));
  }

  sort(a.begin(), a.end());
  int center = n / 2;
  int left = a[center].first, right = a[center - 1].first;
  vector<pair<int, int> > b(n);
  for (int i = 0; i < n; ++i) {
    int ix = a[i].second;
    int median = (i < center) ? left : right;
    // (original-index, median)
    b[i] = make_pair(ix, median);
  }

  sort(b.begin(), b.end());
  for (int i = 0; i < n; ++i) {
    printf("%d\n", b[i].second);
  }
  return 0;
}


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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int n;
    while (n = in()){
        vector<pair<double, int> > bank;
        int y = in();
        rep(i, n){
            int b, r, t;
            double per;
            b = in();
            r = in();
            t = in();
            if (t == 1){
                per = 1 + y * (r / 100.);
            }
            else {
                per = pow(1 + (r / 100.), y);
            }
            bank.push_back(make_pair(per, b));
        }
        sort(bank.begin(), bank.end(), greater<pair<double, int> >());
        printf("%d\n", bank[0].second);
    }
    return (0);
}

Measured memory_bytes: 1196
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <string.h>
#include <algorithm>
#define ll long long int
#define test_case int t,i;cin>>t;for(i=0;i<t;i++)
using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if ((a+b)%2==0)
        cout<<(a+b)/2<<"\n";
    else
        cout<<"IMPOSSIBLE\n";
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define ll long long
#define pii pair<int,int>
#define pll pair<long,long> 
#define xmod 1000000007
#define pi 3.14159265358
using namespace std;

char s[105];
int y,m,d;
int main(){
	scanf("%s",s);
	m=(s[5]-48)*10+(s[6]-48);
	d=(s[8]-48)*10+(s[9]-48);
	
	if (m <= 4 || (m == 4 && d <= 30))
	printf("Heisei\n");
	else
	printf("TBD\n");
	return 0;
}
//kikkik kik kik

Measured memory_bytes: 256
num, sel = map(int, input().split(" "))
a = sorted(list((int)(input()) for i in range(num)))
mini = 10 ** 9
for i in range(num - sel + 1):
  if mini > a[i + sel - 1] - a[i]:
    mini = a[i + sel - 1] - a[i]
print(mini)

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

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

using namespace std;
using lint=long long;

template<class T>
class Fenwick_tree{
	vector<T> a;
public:
	Fenwick_tree(int n):a(n){}
	void add(int i,T val){
		for(;i<a.size();i|=i+1) a[i]+=val;
	}
	T sum(int l,int r){
		if(l==0){
			T res{};
			for(r--;r>=0;r=(r&(r+1))-1) res+=a[r];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
};

int n,a[100000];

// number of pairs (l, r) such that median of a[l..r) >= x
lint solve(int x){
	lint res=0;
	int sum=0;
	Fenwick_tree<int> F(2*n+1);
	F.add(n,1);
	rep(i,n){
		sum+=(a[i]>=x?1:-1);
		res+=F.sum(0,n+sum+1);
		F.add(n+sum,1);
	}
	return res;
}

int main(){
	scanf("%d",&n);
	rep(i,n) scanf("%d",a+i);

	lint m=n*(n+1LL)/2;

	int lo=0,hi=1e9+1;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		if((m+1)/2<=solve(mi)) lo=mi;
		else                   hi=mi;
	}
	printf("%d\n",lo);

	return 0;
}


Measured memory_bytes: 1420
S = input()
count = 0
val = 0

if len(S) % 2 == 0:
    val = len(S)/2
else:
    val = (len(S)-1)/2

for i in range(len(S)):
    if S[i] != S[-i-1]:
        count += 1
    if i+1 == val:
        break

print(count)


Measured memory_bytes: 2940
n,i,j,u,v=1,a[2][3];long dp[25000005];solve(){for(i=n;~i;--i)dp[i]=i;for(i=1;i<=n;++i)for(j=0;j<3;++j)if(a[v][j]>a[u][j]&&i>=a[u][j])dp[i]=fmax(dp[i],dp[i-a[u][j]]+a[v][j]);}main(){for(i=scanf("%d",&n)&0;i<2;i++)for(j=0;j<3;j++)scanf("%d",a[i]+j);solve(),n=dp[n],u=1,v=0,solve();printf("%lld\n",dp[n]);}

Measured memory_bytes: 195456
#include <iostream>
#include <vector>
 
int main(){
	const int max_number = 20;
	const int min_number = 0;
	int N;
	
	while(std::cin >> N){
		//dp[N][max_number + 1]
		//dp[n][i]ならば、n個目の数字まで計算してその計算結果がiとなったものの数
		std::vector<std::vector<unsigned long long> > dp(N, std::vector<unsigned long long>(max_number + 1, 0));
		
		//入力した数字N個分を格納するベクター
		std::vector<int> num(N);
		
		for(int i = 0 ; i < N ; ++i){
			std::cin >> num[i];
		}
		dp[0][num[0]] = 1;
		
		for(int i = 1 ; i < N - 1 ; ++i){
			for(int j = 0 ; j <= max_number ; ++j){
				//i-1個目まで計算してその計算結果がjとなるものの組み合わせが１つ以上あれば実行
				if(dp[i - 1][j] > 0){
					/*jにi個目の数字を足し引きして、
					  範囲におさまっていればそれまでの組み合わせの数を引き継ぐ*/
					if(j + num[i] <= max_number){
						dp[i][j + num[i]] += dp[i - 1][j];
					}
					if(j - num[i] >= min_number){
						dp[i][j - num[i]] += dp[i - 1][j];
					}
				}
			}
		}
		std::cout << dp[N - 2][num[N - 1]] << std::endl;
	}
	
    return 0;
}

Measured memory_bytes: 1228
using System;

class Test{
 
  public static void Main(){
    
    var str = Console.ReadLine().Split(' ');
    int N = int.Parse(str[0]);
    int M = int.Parse(str[1]);
    Console.WriteLine(((N+M) * (N+M-1))/2 -(N*M));
  }
}

Measured memory_bytes: 13140
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
      
         int x =  Math.abs((c-a)+(b-c));
         int y =  Math.abs((b-c)+(a-b));
         int z =  Math.abs((a-b)+(c-a));
         
         int d =  Math.max(x,y);
         int e =  Math.max(d,z);
      
         System.out.println(e);
        
    }
}

Measured memory_bytes: 22996
#include <iostream>

using namespace std;

void solve(int h, int m, int s, int _h, int _m, int _s) {
    int total_time_s = _h * 3600 + _m * 60 + _s - h * 3600 - m * 60 - s;
    int time_h = total_time_s / 3600;
    int time_m = total_time_s % 3600 / 60;
    int time_s = total_time_s % 60;
    cout << time_h << ' ' << time_m << ' ' << time_s << endl;
}

int main() {
    for (int i = 0; i < 3; i++) {
        int h, m, s;
        int _h, _m, _s;
        cin >> h >> m >> s >> _h >> _m >> _s;
        solve(h, m, s, _h, _m, _s);
    }
    return 0;
}

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

ll lpow(ll x, ll y, ll m){
  ll r = 1;
  x %= m;
  while (y) {
    if (y & 1) r = (r * x) % m;
    x = (x * x) % m;
    y >>= 1;
  }
  return r;
}

void fast_io() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
}

int main() {
  fast_io();

  ll n;
  cin >> n;
  ll mod = 1e9 + 7;
  ll ans = lpow(10, n, mod) - 2 * lpow(9, n, mod) + lpow(8, n, mod);
  ans %= mod;
  cout << (ans + mod) % mod << '\n';
}


Measured memory_bytes: 3636
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int a,b,c;cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c;
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	int H, W, h, w, ans;
	cin >> H >> W >> h >> w;
	ans = H*W - (h*W+w*H-h*w);
	cout << ans <<endl;
	return 0;
}

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

struct Info {
    int to, distance;
    Info(int a, int b)
    :to(a),
    distance(b)
    {};
};

struct X {
    long long pos = -1;
    std::vector<Info> info;
};

X *x;
bool *done;

bool consistent();
bool dfs(const int);

int main()
{
    if (consistent())
        printf("Yes\n");
    else
        printf("No\n");
    delete[] x;
    delete[] done;
    return 0;
}

bool consistent() {
    int n, m;
    scanf("%d%d", &n, &m);
    x = new X[n];
    done = new bool[n];
    std::fill(done, done + n, false);
    for (int i = 0; i < m; i++)
    {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        l--; r--;
        x[l].info.push_back(Info(r, d));
        x[r].info.push_back(Info(l, -d));
    }
    for (int i = 0; i < n; i++)
    {
        if (!dfs(i)) return false;
    }

    return true;
}

bool dfs(const int here)
{
    if (done[here]) return true;
    done[here] = true;
    if (x[here].pos == -1) x[here].pos = 1000000000;
    for (auto& e : x[here].info)
    {
        const int next_pos = x[here].pos + e.distance;
        if (x[e.to].pos == -1 || x[e.to].pos == next_pos)
        {
            x[e.to].pos = next_pos;
            if (!dfs(e.to)) return false;
        }
        else
        {
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 12416
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,K;
vector<ll> A;
void input(){
    fast_io();
    cin >> N >> K;
    A = fetch_vec<ll>(N);
}

bool C(ll x){
    ll cnt = 0;
    for (int i = 0; i < N; i++)
    {
        cnt += A[i]/x;
        if(A[i]%x==0) cnt--;
    }
    return (cnt<=K);    
}

int solve(){
    ll ng = 0;
    ll ok = 1e9;
    while(ok-ng>1){
        ll mid = (ok+ng)/2;
        if(C(mid)) ok=mid;
        else ng=mid;
    }
    cout << ok << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 4768
package main

import ( "fmt" ; "sort" )

func main() {
  x := []int { 0,0,0 }

  fmt.Scanf("%d %d %d", &x[0], &x[1], &x[2])

  sort.Slice(x, func(i, j int) bool { return x[i] < x[j] })

  fmt.Printf("%d %d %d\n", x[0], x[1], x[2])
}




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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

template <typename _Ty>
class BIT {
private:
    size_t m_n;
    std::vector<_Ty> m_vec;

public:
    BIT(size_t num) : m_n(num), m_vec(m_n + 1) {}

    // i 番目の要素に a を足す
    void add(size_t i, const _Ty& a) {
        for (++i; i <= m_n; i += i & (-i)) {
            m_vec[i] += a;
        }
    }

    // 区間[0, i)の総和を求める
    _Ty sum(size_t i) const {
        _Ty res = 0;
        for (++i; i >= 1; i -= i & (-i)) {
            res += m_vec[i];
        }
        return res;
    }

    // 区間[i, j)の総和を求める
    _Ty sum(size_t i, size_t j) const {
        return sum(j) - sum(i);
    }

    size_t size() const noexcept {
        return m_n;
    }

    void assign(const _Ty& a) {
        std::fill(m_vec.begin(), m_vec.end(), a);
    }
};

ll N, M;

bool check(int x, const Vl& a) {
    static Vl S(N + 1);
    static BIT<ll> bit(N * 2 + 1);

    S.assign(N + 1, 0);
    bit.assign(0);

    for (int i = 0; i < N; ++i) {
        S[i + 1] = S[i] + ((a[i] >= x) ? 1 : -1);
    }

    ll cnt = 0;
    for (int j = 0; j <= N; ++j) {
        cnt += bit.sum(S[j] + N);
        bit.add(S[j] + N, 1);
    }

    if (cnt >= (M + 1) / 2) {
        return true;
    }
    else {
        return false;
    }
}

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

    cin >> N;

    M = N * (N - 1) / 2 + N;

    Vl a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int left = 1, right = 1000000001;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (check(mid, a)) {
            left = mid;
        }
        else {
            right = mid;
        }
    }

    cout << left << endl;

    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

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

	int x, y;
	cin >> x >> y;
	for(int i = 0; i <= x; i++) {
		if(2 * i + (x - i) * 4 == y) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 3644
n, k = map(int, input().split())

from math import factorial
def div(v, c):
  return factorial(v)//(factorial(max(0, v-c))*factorial(c))

for i in range(1, k+1):
  print(int(div(n-k+1, i)*div(k-1, i-1))%(10**9+7))

Measured memory_bytes: 9308
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define SZ(a) a.size()
#define ll long long
#define ull unsigned long long
using namespace std;

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


	if (N % 2 == 0) {
		cout << N << endl;
	}
	else {
		cout << N * 2 << endl;
	}

	system("pause");
	return 0;
}

Measured memory_bytes: 504
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    String s;
    int k;

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

    void run() {
        FastReader sc = new FastReader();
        s = sc.next();
        k = sc.nextInt();
        solve();
    }

    void solve() {
        PriorityQueue<String> pQueue = new PriorityQueue<>();
        SortedSet<String> set = new TreeSet<>();
        char[] cs = s.toCharArray();
        SortedSet<Character> setC = new TreeSet<>();
        for (int i = 0; i < cs.length; i++) {
            setC.add(cs[i]);
        }
        for (char c : setC) {
            for (int i = 0; i < s.length(); i++) {
                if (cs[i] != c) {
                    continue;
                }
                for (int j = 1; j <= k; j++) {
                    if (i + j <= s.length()) {
                        set.add(s.substring(i, i + j));
                    }
                }
            }
            if (set.size() >= k) {
                break;
            }
        }
        int count = 1;
        for (String str : set) {
            if (count == k) {
                System.out.println(str);
                break;
            }
            count++;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main() {
  int Xmas;
  cin >> Xmas;
  
  if(Xmas==25)
    cout << "Christmas" <<endl;
  else if(Xmas==24)
    cout << "Christmas Eve" <<endl;
  else if(Xmas==23)
    cout << "Christmas Eve Eve" <<endl;
  else if(Xmas==22)
    cout << "Christmas Eve Eve Eve" <<endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let mut ans = 0;

    for i in 0..(s.len()/2) {
        if s[i] != s[s.len() - 1 - i] {
            ans += 1;
        }
    }

    println!("{}", ans);
}


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

int main(){
	int S,h,m,s;
	cin >> S;

	h=S/3600;
	m=(S-h*3600)/60;
	s=(S-h*3600-m*60);


	
	cout << h << ":" << m << ":" << s << endl;
	
	return 0;
}



Measured memory_bytes: 3116
#include<stdio.h>

int main(void){
   int i;
   char S[7];
   scanf("%s",S);
   for(i=0;i<1;i++){
      
      if((S[2]==S[3])&&(S[4]==S[5])){
         printf("Yes\n");
      }else{
         printf("No\n");
      }
   }
      return 0;
}



Measured memory_bytes: 1640
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)((n>>m)&1)
int main(){
    ll n,ans,tmp,num[11],ss=0;
    char s[11];
	scanf("%s",s);
	n=strlen(s);
    rep(i,0,n)num[i]=s[i]-48;
	rep(i,0,1<<(n-1)){
		ss=0;
		tmp=num[0];
		rep(j,0,n-1){
			if(bit(i,j))tmp=tmp*10+num[j+1];
			else {
				ss+=tmp;
				tmp=num[j+1];
			}
		}
		ss+=tmp;
		ans+=ss;
    }
	printf("%lld\n",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <boost/math/common_factor.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    uint N;
    cin >> N;
    ull m{1};
    for (auto &&i: irange(0U, N)){
        ull a;
        cin >> a;
        m = math::lcm(m,a);
    }
    cout << m;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, H, W, N);
    auto vs = makeV<int>(0, H, W);

    rep(i, 0, N) {
        var(int, y, x, v);
        --y, --x;
        vs[y][x] = v;
    }

    auto dp = makeV<i64>(0, H + 1, W + 1, 4);

    rep(y, 0, H) rep(x, 0, W) {
        repr(k, 2, 0) { chmax(dp[y][x][k + 1], dp[y][x][k] + vs[y][x]); }
        rep(k, 0, 4) {
            chmax(dp[y + 1][x][0], dp[y][x][k]);
            chmax(dp[y][x + 1][k], dp[y][x][k]);
        }
    }

    print(*max_element(all(dp[H - 1][W - 1])));

    return 0;
}


Measured memory_bytes: 671796
#include <bits/stdc++.h>
using namespace std;
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = 1e4 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
char F[200];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    } 
    return ret*sgn;
}

inline void write( ll x ) {
    ll tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
       F[cnt++] = tmp % 10 + '0';
       tmp /= 10;
    }
    while(cnt > 0) putchar(F[--cnt]);
}

ll notprime[maxn];
ll prims[maxn];

void Prim()
{
    notprime[1] = 1;

    for(int i = 2; i < maxn; i++)
    {
        if(!notprime[i])
            prims[++prims[0]] = i;

        for(int j = 1; j <= prims[0] && i * prims[j] < maxn; j++)
        {
            notprime[i * prims[j]] = 1;
            if(i % prims[j] == 0)
                break;
        }
    }
}

int main()
{
    NOS
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    ll n;
    cin >> n;

    ll ans = 0;

    for(ll i = 1; i <= n; i++)
    {
        ll cnt = n / i;

        ans += i * cnt * (cnt + 1) / 2;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
s = input()
flag = True
while True:
    if len(s) == 1:
        flag = False
        break
    if len(s) == 0:
        break
    if s[:2] == "hi":
        s = s[2:]
    else:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 200005;
int main()
{
    FAST
    int n;
    cin>>n;
    ll arr[n];
    ll ans=1;
    int c=0;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        c+=(arr[i]==0);
    }
    if(c>0){
        return cout<<0,0;
    }


    for(int i=0; i<n; i++)
    {


        if((ll)ans>((ll)1e18)/arr[i])
           {
               return cout<<-1,0;
           }
 ans=(ll)ans*(ll)arr[i];

    }

    if(ans>(ll)1e18)
        cout<<-1<<endl;
    else{
        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 4436
N = int(input())
A = map(int,input().split())

A = sorted(A)[::-1]

alice = 0
bob = 0

for i in range(N//2):
    alice += A[2*i]
    bob += A[2*i+1]
    
if N%2 == 1:
    alice += A[N-1]
    
print(alice-bob)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 200003

string ss;
int n, dep[mx][3];

int dp(int now, int tadi){
	if(now == n)
		return 0;
	int &ret = dep[now][tadi];
	if(ret != -1)
		return ret;
	ret = -1e9;
	if(tadi == 0){
		ret = dp(now + 1, 1) + 1;
		if(now + 2 <= n)
			ret = max(ret, dp(now + 2, 2) + 1);
		return ret;
	}
	if(tadi == 1){
		if(ss[now] != ss[now - 1])
			ret = dp(now + 1, 1) + 1;
		if(now + 2 <= n)
			ret = max(ret, dp(now + 2, 2) + 1);
		return ret;
	}
	ret = dp(now + 1, 1) + 1;
	if(now + 2 <= n && (ss[now - 2] != ss[now] || ss[now - 1] != ss[now + 1]))
		ret = max(ret, dp(now + 2, 2) + 1);
	return ret;
}

int main(){
	cin >> ss;
	n = sz(ss);
	reset(dep, -1);
	cout << dp(0, 0) << '\n';
}

Measured memory_bytes: 11908
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int main() {
    int h, n;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC064A
{
    class Program
    {
        static void Main(string[] args)
        {
            int X, A, B;
            string[] vals = Console.ReadLine().Split(' ');
            X = int.Parse(vals[0]);
            A = int.Parse(vals[1]);
            B = int.Parse(vals[2]);

            if(B-A <= 0)
            {
                Console.WriteLine("delicious");
            }
            else if(B-A <= X)
            {
                Console.WriteLine("safe");
            }
            else
            {
                Console.WriteLine("dangerous");
            }

        }
    }
}

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

int main(void){
    
   string s,t;
   cin >> s >> t;
   
   int Pos = t.find(s);
   
   if (Pos == string::npos || Pos != 0) {
        cout << "No" <<endl;
    }else {
        cout << "Yes" <<endl;
    }
}

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

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	ll k, ans = 0;
	cin >> k;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			int temp = __gcd(i, j);
			for (int l = 1; l <= k; l++)
				ans += __gcd(temp, l);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>

#define dvidenumber 1000000007

int main()
{
	long long i, j;
	long long multnumber = 1;
	scanf("%lld", &i);
	for (j = 1; j < i + 1; j++) {
		multnumber *= j;
		if (multnumber > dvidenumber) {
			multnumber = multnumber % dvidenumber;
		}
	}
	printf("%lld\n", multnumber);
    return 0;
}

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

int main() {
    int N;
    int a[100];
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a, a + N, greater<int>());
    int alice = 0;
    int bob = 0;
    for(int i = 0; i < N; i++) {
        if(i % 2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << alice - bob << endl;
    return 0;
}

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

Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, char **argv)
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if ( a < b ) {
		printf("a < b\n");
	}else if ( a == b ) {
		printf("a == b\n");
	}else{
		printf("a > b\n");
	}		
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) a.begin(),a.end()
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}

const int iinf = 1111111111;
const ll linf = 4e18;
const int mod = 1e9+7;
const double eps = 1e-10;

struct segtree{
  typedef int T;
  T e = iinf;
  T merge(const T& a, const T& b){return min(a, b);}
  //###################################################
  int n;vector<T> d;
  void init(int _n){n=1; while(n<_n)n*=2;d.resize(2*n-1);FOR(i,0,2*n+1)d[i]=e;}
  void update(int k,T a){k+=n-1;d[k]=a;while(k>0){k=(k-1)/2;d[k]=merge(d[k*2+1],d[k*2+2]);}}
  T q(int a,int b,int k,int l,int r){return (r<=a||b<=l)?e:(a<=l&&r<=b)?d[k]:merge(q(a,b,k*2+1,l,(l+r)/2),q(a,b,k*2+2,(l+r)/2,r));}
  T query(int a,int b){return q(a,b,0,0,n);}
};

segtree seg[2];
int n, p[200005], ip[200005];
typedef pair<pii, pii> qi;
priority_queue<qi, vector<qi>, greater<qi> > que;
vi v;

qi to_qi(pii& p){
  int l = p.fi, r = p.se;
  int _l = seg[l%2].query(l/2, r/2);
  int _r = seg[1-l%2].query((ip[_l]+1)/2, (r+1)/2);
  return qi(pii(_l, _r), pii(l, r));
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, 2)seg[i].init(n/2);
  FOR(i, 0, n){
    cin >> p[i];
    ip[p[i]] = i;
    seg[i%2].update(i/2, p[i]);
  }
  pii t1 = pii(0, n), t2, t3;
  qi tmp;
  que.push(to_qi(t1));
  while(!que.empty()){
    tmp = que.top();
    que.pop();
    t1 = tmp.fi;
    t2 = tmp.se;
    v.pb(t1.fi);
    v.pb(t1.se);
    if(ip[t1.fi] > t2.fi){
      t3 = pii(t2.fi, ip[t1.fi]);
      que.push(to_qi(t3));
    }
    if(ip[t1.se] > ip[t1.fi] + 1){
      t3 = pii(ip[t1.fi] + 1, ip[t1.se]);
      que.push(to_qi(t3));
    }
    if(t2.se > ip[t1.se] + 1){
      t3 = pii(ip[t1.se] + 1, t2.se);
      que.push(to_qi(t3));
    }
  }
  cout << join(v) << endl;
}

Measured memory_bytes: 9208
def triangle?(a, b, c)
  a + b > c
end

def decide_type(a, b, c)
  a ** 2 + b ** 2 <=> c ** 2
end

triangle_count = 0
acute_angle_triangle = 0
right_angle_triangle = 0
obtuse_triangle = 0

loop do
  a, b, c = gets.split.map(&:to_i).sort
  break unless triangle?(a, b, c)

  triangle_count += 1
  case decide_type(a, b, c)
  when 1
    acute_angle_triangle += 1
  when 0
    right_angle_triangle += 1
  when -1
    obtuse_triangle += 1
  end
end

puts [triangle_count, right_angle_triangle, acute_angle_triangle, obtuse_triangle].join("\s")



Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) (x.begin(), x.end())

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int a, b;
    cin >> a >> b;
    if(a == b) cout << 2*a << endl;
    else cout << 2*max(a, b) -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

int main(){
    ll k;
    cin >> k;
    ll now = 7;
    now %= k;
    if(now == 0){
        cout << 1 << endl;
        return 0;
    }
    for(int i = 2; i < 1e7; i++){
        ll nxt = (now*10+7)%k;
        if(nxt == 0){
            cout << i << endl;
            return 0;
        }
        now = nxt;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int search(int key, int X[], int n);

int main(){
  int n,q,key,i=0,count=0;
    int S[10000];
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&S[i]);
    }
    i = 0;
    scanf("%d",&q);
    for(i=0;i<q;i++){
      scanf("%d",&key);
      if(search(key, S, n)){
	count++;
      }
    }
    printf("%d\n",count);
    
    return 0;
}

int search(int key, int X[], int n){
  int i = 0;
  X[n] = key;
  while(X[i]!=key){
    i++;
    if(i==n){
      return 0;
    }
  }
  return 1;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    int N; cin >> N;
    map<int,int> m;
    rep(i,N){
        int a; cin >> a;
        m[a]++;
    }
    if(m.size()==N) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#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++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N;
  cin>>N;
  string name="";
  while(N>0){
    N--;
    name+=(char)(N%26+'a');
    N/=26;
  }
  reverse(name.begin(),name.end());
  cout<<name<<endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<bitset>

using namespace std;

/************************************************/

int main(void) {
	int n, m, x;
	cin >> n >> m >> x;
	vector<int>a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	int sum = 0;
	if (x >= n / 2) {
		for (int i = x; i <= n; i++) {
			for (int j = 0;j < m; j++) {
				if (i == a[j]) {
					sum++;
				}
			}
			if (i == n) {
				cout << sum;
				return 0;
			}
		}
	}
	else {
		for (int i = x; i >= 0; i--) {
			for (int j = 0; j < m; j++) {
				if (i == a[j]) {
					sum ++;
				}
			}
			if (i == 0) {
				cout << sum;
				return 0;
			}
		}
	}
	return 0;
}

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

void solver() {
  int n;
  cin >> n;

  vector<int> as(n);
  int min_a = 1000;
  int max_a = -1;
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    min_a = min(min_a, as[i]);
    max_a = max(max_a, as[i]);
  }

  long long ans = 1000000000;
  for (int i = min_a; i <= max_a; i++) {
    long long cans = 0;
    for (int j = 0; j < n; j++) {
      cans += (as[j] - i) * (as[j] - i);
    }
    ans = min(cans, ans);
  }

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

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


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

constexpr int MAX_N = 100000;
int N;
int A[MAX_N];
int C[MAX_N];

bool CanDraw(int num_colors) {
  for (int i = 0; i < num_colors; ++i) {
    C[i] = -1;
  }
  for (int i = 0; i < N; ++i) {
    int pos = std::lower_bound(C, C + num_colors, A[i]) - C - 1;
    if (pos == -1) {
      return false;
    } else {
      C[pos] = A[i];
    }
  }
  return true;
}

int main() {
  std::cin >> N;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  int min = 0, max = N;
  while (min < max) {
    int mid = (min + max) / 2;
    if (CanDraw(mid)) {
      max = mid;
    } else {
      min = mid + 1;
    }
  }
  std::cout << min << std::endl;
  return 0;
}

Measured memory_bytes: 1024