akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string>
#include<stack>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W,M;
    cin >> H;
    cin >> W;
    cin >> M;
    map<pair<int,int>,int> C;
    map<int,int> x_var;
    map<int,int> y_var;
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x;
        cin >> y;
        x_var[x-1]++;
        y_var[y-1]++;
        C[make_pair(x-1,y-1)]++;
    }
    vector<int> x_vec(H);
    vector<int> y_vec(W);
    map<int,int> :: iterator it;
    int max_x=0;
    int max_y=0;
    for(it=x_var.begin();it!=x_var.end();it++){
        if(it->second > max_x){
            max_x=it->second;
            x_vec.clear();
            x_vec.push_back(it->first);
        }
        else if(it->second == max_x){
            x_vec.push_back(it->first);
        }
    }
    for(it=y_var.begin();it!=y_var.end();it++){
        if(it->second > max_y){
            max_y=it->second;
            y_vec.clear();
            y_vec.push_back(it->first);
        }
        else if(it->second == max_y){
            y_vec.push_back(it->first);
        }
    }
    int total=max_x+max_y-1;
    for(int i=0;i<x_vec.size();i++){
        for(int j=0;j<y_vec.size();j++){
            if(C[make_pair(x_vec[i],y_vec[j])] == 0){
                cout << total+1 << endl;
                return 0;
            }
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 52568
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
#define MAX 1000001 
#define M 998244353
ll inverse(ll n)
{
	ll modu = M;
	ll m = modu;
	ll a = 0, b = 1;
	if (modu == 1)
		return 0;
	while (n > 1)
	{
		ll quo = n / modu;
		ll temp = modu;
		modu = n % modu, n = temp;
		temp = a; 
		a = b - (quo * a);
		b = temp;
	}
	if (b < 0)
		b += m;
	return b;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll k, x;
	cin >> k >> x;
	k *= 500;
	if (k >= x)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]
a = [c-(i+1) for i,c in enumerate(a)]

a.sort()
m = a[n//2]

print(sum(abs(i-m) for i in a))

Measured memory_bytes: 26104
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}
// 本体

constexpr ll MAXN  = 2e5;
ll fact[MAXN + 1]  = {};
ll ifact[MAXN + 1] = {};
void init_fact(ll n, ll mod) {
	fact[0] = ifact[0] = 1;
	for (int i = 0; i < n; i++) {
		fact[i + 1]	 = ((i + 1) * fact[i]) % mod;
		ifact[i + 1] = powm(fact[i + 1], mod - 2, mod);
	}
}

ll nci_m(ll n, ll i, ll mod) {
	return fact[n] * ifact[i] % mod * ifact[n - i] % mod;
}

int main() {
	IOS();
	ll MOD = 998244353;
	ll n, m, k;
	cin >> n >> m >> k;
	init_fact(n, MOD);
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ans += nci_m(n - 1, i, MOD) * m % MOD * powm(m - 1, n - i - 1, MOD) % MOD;
		ans %= MOD;
	}
	dump(ans);
}

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

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=c-a,y=d-b;
	cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<endl;
	return 0;
}

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

using namespace std;

int main (){
	//freopen("input.txt", "r", stdin);

	string str, s, s2;
	cin>>str;

	s.clear();
	s2.clear();

	int len = str.size();

	if(len == 1) cout<<0<<endl;
	else{

			int half = len/2;

		for(int i=0; i<half; i++){
			s += str[i];
			//str.erase(str.begin()+i);
		}

		int cnt2 = 0;
		for(int i=len-1;  ; i--){
			cnt2 ++;
			s2 += str[i];
			if(cnt2 == half) break;
		}
		

		//str.erase(0, (half));
		
		//cout<<s<<endl<<s2<<endl;

		int cnt = 0;
		for(int i=0; i<s2.size(); i++){
			if(s[i] != s2[i]) cnt++;
		}
		cout<<cnt<<endl;

	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define edge pair<ll,ll>
#define mod 1000000007
using namespace std;
 
 
// ¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++¦¦¦++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦¦¦¦¦¦¦¦¦+++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦+++++++¦++¦¦
// ¦¦¦¦¦¦¦¦++¦¦¦¦¦¦++++++¦¦¦¦+++++++++++++¦
// ¦¦¦¦¦¦¦++++++¦¦¦++++++¦¦++++++++++++++¦¦
// ¦¦¦¦¦¦¦+++++++¦¦¦+++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++¦¦¦¦¦¦¦¦+++++++¦ 
// ¦¦¦¦¦¦¦¦¦¦++¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦++++¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦ 
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++++++¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++¦¦+¦++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++¦¦+++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦¦+++¦¦¦¦++++++¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++¦¦+¦¦¦¦¦+++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++++++++++¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++++++++++¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++++¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+¦¦¦+++++++++++¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦+++++++++¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++++¦¦¦¦¦¦¦¦¦¦
// ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦++++++¦¦¦¦¦¦¦¦¦¦¦¦

//ll dp[maxx];
//ll par[maxx];


int main()
{
	
	fast;
	ll a,b,n;
	string s;
	ll c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;	
	
	return 0;
}
//cout<<"YES"<<endl;

//cout<<"NO"<<endl;

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

int main() {
  
  string a,b,c;
  cin >> a >> b >> c;
  
  cout << a[0] << b[1] << c[2] << endl;
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
 		Scanner sc = new Scanner(System.in);

    int n=sc.nextInt();
    int count=0;
    int ans=0;
    for(int i=1;i<=n;i++){
      count=0;
      for(int s=i;s>=1;s--){
        if(i%s==0){
          count++;
        }
      }
      if(i%2!=0 && count==8){
        ans++;
      }
    }
    System.out.println(ans);

	}
}


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

int main() {
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;
  vector< pair<string,int> > H(N);
  for(int i=0;i<N;i++) cin>>H.at(i).first>>H.at(i).second;

  string sleep;
  cin>>sleep;

  int ans=0;
  bool check=false;
  for(int i=0;i<N;i++){
    if(check){
      ans += H.at(i).second;
    }
    if(sleep==H.at(i).first) check=true;
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iomanip>

using namespace std;


int main()
{
    int W, H, x, y;
    cin >> W >> H >> x >> y;
    double area = double(W) * double(H) / 2.0;
    int other = 0;
    if(x==double(W)/2.0 and y==double(H)/2.0)
        other = 1;

    cout<<std::setprecision(30)<<area<<" "<<other<<endl;


//    1000000000 1000000000 1 1
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();
		String str_r = "";
		int i;
		for(i = 0; i < str.length(); i++) {
			str_r = str_r + str.charAt(str.length() - i - 1);
		}
		scanner.close();
		System.out.println(str_r);
	}

}



Measured memory_bytes: 25752
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

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

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

Int n, m;
Int a[110000];
void ng(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    cin >> n >> m;
    Int one = 1;
    for(Int i = 0 ;i < n;i++){
        cin >> a[i];
    }
    int cnt = 0;
    while(a[0] % (1 << cnt) == 0)cnt++;
    for(Int i = 0;i < n;i++){
        if(a[i] % (1 << (cnt-1)))ng();
        if(a[i] % (1 << cnt) == 0)ng();
        a[i] >>= (cnt-1);
    }
    Int now = 1;
    m >>= (cnt-2);
    for(Int i = 0;i < n;i++){
        now = lcm(now, a[i]);
        if(now > m)ng();
    }
    Int ans = m / now;
    ans = (ans + 1) / 2;
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

bool era[252525];

int main(){
  set<int> S;
  map<int,int> X;
  while(true){
    int a,b;
    scanf("%d,%d",&a,&b);
    if(a==0 && b==0)break;
    S.insert(b);
    X[a] = b;
  }
  map<int,int> rank;
  set<int>::iterator iter;
  iter = S.end();
  int k=1;
  do{
    --iter;
    rank[*iter] = k++;
  }while(iter!=S.begin());
  int n;
  while(~scanf("%d",&n))cout<<rank[X[n]]<<endl;
  return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int  xi , i , x1 , x2 , x3 , x4 , x5;
xi =i ;

   cin >> x1 >> x2 >> x3 >> x4 >> x5;
 if (x1 ==0  ) {i =x1 ;
    cout << "1"<< endl;
  }

  else if (x2==0) {i =x2 ;
    cout << "2"<< endl;
  }
  else if (x3== 0) {i ==x3;
    cout << "3"<< endl;
  }

  else if (x4==0) {x4=i ;
    cout << "4"<< endl;
  }
  else if (x5== 0) {x5=i;
    cout << "5"<< endl;
  }
  else {
    cout << "error" << endl;
  }
  }

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <utility>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <map>
#include <climits>
#include <bitset>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

std::vector<int> ZAlgorithm(const std::string& S)
{
    std::vector<int> Z(S.size());
    Z[0] = S.size();

    // 現在の探索位置
    auto idx = 1;

    // 一致した文字数
    auto matched = 0;

    while (idx < S.size())
    {
        // S[i]の位置から何文字がSの共通接頭辞か
        while (idx + matched < S.size() && S[matched] == S[idx + matched])
            matched++;

        Z[idx] = matched;

        if (matched == 0)
        {
            idx++;
            continue;
        }

        // 一致した分だけ既存のZ値をコピーできる
        // ただし k + Z[k] が 一致した文字数 j 以上になると Z[i+k] = Z[k] が成り立たなくなる可能性がある
        auto k = 1;
        while (k + Z[k] < matched)
        {
            Z[idx + k] = Z[k];
            k++;
        }

        // コピーした分を飛ばす
        idx += k;
        matched -= k;
    }

//    for (auto z : Z)
//        std::cout << z << std::endl;

    return Z;
}

int main()
{
    std::ios::sync_with_stdio(false);

    ll N;
    std::string S;
    std::cin >> N >> S;

    auto result = 0;
    for (auto i=0; i<N; ++i)
    {
        auto subStr = S.substr(i, N - i);
        auto zResult = ZAlgorithm(subStr);
        for (auto j=0; j < subStr.size(); ++j)
            result = std::max(result, std::min(j, zResult[j]));
    }

    std::cout << result << std::endl;
}


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

int main() {
  int INF = 100000001;
  int H, N;
  cin >> H >> N;
  
  vector<vector<int>> dp(N + 1, vector<int>(H + 1, INF));
  dp.at(0).at(0) = 0;
  for (int i = 1; i <= N; i++) {
    int A, B;
    cin >> A >> B;
    for (int j = 0; j <= H; j++) {
      dp.at(i).at(j) = min(dp.at(i - 1).at(j), dp.at(i).at(max(j - A, 0)) + B);
    }
  }
  
  int ans = dp.at(N).at(H);

  cout << ans << endl;
}

Measured memory_bytes: 42316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
#include<climits>
using namespace std;

int main()
{
  long long n, x, sum = 0, count = 0;
  cin >> n >> x;
  vector<long long> v(n,0);

  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    sum += v[i];
  }

  sort(v.begin(), v.end());

  long long min = v.front();

  x -= sum;

  while (x >= min)
  {
    x -= min;
    count++;
  }

  cout << count + n << endl;
}


Measured memory_bytes: 256
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End
ll fact[200005];

ll mul(ll a,ll b){return (a*b)%MOD;}
ll add(ll a,ll b){return (a+b)%MOD;}
ll sub(ll a,ll b){return (a-b+MOD)%MOD;}

ll modexp(ll num,ll pow){
	if(num==1 || pow==0)return 1;
	if(pow&1)return mul(num,modexp(mul(num,num),pow/2));
	else return modexp(mul(num,num),pow/2);
}
ll ncr(ll n,ll r){
	ll ret=fact[n];
	ret=mul(ret,modexp(fact[r],MOD-2));
	ret=mul(ret,modexp(fact[n-r],MOD-2));
	return ret;
}
int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		ll n,k;cin>>n>>k;
		ll ans=0;
		for(ll i=k;i<=n+1;i++){
			ans=add(ans,add(mul(i,n+1-i),1));
		}
		cout<<ans<<endl;
		
    }
    return 0;
        
}


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

const int MAX_N = (int)1e5 + 5;

int n;
int a[MAX_N];

int ans = -1;
unordered_map<int, int> mp;

int main(void){
  // Here your code !
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

  for (int i = 0; i < n; ++i) {
    auto itr = mp.find(a[i]);
    if(itr != mp.end()) {
        mp[a[i]] += 1;
    }
    else {
        mp[a[i]] = 1;
    }
  }

  vector<int> keys = {};
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) keys.push_back(itr->first);

  sort(keys.begin(), keys.end());

  for (int i = 0; i < keys.size(); ++i) {
    vector<int> could = {};
    vector<int> base = {};

    base.push_back(keys[i]);
    could.push_back(keys[i] - 1); could.push_back(keys[i]); could.push_back(keys[i]);

    for (int b = i - 1; b >= 0; --b) {
      if (keys[b] + 1 >= keys[i] - 1) {
        base.push_back(keys[b]);
        could.push_back(keys[b] - 1); could.push_back(keys[b]); could.push_back(keys[b]);
      }
      if (keys[b] + 1 < keys[i] - 1) break;
    }

    for (int f = i + 1; f < keys.size(); ++f) {
      if (keys[f] - 1 <= keys[i] + 1) {
        base.push_back(keys[f]);
        could.push_back(keys[f] - 1); could.push_back(keys[f]); could.push_back(keys[f]);
      }
      if (keys[f] -1 > keys[i] + 1) break;
    }

    // sort(base.begin(), base.end());

    sort(could.begin(), could.end());
    could.erase(unique(could.begin(), could.end()), could.end());

    for (int ic = 0; ic < could.size(); ++ic) {
      int tmpsize = 0;
      for (int j = 0; j < base.size(); ++j) {
        if (base[j] - 1 <= could[ic] && could[ic] <= base[j] + 1) {
          tmpsize += mp[base[j]];
        }
      }
      ans = max(ans, tmpsize);
    }
  }

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

  return 0;
}


Measured memory_bytes: 4132
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 1000000
void showColumnLetters(ll n) {
   string str = "";
   while (n) {
      ll rem = n%26;
      if (rem==0) {
         str += 'z';
         n = (n/26)-1;
      }
      else{
         str += (rem-1) + 'a';
         n = n/26;
      }
   }
   reverse(str.begin(), str.begin() + str.length());
   cout << str << endl;
}
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	ll n;
	cin>>n;
	// cout<<n;
	showColumnLetters(n);
	

	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 3796
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define mod 1000000007
int main(){
  long long n,m;
  cin >> n >> m;
  long long ans=0;
  if(abs(n-m)<2){
    ans=1;
    for(long long i=1;i<=n;i++)ans=(ans*i)%mod;
    for(long long i=1;i<=m;i++)ans=(ans*i)%mod;
    if(n==m)ans=(ans*2)%mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i, j, k, n, a[100], tmp;
	scanf("%d",&n);
	for(i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for(i = 0;i < n;i++){
		printf("%d",a[i]);
		if(i != n - 1) printf(" ");
	}
	printf("\n");
	for(i = 1;i < n;i++){
		tmp = a[i];
		for(j = i - 1;j >= 0 && a[j] > tmp;j--)
				a[j + 1] = a[j];
		a[j + 1] = tmp;
		for(j = 0;j < n;j++){
			printf("%d",a[j]);
			if(j != n - 1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

class Unionfind {
public:
    vector < ll > par; // 各元の親を表す配列
    vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    Unionfind(ll sz_): par(sz_), siz(sz_, 1) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main()
{
  cout << fixed << setprecision(10);
  int N,M;
  cin >> N >> M;
  vector<int> A(M),B(M);
  rep(i,M)
  {
    cin >> A[i] >> B[i];
    A[i] --;
    B[i] --;
    if(B[i]>A[i]) swap(A[i],B[i]);
  }
  Unionfind uf(N);
  uf.init(N);
  rep(i,M)
  {
    uf.merge(A[i],B[i]);
  }
  int ans = 0;
  rep(i,N)
  {
    if(ans<uf.size(i))
    {
      ans = uf.size(i);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;

vector<int> dp, v;

int solve(int n)
{
	if(n == 0) return 0;
	if(n == 1) return abs(v[1] - v[0]);
	// o mejor sería de caso base:
	//	if(n <= 1) return abs(v[n] - v[0]);
	// más conciso pero menos explícito
	// a medida que mejores debes buscar escribir menos
	// y entendiendo mejor los atajos como este

	if(dp[n] != -1) return dp[n]; // Para no calcular un estado ya visitado.
	// El valor que indica que no lo has visitado depende del problema
	// En este la respuesta nunca es negativa, luego, -1 es bueno.

	return dp[n] = min(solve(n - 1) + abs(v[n] - v[n - 1]),
			   solve(n - 2) + abs(v[n] - v[n - 2]));
	// y ya está, recuerda siempre guardar el valor de la dp cuando la tengas
	// bien calculada.
}

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

	int n;
	cin >> n;

	// inicializando el vector(array) a tamaño n y valores por defecto 0
	v = vector<int>(n);

	// inicializando el vector(array) a tamaño n y valores por defecto -1
	// para saber que ese estado de la dp no lo hemos visitado y tenemos que
	// calcular su valor. Si ya fue calculado entonces su valor es correcto
	// y solo se devuelve.
	dp = vector<int>(n, -1);

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

	cout << solve(n - 1) << endl;

	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#define mk make_pair
#include<set>

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

const int maxn = 2e5+1e2;

struct Node{
	int x,y;
};

map<pair<int,int>,int> mp;
set<int> s[maxn];
int n,m,num;
Node a[maxn];
int ans=1e9;

void dfs(int x,int y,int now)
{
	if (x>n || y>m) return;
	set<int> :: iterator it;
	it=s[y].lower_bound(x);
	int val = *it;
	val--;
	ans=min(ans,now+val-x);
	
//	cout<<now<<" "<<ans<<" "<<val<<" "<<x<<" "<<y<<" "<<mp[mk(x,y+1)]<<endl; 
	
	//while (1);
	if (mp[mk(x+1,y+1)] || mp[mk(x+1,y)]) 
	{
	   if (!mp[mk(x+1,y)])
	     dfs(x+1,y,now+1);
	}
	else dfs(x+1,y+1,now+1);
}
int main()
{
  n=read(),m=read(),num=read();
  for (int i=1;i<=m;i++) s[i].insert(n+1);
  for (int i=1;i<=num;i++)
  {
  	 a[i].x=read();
  	 a[i].y=read();
  	 s[a[i].y].insert(a[i].x);
  	 mp[make_pair(a[i].x,a[i].y)]=1;
  }
  dfs(1,1,0);
  cout<<ans+1;
  return 0;
}


Measured memory_bytes: 88064
n, t = gets.chomp.split(" ").map(&:to_i)
tt = gets.chomp.split(" ").map(&:to_i)
sum = 0
tt.each_cons(2) do |a, b|
    if b - a > t
        sum += t
    else
        sum += b - a
    end
end
sum += t
puts sum

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

#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  ll n;
  cin >> n;
  if(n%2 == 0)
    cout << n/2 << endl;
  else
    cout << n/2 + 1 << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double
 
const int N=305;
 
int n;
int a[N], f[N];
bool vis[N][N][N];
double cache[N][N][N];
 
double dp(int a, int b, int c)
{
	if(a<0 || b<0 || c<0)
		return 0;
	if(a==0 && b==0 && c==0)
		return 0;
	double &ans=cache[a][b][c];
	if(vis[a][b][c])
		return ans;
	vis[a][b][c]=1;
	ans=n + a*dp(a-1, b, c) + b*dp(a+1, b-1, c) + c*dp(a, b+1, c-1);
	ans/=(a+b+c);
	return ans;
}
 
int32_t main()
{
	IOS;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		f[a[i]]++;
	}
	double ans=dp(f[1], f[2], f[3]);
	cout<<fixed<<setprecision(12)<<ans;
	return 0;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  bool f = false;
  int i = 0;
  char s[1025];
  while ((s[i] = getchar()) != EOF) {
    if (s[i] == ' ' || s[i] == '.' || s[i] == ',') {
      s[i] = '\0';
      if (i >= 3 && i <= 6) {
        if (f) putchar(' ');
        printf(s);
        f = true;
      }
      i = -1;
    }
    i++;
  }
  putchar('\n');
  return 0;
}

Measured memory_bytes: 1088
/* _    _       _       _   __________
  | |  | |     /_\     | | |____  ____|
  | |__| |    //_\\    | |      | |
  |  __  |   / ___ \   | |      | |
  | |  | |  / /   \ \  | |      | |
  |_|  |_| /_/     \_\ |_|      |_|*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
const ll mod=1e9+7;

int main()
{
    ll n,i,j,s=0,k=0;
    ll a,b,c;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k;return 0;
    }
    if(k<=(a+b))
    {
        cout<<a;return 0;
    }
    cout<<a-(k-a-b);
    
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n),x(n+1,0);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)x[a[i]]=x[a[i]-1]+1;
    int res=0;
    for(int i=0;i<n;i++)res=max(res,x[i+1]);
    cout<<n-res<<endl;
}

Measured memory_bytes: 1792
n= int(input())
import sys
pn = list(map(int, sys.stdin.readline().split()))
qn = list(map(int, sys.stdin.readline().split()))

a = 0
b= 0
m = [1]*(n+1)
m[0]=0

import math

for i in pn:

    if sum(m)==2:
        a += sum(m[:i]) +1
        break
    m[i] = 0

    a += sum(m[:i])* math.factorial(sum(m))


m = [1]*(n+1)
m[0]=0

for i in qn:

    if sum(m)==2:
        b += sum(m[:i]) +1
        break
    m[i] = 0

    b += sum(m[:i])* math.factorial(sum(m))


print(abs(a-b))


Measured memory_bytes: 9020
import math

def Cramer(c):
	den = c[0]*c[4] - c[1]*c[3]
	return [(c[2]*c[4] - c[1]*c[5]) / den, (c[0]*c[5] - c[2]*c[3]) / den]

n = eval(input())
for i in range(n):
	c = [eval(item) for item in input().split()]
	sol = Cramer([2*(c[0] - c[2]),\
				  2*(c[1] - c[3]),\
				  c[0]**2 + c[1]**2 - c[2]**2 - c[3]**2,\
				  2*(c[0] - c[4]),\
				  2*(c[1] - c[5]),\
				  c[0]**2 + c[1]**2 - c[4]**2 - c[5]**2])
	r = math.sqrt((sol[0] - c[0])**2+(sol[1] - c[1])**2)
	print('%.3f %.3f %.3f' %(sol[0], sol[1], r))

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


int main(){
    int N;
    int P[10], Q[10];
    cin >> N;
    int p=0, q=0;
    
    for(int i=0; i<N; i++){
        cin >> P[i];
        p = p*10 + P[i];
    }
    for(int j=0; j<N; j++){
        cin >> Q[j];
        q = q*10 + Q[j];
    }
    
    int R[50000];
    int a=0;
    R[a] = 0;

    vector<int> v;
    for(int k=1; k<=N; k++){
        v.push_back(k);
    }
    do {
        for(auto x : v){
            R[a] = R[a]*10 + x;
            //cout << x << " ";     
        }
        //cout << endl;
        a++;
    }while(next_permutation(v.begin(), v.end()));
    /*
    for(int c=0; c<a; c++)
    {
        cout << R[c];
        cout << endl;
    }

    cout << p << endl;
    cout << q << endl;
    */
    int countP = 0;
    int countQ = 0;

    for(int d=0; d<a; d++){
        if(R[d] == p){
            countP = d+1;
        }
        if(R[d] == q){
            countQ = d+1;
        }
    }

    if(countP-countQ > 0){
        cout << countP-countQ;
    }
    else{
        cout << countQ-countP;
    }
    
    //cout << a;

    return 0;
}

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


int main(){
  int N,D;
  cin >> N>>D;
  int i=1;
  int look=0;
  while(1){
    look+=2*D+1;
    if(look>=N){
      break;
    }
    i++;
  }
  cout<<i<<endl;
}


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

int main() {
	string s;
	int count=0;
	cin>>s;
	for(int i=0;i<s.length()/2;i++){
	    if(s[i]==s[s.length()-i-1]){
	        count+=0;
	    }
	    else{
	        count+=1;
	    }
	}
	cout<<count;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; string S; 
	cin >> N >> S; 
	int ans = 1; 
	for(int i = 0; i < N-1; i++){
		if(S.at(i) != S.at(i+1)) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 512
import sys
input = lambda: sys.stdin.readline().rstrip()
P = 10 ** 40 + 121
N = int(input())
X = sorted([input()[::-1] for _ in range(N)], key = len)

D = {}
ans = 0
for x in X:
    L = [0] * 26
    T, a = x[:-1], ord(x[-1]) - 97
    h = 0
    for t in T:
        if h in D:
            for i in range(26):
                L[i] += D[h][i]
        b = ord(t) - 97
        ans += L[b]
        L[b] = 0
        
        h = (h + b + 135) * 71 % P
    ans += L[a]
    if h in D:
        D[h][a] += 1
    else:
        D[h] = [0] * 26
        D[h][a] = 1
    
print(ans)

Measured memory_bytes: 183700
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
int main(){
  char c;
  int i = 0;
  while((c=getchar())!=EOF){
    if(c=='+'){
      i=i+1;
    }
    else if(c=='-'){
      i=i-1;
    }
  }
  printf("%d",i);
  return 0;
}

Measured memory_bytes: 128
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = []
for _ in range(n):
    ab.append(tuple(li()))
    
ab.sort()

rest = m
ans = 0
for a,b in ab:
    if rest > b:
        ans += a*b
        rest -= b
        
    elif rest == b:
        ans += a*b
        rest = 0
        
    else:
        ans += a*rest
        rest = 0
        
    if rest == 0:
        break
    
print(ans)

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  ll P;cin >> P;
  map<ll, ll> m;
  for(ll i=2;i*i<=P;i++){
    while(P%i==0){
      m[i]++;
      P/=i;
    }
  }
  m[P]++;
  ll ans = 1;
  for(auto i: m){
    ans *= pow(i.first, i.second/N);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
	int S,K;
	int C=0;
	scanf("%d%d", &K, &S);
	for(int X=0;X<=K;X++){
		for(int Y=0;Y<=K;Y++){
			int Z=S-(X+Y);
			if(Z>=0&&Z<=K)
			C++;
		}
	}
	printf("\n%d", C);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int X,Y,Z,tmp;
  scanf("%d %d %d",&X,&Y,&Z);
  tmp=X;
  X=Y;
  Y=tmp;
  tmp=X;
  X=Z;
  Z=tmp;
  printf("%d %d %d",X,Y,Z);
 return 0;　
}

Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
typedef pair<int,int> P;//to, cov
vector<P> E[2000];
bool used[2000];

int n,k,s,S,ans;

void dfs(int st, int v, int len, int sur){
    used[v]=true;
    // cout<<v<<' '<<len<<endl;
    if(len==k) ans = min(ans,sur);
    for(auto p:E[v]){
        int to, cov;
        tie(to,cov)=p;
        if(to==st&&len==k&&k>2){
            ans = min(ans, sur-cov);
        }else if(len<k&&!used[to]){
            dfs(st,to,len+1,sur+S-cov);
        }
    }
    used[v]=false;
}

int main(){
    while(cin>>n>>k>>s,n){
        vector<int> X,Y,Z;
        for(int i=0;i<2000;i++) E[i].clear();
        S=s*s*6;
        ans = 1000000000;
        for(int i=0;i<n;i++){
            int x,y,z;
            cin>>x>>y>>z;
            X.push_back(x);
            Y.push_back(y);
            Z.push_back(z);
        }
        if(k==1){
            cout<<S<<endl;
            continue;
        }
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int dx = abs(X[i]-X[j]);
                int dy = abs(Y[i]-Y[j]);
                int dz = abs(Z[i]-Z[j]);
                if(dx<s&&dy<s&&dz<s){
                    // cout<<i<<' '<<j<<':'<<dx<<' '<<dy<<' '<<dz<<endl;
                    int cov=((s-dx)*(s-dy)+(s-dy)*(s-dz)+(s-dz)*(s-dx))*2;
                    E[i].emplace_back(j,cov);
                    E[j].emplace_back(i,cov);
                }
            }
        }
        for(int i=0;i<n;i++){
            dfs(i,i,1,S);
        }
        if(ans==1000000000)ans=-1;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3228
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

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

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int C[N], S[N], F[N];
	C[0] = 0;
	S[0] = 0;
	F[0] = 0;
	FOR(i, 1, N) {
		cin >> C[i] >> S[i] >> F[i];
	}
	FOR(i, 1, N) {
		int time = 0;
		time += S[i] + C[i];
		FOR(j, i+1, N) {
			int t = 0;
			while (true) {
				if (F[j] * t >= S[j] && F[j] * t >= time) {
					time = F[j] * t + C[j];
                  break;
				}
				t++;
			}
		}
		cout << time << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{	if(a.first!=b.first)
    {
    	return a.first<b.first;
	}
	return a.second<b.second;
}
void printQ(vector<int> q)
{   
    cout<<"v->  ";
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int h,n;
    cin>>h>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
    	int a;
    	cin>>a;
    	sum+=a;
	}
    if(sum>=h)
    {
    	cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}













Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <tuple>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int N = 20;

int n;
int a[N];
map<pair<int, int>, ll> dp[N][N];

ll dfs(int l, int r, int x, int y) {
  if (l + 1 == r) return 0;
  auto it = dp[l][r].find(make_pair(x, y));
  if (it != dp[l][r].end())
    return it->second;
  ll cur = 1LL << 60;
  for (int i = l + 1; i < r; ++i)
    cur = min(cur, dfs(l, i, x, x + y) + dfs(i, r, x + y, y) + a[i] * (ll)(x + y));
  return dp[l][r][make_pair(x, y)] = cur;
}

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

  cin >> n;
  for (int i = 1; i <= n; ++i)
    cin >> a[i];
  cout << (dfs(1, n, 1, 1) + a[1] + a[n]) << '\n';

  return 0;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N, M, ans;
vector<int> G[202020];

void f(int u, int p, int dis){
    if (ans < dis) ans = dis, M = u;
    for (int v : G[u]) if (v != p) f(v, u, dis+1);
}

int main(){
    int u, v;
    scanf("%d", &N);
    for (int i=1; i<N; i++){
        scanf("%d %d", &u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    f(1, 0, 1);
    f(M, 0, 1);
    if (ans % 3 == 2) puts("Second");
    else puts("First");
    return 0;
}


Measured memory_bytes: 20608
//test
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
int n, m, clk, cnt;
std::vector<std::vector<std::pair<int, int>>> e;
std::vector<int> a, b, ans, dfn, low, belong, stk;
std::vector<std::vector<int>> f;
void dfs(int u) {
    stk.push_back(u);
    dfn[u] = low[u] = clk++;
    for (auto &&edge : e[u]) {
        int v, i;
        std::tie(v, i) = edge;
        if (dfn[v] == -1) {
            dfs(v);
            low[u] = std::min(low[u], low[v]);
        } else if (belong[v] == -1) {
            low[u] = std::min(low[u], dfn[v]);
        }
    }
    if (dfn[u] == low[u]) {
        int v;
        do {
            v = stk.back();
            stk.pop_back();
            belong[v] = cnt;
        } while (v != u);
        ++cnt;
    }
}
void solve() {
    for (int s = 0; s < n; ++s) {
        f.assign(n, std::vector<int>(2, -1));
        std::queue<std::pair<int, int>> que;
        f[s][0] = f[s][1] = s;
        for (auto &&edge : e[s]) {
            int v, i;
            std::tie(v, i) = edge;
            f[v][0] = v;
            que.emplace(v, 0);
        }
        while (!que.empty()) {
            int u, j;
            std::tie(u, j) = que.front();
            que.pop();
            for (auto &&edge : e[u]) {
                int v, i;
                std::tie(v, i) = edge;
                if (f[v][0] == -1) {
                    f[v][0] = f[u][j];
                    que.emplace(v, 0);
                } else if (f[v][1] == -1 && f[v][0] != f[u][j]) {
                    f[v][1] = f[u][j];
                    que.emplace(v, 1);
                }
            }
        }
        for (auto &&edge : e[s]) {
            int v, i;
            std::tie(v, i) = edge;
            if (f[v][1] != -1)
                ans[i] ^= 1;
        }
    }
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> m;
    a.resize(m);
    b.resize(m);
    ans.resize(m);
    e.resize(n);
    dfn.assign(n, -1);
    low.resize(n);
    belong.assign(n, -1);
    for (int i = 0; i < m; ++i) {
        std::cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        e[a[i]].emplace_back(b[i], i);
    }
    for (int i = 0; i < n; ++i)
        if (dfn[i] == -1)
            dfs(i);
    for (int i = 0; i < m; ++i)
        if (belong[a[i]] == belong[b[i]])
            ans[i] = 1;
    solve();
    for (int i = 0; i < m; ++i)
        std::cout << (ans[i] == 1 ? "diff" : "same") << "\n";
    return 0;
}

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

int N;
long long A[100000], B[100000];
long long sum, min_aside = 1LL << 62;

int main() {
  cin >> N;
  bool even = true;
  for(int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
    if(A[i] != B[i]) even = false;
    sum += A[i];
    if(A[i] > B[i]) {
      min_aside = min(min_aside, B[i]);
    }
  }
  if(even) cout << 0 << endl;
  else cout << sum - min_aside << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n;
	cin >> n;
	vector<pi> red(n), rred(n);
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		red[i] = { a,b };
	}
	sort(rall(red));
	vector<pi> blue(n), rblue(n);
	rep(i, 0, n) {
		int c, d;
		cin >> c >> d;
		blue[i] = { c,d };
		rblue[i] = { d,c };
	}
	sort(all(blue));
	sort(all(rblue));

	int ans = 0;
	{
		int cou = 0;
		rep(i, 0, n) {
			int a = red[i].first, b = red[i].second;
			rep(j, 0, n) {
				if (a < blue[j].first&&b < blue[j].second) {
					blue[j].first = blue[j].second = INT_MIN;
					cou++;
					break;
				}
			}
		}
		ans = max(ans, cou);
	}
	{
		int cou = 0;
		rep(i, 0, n) {
			int a = red[i].first, b = red[i].second;
			rep(j, 0, n) {
				if (b < rblue[j].first&&a < rblue[j].second) {
					rblue[j].first = rblue[j].second = INT_MIN;
					cou++;
					break;
				}
			}
		}
		ans = max(ans, cou);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
  var input=input.trim();
  var a=0,b=0;
  for(var i=0;i<input.length;i++){
    if(input[i] == '0') a++;
    else b++;
  }
  console.log(Math.min(a,b)*2);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 11468