akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        if (i & 1) {
            res -= A[i];
        } else {
            res += A[i];
        }
    }

    cout << res << '\n';

    return 0;
}

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

vector<vector<int>> graph(100001,vector<int>());

int main(){
  int n;cin >> n;
  long long s = 0;
  long long a[n];rep{
    cin >> a[i];
    s += a[i];
  }
  long long x[n+1];
  x[0] = s;
  int i = 1;
  while(i<n){
    x[0] -= 2*a[i]; i+=2;
  }
  for(int i = 1;i<n;i++){
    x[i] = 2*a[i-1]-x[i-1];
  }
  for(int i = 0;i<n;i++){
    cout << x[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 5248
//long time no ac
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";


#define     SPEED     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	ll          long long int
#define 	pb          push_back
#define 	pii         pair<int,int>
#define 	vi          vector<int>
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	hell        1000000007
#define 	rep(i,n)    for(i=0;i<n;i++)
#define 	repe(i,a,b) for(i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search
#define 	mp          make_pair

ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2);
	if(b%2==0)
		return((c%hell)*(c%hell))%hell;
	return ((((c%hell)*(c%hell))%hell)*(a%hell))%hell;
}

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



int main()
{
	SPEED;
	ll n,k,t,c=0,i,j,m,cs=0;
	t=1;

	//cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m>>k;
		// n=s.length();
		// ll a[n];
		
		
		cout<<min(m,k)<<" "<<max(c,m+k-n);
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#import <Foundation/Foundation.h>
int main(int argc, char **argv) {
  	NSInteger N, H;
  	scanf("%ld %ld", &H, &N);
  	int i = 0;
  	NSInteger remained = H;
  	BOOL result = NO;
  	for (i=0;i<N;i++) {
      NSInteger v;
      scanf("%ld", &v);
      H -= v;
      if (H <= 0) {
        result = YES;
        break;
      }
    }
  	printf("%s", result ? "Yes" : "No");
	return 0;
}

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

static const int MAX = 100;
#define INF 2000000000000ll
int V, E;
long long dp[MAX][MAX];

void Warshall_Floyd()
{
	for (int k = 0; k < V; k++)
	{
		for (int i = 0; i < V; i++)
		{
			for (int j = 0; j < V; j++)
			{
				if (dp[i][k] == INF||dp[k][j]==INF)
				{
					continue;
				}

				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
}

int main()
{
	cin >> V >> E;
	for (int i = 0; i < V; i++)
	{
		for (int j = 0; j < V; j++)
		{
			if (i == j)
			{
				dp[i][j] = 0;
			}
			else
			{
				dp[i][j] = INF;
			}

		}
	}
	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		cin >> s >> t >> d;
		dp[s][t] = d;
	}
	Warshall_Floyd();

	bool minus = false;
	for (int i = 0; i < V; i++)
	{
		if (dp[i][i] < 0)
		{
			minus = true;
		}
	}

	if (minus)
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
	else
	{
		for (int i = 0; i < V; i++)
		{
			for (int j = 0; j < V; j++)
			{
				if (j != 0)
				{
					cout << " ";
				}
				if (dp[i][j] == INF)
				{
					cout << "INF";
				}
				else
				{
					cout << dp[i][j];
				}
			}
			cout << endl;
		}
	}
	return 0;


}



Measured memory_bytes: 3168
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    int g = 0;
    for (auto &ai: a) g = gcd(g, abs(ai - k));
    cout << g << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>

using namespace std;

#define PRIME 998244353
template<typename T1, typename T2>
constexpr auto ADD(T1 i, T2  n) { return (i % PRIME + n % PRIME) % PRIME; }
template<typename T1, typename T2>
constexpr auto SUB(T1 i, T2  n) { return (PRIME + i % PRIME - n % PRIME) % PRIME; }
template<typename T1, typename T2>
constexpr auto MUL(T1 i, T2  n) { return ((i % PRIME) * (n % PRIME) )% PRIME; }

#define ll long long

int main() {
	int n, s; cin >> n >> s;
	int a[3001] = {};
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	//1: a[i], 2: s[i]
	int dp[3002][3002] = {1};

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

		for (int _s = 0; _s <= s; _s++) {
			dp[i][_s] = MUL(dp[i - 1][_s], 2);
		}

		for (int _s = a[i]; _s <= s; _s++) {
			dp[i][_s] = ADD(dp[i][_s], dp[i - 1][_s - a[i]]);
		}

		cout << endl;
	}

	cout << dp[n][s] << endl;

	return 0;
}

Measured memory_bytes: 38856
A, B, C, K = [int(x) for x in input().strip().split(" ")]

S = 0
k = K

# A
S += 1 * min(A, k)
k = max(k - A, 0)

k = max(k - B, 0)

S -= 1 * min(C, k)

print(S)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define ll long long
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void prime_factorize(ll N,map<ll,ll> &res) {
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res[a]=ex;
    }

    // 最後に残った数について
    if (N != 1) res[N]=1;
}


int main() {
    COMinit();
    ll n,m; cin >> n >> m;
    map<ll,ll> mp;
    prime_factorize(m,mp);
    ll ans=1;
    for(auto itr=mp.begin();itr!=mp.end();++itr){
        ans *= COM(itr->second + n -1,itr->second);
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 12160
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    s = str(n)
    d = len(s)
    maxv = 0
    sumv = int(s[0])+(d-1)*9
    sumc = s[0]+'9'*(d-1)
    if int(sumc) > n:
        sumv -= 1
    print(sumv)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;

int main(){
   string s; cin >> s;
   ll n = s.size();
   vector<ll> left_count(n + 1);
   vector<ll> right_count(n + 1);
   left_count[0] = 0;
   right_count[n] = 0;

   _rep(i,1,n + 1){
      if(s[i - 1] == '<') left_count[i] = left_count[i - 1] + 1;
      else left_count[i] = 0;
   }
   _rep(i,1,n + 1){
      if(s[n - i] == '>') right_count[n - i] = right_count[(n + 1) - i] + 1;
      else right_count[n - i] = 0;
   }

   ll ans = 0;
   rep(i,n + 1) ans += max(left_count[i],right_count[i]);
   cout << ans << endl;
}


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

using namespace std;

int main(){
int a, b, c, d ,sum,min,sec;

cin >> a >> b >> c >> d;

sum = a + b + c + d;

min = sum / 60;

sec = sum % 60;

cout << min << endl;
 cout << sec  << endl;

  return 0;
}


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

int main(void)
{
    int X;
    cin >> X;

    vector<int> dp(100001,0);

    dp[0]=1;
    for(int i=1;i<=X;++i)
    {
        if (i>=100 && dp[i-100]==1) dp[i]=1;
        if (i>=101 && dp[i-101]==1) dp[i]=1;
        if (i>=102 && dp[i-102]==1) dp[i]=1;
        if (i>=103 && dp[i-103]==1) dp[i]=1;
        if (i>=104 && dp[i-104]==1) dp[i]=1;
        if (i>=105 && dp[i-105]==1) dp[i]=1;
    }

    cout << dp[X] << endl;

    return 0;
}


Measured memory_bytes: 640
////////////
//||||| ||//
//   || ||//
//||||||||//
//|| ||   //
//|| |||||//
////////////
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   MAX 1000000
#define   eps 1e-8
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_multiset;
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
//S.order_of_key(x)[Give me the position of x]
//S.find_by_order(x)[Give me the x th element in set]
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll a, b, c = 0, d, e, f = 0, g, h, i, j, k, m, n, o, p, s, t, v, w, x = 0, y, z, l;
    ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = 0;
    ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
    string str, str1, str2, str3 = "", str4 = "";
    ll ide = 0, idx = 0, Q;
    
scll(n);
scll(x);
scll(t);
cout<<(ll)ceil(n/(1.0*x))*t<<'\n';
    return 0;
}

Measured memory_bytes: 3812
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
using namespace std;

typedef unsigned long long ull;

void Factorize(int n,vector<int> &result){
	int amari;
	int i=2;
	int N=n;
	bool flag=true;
	while(i<=sqrt(N)){
		amari=n%i;
		if(amari){
			i++;
			flag=true;
		}else{
			n=n/i;
			if(flag){
				result.push_back(i);
				flag=false;
			}
		}
	}
	if(n!=1){
		result.push_back(n);
	}
	return;
}

int main(){
	int n;
	cin >> n;
	vector<int> result;
	Factorize(n,result);
	int s=result.size();
	ull A=1;
	ull B=1;
	for(int i=0;i<s;i++){
		A*=(result[i]-1);
		B*=result[i];
	}
	cout << n*A/B << endl;
	return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;


int main() {
	long long int x, y;
	cin >> x >> y;
	long long int count = 0;
	while (y >= x) {
		x *= 2;
		count++;
	}
	cout << count << endl;

	return 0;
}



Measured memory_bytes: 256
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#ifdef local
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(...) qqbx(#__VA_ARGS__,  __VA_ARGS__)
template <typename H, typename ...T> constexpr void qqbx(const char *s, const H &h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, args...); // C++ 17!
}
#else
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) (lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 200025, INF = 1e18, MOD = 1000000007, K = 357, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + ((x<0 ^ m>0) && (x%m)); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << 100 << ' ' << 100 << '\n';
    --a, --b;
    for(int i = 0; i < 50; i++) {
        for(int j = 0; j < 100; j++) {
            if(a > 0 && (i&1) && (j&1))
                cout << '.', --a;
            else
                cout << '#';
        }
        cout << '\n';
    }
    for(int i = 0; i < 50; i++) {
        for(int j = 0; j < 100; j++) {
            if(b > 0 && (i&1) && (j&1))
                cout << '#', --b;
            else
                cout << '.';
        }
        cout << '\n';
    }
}



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

const int ALPHABET = 26; // アルファベットの文字数
int main() {
	string s;
	cin >> s;
	bool alphabet[ALPHABET];
	for (int i = 0;i < ALPHABET;++ i) alphabet[i] = false;
	for (int i = 0, l = s.size();i < l;++ i) alphabet[s[i] - 'A'] = true;
	if (alphabet['N' - 'A'] ^ alphabet['S' - 'A'] || alphabet['W' - 'A'] ^ alphabet['E' - 'A']) cout << "No";
	else cout << "Yes";
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、NとSが両方あるなら、Sの時にはNの個数と同等だけ、Nの時にはSの個数と同等だけ移動すれば移動距離NS-NS=0で戻ってくる
WとEも同様なので、要はどちらか片方だけが出てこないかを調べれば良い
*/

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<set>

using namespace std;

int main()

{
   set<char>joy;

   string s;

   cin>>s;

   for(int i=0;i<s.size();i++)

   {
       joy.insert(s[i]);

   }

   if(joy.size()==s.size())

   {
       cout<<"yes"<<endl;
   }

   else

   {

    cout<<"no"<<endl;

   }

   return 0;

}


Measured memory_bytes: 256
/*
{By GWj
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
const int MOD=998244353;
void add(LL & A,LL B){
	B%=MOD;
	A+=B;
	if(A>=MOD) A-=MOD;
}
void miu(LL & A,LL B){
	A-=B;
	if(A<0) A+=MOD;
}
mp seg[11];
LL n,k,dp[200000+20],sum[200000+20];
int main(){
	fastio;
	R2(n,k);
	rb(i,1,k)
		R2(seg[i].FIR,seg[i].SEC);
	dp[1]=1;	
	sum[1]=1;
	rb(j,2,n)
		rb(i,1,k){	
			{
				add(dp[j],sum[max(0,j-seg[i].FIR)]-sum[max(0,j-seg[i].SEC-1)]+MOD);
			}
		sum[j]=sum[j-1]+dp[j];
		sum[j]%=MOD;
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 6680
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line
}

fn main() {
    let _ = get_line();
    let nums: Vec<i64> = get_line().trim()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    println!("{} {} {}",
        nums.iter().min().unwrap(),
        nums.iter().max().unwrap(),
        nums.iter().fold(0, |sum, a| sum + a))
}



Measured memory_bytes: 5036
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int MAX = 100001;
const int NIL = -1;
struct Node {
	int parent, left, right, depth;
};
struct Node T[MAX];

void setDepth(int u, int p)
{
	T[u].depth = p;
	if (T[u].right != NIL)
		setDepth(T[u].right, p);
	if (T[u].left != NIL)
		setDepth(T[u].left, p + 1);
}

void printChildren(int u)
{
	int c = T[u].left;
	cout << "[";
	while (c != NIL) {
		cout << c;
		c = T[c].right;
		if (c != NIL)
			cout << ", ";
		else
			break;
	}
	cout << "]";
}

int main(void)
{
	int n, node, degree, child;
	vector<int> children;
	cin >> n;
	for (int i = 0; i < n; i++) {
		T[i].parent = T[i].left = T[i].right = NIL;
	}
	for (int i = 0; i < n; i++) {
		cin >> node >> degree;
		for (int j = 0; j < degree; j++) {
			cin >> child;
			children.push_back(child);
		}
		if (degree)
			T[node].left = children[0];
		for (int j = 0; j < degree - 1; j++) {
			T[children[j]].right = children[j + 1];
		}
		for (int j = 0; j < degree; j++)
			T[children[j]].parent = node;
		children.clear();
	}
	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL) {
			setDepth(i, 0);
			break;
		}
	}
	for (int i = 0; i < n; i++) {
		cout << "node " << i << ": parent = " << T[i].parent << ", depth = " << T[i].depth << ", ";
		if (T[i].parent == NIL)
			cout << "root, ";
		else if (T[i].left == NIL)
			cout << "leaf, ";
		else
			cout << "internal node, ";
		printChildren(i);
		cout << endl;
	}
	return 0;
}



Measured memory_bytes: 8040
from functools import lru_cache

N, K = [int(i) for i in input().split()]

P = 10**9 + 7


@lru_cache(None)
def modinv(x):
    return pow(x, P-2, P)


@lru_cache(None)
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n-1)


for i in range(2000):
    factorial(i)


def ncr(n, r):
    if r > n:
        return 0
    if n == 0:
        return 1
    a = factorial(n) * modinv(factorial(r) * factorial(n-r))
    return a % P


def m():
    for i in range(1, K+1):
        blue = ncr(K-1, i-1)
        red = ncr(N-K+1, i)
        print((blue * red) % P)


m()


Measured memory_bytes: 51056
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,cnt,size[100005];
ll dis[100005];
struct node{
	ll d;
	int id;
}a[100005];
struct edge{
	int x,y;
}e[100005];

int cmp(node u,node v){
	return u.d<v.d;
}

int cmp1(edge u,edge v){
	return u.x<v.x||(u.x==v.x&&u.y<v.y);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i].d),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) size[i]=1;
	for(int i=n;i>=2;i--){
		ll o=a[i].d+1ll*(2*size[a[i].id]-n);
		int l=1,r=i-1,mid,p=i;
		while(l<=r){
			mid=(l+r)/2;
			if(a[mid].d>=o) p=min(p,mid),r=mid-1;
			else l=mid+1;
		}
		if(p==i||a[p].d!=o){puts("-1");return 0;}
		size[a[p].id]+=size[a[i].id];
		e[++cnt]=(edge){a[p].id,a[i].id};
		if(e[cnt].x>e[cnt].y) swap(e[cnt].x,e[cnt].y);
		dis[a[p].id]+=dis[a[i].id]+1ll*size[a[i].id];
	}
	if(dis[a[1].id]!=a[1].d){puts("-1");return 0;}
	sort(e+1,e+cnt+1,cmp1);
	for(int i=1;i<=cnt;i++) printf("%d %d\n",e[i].x,e[i].y); 

	return 0; 
} 

Measured memory_bytes: 4864
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
	while(cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;


}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 32968
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#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>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,x;
  cin>>a>>b>>c>>x;
  ll ans = 0;
  repl(i,0,a+1)repl(j,0,b+1)repl(k,0,c+1) if(500*i+100*j+50*k == x) ans++;
  cout<<ans<<endl;

}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll x;
    cin >> x;
    ll n500 = x/500;
    ll n5 = (x - n500 * 500)/5;

    //cout << n500 << ' ' << n5 << endl;

    cout << n500 * 1000 + n5 * 5 << endl;

    return 0;
}


Measured memory_bytes: 256
n,k,*v=map(int,open(0).read().split());a=0
for i in range(min(n,k)+1):
	for j in range(i+1):
		s=sorted(v[:j]+v[n-i+j:])
		a=max(a,sum(s[min(sum(x<0for x in s),k-i):]))
print(a)

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

using namespace std;

// ?´?????????????????§????
struct UnionFind
{
  // par[i]????????????i????±?????????¨??????????????????i == par[i]?????¨???????????????i?????¨?????????????????§??????
  vector<long long int> par;
  // sizes[i]???????????????i?????¨?????????????????????????????°???i?????????????????§????????´???????????????????????¨??????
  vector<long long int> sizes;

  UnionFind(long long int n) : par(n), sizes(n, 1) {
    // ???????????¨???????????????i?????°?????????i????????¨??????????????¨???????????????
    rep(i,n) par[i] = i;
  }

  // ?????????x????±?????????¨???????????????
  long long int find(long long int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // ????????????????????????????????°???????????????????????¢???
  }

  // 2???????????????x, y????±?????????¨??????????????????
  void unite(long long int x, long long int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    par[y] = x;
    sizes[x] += sizes[y];
  }

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

  int size(long long int x) {
    return sizes[find(x)];
  }
};

int main(){
	long long int n,q;
	while(cin >> n >> q,n||q){
		int a[100002];
		a[1] = 1;
		for(long long int i=2;i<=n;i++){
			cin >> a[i];
		}
		set<long long int> roots;
		roots.insert(1);
		vector<pair<char,long long int>> queries;
		for(long long int i=0;i<q;i++){
			char c;
			long long int v;
			cin >> c >> v;
			if(c == 'M' && roots.find(v) != roots.end()) continue;
			if(c == 'M') roots.insert(v);
			queries.emplace_back(make_pair(c,v));
		}
		UnionFind uf(n+2);
		for(long long int i=2;i<=n;i++){
			if(roots.find(i) == roots.end()){
				//cout << a[i] << " - " << i << endl;
				uf.unite(a[i],i);
			}
		}
		long long int sum = 0;
		for(long long int i=(long long int)queries.size()-1;i>=0;i--){
			//cout << queries[i].first << " " << queries[i].second << endl;
			if(queries[i].first == 'M'){
				uf.unite(a[queries[i].second],queries[i].second);
			}
			if(queries[i].first == 'Q'){
				//cout << uf.find(queries[i].second) << endl;
				sum += uf.find(queries[i].second);
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 8636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    r = 0
    for i in range(a,b+1):
        s = str(i)
        if s == s[::-1]:
            r += 1

    return r


print(main())




Measured memory_bytes: 7748
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e9 + 7, INF = 1e9;


int main(void) {
    int n, l, ans, i;

    scanf("%d%d", &n, &l);

    ans = 0;
    if (l > 0) {
        for (i = 1; i < n; i++) {
            ans += l + i;
        }
    }
    else {
        for (i = 0; i < n; i++) {
            ans += l + i;
        }
        if (n + l - 1 < 0) ans -= n + l - 1;
    }

    printf("%d\n", ans);

    return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> p(m);
  rep(i,m){
    cin >> p[i].second >> p[i].first;
  }
  sort(p.begin(),p.end());
  int ans=0;
  int now=0;
  for(pair<int,int> q:p){
    if(q.second>=now) {
      ans++;
      now=q.first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc139/abc139_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S, T;
  cin >> S >> T;

  ll ans = 0;
  rep(i, S.size()) {
    if (S[i] == T[i]) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3596
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;

void main()
{
    Input input = void;
    parseInput(input, stdin);
    auto result = main2(&input);
    writeln(result);
}

auto main2(Input* input)
{
	foreach (i, c; input.s)
	{
		if (i & 1)
		{
			if (c == 'L' || c == 'U' || c == 'D')
			{

			}
			else
				return "No";
		}
		else
		{
			if (c == 'R' || c == 'U' || c == 'D')
			{

			}
			else
				return "No";
		}
	}
    return "Yes";
}

unittest // example1
{
    string example =
`RUDLUDR`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == "Yes");
}

unittest // example2
{
    string example =
`UUUUUUUUUUUUUUU`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == "Yes");
}

unittest // example3
{
    string example =
`DULL`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == "No");
}

struct Input
{
	string s;
}

void parseInput(T)(out Input input, T file)
{
    with (file) with (input)
    {
	    s = readln().strip();
    }
}

void parseExample(out Input input, string example)
{
    struct Adapter
    {
        import std.string;
        string[] _lines;
        this(string input) { _lines = input.splitLines(); }

        string readln()
        {
            auto line = _lines[0];
            _lines = _lines[1..$];
            return line;
        }
    }
    Adapter a = Adapter(example);
    parseInput(input, a);
}


Measured memory_bytes: 256
n, m = map(int, input().split())                    
route_lists = [input().split() for i in range(m)]   
new_lists = []                                      
for i in route_lists:                               
  for j in range(2):                                
    new_lists.append(i[j])                          
                                                    
new_lists.sort()                                    
for i in range(1, n+1, 1):                          
  print(new_lists.count(str(i)))                    

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	ll ret=0;
	int pre=0;
	
	FOR(i,N) {
		cin>>x;
		if(pre==0) {
			ret += x-1;
			pre=1;
		}
		else if(x==pre+1) {
			pre++;
		}
		else if(x>pre+1) {
			ret += (x-1)/(pre+1);
		}
	}
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
int main(){
    int n,t[MAX],x[MAX],y[MAX];
    cin>>n;
    t[0]=x[0]=y[0]=0;
    rep(i,n)cin>>t[i+1]>>x[i+1]>>y[i+1];
    rep(i,n){
        int dt=t[i+1]-t[i];
        int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dt<dist || dt%2!=dist%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1408
// ALDS1_9_B Maximum Heap
#include <iostream>
#include <algorithm>
#include <vector>
#define NIL -2000000000-1
bool debug = false;

std::vector<int> heap;

void MaxHeapify(int num) {
    int largest = num;
    int L_child = num*2, R_child = num*2+1;
    if (debug) std::cout << "L_child = " << L_child << ", " << "R_child = " << R_child << "\n";
    
    if (L_child <= heap.size()-1) {
        if (heap.at(largest) < heap.at(L_child)) {
            largest = L_child;
        }
    }
    if (R_child <= heap.size()-1) {
        if (heap.at(largest) < heap.at(R_child)) {
            largest = R_child;
        }     
    }
    if (debug) std::cout << "largest = " << largest << "\n";
    if (heap.at(largest) != heap.at(num)) {
        std::swap(heap.at(largest), heap.at(num));
        MaxHeapify(largest);
    }
}

void BuildMaxHeap() {
    /* If i > heap.size()/2, then heap.at(i) does not have any children. */
    for (int i=heap.size()/2; i>=1; i--) {
        if (debug) std::cout << "heap start point = " << i << "\n";
        MaxHeapify(i);
    }
}

int main() {
    int total; std::cin >> total;

    heap.resize(total+1);
    for (int i=1; i<heap.size(); i++) {
        std::cin >> heap.at(i);
    }
    if (debug) std::cout << "heap.size() = " << heap.size() << "\n";

    BuildMaxHeap();

    for (int i=1; i<heap.size(); i++) {
        std::cout << " " << heap.at(i);
    }
    std::cout << "\n";
}


Measured memory_bytes: 4592
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  int n = N, sum = 0;
  while (n != 0) {
    sum += n % 10;
    n /= 10;
  }
  N % sum == 0 ? cout << "Yes" << endl : cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main(){
    double A,B;
    cin>>A>>B;
    for(double i=0;i<2000;i++){
        if(floor(i*0.08)==A&&floor(i*0.1)==B){
            cout<<(int)(i);
            return 0;
        }
    }
    cout<<-1;
 return 0;   
}

Measured memory_bytes: 256
n,m = map(int,input().split())
li = [0]*m
for i in range(m):
  li[i] = list(map(int,input().split()))
  li[i].append(i)
  li[i].append(0)
li = sorted(li,key=lambda x:x[1])
li = sorted(li,key=lambda x:x[0])
pre = 0
conti = 0
for i in range(m):
  if pre != li[i][0]:
    pre = li[i][0]
    conti = 0
    li[i][3] = str(pre).zfill(6) + str(1).zfill(6)
  else:
    conti += 1
    li[i][3] = str(pre).zfill(6) + str(conti+1).zfill(6)
li = sorted(li,key = lambda x:x[2])
for i in range(m):
  print(li[i][3])

Measured memory_bytes: 39848
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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



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

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

    set <string> r;
    for(int i = 1; i <= n; i++) {
        string fruit;
        cin >> fruit;
        r.insert(fruit);
    }

    cout << r.size();

    return 0;
}


Measured memory_bytes: 19124
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int l=0, d=0, m=0, L=0, D=0, M=0;
        for(int i=0; i < n; i++){
            int ho, mi, mm;
            scanf("%d:%d %d", &ho ,&mi, &mm);
            int diff = mm-mi+(mm-mi<0?60:0);
            int min = ho*60+mi;
            if(11*60 <= min && min <= 14*60+59){
                l++;
                if(diff <= 8) L++;
            }
            else if(18*60 <= min && min <= 20*60+59){
                d++;
                if(diff <= 8) D++;
            }
            else if(21*60 <= min || min <= 1*60+59){
                m++;
                if(diff <= 8) M++;
            }
        }
        string no = "no guest";
        cout << "lunch "; if(l==0) cout << no; else cout << L*100/l; cout << endl;
        cout << "dinner "; if(d==0) cout << no; else cout << D*100/d; cout << endl;
        cout << "midnight "; if(m==0) cout << no; else cout << M*100/m; cout << endl;
    }
}

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

#define ll long long

int main() {
    int t=1;
    //cin>>t;
    while(t--)
    {
        int x,y;
        cin>>x>>y;
        cout<<max(x+x-1,max(x+y,y+y-1));
        
    }
    return 0;
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;

main()
{
	ios_base::sync_with_stdio(false);
		cin.tie(NULL);
  ll n,m;
  cin>>n>>m;
  string x=to_string(n),y=to_string(m),ans1,ans2;
  for(int i=1;i<=m;i++)
    ans1+=x;
  for(int i=1;i<=n;i++)
    ans2+=y;
   // cout<<ans1<<sp<<ans2<<sp;
  if(ans1<=ans2)
    cout<<ans1;
  else
    cout<<ans2;
}
  
  

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

int k;

int dp[15][15],a[15],len;

int dfs(int pos,int pre,int lead,int limit){
    if(pos>len) return 1;
    if((!lead)&&(!limit)&&~dp[pos][pre]) return dp[pos][pre];
    int top=limit?a[len-pos+1]:9;
    int res=0;
    for(REG int i=0;i<=top;++i){
        if(abs(i-pre)>=2&&(!lead)) continue;
        if((!i)&&lead) res+=dfs(pos+1,i,1,(i==top)&&limit);
        else res+=dfs(pos+1,i,0,(i==top)&&limit);
    }
    if((!lead)&&(!limit)) dp[pos][pre]=res;
    return res;
}

inline int solve(long long n){
    len=0;
    while(n) a[++len]=n%10,n/=10;
    memset(dp,-1,sizeof dp);
    return dfs(1,1,1,1)-1;
}

inline void Work(){
    scanf("%d",&k);
    long long l=1,r=3300000000ll,mid,ans=1;
    while(l<=r){
        mid=(l+r)>>1;
        if(solve(mid)>=k) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld\n",ans);
    // getchar(),getchar();
}

int main(){Work();}

Measured memory_bytes: 256
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

typedef struct {
  int from, to, cost;
} edge;

int main(int argc, char **argv)
{

  int k;

  cin >> k;

  vector<vector<edge>> g(k);

  for (int i = 0; i < k; i++) {
    g[i].pb(edge{i, (i+1)%k, 1});
    g[i].pb(edge{i, (i*10)%k, 0});
  }

  auto cmp = [](edge a, edge b) { return a.cost > b.cost; };
  priority_queue<edge, vector<edge>, decltype(cmp)> pq(cmp);

  vector<int> ans(k);
  for (int i = 0; i < k; i++) {
    ans[i] = INT_MAX;
  }

  ans[1] = 0;
  for (int i = 0; i < sz(g[1]); i++) {
    pq.push(g[1][i]);
  }

  while (!pq.empty()) {
    edge e = pq.top(); pq.pop();
    if (ans[e.to] <= ans[e.from]+e.cost) continue;
    ans[e.to] = ans[e.from]+e.cost;
    for (int i = 0; i < sz(g[e.to]); i++) {
      pq.push(g[e.to][i]);
    }
  }

  cout << ans[0] + 1 << endl;

  return 0;
}




Measured memory_bytes: 10608
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 100005;
const int INF = 1e9;
const int MOD = 1e9 + 7;

class TaskC {
private:
	int mul(int a, int b) {
		return (ll) a * b % MOD;
	}

	int get(int base, int rep) {
		int ans = 1;
		while(rep--) {
			ans = mul(ans, base);
		}
		return ans;
	}


public:
	void solveOne(int it){
		int n;
		cin >> n;
		ll ans = ( (get(10, n) - get(9, n)) % MOD + MOD ) % MOD;
		ans = mul(ans, 2);
		ll ans2 = ( (get(10, n) - get(8, n)) % MOD + MOD ) % MOD;

		cout << ((ans - ans2) % MOD + MOD ) % MOD << endl;

	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 3648
package main

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

func main() {
	var n int
	fmt.Scanf("%d", &n)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var a []int
	for i := 0; i < 2*n; i++ {
		a = append(a, nextInt(sc))
	}

	var num int

	for i := 0; i < n; i++ {
		_, v1 := popMin(a)
		_, v2 := popMin(a)
		if v1 < v2 {
			num += v1
		} else {
			num += v2
		}
	}

	fmt.Println(num)
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func popMin(a []int) (int, int) {
	var minI, minV int = 0, math.MaxInt64
	for i, v := range a {
		if minV > v {
			minI = i
			minV = v
		}
	}
	a[minI] = math.MaxInt64
	return minI, minV
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
typedef long long ll;

using namespace std;
int A, B, K = 0;
vector<int > a;



int main(){

    cin >> A >> B >> K;
    vector<int > t;

    int temp;
    if(A > B){
        temp = A;
        A = B;
        B = temp;
    }

    for(int i = 1; i <= A; i++){
        if(B % i == 0 && A % i == 0){
            t.push_back(i);
            //cout << i << endl;
        }
    }

    sort(t.rbegin(), t.rend());

    cout << t[K-1] << endl;
    
    
    


}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int M = 0, m = 1000000000;
  for(int i = 0; i < n; i++){
  	cin >> a.at(i);
    M = max(M, a.at(i));
    m = min(m, a.at(i));
  }
  
  cout << M - m << endl;
}


Measured memory_bytes: 256