akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define rep(i,j,n) for(int i=j; i<n; i++)
#define INF 1000000000000000000 // If you use it, make sure not to put in "int" type variable ;(, use long long int
void optimizeIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
const ll mod=1000000007;

int main()
{
    optimizeIO();
    int nT; nT=1;
	while(nT--)
	{
		int n; cin>>n;
		double a[n]; rep(i,0,n) cin>>a[i];
		double ans=0;
		rep(i,0,n) ans+=1.0/a[i];
		printf("%.20f",1.0/ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
int main() {
	int test[3];
	cin >> test[0] >> test[1] >> test[2];
	for (int i = 0 ; i < (3-1) ; i++) {
		for(int j = i+1 ; j < 3 ; j++){
			if (test[i] > test[j]) {
					swap(test[i], test[j]);
			}
		}
	}
	//出力
	for (int i = 0; i < 3; i++) {
		if (i != 2) {
			cout << test[i] << " ";
		}
		else {
			cout << test[i];
		}
	}
	cout << endl;
	return 0;
}


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

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0, cnt = 0; i < S.size(); i++) {
    if (S.at(i) == 'R') cnt++;
    else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

//string型からint型に変換する
int s_to_i(string s){
	int n = 0;
	for(int i=0 ; i < s.size() ; i++ ){
		n *= 10;
		n += s[i] - '0';
    }
    return n ;
}

//int型からstring型に変換する
string i_to_s(int n){
	string s;
	do{
		s.push_back( (n%10)+'0' );
		n /= 10;
	}while( n != 0 );
	
	reverse( s.begin() , s.end() );
	return s;
}

// s[0..i] と s[i+1..s.size()-1]に分割して掛け算して最大の数字を返す. (返すのは文字列)
string f(string s){
	int res = 0;
	for(int i=0 ; i <= s.size()-2 ; i++ ){
		// a := s[0] から i+1 文字の部分文字列
		string a = s.substr( 0 , i+1 );
		// b := s[i+1] から最後までの部分文字列 
		string b = s.substr( i+1 );
		res = max( res , s_to_i(a) * s_to_i(b) );
	}
	return i_to_s( res );
}

int main(){
	int Q;
	
	cin >> Q;
	for(int i=0 ; i < Q ; i++ ){
		string N;
		cin >> N;
		
		int ans = 0;
		// memo[n] := 手順の途中で n が登場しているかどうかを返す. 
		map<string,bool> memo;
		
		while( true ){
			// N いままでの手順で登場しているかのチェック
			if( memo.count(N) ){
				ans = -1;
				break;
			}else{
				memo[N] = true;
			}
			
			if( N.size() == 1 ){ // 1 桁のとき
				break;
			}else{ // それ以外
				ans++;
				N = f(N);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1220
import math
import bisect
n,d,a = map(int,input().split())
L = []
kyo = []
for i in range(n):
    x,h = map(int,input().split())
    L.append([x,h])
    kyo.append(x)
L.sort()
kyo.sort()
ans = 0
imos = [0]*(n+1)
cur = 0
ran = 2*d
for i in range(n):
    if imos[cur] < L[cur][1]:
        t = int(math.ceil((L[cur][1]-imos[cur])/a))
        ans += t
        imos[cur] += t*a
        lim = bisect.bisect_right(kyo, kyo[cur]+ran)
        imos[lim] -= t*a
    imos[i+1] += imos[i]
    cur += 1
print(ans)


Measured memory_bytes: 46484
NMC=list(map(int,input().split()))
B=list(map(int,input().split()))


count=0
for i in range(NMC[0]):
 A=list(map(int,input().split()))
 sum=0
 for j in range(NMC[1]):
  sum=sum+A[j]*B[j]
 if sum+NMC[2]>0:
  count=count+1

print(count)

Measured memory_bytes: 3060
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	l := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&l[i])
	}

	sort.Ints(l)
	var ans int
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			for k := j; k < n; k++ {
				if l[i] != l[j] && l[j] != l[k] && l[k] != l[i] {
					if l[i]+l[j] > l[k] {
						ans++
					}
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1844
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

    double n, k;
    cin >> n >> k;
    double p = 0;
    for (int i = 1; i <= min(n, k-1); i++)
    {
        p += pow(2, -ceil(log2(k / i))) / n;
    }
    if (n >= k)
    {
        p += (n - k + 1) / n;
    }
    cout << setprecision(numeric_limits<double>::max_digits10) << p << endl;

    return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()

typedef pair< int, int > pii;
typedef vector< pii > PArray;

int n, m;

void solve() {
	int cnt[110] = { 0 };
	for_(i,0,n) for_(j,0,m) {
		int c; scanf("%d", &c), cnt[j] += c;
	}
	
	PArray vp;
	for_(i,0,m) vp.push_back(pii(cnt[i], -(i + 1)));
	sort(allof(vp));
	
	for_rev(i,m-1,0) {
		if (i > 0) printf("%d ", -vp[i].second);
		else printf("%d\n", -vp[i].second);
	}
}

int main() {
	while (scanf("%d %d", &n, &m), n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <numeric>

int main(void) {
    int n, k;
    int* h;
    std::cin >> n >> k;
    h = new int[n];
    for(int i=0;i<n;i++) std::cin >> h[i];

    std::sort(h, h+n);
    int min = h[n-1] - h[0];
    for(int i=0;i<n-(k-1);i++){
        int val = h[i+k-1] - h[i];
        if(min > val) min = val;
    }

    std::cout << min << std::endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    string s;
    cin>>s;
    bool slag=0,flag=0;
    int x = (s[0]-'0')*10 + s[1]-'0';
    int y = (s[2]-'0')*10 + s[3]-'0';
    if(x >=1 && x<=12)flag = 1;
    if(y >=1 && y<=12)slag = 1;
    if(flag==1 && slag==1){
        cout<<"AMBIGUOUS\n";
    }else if(flag==1 && slag==0){
        cout<<"MMYY\n";
    }else if(flag==0 && slag==1){
        cout<<"YYMM\n";
    }else{
        cout<<"NA\n";
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  char S[22222];
  cin >> S;
  ll N = 0;
  while(S[N]) N++;
  if(S[N-1]=='s') {S[N]='e'; S[N+1] = 's';}
  else S[N] = 's';
  cout << S << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

signed main(){
    int a, b;
    cin >> a >> b;
    double r = 1.0 / a + 1.0 / b;
    printf("%.10f\n", 1.0/r);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int five = 0, seven = 0;
        for (int i = 0; i <3; i++){
            int x = in.nextInt();
            if (x == 5) five++;
            else if (x == 7)seven++;
        }
        if (five == 2 && seven == 1) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 21588
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int[][] switchPatterns = new int[m][];
		int[] p = new int[m];
		for ( int i = 0; i < m; i++ ) {
			int k = in.nextInt();
			int[] s = new int[k];
			for ( int j = 0; j < k; j++ ) {
				s[j] = in.nextInt();
			}
			switchPatterns[i] = s;
		}
		for ( int i = 0; i < m; i++ ) {
			p[i] = in.nextInt();
		}

		int Allpatterns = 2 << (n - 1); // 2のn乗
		int cnt = Allpatterns;
//		boolean[] light = new boolean[Allpatterns];
//		Arrays.fill(light, true);

		// スイッチのパターンを上限まで列挙
		for ( int ptr = 0; ptr < Allpatterns; ptr++ ) {
			// 電球ごとのスイッチパターンと照らし合わせる
			for ( int d = 0; d < m; d++ ) {
				int temp = 0;
				for ( int i : switchPatterns[d] ) {
					// System.out.println("switch:" + i);
					//					int mask = 1 << (i - 1);
					//					temp += ((ptr & mask) >> (i - 1));

					temp += ptr >> i - 1 & 1; // 順序：四則演算 → ビットシフト → 論理演算 → 代入
				}
				// System.out.println("temp:" + temp);
				if ( temp % 2 != p[d] ) {
					//light[ptr] = false;
					cnt--;
					break;
				}
				// if(d == m-1)System.out.println("ptr:" + Integer.toBinaryString(ptr) + " is OK");
			}
		}

//		int cnt = 0;
//		for ( int i = 0; i < Allpatterns; i++ ) {
//			if ( light[i] ) {
//				// System.out.println(Integer.toBinaryString(i));
//				cnt++;
//			}
//		}

		System.out.println(cnt);

		// 確認用
		//		for ( int i = 0; i < m; i++ ) {
		//			System.out.print("電球 " + i + "     p: " + p[i] + "    s: ");
		//			for ( int j : switches[i] ) {
		//				System.out.print(j + " ");
		//			}
		//			//System.out.print(" p:" + p[i]);			
		//			System.out.println();
		//		}
		in.close();
	}
}


Measured memory_bytes: 21844
#include <cstdio>
#include <string>
using namespace std;

int main(){
	char tmp[101];
	scanf("%s", tmp);
	string str = tmp;
	int a[26] = {};
	for(int i=0; i<str.size(); i++){
		a[str[i] - 'a']++;
	}
	bool ok = true;
	for(int i=0; i<26; i++){
		if(a[i] % 2 == 1){
			ok = false;
		}
	}
	if(ok) printf("Yes\n");
	else printf("No\n");

	return 0;
}

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

int main() {
    vector<int> q;
    rep(i,5) {
        int a;
        cin >> a;
        q.push_back(a);
    }
    int k;
    cin >> k;
    bool ok = true;
    rep(i,4) {
        for (int j = i+1; j <= 4; j++)
            if (abs(q[i]-q[j]) > k) ok = false;
    }
    puts(ok?"Yay!":":(");
}

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

int main(){
  int a,b,c; cin >> a >> b >> c;
  bool check=false;
  for(int i=1; i<=b; i++){
    if((a*i)%b==c) check=true;
  }
  cout << (check?"YES":"NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int q;
	cin>>q;
	vector<int> v(q),d(q),c(q);
	rep(i,q) cin>>v[i]>>d[i]>>c[i];
	vector<int> ans(n,0);
	vector<vector<bool>> dp(n,vector<bool>(11,false));
	auto dfs=[&](auto &dfs,int v,int d,int c)->void{
		if(dp[v][d]) return ;
		if(ans[v]==0) ans[v]=c;
		dp[v][d]=true;
		if(d==0) return ;
		dfs(dfs,v,d-1,c);
		for(auto to:g[v]){
			dfs(dfs,to,d-1,c);
		}
	};
	for(int i=q-1;i>=0;i--){
		v[i]--;
		dfs(dfs,v[i],d[i],c[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 15096
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def std_in():
    return sys.stdin.readline().strip()


def main():
    n = int(std_in())
    if n % 9 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9320
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	while(1)
	{
		int n,m;
		bool used[510];
		memset(used,0,sizeof(used));
		used[1]=true;
		cin >> n;
		cin >> m;
		if(n==0&&m==0)break;
		vector<int> f[n+1];
		int ans=0;
		for(int i=0;i<m;i++)
		{
			int a,b;
			cin >> a >> b;
			if(a==1)
			{
				ans++;
				used[b]=true;
			}
			f[a].pb(b);
            f[b].pb(a);
		}
		for(int i=0;i<f[1].size();i++)
		{
			for(int j=0;j<f[f[1][i]].size();j++)
			{
				if(!used[f[f[1][i]][j]])
				{
					ans++;
					used[f[f[1][i]][j]]=true;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
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; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)


signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n];
    intl b[n];
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    intl cnt = 0;
    intl ans = 0;
    intl sub[n];
    m0(sub);
    rep(i,n){
        if(a[i] < b[i]){
            cnt += (b[i] - a[i]);
            ans++;
        }
        else sub[i] = (a[i] - b[i]);
    }
    //debug(cnt);
    sort(sub, sub + n, greater<>());
    intl add = 0;
    rep(i,n){
        if(cnt <= add){
            cout << ans << endl;
            return 0;
        }
        add += sub[i];
        ans++;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 5876
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; //mp::cpp_intで宣言
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////

ll h,w;

ll z(string s,string t){
    //cout<<s<<" "<<t<<endl;
    ll pre[2*h+1][h];memset(pre,0,sizeof(pre));
    string k;rep(i,0,h-1)k+='A';
    s=k+s+k;
    rep(i,0,2*h){
        ll k=2*h-i;
        if(s[k]==t[0])pre[i][0]=1;
        rep(j,1,h-1){
            k++;
            
            if(s[k]==t[j])pre[i][j]=pre[i][j-1]+1;
            else pre[i][j]=pre[i][j-1];
        }
    }
  /*  rep(i,0,2*h){
        rep(j,0,h-1){
            cout<<pre[i][j]<<" ";
        }cout<<endl;
    }
    cout<<endl;*/
    ll dp[h+1][h+1];rep(i,0,h)rep(j,0,h)dp[i][j]=inf;
    dp[0][0]=0;
    rep(i,0,h){
        rep(j,0,h){
            ll m;
            if(h-j-1<0)m=dp[i][j];
            else m=pre[h-j+i][h-j-1]+dp[i][j];
            if(i+1<=h)Min(&dp[i+1][j],m);
            if(j+1<=h)Min(&dp[i][j+1],m);
        }
    }
 /*   rep(i,0,h){
        rep(j,0,h){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }
    */
    return dp[h][h];
}


int main(){
    cin>>h>>w;
    string q[h];rep(i,0,h-1)cin>>q[i];
    
    ll ans=0;
    string s,t;
    rep(j,0,h-1)s+=q[j][0];
    rep(i,1,w-1){
        t.erase();
        rep(j,0,h-1)t+=q[j][i];
        ll ccc=z(s,t);
       // cout<<ccc<<endl;
        ans+=ccc;
        s=t;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 2560
def max(a, b, c)
  a < b ? (b < c ? c : b) : (a < c ? c : a)
end
def min(a, b, c)
  a > b ? (b > c ? c : b) : (a > c ? c : a)
end
def cdiv(a, b)
  (a + b - 1) / b
end

H, W = gets.split.map(&:to_i)



results = []
if H == 2

elsif H % 3 == 0
  results.push(0)
else
  results.push(((H / 3 + 1) * W) - ((H / 3) * W))
end

if W == 2

elsif W % 3 == 0
  results.push(0)
else
  results.push(((W / 3 + 1) * H) - ((W / 3) * H))
end

(cdiv(H, 4)..cdiv(H, 2)).each do |h|
  pieces = [h * W]
  pieces.push (H - h) * (W / 2)
  pieces.push (H - h) * ((W + 1) / 2)
  results.push max(pieces[0], pieces[1], pieces[2]) - min(pieces[0], pieces[1], pieces[2])
end

(cdiv(W, 4)..cdiv(W, 2)).each do |h|
  pieces = [h * H]
  pieces.push (W - h) * (H / 2)
  pieces.push (W - h) * ((H + 1) / 2)
  results.push max(pieces[0], pieces[1], pieces[2]) - min(pieces[0], pieces[1], pieces[2])
end

puts results.min

Measured memory_bytes: 2300
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

template<typename T>
T v_max(const vector<T>& vec){
    T max=vec[0];
    for(uint i=1; i<vec.size(); ++i){
        if(vec[i]>max){ max=vec[i]; }
    }
    return max;
}
template<typename T>
T v_min(const vector<T>& vec){
    T min=vec[0];
    for(uint i=1; i<vec.size(); ++i){
        if(vec[i]<min){ min=vec[i]; }
    }
    return min;
}

int64 sad(const vector<int>& vA, int b){
    int64 sum=0ll;
    for(uint vi=0; vi<vA.size(); ++vi){
        sum += abs(vA[vi] - b);
    }
    return sum;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N; cin >> N;
    
    vector<int> vA(N);
    for(uint i=0; i<N; ++i){
        int a; cin >> a;
        vA[i] = a-(i+1);
    }
    
    sort(vA.begin(), vA.end());
    int median = vA[N/2];

    int64 sum=0;
    for(uint i=0; i<N; ++i){
        sum += abs(vA[i]-median);
    }
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<vector<int>> dp(N, vector<int>(K, 0));
    rep(i, 0, K) {
        dp[0][i] = 1;
    }
    int sum = K;
    rep(i, 1, N) {
        rep(j, 0, K) {
            dp[i][j] = sum - dp[i - 1][j];
        }
        sum = 0;
        rep(j, 0, K) {
            sum += dp[i][j];
        }
    }
    int ans = 0;
    rep(i, 0, K) {
        ans += dp[N - 1][i];
    }
    cout << ans << endl;
    return 0;
}

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

#define pb push_back
#define sz size()

using namespace std;

const int N = 1e6 + 1;
const int inf = 1e9 + 7;

int n, m;
int d[N], dis[N];

bool us[N];

vector <int> g[N];

void dfs(int v){
    us[v] = 1;
    for(int i = 0; i < g[v].sz; i++){
        int to = g[v][i];
        dis[to] = max(dis[to], dis[v] + 1);
        d[to]--;
        if(d[to] == 0)dfs(to);
    }
}

main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin>> n>> m;
    for(int i = 1; i <= m; i++){
        int l, r;
        cin>> l>> r;
        d[r]++;
        g[l].pb(r);
    }
    for(int i = 1; i <= n; i++){
        if(!us[i] && d[i] == 0)dfs(i);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, dis[i]);
    }
    cout<< ans;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<ll> vSize;

    UnionFind(ll N) : par(N), vSize(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++)
        {
            par[i] = i;
            vSize[i] = 1;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        vSize[ry] += vSize[rx];
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x){    // データxが属する木の頂点数を得る
        ll rx = root(x);
        return vSize[rx];
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    REP(i, M)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    UnionFind uf(N);
    vector<ll> sumPairs;
    sumPairs.push_back(0);
    REP(i, M - 1)
    {
        ll a, b;
        a = A[M - 1 - i];
        b = B[M - 1 - i];
        ll prev = sumPairs[sumPairs.size() - 1];
        if (!uf.same(a, b))
        {
            sumPairs.push_back(prev + uf.size(a) * uf.size(b));
        }
        else
        {
            sumPairs.push_back(prev);
        }
        uf.unite(a, b);
    }
    ll sumAll = N * (N - 1) / 2;
    REP(i, M)
    {
        cout << sumAll - sumPairs[M - 1 - i] << endl;
    }
}

Measured memory_bytes: 5364
package main

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

func main() {
	a := nextInt64()
	b := nextInt64()
	c := nextInt64()
	d := nextInt64()

	x := int64(math.MinInt64)

	x = max(x, a*c)
	x = max(x, a*d)
	x = max(x, b*c)
	x = max(x, b*d)

	if a <= 0 && b >= 0 || c <= 0 && 0 <= d {
		x = max(x, 0)
	}

	fmt.Println(x)
}

func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args...)
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int N = int.Parse(imp[0]);
            int K = int.Parse(imp[1]);
            int ans = 1;
            for (int i = 0; i < N; ++i)
            {
                if(i==0)
                {
                    ans *= K;
                }
                else
                {
                    ans *= (K - 1);
                }
            }
            Console.Write(ans);

            //System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 11092
SA = input()
SB = input()
SC = input()
cards = { 'a': SA, 'b': SB, 'c': SC }

turn = 'a'
while True:
  if not cards[turn]:
    break
  next_turn = cards[turn][0]
  cards[turn] = cards[turn][1:]
  turn = next_turn

print(turn.upper())

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a += b;
    c += d;
    if(a>c)cout << "Left" << endl;
    else if(a<c)cout << "Right" << endl;
    else cout << "Balanced" << endl;
}


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

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

    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int &i : a) std::cin >> i;

    int ans = INT_MAX;
	
	for (int p = 1; p <= 100; p++) {
		int stamina = 0;
		for (int i : a) stamina += (i - p) * (i - p);

		ans = std::min(ans, stamina);
	}

	std::cout << ans;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
    int n,m; cin >> n >> m;
    vector<int> x(m); rep(i,m) cin >> x[i];

    sort(all(x));

    int first = x.front();
    int end = x.back();
    priority_queue<int> q;
    rep(i,m-1){
        q.push(x[i+1]-x[i]);
    }

    int ans = end - first;
    rep(i,n-1){
        if(q.size() == 0) break;
        ans -= q.top();
        q.pop();
    }

    cout << ans << endl;
}


Measured memory_bytes: 1276
def exgcd(a, b)
  if b == 0
    return [1, 0]
  end

  y, x = exgcd(b, a % b)
  y -= a / b * x
  return [x, y]
end

MOD = 1_000_000_007

def inv(a)
  x, y = exgcd(a, MOD)
  return x
end

def modpow(b, i)
  t = 1
  i.times do
    t = t * b % MOD
  end
  return t
end

n = gets.to_i
as = gets.split.map(&:to_i)


lcm = 1


facts = {}

as.each do |a|
  x = a
  fs = []
  2.upto(Math.sqrt(a).ceil) do |k|
    cnt = 0
    while x % k == 0
      x /= k
      cnt += 1
    end

    if cnt > 0
      facts[k] = [facts[k] || 0, cnt].max
    end
  end

  # prime number
  if x > 1
    facts[x] = [facts[x] || 0, 1].max
  end
end

lcm = 1
facts.map { |k, v|
  modpow(k, v)
}.each do |x|
  lcm = lcm * x % MOD
end

sum = 0
as.each do |a|
  iv = inv(a)
  sum += lcm * iv % MOD
end

p sum % MOD

# bs = as.map {|a| lcm / a }

# p bs.reduce(&:+) % MOD



Measured memory_bytes: 3452
#include <iostream>

using namespace std;

int main(){
    string vowel = "aiueo";
    char c;
    cin >> c;
    for (int i=0; i < vowel.size(); i++){
        if (c == vowel.at(i)){
            cout << "vowel" << endl;
            return 0;
        }
    }

    cout << "consonant" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;
 
long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}
 
ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  while (q-- >0) {
    int a;
    cin >> a;
    cout << (a + a * a + a * a * a) << "\n";
  }
 
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

int main() {
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    bool can = false;
    for (int i=a;i<=b;i++){
        if(i%k==0) can =true;
    }
    if(can){
        cout << "OK" << endl; 
    }
    else cout << "NG" << endl;
    return 0;
}



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

signed main() {
    int n, a, b;
    cin >> n >> a >> b;

    int c = a + b;
    int d = n / c;
    int left = n - d * c;
    int ans = d * a;
    ans += min(a, left);
    cout << ans << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, i) = (v[0], v[1]);
    println!("{}", n + 1 - i);
}

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()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
def readinput():
    n,k=map(int,input().split())
    return n,k

# 法Pの下での組み合わせ数 nCk を求める
# MAX: nの最大値

MAX = 2000+5  # (X+Y)/3より大きい整数 1 <= X, Y <= 10**6
MOD = (10**9)+7

fac=[1 for x in range(MAX)]
inv=[1 for x in range(MAX)]
finv=[1 for x in range(MAX)]

# 拡張ユークリッドアルゴリズム
# (d, x, y): d=ax+by を満たすd, x, yを求める
# aとbが互いに素な整数であればgcd(a,b)=d=1, ax=1 (mod b)
# xは法bの元でaの乗法逆元a^-1になる
def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def COMinit():
    for i in range(2,MAX):
        #print(i,fac)
        fac[i] = fac[i-1]*i % MOD
        (d, x, y) = exEuclid(i, MOD)
        inv[i] = x
        finv[i] = finv[i-1]*inv[i] % MOD

def COM(n, k):
    if(n<k):
        return 0
    elif ( (n<0)or(k<0)):
        return 0
    else:
        return fac[n]*(finv[n-k]*finv[k] % MOD) % MOD




def main(n,k):
    COMinit()
    m=n-k+1
    for i in range(1,k+1):
        if i > min(m,k):
            print(0)
        else:
            print( ( COM(m,i)*COM(k-1,i-1) ) %MOD )

if __name__=='__main__':
    n,k=readinput()
    main(n,k)


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

void print_info(int i, vector<int> const & heap){
    cout << "node " << i << ": key = " << heap[i] << ", ";
    if (i != 1) cout << "parent key = " << heap[i>>1] << ", ";
    if ((i << 1) < heap.size()) cout << "left key = " << heap[i<<1] << ", ";
    if ((i << 1) + 1 < heap.size()) cout << "right key = " << heap[(i<<1) + 1] << ", ";
    cout << endl;
}

int main()
{
    int H = 0;
    cin >> H;
    vector<int> heap(H + 1);
    heap[0] = 0;
    for (auto it = heap.begin() + 1; it != heap.end(); ++it) cin >> *it;
    for (int i = 1; i != H + 1; ++i) print_info(i, heap);
    
    return 0;
}

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

#define out(v) cout<<v<<"\n"
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using ll = long long;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  ll N; cin >> N;
  ll ans = N + 1;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      ans = i + (N / i);
    }
  }
  out(ans - 2);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int s=a+k-1;
	int sub=s-a+1;
	if(k*2<=b-a+1){for(int i=0;i<sub;i++){
						cout<<a+i<<endl;}
				   for(int i=sub-1;i>-1;i--){
				   cout<<b-i<<endl;}}
	else{for(int i=0;i<b-a+1;i++){
			cout<<a+i<<endl;}
		}
	return 0;
}


Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 998244353
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define sz(a) int((a).size())

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

ll dp[3005][3005];

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	dp[a][b]=1;
	for(int i=a;i<=c;i++)
	{
		for(int j=b;j<=d;j++)
		{
			if(i-a|j-b)
			{
				dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*\
				(i-1)*(j-1)%MOD+MOD)%MOD;
			}
		}
	}
	cout<<dp[c][d]<<endl;
	return 0;
}


Measured memory_bytes: 73980
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 200000;
const int MOD = (int)1e9 + 7;

int INV[N + 1], x[N + N], parent[N], from[N], size[N];
std::vector<int> graph[N], vertices;

int find(int u)
{
    return ~parent[u] ? parent[u] = find(parent[u]) : u;
}

bool dfs(int u, int v)
{
    if (~from[v]) {
        if (from[v] != u) {
            return false;
        }
    } else {
        from[v] = u;
        size[v] = 0;
        vertices.push_back(v);
        for (auto w : graph[v]) {
            if (w != u) {
                if (!dfs(v, w)) {
                    return false;
                }
            }
        }
    }
    return true;
}

int rec(int u, int v)
{
    if (!size[v]) {
        size[v] = 1;
        for (int w : graph[v]) {
            if (w < u) {
                size[v] += rec(v, w);
            }
        }
    }
    return size[v];
}

int solve(int a, int b)
{
    for (int v : vertices) {
        from[v] = -1;
    }
    vertices.clear();
    if (!dfs(a, b)) {
        return 0;
    }
    int result = 1;
    for (int v : vertices) {
        result = 1LL * result * INV[rec(from[v], v)] % MOD;
    }
    return result;
}

int main()
{
#ifdef LOCAL_JUDGE
    freopen("F.in", "r", stdin);
#endif
    INV[1] = 1;
    for (int i = 2; i <= N; ++ i) {
        INV[i] = 1LL * (MOD - MOD / i) * INV[MOD % i] % MOD;
    }
    int n;
    while (scanf("%d", &n) == 1) {
        for (int i = 0; i < n << 1; ++ i) {
            graph[i].clear();
        }
        for (int i = 0; i < n << 2; ++ i) {
            scanf("%d", x + i);
            x[i] --;
            if (i & 1) {
                x[i] += n;
            }
        }
        for (int i = 0; i < n << 2; ++ i) {
            graph[x[i]].push_back(x[i ^ 1]);
        }
        int result = 1;
        memset(from, -1, sizeof(from));
        memset(parent, -1, sizeof(parent));
        for (int i = 0; i < n << 1 && result; ++ i) {
            result = result * (i + 1LL) % MOD;
            int a = x[i << 1];
            int b = x[i << 1 | 1];
            if (find(a) == find(b)) {
                result = 1LL * result * (solve(a, b) + solve(b, a)) % MOD;
            } else {
                parent[find(a)] = find(b);
            }
        }
        printf("%d\n", result);
    }
}

Measured memory_bytes: 19708
#include <bits/stdc++.h>
using namespace std;
 
int main(){

int N;
  cin >> N;
  
string s;
long long mcnt = 0, acnt = 0, rcnt = 0, ccnt = 0, hcnt = 0, ans = 0;
  
  for(int i = 0;i < N;i++){
  cin >> s;
    if(s.at(0) == 'M') mcnt++;
    else if(s.at(0) == 'A') acnt++;
    else if(s.at(0) == 'R') rcnt++;
    else if(s.at(0) == 'C') ccnt++;
    else if(s.at(0) == 'H') hcnt++;
  }

  ans = mcnt * (acnt * (rcnt + ccnt + hcnt) + rcnt * (ccnt + hcnt) + (ccnt * hcnt));
  ans += acnt * (rcnt * (ccnt + hcnt) + (ccnt * hcnt));
  ans += rcnt * ccnt * hcnt;
    cout << ans << endl;  

  
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	cin >> N;
	vector<ll> A(N);
	ll sum = 0;
	vector<ll> SUM;
	SUM.pb(0);
	vector<int> minusPos;
	int absmin = 1000000005;
	int absminpos;
	for(int i = 0; i < N; i ++){
		cin >> A[i];
		if(abs(A[i]) < absmin){
			absmin = abs(A[i]);
			absminpos = i;
		}
		if(A[i] <= 0){
			minusPos.pb(i);
		}
		sum += abs(A[i]);
	}
	if(minusPos.size()%2 == 0){
	}
	else{
		sum -= 2 * abs(A[absminpos]);
	}
	cout << sum << endl;

	return 0;
}

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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

lli dp[301][301]; // k 個分用意しなくても上書きしてけば良いので、dp[i][j]のみ用意
#define INF (LLONG_MAX / 3);


int main() {
    lli N, M, R;
    cin3(N, M, R);
    lli r[8];
    ncin1(R, r);
    REP(i, 0, M) {
        lli from, to, cost;
        cin >> from >> to >> cost;
        dp[from][to] = dp[to][from] = cost;
    }

    // 初期化
    REPE(i, 1, N) {
        REPE(j, 1, N) {
            if (dp[i][j])
                continue;
            if (i == j)
                continue;
            dp[i][j] = INF;
        }
    }

    REPE(k, 1, N) {
        REPE(i, 1, N) {
            REPE(j, 1, N) {
                dp[j][i] = dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }
    lli ans = LLONG_MAX;
    sort(r, r+R);
    do {
        lli total = 0;
        REP(i, 0, R-1) {
            total += dp[r[i]][r[i+1]];
        }
        ans = min(ans, total);

    } while (next_permutation(r, r+R));
    cout << ans << endl;
    // dump
    //cout << endl;
    //REPE(i, 1, N) {
    //    REPE(j, 1, N) {
    //        cout << i << "-" << j << ": " << dp[i][j] << endl;
    //    }
    //    cout << endl;
    //}

    // Rの順番を全て舐める

}






Measured memory_bytes: 768
n, x = [int(i) for i in input().split()]

a = [1]
p = [1]

for i in range(n):
    a.append(a[i]*2+3) 
    p.append(p[i]*2+1)

def patty_count(num, x_bot):
    if num == 0:
        return 0 if x_bot<=0 else 1
    elif x_bot<=1+a[num-1]:
        return patty_count(num-1, x_bot-1)
    else:
        return p[num-1] + 1 + patty_count(num-1, x_bot-2-a[num-1])
 
print(patty_count(n, x))
# print()

Measured memory_bytes: 3064
import math

h, w = map(int, input().split())

is_odd_h = False
is_odd_w = False

if h % 2 == 0:
     pass
else:
     is_odd_h = True

if w % 2 == 0:
     pass
else:
     is_odd_w = True

if is_odd_h and is_odd_w:
    ans = math.ceil(h * w / 2)
else:
    ans = h * w / 2

if h == 1 or w == 1:
    ans = 1

print(int(ans))

Measured memory_bytes: 3060
use std::io::*;
use std::str::*;

// const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();
    let mut x: u32 = read().unwrap();
    // 0 initialize
    let mut a: Vec<u32> = Vec::new();
    for _ in 0..n {
        let tmp: u32 = read().unwrap();
        a.push(tmp);
    }
    a.sort();

    for i in 0..n {
        x -= a[i];
    }

    let ans = x / a[0];
    println!("{}", ans + n as u32);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ft first
#define sd second
#define mp make_pair
#define MAX 100010
#define pub push_back
#define pob pop_back
#define mt make_tuple
#define len length
#define dbgn(x) cerr<<#x<<": "<<x<<'\n'
#define dbg(x) cerr<<#x<<": "<<x<<' '
#define FOR(i,lbd,rbd) for((i)=(lbd);(i)<(rbd);++(i))
#define setZ(A) memset(A,0,sizeof A)
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
typedef map<lli,lli> mll;
typedef map<int,int> mii;
typedef priority_queue<int,vector<int>,greater<int> > pqi_min;
template<class T, class Y> 
T pow(T a,Y p) {
	if (p==0) return 1;
	if (p&1) {
		return (a*pow(a,p-1));
	}
	T y = pow(a,p>>1);
	return (y*y);
}
//int+string
//cin.ignore();

const int M=1e9+7;

pii a[1<<20];
void solve() {
	int n,i;
	cin>>n;

	FOR(i,0,n) 
		cin>>a[i].ft>>a[i].sd;

	sort(a,a+n,[] (const pii &a, const pii &b) {
		if (a.sd==b.sd) return a.ft<b.ft;
		return a.sd<b.sd;
	});

	int k=0;
	int ans=0;
	for(i=1;i<n;i++) {
		if (a[i].ft>a[k].sd) {
			ans+=(a[i-1].sd-a[k].ft+1);
			k=i;
		}
		a[k].sd=max(a[k].sd,a[i].sd);
	}
	ans+=(a[i-1].sd-a[k].ft+1);
	cout<<ans<<'\n';
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		string s;
		cin >> s;
		ll n = s.size() - 1;
		if (s[n] == '2' || s[n] == '4' || s[n] == '5' || s[n] == '7' || s[n] == '9')
			cout << "hon" << endl;
		else if (s[n] == '0' || s[n] == '1' || s[n] == '6' || s[n] == '8')
			cout << "pon" << endl;
		else
			cout << "bon" << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
from collections import deque
n, m = map(int, input().split())
g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

visited = [False]*n
d = [10**15]*n

visited[0] = True
d[0] = 0
q = deque([0])

ans = [0]*n

while q:
    v = q.popleft()
    for w in g[v]:
        if not visited[w]:
            visited[w] = True
            d[w] = d[v] + 1
            ans[w] = v+1
            q.append(w)

print('Yes')
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 95648
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;

ll cost[2020];
ll memo[2020];
int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int N;
  cin >> N;
  ll x;
  cin >> x;
  rep(i,N){
    cin >> cost[i];
    memo[i] = cost[i];
  }
  ll ans = 1LL<<60;
  for (int k = 0; k < N; k++) {
    ll cur = 0;
    rep(i,N){
      cur += memo[i];
    }
    ans = min(ans, cur + x * k);
    rep(i,N){
      memo[i] = min(memo[i], cost[(i-(k+1)+N) % N]);
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256