akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAXN 3005
#define REG register
using namespace std;
inline void read(int& x){
    static char c;
    while(!isdigit(c=getchar()));x=c^48;
    while(isdigit(c=getchar()))x=(x*10)+(c^48);
}

int n;

struct Edge{int v,nxt;}ed[MAXN<<1];
int head[MAXN],cnt;
inline void adde(int u,int v){ed[++cnt]=(Edge){v,head[u]},head[u]=cnt;}
inline void add(int u,int v){adde(u,v),adde(v,u);}
#define FORE(i,Now) for(REG int i=head[Now];i;i=ed[i].nxt)

int A[MAXN];

int Win[MAXN];

void dfs(int Now,int Fa){
    int Min=1000000001;
    FORE(i,Now){
        int v=ed[i].v;
        if(v==Fa) continue;
        dfs(v,Now);
        if(Win[v]) continue;
        Min=A[v]<Min?A[v]:Min;
    }
    if(Min>=A[Now]) Win[Now]=0;
    else Win[Now]=1;
}

inline void Work(){
    read(n);
    for(REG int i=1;i<=n;++i) read(A[i]);
    for(REG int i=1;i<n;++i){int u,v;read(u),read(v),add(u,v);}
    for(REG int i=1;i<=n;++i){
        memset(Win,0,sizeof Win);
        dfs(i,i);
        if(Win[i]) printf("%d ",i);
    }
}

int main(){Work();}

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

class fraction {
    long long numer; // bunshi
    long long denom; // bunbo
public:
    fraction(long long numer, long long denom) : numer(numer), denom(denom) {}
    int compare_to(const fraction& f) const {
        assert(denom > 0 && f.denom > 0);
        long long res = numer * f.denom - denom * f.numer;
        if (res > 0) return 1;
        else if (res < 0) return -1;
        else return 0;
    }
    long double to_float() const {
        return numer / (long double)denom;
    }
};

using P = pair<fraction, fraction>;


int main() {
    long long t;
    int n;
    cin >> t >> n;
    vector<P> upper, lower, middle;
    for (int i = 0; i < n; ++i) {
        long long x, a, b;
        cin >> x >> a >> b;
        fraction ta(a, x * (t - x));
        fraction tb(b, x * (t - x));
        if (a * t > x * (t - x)) upper.push_back({ta, tb});
        else if (b * t < x * (t - x)) lower.push_back({ta, tb});
        else middle.push_back({ta, tb});
    }
    sort(upper.begin(), upper.end(), [](const P& a, const P& b) { return a.first.compare_to(b.first) > 0; });
    sort(lower.begin(), lower.end(), [](const P& a, const P& b) { return a.second.compare_to(b.second) < 0; });

    long double ans = 0;
    fraction last1(1e6 + 10, 1), last2(-(1e6 + 10), 1);
    for (auto& i : upper) {
        if (last1.compare_to(i.second) > 0) {
            ans += sqrt(i.first.to_float() * t * t / 2 + 1 / (i.first.to_float() * 2));
            last1 = i.first;
        }
    }
    for (auto& i : lower) {
        if (last2.compare_to(i.first) < 0) {
            ans += sqrt(i.second.to_float() * t * t / 2 + 1 / (i.second.to_float() * 2));
            last2 = i.second;
        }
    }
    bool ad = false;
    for (auto& i : middle) {
        if ((i.second.compare_to(last1) < 0 || i.first.compare_to(last1) > 0) && (i.second.compare_to(last2) < 0 || i.first.compare_to(last2) > 0)) {
            ad = true;
            break;
        }
    }
    if (ad) ans += sqrt(t);
    cout << setprecision(24) << ans << '\n';
    return 0;
}



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

int main() {
    int N, ans=0, A, B, C, K;
    cin >> A >> B >> C >> K;

    if(K >= A){
	ans += A;
	K -= A;
    }
    else{
	ans += K;
	K=0;
    }

    K -= B;

    if(K>=0)
	ans -= K;

    cout << ans << endl;
} 




Measured memory_bytes: 3596
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float("INF")
for i in range(1 << n):
    h = 0
    cost = 0
    count = 0
    for j in range(n):
        if j != 0:
            h = max(h, a[j - 1])
        if i >> j & 1:
            if h < a[j]:
                h = a[j]
                count += 1
            else:
                h += 1
                cost += h - a[j]
                count += 1
    if count >= k:
        ans = min(ans, cost)

print(ans)
        
            



Measured memory_bytes: 74068
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Math;
using static System.Console;
class E { static void Main() => new K(); }
class K
{
	public K()
	{
		var N = int.Parse(ReadLine());
		var surf = new uint[N][];
		var per = new int[N];
		var hash = new ulong[N];
		var dict = new Dictionary<ulong, int>();
		for (var i = 0; i < N; i++)
		{
			surf[i] = ReadLine().Split().Select(uint.Parse).ToArray();
			per[i] = surf[i][0] == surf[i][2] && surf[i][1] == surf[i][3] ? surf[i][0] == surf[i][1] ? 1 : 2 : 4;
			if (per[i] == 1) hash[i] = Hash1(surf[i][0]);
			else if (per[i] == 2) hash[i] = Hash2(surf[i][0], surf[i][1]);
			else hash[i] = Hash(surf[i][0], surf[i][1], surf[i][2], surf[i][3]);
			if (!dict.ContainsKey(hash[i])) dict[hash[i]] = 0;
			dict[hash[i]]++;
		}
		var a = 0L;
		var y = new uint[4];
		for (var i = 0; i < N; i++)
			for (var j = i + 1; j < N; j++)
			{
				var count = 0L;
				dict[hash[i]]--;
				dict[hash[j]]--;
				for (var rj = 0; rj < per[j]; rj++)
				{
					var x = surf[i];
					for (var k = 0; k < 4; k++) y[k] = surf[j][(k + rj) % 4];
					var s = new[] {
						Hash(y[3], y[2], x[3], x[2]),
						Hash(y[2], y[1], x[0], x[3]),
						Hash(y[1], y[0], x[1], x[0]),
						Hash(y[0], y[3], x[2], x[1])
					};
					var p = 1L;
					var dup = new Dictionary<ulong, int>();
					foreach (var h in s)
					{
						if (!dict.ContainsKey(h)) { p = 0; break; }
						if (!dup.ContainsKey(h)) dup[h] = 0;
						p *= (4 / Period(h)) * (dict[h] - dup[h]);
						dup[h]++;
					}
					count += p;
				}
				a += count * (4 / per[j]);
				dict[hash[i]]++;
				dict[hash[j]]++;
			}
		WriteLine(a / 3);
	}
	static ulong Hash(uint i, uint j, uint k, uint l)
	{
		var a = ((ulong)i << 30) | (j << 20) | (k << 10) | l;
		a = Min(a, ((ulong)j << 30) | (k << 20) | (l << 10) | i);
		a = Min(a, ((ulong)k << 30) | (l << 20) | (i << 10) | j);
		a = Min(a, ((ulong)l << 30) | (i << 20) | (j << 10) | k);
		return a;
	}
	static ulong Hash1(uint i) => ((ulong)i << 30) | (i << 20) | (i << 10) | i;
	static ulong Hash2(uint i, uint j)
	{
		if (i > j) return ((ulong)j << 30) | (i << 20) | (j << 10) | i;
		return ((ulong)i << 30) | (j << 20) | (i << 10) | j;
	}
	const ulong p1 = (1 << 30) | (1 << 20) | (1 << 10) | 1;
	const ulong p2 = (1 << 20) | 1;
	static int Period(ulong h) => h % p2 == 0 ? h % p1 == 0 ? 1 : 2 : 4;
}


Measured memory_bytes: 17612
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n,w,x,c[4]={0};
    long long v[4][100],m=0;
    cin>>n>>w;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(i==0){
            x=a;
            v[0][0]=b;
            c[0]++;
        }else{
            v[a-x][c[a-x]]=b;
            c[a-x]++;
        }
    }
    for(int i=0;i<4;i++){
        sort(v[i],v[i]+c[i],greater<long long>());
        for(int j=1;j<c[i];j++){
            v[i][j]+=v[i][j-1];
        }
    }
    
    for(int i=0;i*(x+3)<=w&&i<=c[3];i++){
        for(int j=0;i*(x+3)+j*(x+2)<=w&&j<=c[2];j++){
            for(int k=0;i*(x+3)+j*(x+2)+k*(x+1)<=w&&k<=c[1];k++){
                int l=(w-(i*(x+3)+j*(x+2)+k*(x+1)))/x;
                if(l>c[0])l=c[0];
                long long p=0;
                if(i>0)p+=v[3][i-1];
                if(j>0)p+=v[2][j-1];
                if(k>0)p+=v[1][k-1];
                if(l>0)p+=v[0][l-1];
                m=max(m,p);
                //cout<<i<<j<<k<<l<<p<<endl;
            }
        }
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

N,D = inpl()

ls = []

for _ in range(N):
    x,y = inpl()
    ls.append((x,y))
count = 0

for item in ls:
    if (item[0]**2 + item[1]**2)**(1/2) <=D:
        count += 1

print(count)


Measured memory_bytes: 88580
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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


    [] {
        [] {
            [] {
                int N;

                N = 3;
                vector<vector<int> > vv(N,vector<int>(N));
                [&] {
                    rep(i, 0, N) {
                        rep(j, 0, N) {
                            cin >> vv[i][j];
                        }
                    }
                }();

                [&] {
                    rep(i, 0, N) {
                        int mini = 114514;
                        rep(j,0,N){
                            mini = min(mini,vv[i][j]);
                        }
                        rep(j,0,N){
                            vv[i][j] -= mini;
                        }
                    }
                }();
                [&] {
                    rep(j, 0, N) {
                        int mini = 114514;
                        rep(i,0,N){
                            mini = min(mini,vv[i][j]);
                        }
                        rep(i,0,N){
                            vv[i][j] -= mini;
                        }
                    }
                }();
                if([&]{
                    rep(i,0,N){
                        rep(j,0,N){
                            if(vv[i][j]) return false;
                        }
                    }
                    return true;
                }()){
                    cout << "Yes" << endl;
                }else{
                    cout << "No" << endl;
                }
            }();

        }();
    }();

    return 0;
}


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

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    for (int i=0; i<N; i++) cin >> t.at(i);

    int ans = T * N;
    for (int i=0; i<N-1; i++){
        ans -= max(0, t.at(i) + T - t.at(i+1));
    }

    cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
        cin >> p[i];

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (p[i] != i + 1) cnt++;
    }

    if (cnt > 2)
        cout << "NO" << endl;
    else
        cout << "YES" << endl;

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  string s[n];
  rep(i,n)cin>>s[i];
  bool ans=true;
  rep(i,n)rep(j,n)if(s[i]==s[j]&&i!=j)ans=false;
  rep(i,n-1)if(s[i].back()!=s[i+1].front())ans=false;
  cout<<(ans?"Yes":"No")<<endl;
  return 0;
  }


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

int main()
{
    unsigned char N;
    unsigned char i, j;
    unsigned int sum = 0;
    unsigned char *p;
    scanf("%u", &N);
    p = (unsigned char*) malloc(N*(sizeof(char)));
    
    for(i = 0; i < N; i++)
    {
        scanf("%u ", &p[i]);
    }
    
    for(i = 0; i < N-1; i++)
    {
        for(j = i+1; j < N; j++)
        {
            sum = sum + (p[i] * p[j]);
        }
    }
    
    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: str(sys.stdin.buffer.readline().rstrip())
rs = lambda: map(str, sys.stdin.buffer.readline().split())
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
a = rl()
def heapsort(l):
  li = []
  for v in l:
    heapq.heappush(li, v)
  return [heapq.heappop(li) for _ in range(len(li))]
a = heapsort(a)
ans = a[0]
for i in a:
  ans = (ans + i)/2
print(ans)


Measured memory_bytes: 12508
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    int N; cin>>N;
    vector<int> L(N);
    for (int i = 0; i < N; ++i) cin>>L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    for (int i = 0; i < N-2; ++i) {
        for (int j = i+1; j < N-1; ++j) {
            int syu = L[i] + L[j]; //syu > 3つめ　になればよい
            auto itr = lower_bound(L.begin() + j + 1, L.end(), syu);
            int kyori = distance(L.begin()+j+1, itr);
            ans += kyori;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    rep(i, M) cin >> X[i];
    sort(X.begin(), X.end());

    vector<int> gaps(M);
    gaps[0] = 0;
    for(int i=1; i<M; i++) {
        gaps[i] = X[i] - X[i-1];
    }
    sort(gaps.begin(), gaps.end(), greater<int>());
    int seq = -1;
    rep(i, N-1) seq++;

    int res = 0;
    for(int i=seq+1; i<M; i++) {
        res += gaps[i];
    }

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

Measured memory_bytes: 1024
#include<stdio.h>
#define M 100001
#define NULL -1
void print(int);
int rec(int,int);
typedef struct Node{
  int p,l,r;
}Node;
Node T[M];
int N,dep[M];
int main(){
  int i,j,id,k,c,l,r;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    T[i].p=T[i].l=T[i].r=NULL;
  }
  for(i=0;i<N;i++){
    scanf("%d%d",&id,&k);   /*idは節点の番号kは子の数*/
    for(j=0;j<k;j++){
      scanf("%d",&c);
      if(j==0){
	T[id].l=c;
      }else T[l].r=c;
      l=c;
      T[c].p=id;
      
     }
  }
  for(i=0;i<N;i++){
    if(T[i].p==NULL)r=i;
  }
  rec(r,0);
  for(i=0;i<N;i++){
    print(i);
  }
  return 0;
}
int rec(int u,int q){
  dep[u]=q;
  if(T[u].r != NULL)rec(T[u].r,q);
  if(T[u].l != NULL)rec(T[u].l,q+1);
}

void print(int w){
  printf("node %d: ",w);
  printf("parent = %d, ",T[w].p);
  printf("depth = %d, ",dep[w]);

  if(T[w].p==NULL)printf("root, ");
  else if(T[w].l==NULL)printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(int i=0,c=T[w].l; c!=NULL;i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}
	 



Measured memory_bytes: 6376
#include<bits/stdc++.h>
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; }
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); i++)

int main()
{
  int D,T,S;
  cin >> D >> T >> S;
  if(D<=T*S)
	cout<<"Yes"<< endl;
  else cout<<"No"<< endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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; }

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n);
  REP(sv, n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    REP(i, n) ans[dist[i]]++;
  }
  REP(i, n) ans[i] /= 2;
  FORe(i, 1, n-1) cout << ans[i] << endl;

  return 0;
}

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

int cnt=0;

void bubbleSort(int *A, int N){
  bool flag=true;
  while(flag){
    flag=false;
    for(int i=N-1;i>0;i--){
      if(A[i-1]>A[i]){
        swap(A[i-1], A[i]);
        flag=true;
        cnt++;
      }
    }
  }
}

int main(){

  int n, a[110];

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

  bubbleSort(a, n);

  for(int i=0;i<n;i++){
    cout<<(i?" ":"");
    cout<<a[i];
  }
  cout<<endl<<cnt<<endl;

  return 0;
}



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

#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
//template<typename T> T vpop(vector<T> *v) {
//	T res = v->back();
//	v->pop_back();
//	return res;
//}
//char vpop(string *v) {
//	char res = v->back();
//	v->pop_back();
//	return res;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

//#define lint long long
typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<lint> lvec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

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

template<class T>inline bool maxi(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main(){
	setc;

	lint n,m,x;cin>>n>>m;
	if (2*n>m){
		co(m/2);gc();return 0;
	}
	x=(m-2*n)/4;
	co(min(n+x,m-2*x));
	gc();
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

	//1344 start

	class C implements Comparable<C>{
		int p,a,b,c,d,e,f,s,m;
		String name;
		int time, sum;
		double value;

		public C(int p,int a, int b, int c, int d, int e, int f, int s, int m,
				String name, int time, int sum, double value) {
			this.p = p;
			this.a = a;
			this.b = b;
			this.c = c;
			this.d = d;
			this.e = e;
			this.f = f;
			this.s = s;
			this.m = m;
			this.name = name;
			this.time = time;
			this.sum = sum;
			this.value = value;
		}

		@Override
		public int compareTo(C o) {
			if(this.value < o.value) return -1;
			if(this.value > o.value) return 1;
			return -1 * this.name.compareTo(o.name);
		}

		@Override
		public String toString() {
			return "C [p=" + p + ", a=" + a + ", b=" + b + ", c=" + c + ", d="
					+ d + ", e=" + e + ", f=" + f + ", s=" + s + ", m=" + m
					+ ", name=" + name + ", time=" + time + ", sum=" + sum
					+ ", value=" + value + "]";
		}

		
	}

	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			C [] data = new C[n];
			for(int i = 0 ; i < n; i++){
				String l = sc.next();
				int p = sc.nextInt();
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				int d = sc.nextInt();
				int e = sc.nextInt();
				int f = sc.nextInt();
				int s = sc.nextInt();
				int m = sc.nextInt();
				C now = new C(p, a, b, c, d, e, f, s, m, l, 0, 0, 0.0);
				data[i] = now;
			}

			for(int i = 0 ; i < n; i++){
				data[i].time += data[i].a + data[i].b + data[i].c;
				data[i].sum = data[i].s * data[i].m * data[i].f- data[i].p;
				for(int j = 0 ; j < data[i].m; j++){
					data[i].time += data[i].d + data[i].e;
				}
				data[i].value = (double)data[i].sum / data[i].time;
			}
			Arrays.sort(data);
			for(int i = n-1; i >= 0; i--){
				System.out.println(data[i].name);
				//System.out.println(data[i]);
			}
			System.out.println("#");
		}
	}

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

Measured memory_bytes: 12000
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        System.out.println((int)Math.pow(reader.nextInt(), 2));
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



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

int solve(const int K) {
    for (int i = 1, sevens = 7 % K; i <= K;
         ++i, sevens = (sevens * 10 + 7) % K) {
        if (sevens == 0) return i;
    }

    return -1;
}

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

    int K;
    cin >> K;
    cout << solve(K) << '\n';

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

int main() {
  static const double pi = 3.141592653589793;
  double a,b,x;cin >> a >> b >> x;
  double s= 2*x/a;
  double z,ang;
  if(x<=a*a*b/2){
    z=s/b;
  }else{
    z=a*b/(2*b-s/a);
  }
  ang = atan(double(b/z));
  cout << fixed<<setprecision(10) <<double(ang*180)/pi;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b[10000],c,d,s,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  d=a-1;
  for(i=d;i>=0;i--){
    if (i>0)printf("%d ",b[i]);
    else printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2040
def main():
    import sys
    input = sys.stdin.readline
    
    k,n=map(int,input().split())
    a=list(map(int,input().split()))
    
    mini=k
    for i in range(n):
        tmp=a[i-1]-a[i]
        if tmp<0:
            tmp+=k
        mini=min(mini,tmp)
    print(mini)

if __name__ == '__main__':
    main()

Measured memory_bytes: 25880
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N, M;
	static int[] MP, CP, sum;
	static Colony[] cats;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			M = sc.nextInt();
			if (M == 0) break;
			cats = new Colony[N];
			int hi = 0;
			int[] cc = new int[20001];
			for (int i = 0; i < N; ++i) {
				int x = sc.nextInt() + 10000;
				sc.nextInt();
				cc[x] += sc.nextInt();
			}
			ArrayList<Colony> cats = new ArrayList<Colony>();
			cats.add(new Colony(-20000, 0));
			for (int i = 0; i < cc.length; ++i) {
				if (cc[i] != 0) cats.add(new Colony(i, cc[i]));
				hi += cc[i];
			}
			Collections.sort(cats);
			CP = new int[cats.size()];
			sum = new int[cats.size()];
			for (int i = 0; i < CP.length; ++i) {
				CP[i] = cats.get(i).x;
				if (i > 0) sum[i] = sum[i - 1] + cats.get(i).c;
			}
			MP = new int[M];
			for (int i = 0; i < M; ++i) {
				MP[i] = sc.nextInt() + 10000;
			}
			Arrays.sort(MP);
			int lo = 0;
			while (hi - lo > 1) {
				int mid = (hi + lo) / 2;
				if (ok(mid)) {
					hi = mid;
				} else {
					lo = mid;
				}
			}
			System.out.println(hi);
		}
	}

	static boolean ok(int num) {
		int[] dp = new int[M];
		Arrays.fill(dp, 1 << 30);
		dp[0] = count(MP[0]);
		for (int i = 1; i < M; ++i) {
			for (int j = i - 1; j >= 0; --j) {
				int add = count((MP[i] + MP[j]) / 2) - count(MP[j]);
				if (dp[j] + add > num) continue;
				dp[i] = count(MP[i]) - count((MP[i] + MP[j]) / 2);
				break;
			}
		}
		return dp[M - 1] + sum[sum.length - 1] - count(MP[M - 1]) <= num;
	}

	static int count(int pos) {
		int idx = Arrays.binarySearch(CP, pos);
		if (idx < 0) {
			idx = -idx - 2;
		}
		return sum[idx];
	}

	static class Colony implements Comparable<Colony> {
		int x, c;

		public Colony(int x, int c) {
			this.x = x;
			this.c = c;
		}

		public int compareTo(Colony o) {
			return this.x - o.x;
		}
	}

}

Measured memory_bytes: 61524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    set<string> se;
    rep(i, n) se.insert(s[i]);
    cout << sz(se) << endl;
    return 0;
}


Measured memory_bytes: 25108
#include <cstdio>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ck(a) (0 <= (a) && (a) < 9)

int di[] = {-3, -1, 1, 3};

int main() {
    int n, s, t, b; char cs, ct, cb;
    while(scanf("%d", &n)) {
        if(n == 0) break;
        getchar();
        scanf("%c %c %c", &cs, &ct, &cb);
        s = cs - 'A', t = ct - 'A', b = cb - 'A';
        double p[9] = {0}; p[s] = 1.0;


        while(n--) {
            double q[9] = {0};
            rep(i, 9) rep(d, 4) {
                if(ck(i + di[d]) && !(i % 3 == 0 && di[d] == -1) &&
                   !(i % 3 == 2 && di[d] == 1) &&
                   !(i / 3 == 0 && di[d] == -3) &&
                   !(i / 3 == 2 && di[d] == 3) && i + di[d] != b)
                    q[i + di[d]] += p[i] / 4;
                else q[i] += p[i] / 4;
            }
            rep(i, 9) p[i] = q[i];
        }
        printf("%.8lf\n", p[t]);
    }
    return 0;
}

Measured memory_bytes: 1072
using System;
using System.Text;

namespace AOJ2
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = 0;
            string input;
            while ((input = Console.ReadLine()) != null)
            {
                bool flag = false;
                StringBuilder sb = new StringBuilder();

                foreach (char c in input)
                {
                    int code = c;
                    
                    
                    if (code >= 48 && code <= 57)
                    {
                        flag = true;
                        sb.Append(c);
                    }
                    else
                    {
                        if (flag)
                        {
                            num += int.Parse(sb.ToString());
                            sb = new StringBuilder();
                            flag = false;
                        }
                    }

                }

                if (flag)
                {
                    num += int.Parse(sb.ToString());
                    sb = new StringBuilder();
                    flag = false;
                }

            }

            Console.WriteLine(num);

        }
    }
}

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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

#define ll long long int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
#define pa pair<ll,ll>
//#define goodset tree<pa, null_type, less<pa>, rb_tree_tag, tree_order_statistics_node_update>
//#define FRE freopen("acm.in","r",stdin); freopen("acm.out","w",stdout);

const ll mod = 1e9+7 ;
const ll N = 3e5+5;

int main()
{
    FAST

    ll tc,i,j,k;
    //cin>>tc;
    tc=1;

    while(tc--)
    {
        ll x;
        cin>>x;
        if(x>=30)
            cout<<"Yes"<<"\n";
        else
            cout<<"No"<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3648
#!/usr/bin/perl

my ($n) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = map {$_ - 0} split(/\s+/o,<STDIN>);

my $s = 0;
my %ss = ();
$ss{$s} ++;
for(my $i=0;$i<$n;$i++){
  $s += $a[$i];
  $ss{$s} ++;
}
my $ans = 0;
foreach my $s1 ( keys %ss ){
  my $k = $ss{$s1} - 0;
  next if $k <= 1;
  $k --;
  $ans += $k * ($k + 1 )/2;
}
print "$ans\n";
exit(0);




Measured memory_bytes: 52260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = INF;
	range(i, 2, s.size()) {
		int t = 0;
		t += (s[i - 2] - '0') * 100;
		t += (s[i - 1] - '0') * 10;
		t += (s[i - 0] - '0');
		ans = min(ans, abs(t-753));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,c=0,t=0,b,s=0,f,g,d=0,x=0;
    cin>>n;
    f = n-1;
    g = n*f;
    g/=2;
    cout<<g<<endl;
}


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

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

//****************************don't use int!!!!!!!****************************//
//***************************code starts here!!!!!****************************//


int main() {
    IOS

    ll n;
    cin >> n;
    vector<pll > a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(all(a));
    for (auto i : a) {
        cout << i.second << ' ';
    }

    return 0;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1},INF=1e9;

void solve(int w,int h){
    vector<vector<int>> S(h,vector<int>(w));
    int sx,sy;
    for (int i=0;i<h;++i){
        for (int j=0;j<w;++j){
            cin >> S[i][j];
            if (S[i][j]==2) sx=i,sy=j;
        }
    }
    auto dfs=[&](auto self,int x,int y,int d)->int{
        int res=INF;
        if (10<=d) return INF;
        for (int i=0;i<4;++i){
            int nx=x,ny=y;
            bool ok=true;
            while(1){
                nx+=dx[i],ny+=dy[i];
                if (nx<0||h<=nx||ny<0||w<=ny){ok=false; break;}
                if (S[nx][ny]==3) return d+1;
                if (S[nx][ny]==1) break;
            }
            if (ok&&abs(nx-x)+abs(ny-y)>1){
                S[nx][ny]=0;
                res=min(res,self(self,nx-dx[i],ny-dy[i],d+1));
                S[nx][ny]=1;
            }
        }
        return res;
    };
    int ans=dfs(dfs,sx,sy,0);
    cout << (ans<=10?ans:-1) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w,h;
    while(cin >> w >> h,w){
        solve(w,h);
    }
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

void solve()
{
    int k;
    cin >> k;
    int x = 0;
    for (int i = 1; i <= k; ++i) {
        x = x * 10 + 7;
        x %= k;
        if (x == 0) {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    double d,t,s,ans;
    cin >> d >> t >> s;
    if((double)(d/t)<=s)cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 3736
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

h,w,n = na()
sh,sw = na()
s = ns()
t = ns()

iit = [sw,sh,h-sh+1,w-sw+1]

#ludr
tshi = [0,0,0,0]
aoki = [0,0,0,0]

for i in range(n):
    if s[i] == 'L':
        tshi[0] += 1
    if s[i] == 'U':
        tshi[1] += 1
    if s[i] == 'D':
        tshi[2] += 1
    if s[i] == 'R':
        tshi[3] += 1
    for j in range(4):
        if tshi[j] >= iit[j]+aoki[3-j]:
            print('NO')
            exit()
    if t[i] == 'L':
        aoki[0] += 1
    if t[i] == 'U':
        aoki[1] += 1
    if t[i] == 'D':
        aoki[2] += 1
    if t[i] == 'R':
        aoki[3] += 1
    for j in range(4):
        if aoki[j] >= iit[j]+tshi[3-j]:
            aoki[j] -= 1

print('YES')

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

int main(){
  string S;
  cin>>S;
  int N=S.size();
  map<char, int> trip;
  int tate=0;
  int yoko=0;
  for(int i=0; i<N; i++){
    trip[S.at(i)]=1;
  }
  if(trip.count('N')) tate++;
  if(trip.count('S')) tate++;;
  if(trip.count('E')) yoko++;
  if(trip.count('W')) yoko++;
  
  if(tate%2==0 && yoko%2==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main() {
  int h, w, K;
  cin >> h >> w >> K;
  vector<string> cake(h);
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    cake[i] = s;
  }

  vector<vector<int>> ans(h, vector<int>(w));

  int cake_num = 1;
  int no_cake_line = 0;
  string no_cake = string(w, '.');

  for (int i = 0; i < h; i++) {
    if (cake[i] == no_cake) {
      no_cake_line++;
      continue;
    }

    bool appear = false;
    for (int j = 0; j < w; j++) {
      if (cake[i][j] == '#') {
        if (appear) {
          cake_num++;
        }
        else {
          appear = true;
        }
      }
      for (int k = 0; k <= no_cake_line; k++) {
        ans[i - k][j] = cake_num;
      }
    }
    cake_num++;
    no_cake_line = 0;
  }

  if (no_cake_line) {
    for (int i = 0; i < h; i++) {
      if (ans[i][0] == 0) {
        for (int j = i; j < h; j++) {
          for (int k = 0; k < w; k++) {
            ans[j][k] = ans[j-1][k];
          }
        }
        break;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ans[i][j];
      if (j != w - 1) cout << " ";
      else cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1280
import math
A, B, H, M = map(int, input().split())

p = 0
o = 0
for i in range(1, H+1):
    p += 30
for q in range(1, M+1):
    o += 6
y = M * 0.5
p = p + y
C = p - o

H = abs(o - p)
total = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(math.radians(C)))
print(total)



Measured memory_bytes: 9500
#include <iostream>
#include <string.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long
#define ii pair < int, int >
#define iii pair < int, ii >
#define INF 987654321
#define LINF 987654321987654321

ll arr[85];

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

	for (ll i = 1; i <= n; i++)
		cin >> arr[i];
	arr[n + 1] = 0;

	ll mon = 1000;
	ll item = 0;

	for (ll i = 1; i <= n; i++)
	{
		// sell all
		mon += item * arr[i];
		item = 0;

		// next day expensive, buy all
		ll buyable = mon / arr[i];

		if (arr[i] < arr[i + 1])
		{
			mon %= arr[i];
			item = buyable;
		}
	}

	cout << mon << endl;
}

Measured memory_bytes: 3192
#include<iostream>
using namespace std;
using ull = unsigned long long;

ull K;

ull calcSunuke(ull n) {
  ull sunuke = 0;
  while (n != 0) {
    sunuke += n % 10;
    n /= 10;
  }
  return sunuke;
}

bool check(ull n, ull base) {
  return n * calcSunuke(n + base) <= calcSunuke(n) * (n + base);
}

int main() {
  scanf("%llu", &K);

  ull c = 0;
  ull n = 0;
  ull base = 1;

  while (1) {
    if (K <= c) break;
    
    if (!check(n + base, base)) base *= 10;

    n += base;
    printf("%llu\n", n);
    ++c;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int a; //出席番号
	int b; //登校順番
} order;

int compare_order_b(const void *p, const void *q) {
    return ((order*)p)->b - ((order*)q)->b;
}

int main() {
	int N;
	scanf("%d",&N);
	order A[N];
	for (int i = 0; i < N; i++) {
		scanf("%d",&A[i].b);
		A[i].a = i+1;
	}
	qsort(A, N, sizeof(order), compare_order_b);
	for (int i = 0; i < N; i++) {
		printf("%d ",A[i].a);
	}
	printf("\n");
	return 0;
}

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

int main() {
    long long int N;
    cin >> N;
    long long int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    long long int min_val = min(A, min(B, min(C, min(D, E))));
    long long int res = ceil(N*1.0 / min_val) + 4;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = A*X+B*Y
ans = min(max(X,Y)*C*2,ans)
if X > Y:
    ans = min(Y*C*2+(X-Y)*A, ans)
else:
    ans = min(X*C*2+(Y-X)*B, ans)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 100005
using namespace std;
const int mod=3;
char A[N],B[N];
int sa[N],sb[N];
int main(){
	scanf("%s",A+1);
	scanf("%s",B+1);
	for(int i=1,len=strlen(A+1);i<=len;i++) sa[i]=sa[i-1]+(A[i]=='A'? 1:2);
	for(int i=1,len=strlen(B+1);i<=len;i++) sb[i]=sb[i-1]+(B[i]=='A'? 1:2);
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int l1,r1,l2,r2;
		scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
		puts((sa[r1]-sa[l1-1]-sb[r2]+sb[l2-1])%3==0? "YES":"NO");
	}
	return 0;
} 

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
// typename alias
template <class T> using vec = vector<T>;
template <class T, class U> using vep = vec<pair<T,U> >;
template <class T> using PQ = priority_queue<T>;
using ll = long long;
using vll = vec<ll>;
using pll = pair<ll, ll>;
using vpll = vec<pll>;
using str = string;
// あくまのちから
//#define int ll

// const
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;
static const double PI = 3.14159265358979323846;

// accelerate stdin, stdout
#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
// repeat macro
#define FOR(i, a, b) for(ll (i)=(a);(i)<=(b);i++)
#define rFOR(i, a, b) for(ll (i)=(b);(i)>=(a);i--)
#define REP(i, n) for(ll i=0;i<n;i++)
// vector macro
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort(WHOLE(v))
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse(WHOLE(v))
#define FOLDL(src, dst, lambda) partial_sum(WHOLE(src), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum(WHOLE(src), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate(WHOLE(v), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

// io helper
template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}
template <typename T>istream& operator>>(istream &is, vec<T> &v) {for(auto &a:v) is >> a; return is;}
template <typename T>ostream& operator<<(ostream &os, vec<T> &v) {os << "[";REP(i, v.size() - 1) os << v[i] <<", "; os << v[v.size()-1]<<"]";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")";return os;}
template <typename T, typename U>ostream& operator<<(ostream &os, map<T, U> &mp) {os << "{ ";for(auto &p:mp) os << p.first << ": " << p.second << ", "; os << "}";return os;}

void solve() {
    ll n, m;
    while(1) {
        cin >> n >> m;
        if(n == 0 && m == 0) {
            break;
        }
        out(min(n,m), max(n,m));
    }
}

signed main() {
    fast_io;
    cout << setprecision(20) << fixed;
    solve();
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;



int main(){

    int n, k;
    cin >> n >> k;

    int ans = 0;
    while(n > 0){
        n = int(n/k);
        ans += 1;
    }

    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC081_C();
        }

        static void ABC081_C()
        {
            var NK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var balls = new int[N + 1];
            for (var i = 0; i < N; i++)
                balls[Ai[i]] += 1;

            var list = balls.Where(x => x > 0).OrderBy(x => x).ToArray();
            var count = 0;
            var k = 0;
            var listCount = list.Count(x => x > 0);
            while (listCount > K)
            {
                list[k]--;
                count++;
                if (list[k] < 1)
                {
                    k++;
                    listCount--;
                }
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 34384