akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define iso ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define clr(x) memset((x), 0, sizeof(x))
#define mod 998244353
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_tree;*/


ll arr[200005],ans[200005];

int main()
{
    iso;
    int i,n,k,j;
    cin>>n>>k;
    for(i=0;i<n;i++)
        cin>>arr[i];
    ans[0]=0;

    for(i=1;i<n;i++)
    {
        ll mini=1e10;
        for(j=1;j<=k;j++)
        {
            if(i-j>=0&&mini>(abs(arr[i]-arr[i-j])+ans[i-j]))
            {
                mini=abs(arr[i]-arr[i-j])+ans[i-j];
            }
        }
        ans[i]=mini;
    }
    cout<<ans[n-1];

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    string s1, s2;
    
    cin >> s1;
    cin >> s2;
    for(int i = 0; i < s1.size(); i++){
        bool flag = true;
        for(int j = 0; j < s2.size(); j++)
            if(s1[j] != s2[(i+j)%s2.size()])
                flag = false;
        
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"

using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
const int N = 2e5 + 10;
const ll inf = 1e18 + 10, mod = 1e9 + 7;

int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("lca_rmq.in", "r", stdin);
    //freopen("lca_rmq.out", "w", stdout);
    int n, k, a[N], ma;
    cin >> k >> n;
    for(int i = 1; i <= n; i++)cin >> a[i];
    sort(a + 1, a + 1 + n);
    ma = k - a[n] + a[1];
    for(int i = 2; i <= n; i++)
    {
        ma = max(ma, a[i] - a[i - 1]);
    }
    cout << k - ma;
}


Measured memory_bytes: 1024
#include <stdio.h>

int min, n, sum, a[100];

void solve(int i, int gon)
{
	int m;
	
	if (i == n - 1){
		m = gon * 2 - sum;
		
		if (m < 0){
			m *= -1;
		}
		if (min > m){
			min = m;
		}
		return;
	}
	
	solve(i + 1, gon + a[i]);
	solve(i + 1, gon);
}

int main(void)
{
	int i;
	
	while (1){
		
		sum = 0;
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf("%d", &a[i]);
			sum += a[i];
		}
		min = 200000000;
		solve (0, 0);
		
		printf("%d\n", min);
	}
	return (0);
}
		

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long l;
l h,w,n,i;
l k(l a,l b){for(i=0;i<a;i++)n=min(n,max(i*b,(b/2+(b%2==0?0:1))*(a-i))-min(i*b,(b/2)*(a-i)));}
int main(){cin>>h>>w,n=h%3==0||w%3==0?0:min(h,w),k(h,w),k(w,h),cout<<n;}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	string s; cin >> s;
	int ans = s.size();
	int c=0;
	rep(i,s.size())
	{
		if(s[i]=='S')
		{
			c++;
		}
		if(s[i]=='T'&&c>0)
		{
			ans-=2;
			c--;
		}

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

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

#include <string.h>

using namespace std;

#define MAX_D 100000
#define MAX_N 1000000
#define MAX_F 200

#define INF 100000000

int main()
{
	static int N[MAX_D], F[MAX_F], dp1[MAX_N], dp2[MAX_N];

	int c = 0;

	for (int i = 0; i < MAX_N; i++) { dp1[i] = INF; dp2[i] = INF; }

	while (true)
	{
		cin >> N[c];

		if (N[c] == 0) { break; }

		c++;
	}

	int max = *max_element(N, N + c);

	for (int i = 1; i < MAX_F; i++)
	{
		F[i] = i * (i + 1) * (i + 2) / 6;
	}

	dp1[0] = 0;
	dp2[0] = 0;

	for (int i = 1; i <= max; i++)
	{
		for (int j = 1; j < MAX_F; j++)
		{
			if (i < F[j])
			{
				goto Exit1;
			}
			else
			{
				if (dp1[i - F[j]] + 1 < dp1[i])
				{
					dp1[i] = dp1[i - F[j]] + 1;
				}
			}

		Exit1:;
		}
	}

	for (int i = 1; i <= max; i++)
	{
		for (int j = 1; j < MAX_F; j++)
		{
			if (F[j] % 2 == 1)
			{
				if (i < F[j])
				{
					goto Exit2;
				}
				else
				{
					if (dp2[i - F[j]] + 1 < dp2[i])
					{
						dp2[i] = dp2[i - F[j]] + 1;
					}
				}
			}

		Exit2:;
		}
	}

	for (int i = 0; i < c; i++)
	{
		cout << dp1[N[i]] << ' ' << dp2[N[i]] << endl;
	}

	return 0;
}

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

typedef long long ll;

int main() {
	int n; cin >> n;
	vector<ll>a(n), b(n), c(n);
	for (auto&& x : a)cin >> x;
	for (auto&& x : b)cin >> x;
	for (auto&& x : c)cin >> x;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		decltype(a)::iterator lowA = lower_bound(a.begin(), a.end(), b[i]);
		decltype(c)::iterator upC = upper_bound(c.begin(), c.end(), b[i]);
		ll aSum = lowA - a.begin(), cSum = c.end() - upC;
		ans += aSum * cSum;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main(void){
  int yen;
  int fivehun=0;
  int five=0;
  int happy;
  
  scanf("%d",&yen);
  
  fivehun=yen/500;
  yen%=500;
  
  five=yen/5;
  
  happy=fivehun*1000+five*5;
  
  printf("%d",happy);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int f[40][40];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int K = 38, N = 1407;
    // int K = 2, N = 3;
    cout << N << ' '<< K << endl;
    for(int i = 0; i < K-1; i++){
        for(int j = 0; j < K-1; j++){
            f[i][j] = K+1+i*(K-1)+j;
            // cout << f[i][j] << ' ';
        }
        // cout << endl;
    }
    for(int i = 0; i < K; i++){
        cout << 1 << ' ';
        for(int j = 1; j <= K-1;j++){
            cout << 1+i*(K-1)+j;
            if(j == K-1) cout << endl;
            else cout << ' ';
        }
    }
    
    for(int i = 1; i <= K-1; i++){
        for(int j = 0; j < K-1; j++){
            cout << i+1 << ' ';
            for(int k = 0; k < K-1; k++){
                cout << f[k][(j+i*k)%(K-1)];
                if(k+1 == K-1) cout << endl;
                else cout << ' ';
            }
        }
    }
}

Measured memory_bytes: 512
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
h,w=gsmi
s=h.times.map{gs.chars}

#dp[i行目][j列目]=最小操作回数
dp=ar2(h,w,0)
dp[0][0] = (s[0][0]=='#') ? 1 : 0

prev=s[0][0]
1.upto(w-1) do |j|
  add = (prev=='.'&&s[0][j]=='#') ? 1 : 0
  dp[0][j]=dp[0][j-1]+add
  prev=s[0][j]
end

prev=s[0][0]
1.upto(h-1) do |i|
  add = (prev=='.'&&s[i][0]=='#') ? 1 : 0
  dp[i][0]=dp[i-1][0]+add
  prev=s[i][0]
end

1.upto (h-1) do |i|
  1.upto(w-1) do |j|
    c1= dp[i][j-1] + (s[i][j-1]=='.'&&s[i][j]=='#' ? 1 : 0)
    c2= dp[i-1][j] + (s[i-1][j]=='.'&&s[i][j]=='#' ? 1 : 0)
    dp[i][j]=min(c1,c2)
  end
end
puts dp[h-1][w-1]

Measured memory_bytes: 2812
package main

import (
	"fmt"
	"sort"
)

func main() {
	N := readInt()

	Count, Max := map[string]int{}, 1
	for i := 0; i < N; i++ {
		s := readString()

		v, exists := Count[s]
		if exists {
			Count[s] = v + 1
			if Max < v+1 {
				Max = v + 1
			}
		} else {
			Count[s] = 1
		}
	}

	Keys, i := make([]string, len(Count)), 0
	for k := range Count {
		Keys[i] = k
		i++
	}

	sort.Strings(Keys)

	for _, k := range Keys {
		v := Count[k]
		if v == Max {
			fmt.Println(k)
		}
	}
}

func readInt() int {
	var v int
	fmt.Scan(&v)
	return v
}

func readString() string {
	var v string
	fmt.Scanln(&v)
	return v
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	ll n;
	cin >> n;
	pv(n*(n - 1) / 2);
	return(0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N, M; cin >> N;
		if (!N)break;
		cin >> M;
		int P, Q, R; cin >> P >> Q >> R;
		vector<pair<int, int>>cards(1, make_pair(1, N));
		for (int i = 0; i < M; ++i) {
			int x, y; cin >> x >> y;
			vector<pair<int, int>>a, b, c;
			int h = 0;
			int n = 0;
			for (; n < cards.size(); ++n) {
				auto acard(cards[n]);
				int nh = h + acard.second;
				if (nh > x) {
					a.push_back(make_pair(acard.first, x - h));
					if (nh > y) {
						b.push_back(make_pair(acard.first+(x-h), y-x));
						c.push_back(make_pair(acard.first +(y-h), nh - y));
					}
					else {
						b.push_back(make_pair(acard.first + (x - h), nh - x));
					}
					h = nh;
					n++;
					break;
				}
				else if (nh == x) {
					a.push_back(make_pair(acard.first, x - h));
					h = nh;
					n++;
					break;
				}
				else {
					a.push_back(acard);
					h = nh;
				}
			}
			for (; n < cards.size(); ++n) {
				if (h > y)break;
				auto acard(cards[n]);
				int nh = h + acard.second;
				if (nh > y) {
					b.push_back(make_pair(acard.first, y-h));
					c.push_back(make_pair(acard.first + y-h, nh - y));
					h = nh;
					n++;
					break;
				}
				else if (nh == y) {
					b.push_back(make_pair(acard.first, y - h));
					h = nh;
					n++;
					break;
				}
				else {
					b.push_back(acard);
					h = nh;
				}
			}
			for (; n < cards.size(); ++n) {
				auto acard(cards[n]);		
				c.push_back(acard);
			}
			vector<pair<int, int>>nextcards(c);
			nextcards.insert(nextcards.end(), b.begin(), b.end());
			nextcards.insert(nextcards.end(), a.begin(), a.end());
			for (int i = 0; i < nextcards.size(); ++i)assert(nextcards[i].first>0);
			cards = nextcards;
		}
		int h = 0 ;
		int ans = 0;
		for (int n = 0; n < cards.size(); ++n) {
			auto card(cards[n]);
			int nh = h + card.second;
			if (h < P&&nh >= P) {
				int pnum = card.first + P - h-1;
				if (pnum > R)ans += 0;
				else {
					ans += min(R - pnum+1, nh - P+1);
				}

			}

			if (h >= P) {
				int pnum = card.first;
				if (pnum > R)ans += 0;
				else {
					ans += min(R - pnum+1, card.second);
				}
			}
			h = nh;
		}
		h = 0;
		for (int n = 0; n < cards.size(); ++n) {
			auto card(cards[n]);
			int nh = h + card.second;
			if (h <Q&&nh>Q) {
				int pnum = card.first;
				if (pnum > R)ans += 0;
				else {

					ans += min(Q - pnum + 1, Q - h);
				}

			}
			if (nh <= Q) {
				int pnum = card.first;
				if (pnum > R)ans += 0;
				else {
					ans += min(R - pnum + 1, card.second);
				}
			}
			h = nh;
		}
		ans -= R;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3292
use proconio::input;

fn main() {
    let mut a:Vec<i32>;
    input!{
        n: i32,
        a: [i32; n - 1]
    }

    let mut result = vec![0; (n+1) as usize];

    a.into_iter().for_each(|x| result[x as usize] += 1);

    for i in 1..=n {
        println!("{}", result[i as usize]);
    }
}


Measured memory_bytes: 4752
/*
   19-3-30 Atcoder2019
   */
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c && c==a)puts("Yes");
    else puts("No");
   // cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    rep(S, 1 << 4)if (S & 1) {
        int x = 0;
        rep(i, 4) {
            if (S >> i & 1)x += s[i] - '0';
            else x -= s[i] - '0';
        }
        if (x == 7) {
            rep(i, 4) {
                if (i)cout << ((S >> i & 1) ? '+' : '-');
                cout << s[i];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}


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

using namespace std;

int countOnbit(int x) {
    if (x == 0)
        return 0;

    return countOnbit(x >> 1) + (x & 1);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);
    vector<vector<int>> x(N + 1);  // 指定した番号
    vector<vector<int>> y(N + 1);  // 正直者であるか否か

    for (int i = 1; i <= N; i++) {
        cin >> A.at(i);
        x.at(i).resize(A.at(i) + 1);
        y.at(i).resize(A.at(i) + 1);
        for (int j = 1; j <= A.at(i); j++) {
            cin >> x.at(i).at(j);
            cin >> y.at(i).at(j);
        }
    }

    // 考え方メモ
    // 正直者か不親切な人かのパターンをビットで全て表す
    // ある人kが正直者でかつ証言に矛盾がない時、のビットの1を数える
    // ある人kが正直者である -> 右から(k - 1)番目のビットが1である
    // 矛盾がない時 -> 指定した番号のビット桁の数字が、パターンと等しい時

    int maxCount = 0;
    for (int bits = 1; bits < (1 << N); bits++) {
        bool isOk = true;
        for (int i = 1; i <= N; i++) {                // 人
            if (bits & (1 << (i - 1))) {              // ある人kが正直者である
                for (int j = 1; j <= A.at(i); j++) {  // 証言
                    if (y.at(i).at(j) == 1) {
                        if (!((bits >> (x.at(i).at(j) - 1)) & 1)) isOk = false;
                    } else {
                        if ((bits >> (x.at(i).at(j) - 1)) & 1) isOk = false;
                    }
                }
            }
        }
        if (isOk) maxCount = max(maxCount, countOnbit(bits));
    }

    cout << maxCount << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);

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

  sort(a.begin(), a.end());
  int ans = 0;

  for(int i = 0; i < N; i++) {
    ans = max(ans, (int)distance(a.begin(), upper_bound(a.begin(), a.end(), a[i] + 2)) - i);
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N, K;
    cin >> N >> K;
    set<int> s;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int A;
            cin >> A;
            s.insert(A);
        }
    }
    cout << N-s.size() << endl;
}

Measured memory_bytes: 3636
dic = {'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0 }
N = gets.to_i
N.times do
  s = gets.chomp
  dic[s] += 1
end

dic.each_pair do |key, val|
  puts "#{key} x #{val}"
end


Measured memory_bytes: 14324
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
double a,b,c,d,R=6378.1,pi=acos(-1);
while(cin>>a>>b>>c>>d){
if(a==-1&&b==-1&&c==-1&&d==-1)break;
a*=pi/180;
b*=pi/180;
c*=pi/180;
d*=pi/180;
printf("%.0f\n",asin(sqrt(
(cos(a)*cos(b)-cos(c)*cos(d))*(cos(a)*cos(b)-cos(c)*cos(d))
+(cos(a)*sin(b)-cos(c)*sin(d))*(cos(a)*sin(b)-cos(c)*sin(d))
+(sin(a)-sin(c))*(sin(a)-sin(c)))*0.5)*2*R);
}
return 0;
}

Measured memory_bytes: 1284
#include<stdio.h>
#include<string.h>
#define INF (1<<29)
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
int w,h;
char map[20][20];
struct P{
	int y,x;
};
int bfs(struct P s,struct P e){
	struct P a,b,que[400];
	int head=0,tail=0,i;
	int step[20][20];
	a=s;
	memset(step,-1,sizeof(step));	
	step[s.y][s.x]=0;
	que[tail++]=a;
	while(head < tail){
		a=que[head++];
		for(i=0;i<4;i++){
			b.y=a.y+dy[i];
			b.x=a.x+dx[i];
			if(b.y<0||h<=b.y||b.x<0||w<=b.x||step[b.y][b.x]!=-1||map[b.y][b.x]=='x')continue;
			if(b.y==e.y && b.x==e.x)return step[a.y][a.x]+1;
			step[b.y][b.x] = step[a.y][a.x]+1;
			que[tail++] = b;
		}
	}
	return -1;
}
int used[11];
int dist[11][11];
int n;
int search(int i,int depth){
	int j;
	int t,min=INF;
	if(depth==n){return 0;}
	for(j=1;j<n;j++){
		if(used[j])continue;
		used[j]=1;
		t = dist[i][j]+search(j,depth+1);
		used[j]=0;
		if(t<min)min=t;
	}
	return min;
}
int main(){
	int i,j;
	struct P yogore[11];
	while(scanf("%d%d",&w,&h)==2&&(w|h)){
		int ans=-1;
		n=1;
		scanf("\n");
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				scanf("%c",&map[i][j]);
				if(map[i][j]=='*'){
					yogore[n].y=i;
					yogore[n].x=j;
					n++;
				}
				if(map[i][j]=='o'){
					yogore[0].y=i;
					yogore[0].x=j;
				}
			}
			scanf("\n");
		}
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				int d=bfs(yogore[i],yogore[j]);
				dist[i][j]=dist[j][i]=d;
				if(d==-1)goto END;
			}
		}
		memset(used,0,sizeof(used));
		ans=search(0,1);
		END:
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 424
n=int(input())
a=list(map(int,input().split()))
sum=0
cnt=0
# 奇数+
for i in range(n):
    sum+=a[i]
    if i%2==0:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_sbst=cnt
# 奇数-
cnt=0
sum=0
for i in range(n):
    sum+=a[i]
    if i%2==1:
        if sum>=0:
            cnt+=(sum+1)
            sum=-1
    else:
        if sum<=0:
            cnt+=(1-sum)
            sum=1
cnt_plus=cnt
ans=min(cnt_plus,cnt_sbst)
print(ans)




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


int main(void){
  int cnt[7], n;
  
  while (cin >> n){
    if (n==0) break;
    int age;
    for (int i=0; i<7; i++) cnt[i] = 0;
    for (int i=0; i<n; i++){
      cin >> age;
      age/=10;
      cnt[age<6?age:6]++;
    }
    for (int i=0; i<7; i++) cout << cnt[i] << endl;
  }
  return 0;
}
  
  



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

using namespace std;

struct res
{
    int index;
    int p;
    string s;

    bool operator < (const res& rhs) const
    {
        if(rhs.s == s)
        {
            return p > rhs.p; //we use > instead of < because we need descending order
        }
        return s < rhs.s;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<res> restaurant(n);
    for(int i = 0; i < n; i++)
    {
        restaurant[i].index = i + 1;
        cin >> restaurant[i].s >> restaurant[i].p;
    }
    sort(restaurant.begin(), restaurant.end());
    for(int i = 0; i < n; i++)
    {
        cout << restaurant[i].index << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.begin()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

int dp[100010];

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

  int n; cin >> n;
  int r[200010];
  rep(i, n) {
    cin >> r[i];
  }

  int maxv = -INF;
  int minv = r[0];
  for (int i = 1; i < n; ++i) {
    maxv = max( maxv, r[i] - minv );
    minv = min( minv, r[i] );
  }

  cout << maxv << endl;

  return 0;
}




Measured memory_bytes: 3952
N, M = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
lmax = 1
rmin = N
for l, r in LR:
    lmax = max(lmax, l)
    rmin = min(rmin, r)
print(max([0, rmin - lmax + 1]))


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

using namespace std;

class Num{
public:
  int x=0;
  int y=0;
};

int main(){

  int N;
  int n,d;
  vector<Num> num;
  int left=0,down=0,right=0,up=0;

  while(true){
    cin >> N;
    if(N==0) break;

    num.resize(N);

    for(int i=1; i<N; ++i){
      cin >> n >> d;

      num[i].x+=num[n].x;
      num[i].y+=num[n].y;

      if(d==0){
	--num[i].x;
      }
      else if(d==1){
	++num[i].y;
      }else if(d==2){
	++num[i].x;
      }else if(d==3){
	--num[i].y;
      }

      left=min(left,num[i].x);
      right=max(right,num[i].x);
      up=min(up,num[i].y);
      down=max(down,num[i].y);
    }

    cout << right - left +1 << " " << down - up +1 << endl;


    left=0,down=0,right=0,up=0;
    num.clear();
  }


  
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int n, k; cin >> n >> k;
  vector<bool> x(n, false);
  vector<int> d(k);
  int cnt = 0;
  for(int i=0; i<k; i++){
    cin >> d[i];
    vector<int> a(d[i]);
    for(int j=0; j<d[i]; j++) {
      cin >> a[j];
      x[a[j]-1] = true;
    }
  }

  for(int i=0; i<n; i++) if (!x[i]) cnt++;
  cout << cnt << endl;


  return 0;
}

// EOF


Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
int a,b;
int main(){
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");              
    else if(b>=0)puts("Zero");             
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
n, ma, mb = map(int, input().split())
d = []
for i in range(n):#h:高さ
    d.append([int(m) for m in input().split()])

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)

#dptable,dp[n][a][b][c](a = dp[n][0])
"""dp = []
for i in range(401):
    for j in range(401):
        dp.append([i,j])"""

cost = []
for i in range(401):
    cost.append([])
for i in range(401):
    for j in range(401):
        cost[i].append([])
for i in range(401):
    for j in range(401):
        cost[i][j] = float("INF")
cost[0][0] = 0
pos = []
pos.append([0,0])
pos2 = set()
pos2.add((0,0))
#cppos = []
#cppos.append([0,0])
cppos2 = set()
cppos2.add((0,0))

cpcost = {}
cpcost = defaultdict(lambda: float("INF"))
for i in range(n):
    for v in range(2):
        for w in range(len(pos)):
            p = pos[w][0] + v * d[i][0]
            q = pos[w][1] + v * d[i][1]
            if (p, q) not in pos2:
                #cppos.append([p, q])
                cppos2.add((p, q))
            if cost[p][q] > cost[pos[w][0]][pos[w][1]] + d[i][2]:
                if cpcost[p, q] > cost[pos[w][0]][pos[w][1]] + d[i][2]:
                    cpcost[p, q] = cost[pos[w][0]][pos[w][1]] + d[i][2]
    #pos += cppos
    for u in cppos2:
        pos2.add(u)
        pos.append(list(u))
    for u in cpcost:
        cost[u[0]][u[1]] = cpcost[u]
    cppos = []
    cppos2 = set()
    cpcost = {}
    cpcost = defaultdict(lambda: float("INF"))

realcost = []
for i in range(401):
    for j in range(401):
        if gcd(i, j) != 0:
            if i // gcd(i, j) == ma and j // gcd(i, j) == mb and cost[i][j] != float("INF"):
                realcost.append(cost[i][j])

if len(realcost) > 0:
    print(min(realcost))
else:
    print(-1)

Measured memory_bytes: 18588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int a = std.nextInt();
        int b = std.nextInt();
        
        if (a >= 10 || b >= 10) {
            System.out.println(-1);
        } else {
            System.out.println(a * b);
        }
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;

ll N;
vector<string> s;

void input() {
	scanf("%lld", &N);
	s.assign(N,"");
	rep(i, N) cin>>s[i];
}

void solve() {
	ll ans = 0;
	map<vector<ll>,ll> m;
	rep(i,N){
		vector<ll> aa(26,0);
		rep(j,s[i].size()){
			ll tt=s[i][j]-'a';
			aa[tt]++;
		}

		m[aa]++;
	}
	
	for(auto mm:m){
		ans+=mm.second*(mm.second-1)/2;
	}

	printf("%lld\n", ans);
}

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


Measured memory_bytes: 36992
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
int facctorialMethod(int k);

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

int main(){
    int N,num,first,last,sum,cnt,temp;
    cin>>N;
    sum=0;
    vector<vector<int>> c(10,vector<int>(10));
    for(int k=1;k<= N;++k){
        string s = to_string(k);
        int i = s.front() - '0';
        int j = s.back() - '0';
        c.at(i).at(j)++;
        //cout<<i<<" "<<j<<endl;
    }

    int res=0;
    for(int k=1;k<= N;++k){
        string s = to_string(k);
        int i = s.front() - '0';
        int j = s.back() - '0';
        res+=c.at(j).at(i);
        //cout<<j<<" "<<i<<" "<<c.at(j).at(i)<<endl;
    }
    cout<<res<<endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    val t = readLine() ?: return
    0.until(n).forEach {
        val i = n - it
        val ss = s.takeLast(i)
        val tt = t.take(i)
        if (ss == tt) {
            println((n + it).toString())
            return
        }
    }
    println((2 * n).toString())
}

Measured memory_bytes: 31820
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;

LL ans = 0;

void solve(){
	//Nをmで割った時、商とあまりが同じ
	//これは N = pm + p (1<=p<=m-1)
	//と言い換えられる
	//N = p(m+1) より
	//各pについて、
	//Nがpで割り切れて、かつ m = N/p - 1 が
	//(1<=p<=m-1)
	//を満たすならmをどんどん加算していく
	for(LL p=1;p*p<N;p++){
		if(N%p==0){
			LL m = N/p - 1;
			if(p<=m-1) ans += m;
		}
	}
}
 
int main(){
    cin >> N;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

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

int main() {
  int i;
  char password_odd[MAX_STRING_LENGTH], password_even[MAX_STRING_LENGTH];
  scanf("%s", password_odd);
  scanf("%s", password_even);
  for(i = 0; i < strlen(password_odd) + strlen(password_even); i++) {
    if(i % 2 == 0) {
      printf("%c", password_odd[i/2]);
    } else {
      printf("%c", password_even[i/2]);
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

//----------------------------------------------------------------

int main()
{
    ll n, m;
    cin >> n >> m;
    ll awasete = (n - m) * 100 + m * 1900;
    ll per = pow(2, m);
    cout << awasete * per << endl;
}

Measured memory_bytes: 256
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    x = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    if x >= 30:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9164
#include <stdio.h>
#include <stdlib.h>
#define p (int)(1e9 + 7)

int main(){
	int N, A, i, ans = 1;
	scanf("%d", &N);
	int *A_num = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		A_num[i] = 0;
	}
	for(i = 0; i < N; i++){
		scanf("%d", &A);
		A_num[A]++;
	}
	if(N % 2 == 0){
		for(i = 1; i < N; i += 2){
			if(A_num[i] == 2){
				ans = (ans * 2) % p;
			}
			else{
				printf("0\n");
				return 0;
			}
		}
	}
	else{
		if(A_num[0] != 1){
			printf("0\n");
			return 0;
		}
		else{
			for(i = 2; i < N; i += 2){
				if(A_num[i] == 2){
					ans = (ans * 2) % p;
				}
				else{
					printf("0\n");
					return 0;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

#define ll long long
const ll N = 1000000000000000;

void solve() {

}

int main(){
    long double yen = 100;
    ll x;
    cin >> x;
    int i = 0;
    while(yen < x) {
        yen = floor(yen * 1.01);
        ++i;
    }
    cout << i;

    return 0;
}

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

using namespace std;
typedef vector<bool> Array;
typedef vector<Array> Matrix;
typedef long long LL;

int dfs(int n, int k, LL G[], LL cover[], int ord[], LL now, int ans, int &bound){
    if(ans >= bound) {
        return bound;
    }
    if(now == (1LL << n) - 1) {
        return bound = ans;
    }
    if(k >= n) {
        return bound;
    }
    if((now | cover[k]) != (1LL << n) - 1) {
        return bound;
    }

    int u = ord[k];
    if((now & G[u]) == G[u]) {
        return dfs(n, k + 1, G ,cover, ord, now, ans, bound);
    }

    return min(dfs(n, k + 1, G ,cover, ord, now | G[u], ans + 1, bound),
            dfs(n, k + 1, G ,cover, ord, now, ans, bound));
}

int dominating_set(const Matrix &G){
    int N = G.size();
    LL M[N];
    memset(M, 0, sizeof(M));
    int cnt[N];
    REP(i, N){
        M[i] = 1 << i;
        cnt[i] = 1;
        REP(j, N) if(G[i][j]){
            M[i] |= 1 << j;
            cnt[i] ++;
        }
    }
    int ord[N];
    REP(i, N) ord[i] = i;

    // sort
    REP(i, N) REP(j, N - 1){
        if(cnt[ord[j]] < cnt[ord[j+1]]){
            swap(ord[j], ord[j+1]);
        }
    }

    LL cover[N + 1];
    cover[N] = 0;
    for(int i = N - 1; i >= 0; i--) {
        cover[i] = cover[i + 1] | M[ord[i]];
    }

    int bound = N;
    return dfs(N, 0, M, cover, ord, 0, 0, bound);
}

int main(){
    int x, y;
    while(cin >> x >> y && x > 0) {
        Matrix M(x, Array(x));
        REP(i, y) {
            int a, b;
            cin >> a >> b;
            M[a][b] = M[b][a] = true;
        }
        cout << dominating_set(M) << endl;
    }
    return 0;
}

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

lint gcd(lint a, lint b) {
  lint tmp;
  while (a % b != 0)
  {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

lint lcm(lint a, lint b)
{
  return a * b / gcd(a, b);
}

int main() {
  lint a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
long long int mod = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//////////////////////////////////


int main(){
    int n; cin >> n;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin >> h[i];
    for(int i=n-2; i>=0; i--) {
        if(h[i+1] >= h[i]) continue;
        if(h[i+1]+1 == h[i]) {
            h[i]--;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;

    
    return 0;
}

// EOF



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

using namespace std;

/**
 * THREE = P W G
 * FOUR  = P W G Y
 */

int main() {
  int N, count = 0;;

  cin >> N;

  char S[100];

  // 格納
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  // ソート&重複を削除
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S[i] > S[j]) {
        char temp = S[i];
        S[i] = S[j];
        S[j] = temp;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (count == 0 && S[i] == 'G') {
      count = 1;
      continue;
    }

    if (count == 1 && S[i] == 'P') {
      count = 2;
      continue;
    }

    if (count == 2 && S[i] == 'W') {
      count = 3;
      continue;
    }

    if (count == 3 && S[i] == 'Y') {
      count = 4;
      break;
    }
  }

  if (count == 4) {
    cout << "Four" << endl;
  } else if (count == 3) {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];

    let ans = if a > b + c {
        0
    } else {
        b + c - a
    };

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


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int a[51], b[51];

bool ableEat(int level, int eat) {
    return eat >= a[level];
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    a[0] = 1, a[1] = 5;
    b[0] = 1, b[1] = 3;
    rep(i, 50) {
        a[i + 1] = a[i] * 2 + 3;
        b[i + 1] = b[i] * 2 + 1;
    }
    int level = N;
    int ans = 0;

    while(X > 0) {
        while(!ableEat(level, X) && X > 0) {
            X--; level--;
        }
        //cout << level << endl;
        if (X == 0) break;
        ans += b[level];
        X -= a[level];
        if (X > 0) {
            X--; ans++;
        } else break;

    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut v = read_vec::<u32>();
    v.sort();
    println!("{}", v[0] + v[1]);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )

#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

const double INF = DBL_MAX / 2;

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

	cout.precision( 5 );
	cout << fixed;

	while ( true )
	{
		int t, n, m, s, g;
		cin >> t >> n >> m >> s >> g;

		if ( !( t | n | m | s | g ) )
		{
			break;
		}

		s--;
		g--;

		VI tickets( t );
		FOR( tic, tickets )
		{
			cin >> tic;
		}

		VVI G( n, VI( n, -1 ) );
		REP( i, 0, m )
		{
			int a, b, d;
			cin >> a >> b >> d;
			a--;
			b--;

			G[a][b] = d;
			G[b][a] = d;
		}
		// 入力終わり

		vector< vector<double> > dp( n, vector<double>( 1 << t, INF ) );
		dp[s][0] = 0;
		REP( s, 0, 1 << t )
		{
			REP( i, 0, n )
			{
				REP( j, 0, n )
				{
					if ( G[i][j] == -1 )
					{
						continue;
					}
					REP( k, 0, t )
					{
						if ( s & ( 1 << k ) )
						{
							continue;
						}
						double d = (double)G[i][j] / tickets[k];
						dp[j][ s | ( 1 << k ) ] = min( dp[j][ s | ( 1 << k ) ], dp[i][s] + d );
					}
				}
			}
		}

		double res = *min_element( ALL( dp[g] ) );
		if ( res == INF )
		{
			cout << "Impossible";
		}
		else
		{
			cout << res;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1364
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  if(((n-1)&n) === 0)return "No";
  console.log("Yes");
  var ans = [(n+1)+" "+(n+3)];
  for(var i = 2; i < n; i+=2){
    var t = i+1;
    ans.push(1+" "+i);
    ans.push(1+" "+t);
    ans.push((n+t)+" "+i);
    ans.push((n+i)+" "+t);
  }
  if(n%2 === 0){
    ans.push((n-1)+" "+n);
    ans.push(((n-2)^n)+" "+n*2);
  }
  return ans.join("\n");
}

Measured memory_bytes: 51788
#include<stdio.h>
#include<algorithm>
using namespace std;
int UF[110000];
int w[110000];
char str[10];
pair<int,int> FIND(int a){
	if(UF[a]<0)return make_pair(a,0);
	pair<int,int> ret=FIND(UF[a]);
	w[a]+=ret.second;
	UF[a]=ret.first;
	return make_pair(UF[a],w[a]);
}
void UNION(int a,int b,int c){
	if(FIND(a).first==FIND(b).first)return ;
	int p=FIND(b).first;
	if(b==p){
		UF[b]=a;
		w[b]=c;
	}else{
		UF[p]=a;
		w[p]=c-w[b];
	}
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)UF[i]=-1;
		for(int i=0;i<a;i++)w[i]=0;
		for(int i=0;i<b;i++){
			scanf("%s",str);
			if(str[0]=='!'){
				int p,q,r;scanf("%d%d%d",&p,&q,&r);
				p--;q--;
				UNION(p,q,r);
			}else{
				int p,q;
				scanf("%d%d",&p,&q);p--;q--;
				if(FIND(p).first!=FIND(q).first)printf("UNKNOWN\n");
				else printf("%d\n",FIND(q).second-FIND(p).second);
			}
		}
	}
}

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

int main(){
  long int n,ans=0,a,b;
  cin >> n ;
  cin >> a;
  for(int i=0;i<5;i++){
    cin >> b;
    a=min(a,b);
  }
  if(n%a==0){
    n/=a;
  }else{
    n=n/a+1;
  }

  cout << n+4 << endl;
  

    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

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

int N,M,Q;
std::vector<std::vector<int>> Qlist;
int ans = 0;

void DFS(std::vector<int> A){
    if(A.size() == N){
        int score = 0;
        rep(i,Q){
            if(A.at(Qlist.at(i).at(1)-1) - A.at(Qlist.at(i).at(0)-1) == Qlist.at(i).at(2)){
                score += Qlist.at(i).at(3);
            }
        }
        chmax(ans,score);
        return;
    }
    
    A.push_back(A.back());
    while(A.back() <= M){
        DFS(A);
        A.back()++;
    }
}


int main() {
    
    cin >> N >> M >> Q;
    
    
    Qlist = std::vector<std::vector<int>>(Q,std::vector<int>(4));
    rep(i,Q){
    	cin >> Qlist.at(i).at(0) >> Qlist.at(i).at(1) >> Qlist.at(i).at(2) >> Qlist.at(i).at(3);
    }

    int cnt = 0;

    std::vector<int> candidateA(1);
    candidateA.at(0) = 1;

    DFS(candidateA);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

struct Edge {
    int from,to,cost;
    Edge(int f, int t, int c): from(f), to(t), cost(c) {};

    bool operator<(const Edge& e) const {
        if(from != e.from) {
            return from < e.from;
        }
        if(to != e.to) {
            return to < e.to;
        }
        return cost < e.cost;
    }
};

int main() {
    int l;
    vector<Edge> edges;
    cin >> l;

    if(l == 2) {
        cout << "2 2\n1 2 0\n1 2 1\n";
        return 0;
    }

    // 2べき部分と残りの部分に分ける
    int node = 0;
    while((1 << node) <= l) node++;

    int edge_cnt = 1 << (node-1);
    for(int i = 1; i <= node-1; i++) {
        edges.push_back(Edge(i, i+1, 0));
        edges.push_back(Edge(i, i+1, 1 << (i-1)));
    }

    for(int i = node-2; i>= 0; i--) {
        if(l - edge_cnt >= (1 << i)) {
            edges.push_back(Edge(i+1, node, edge_cnt));
            edge_cnt += (1 << i);
        }
    }

    cout << node << " " << edges.size() << endl;
    for(Edge e: edges) {
        cout << e.from << " " << e.to << " " << e.cost << endl;
    }

    return 0;
}

Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())
    val dp = new Array[Int](N)

    dp(0) = 0
    var i = 1
    while (i < N) {
      if (i == 1)
        dp(i) = dp(i-1) + Math.abs(H(i-1) - H(i))
      else
        dp(i) =
          (dp(i-1) + Math.abs(H(i-1) - H(i))) min
            (dp(i-2) + Math.abs(H(i-2) - H(i)))
      i += 1
    }
    println(dp(N-1))
  }

}

Measured memory_bytes: 52004
N=int(input())
ans = N
for i in range(N+1):
    cc = 0
    t = i
    while t > 0:
        cc += t%6
        t //=6
    t = N-i
    while t>0:
        cc+=t%9
        t //=9
    ans = min(ans,cc)
print(ans)

Measured memory_bytes: 3068
s = []
t = []

N = int(input())
for i in range(N):
    s.append(input())

M = int(input())
for i in range(M):
    t.append(input())

count = 0
for i in range(N):
    count = max(count, s.count(s[i]) - t.count(s[i]))

print(count)

Measured memory_bytes: 3064