akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct range_edge_graph {
    int n;
    struct edge { int to; long long weight;};
    vector<vector<edge>> g;
    
    range_edge_graph(int n_) {
        n = 1;
        while (n < n_) n <<= 1;
        g.resize(n<<2);
        for (int i = 1; i < n; ++i) {
            int c1 = i<<1|0, c2 = i<<1|1;
            g[i].push_back({c1, 0});
            g[i].push_back({c2, 0});
            g[c1+2*n].push_back({i+2*n, 0});
            g[c2+2*n].push_back({i+2*n, 0});
        }
        for (int i = n; i < 2*n; ++i)
            g[i].push_back({i+2*n, 0});
    }

    // from [l1, r1) to [l2, r2)
    void add_edge(int l1, int r1, int l2, int r2, long long w) {
        int id = g.size();
        l1 += n, r1 += n;
        while (l1 < r1) {
            if (l1 & 1) g[l1+2*n].push_back({id, 0}), l1++;
            if (r1 & 1) --r1, g[r1+2*n].push_back({id, 0});
            l1 >>= 1, r1 >>= 1;
        }
        vector<edge> node;
        l2 += n, r2 += n;
        while (l2 < r2) {
            if (l2 & 1) node.push_back({l2++, w});
            if (r2 & 1) node.push_back({--r2, w});
            l2 >>= 1, r2 >>= 1;
        }
        g.push_back(node);
    }

    vector<long long> dijkstra(int s) {
        s += n;
        vector<long long> dist(g.size(), numeric_limits<long long>::max());
        dist[s] = 0;
        using P = pair<long long, long long>;
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, s);
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (edge& e : g[v]) {
                if (dist[e.to] > dist[v] + e.weight) {
                    dist[e.to] = dist[v] + e.weight;
                    que.emplace(dist[e.to], e.to);
                }
            }
        }
        vector<long long> res(dist.begin() + n, dist.begin() + 2*n);
        return res;
    }
};

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

    int n, m;
    cin >> n >> m;
    range_edge_graph g(n);

    for (int i = 0; i < m; ++i) {
        int l, r, c;
        cin >> l >> r >> c;
        l--; r--;
        g.add_edge(l, r+1, l, r+1, c);
    }
    auto dist = g.dijkstra(0);
    long long ans = dist[n-1];
    cout << (ans == numeric_limits<long long>::max() ? -1 : ans) << endl;
}


Measured memory_bytes: 99332
// ABC144-D
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    double a,b,x,t,ans;
    cin>>a>>b>>x;
    if(x/a<=a*b/2){
        t=2*x/(a*b);
        ans=atan(b/t)*180/M_PI;
    }else{
        t=(2*b*a*a-2*x)/(a*a);
        ans=atan(t/a)*180/M_PI;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
char up(char c) {
    if ('a' <= c && c <= 'z') {
        c = c - ('a' - 'A');
    }
    return c;
}

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

Measured memory_bytes: 256
import sys
H, W = map(int, input().split())
coordinates = [[0]] * (H + 2)
coordinates[0] = ["."] * (W + 2)
coordinates[H + 1] = ["."] * (W + 2)

for i in range(1, H + 1):
    coordinates[i] = ['.'] + [i for i in input()] + ['.']

for j in range(1, H + 1):
    for k in range(1, W + 1):
        if coordinates[j][k] == '#':
            if coordinates[j - 1][k] == '#' or coordinates[j][k - 1] == '#' or coordinates[j + 1][k] == '#' or coordinates[j][k + 1] == '#':
                continue
            else:
                print('No')
                sys.exit()
print('Yes')

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;

void main() {
	auto input = getStdin!(string[])()[0];
	int[] num = input.split(" ").to!(int[]);
	if (num[0] < num[1]) {
		if (num[1] < num[2]) {
			"Yes".writeln;
			return;
		}
	}
	"No".writeln;
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2480
#include<vector>
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int ll;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define MOD 1000000007;

ll dp[2020][2020];
int ac[2001][100001];
int main(){
  int n,m; cin >> n >> m;
  rep(i,2020) rep(j, 2020) dp[i][j] = 0;
  rep(i,n+1) dp[i][0] = 1;
  rep(i,m+1) dp[0][i] = 1;
  vector<long long int> s(n), t(m);
  for(int i=0;i<n;i++) cin >> s[i];
  for(int i=0;i<m;i++) cin >> t[i];
  for(int i=1;i<n+1;i++) for(int j=0;j<100001;j++) ac[i][j] = 0;
  for(int j=0;j<100001;j++) ac[0][j] = 0;

  for(int j=1;j<=m;j++){
    for(int i=0;i<=n;i++) ac[i][t[j-1]] = (ac[i][t[j-1]] + dp[i][j-1]) % MOD;
    for(int i=1;i<=n;i++){
      ll sum = 0;
      // for(int k=j-1;k>=0;k--) if(s[i-1]==t[k]) sum = (dp[i-1][k] + sum) % MOD;
      sum =  (sum + ac[i-1][s[i-1]]) % MOD;
   //   cout << ac[i-1][s[i-1]] << endl;
      dp[i][j] = (dp[i-1][j] + sum)%MOD;
    }
    
  }
  rep(i,n+1){
  //  rep(j,m+1) cout << dp[i][j] << " ";
//    cout << endl;
  }
 cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 813824
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
    string s;cin>>s;
    if(s[s.size()-1]=='2' || s[s.size()-1]=='4'||s[s.size()-1]=='5'||s[s.size()-1]=='7'||s[s.size()-1]=='9')cout<<"hon"<<endl;
    else if(s[s.size()-1]=='3')cout<<"bon"<<endl;
    else cout<<"pon"<<endl;
    return 0;
}
//............ALHAMDULLILAH...........


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

using namespace std;

int main() {

	int x, y;
	
	while (1) {
		cin >> x >> y;
		if (x != 0 || y != 0) {
			cout << min(x, y) << " " << max(x, y) << endl;
		}
		else { return 0; }
	}
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    ll a;
    string b;
    cin >> a >> b;
    //ll b = 1;
    int now = 0;
    for (auto x : b)
    {
        if (x == '.')
            continue;
        else
        {
            now = now * 10 + (x - '0');
            //DBG(now);
        }
    }
    //DBG(now);
    ll ans = a * now / 100;
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(0);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PII pair<int,int>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
using namespace std;
template<class T>inline void rd(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=150;
int n,m,a[maxn];
int main()
{
    cin>>n>>m;
    int sum=0;
    rep(i,1,n) rd(a[i]),sum+=a[i];
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    int flag=1;
    for(int i=1;i<=m;i++)
    {
        if(4*m*a[i]>=sum) continue;
        else {flag=0;break;}
    }
    if(flag) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
k = int(input())
l = set()

# lunnum : 構築中のルンルン数
#  depth : 桁数
#   flag : 上位桁が全て0かどうかのフラグ
def construct(lunnum: str, depth: int, flag: bool):
    global l
    if depth == 0:
        l.add(int(lunnum))
        return
    # m = 末尾桁の値
    m = int(lunnum[-1])
    if flag:
        # 上位桁に0以外の数字が無いなら
        for i in range(0, 10):
            construct(lunnum + str(i), depth - 1, i == 0)
    else:
        # m=[1,8] は [m-1,m,m+1], m=0 は [0,1], m=9 は [8,9] を末尾にくっつけて再帰
        for i in set([max(0, m - 1), m, min(9, m + 1)]):
            construct(lunnum + str(i), depth - 1, False)


# サンプルケース(input=100000 output=3234566667)より、答えは10桁以下であるのでdepth=10としてDFS
construct("0", 10, True)
ls = sorted(list(l))
print(ls[k])


Measured memory_bytes: 21412
#include<bits/stdc++.h>
using namespace std;
#define max1 3005
#define siz 100000
#define mod 1000000007
#define inf 1e18+5
#define ll long long int
#define debug(x) cout<<#x<<" "<<x<<endl
#define jam(x) cout<<"Case #"<<x<<": "
typedef pair<ll,ll> pr;
ll dp[max1][max1][2];
ll n;
vector<ll> a(max1);
ll fun(ll l,ll r,ll x)
{
  //cout<<l<<" "<<r<<" "<<x<<endl;
  if(l>r)
  {
    return 0;
  }
  if(dp[l][r][x]!=inf)
  {
    return dp[l][r][x];
  }
  if(x==0)
  {
    ll cnt=(-1)*inf;
    cnt=max(cnt,fun(l+1,r,x^1)+a[l]);
    cnt=max(cnt,fun(l,r-1,x^1)+a[r]);
    return dp[l][r][x]=cnt;
  }
  ll cnt=inf;
  cnt=min(cnt,fun(l+1,r,x^1)-a[l]);
  cnt=min(cnt,fun(l,r-1,x^1)-a[r]);
  return dp[l][r][x]=cnt;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif*/
  cin>>n;
  //cout<<n<<endl;
  for(ll i=0;i<n;i++)
  {
    for(ll j=0;j<n;j++)
    {
      dp[i][j][0]=dp[i][j][1]=inf;
    }
  }
  for(ll i=0;i<n;i++)
  {
    cin>>a[i];
    //cout<<a[i]<<endl;
  }
  //cout<<n<<endl;
  ll ans=fun(0,n-1,0);
  cout<<ans<<endl;
}

Measured memory_bytes: 141312
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
const int S=62;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int cnt=0,len,t[66];
char ch[66];
string dfs(int l,int r){
	if(l==r){
		string myh(t[l],ch[l]);
		return myh;
	}
	int mid=(l+r)>>1;
	string L=dfs(l,mid),R=dfs(mid+1,r),myh="";
	int j=0;
	for(int i=0;i<(int)L.length();++i){
		while(j<(int)R.size()){
			string s=myh+R[j]+L.substr(i,L.length()-i);
			cout<<"? "<<s<<endl;
			int qwq=read();
			int o=L.length()+j+1;
			if(len-qwq!=o)break;
			myh+=R[j++];
		}
		myh+=L[i];
	}
	for(;j<(int)R.size();++j)myh+=R[j];
	return myh;
}
int main(){
	for(char i='a';i<='z';++i){
		ch[++cnt]=i;
	}
	for(char i='A';i<='Z';++i){
		ch[++cnt]=i;
	}
	for(int i='0';i<='9';++i){
		ch[++cnt]=i;
	}
	for(int i=1;i<=S;++i){
		string s(128,ch[i]);
		cout<<"? "<<s<<endl;
		t[i]=128-read();
		len+=t[i];
	}
	string ans=dfs(1,S);
	cout<<"! "<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define rep(i,j,k) for(ll i=(ll)j;i<(ll)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool v[101],vv[101];
    rep(i,0,101){
        v[i]=false;
        vv[i]=false;
    }
    
    rep(i,a,b+1)v[i]=true;
    rep(i,c,d+1)vv[i]=true;
    
    int ans=0;
    rep(i,0,101){
        if(v[i]&&vv[i])ans++;
    }
    cout<<max(0,ans-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll mod = 1e9+7;

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

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  
  long long ans = 0;
  int MaxNum = 0;
  for (int i = 0; i < N; i++)
  {
    //MaxNumを使いまわすことで計算を抑える
    MaxNum = max(MaxNum, A[i]);
    int Bi = MaxNum;
    ans += Bi - A[i];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
 for(int i=0;i<n;i++){
   if(pow(k,i)<=n&&n<pow(k,i+1)){
     cout<<i+1;
     break;
   }
 }
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int q;cin>>q;
    while(q--){
        int a,b,c;cin>>a>>b>>c;
        int ans = min({a,b,c});
        a-=ans;b-=ans;c-=ans;
        if(b){
            int t = min(a/2,b);
            a-=t*2;b-=t;
            ans += t;
        }
        cout << ans+a/3 << endl;
    }
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rep(i, n) for(int i=0;i<(n);++i)
#define debug(x) cout << #x << " : " << x << " ------------"
using namespace std;
using Info = tuple<int, int>;
int main()
{
    int n, m;
    while (cin >> n >> m, n | m) {
        vector<Info> sections;
        int ev = 0;
        rep (i, n) {
            int d, p;
            cin >> d >> p;
            sections.pb(Info(p, d));
            ev += d * p;
        }
        sort(all(sections), greater<Info>());
        for (auto s : sections) {
            int d = get<1>(s), p = get<0>(s);
            ev -= min(m, d) * p;
            m -= d;
            
            if (m <= 0) break;
            else if (ev < 0) {
                ev = 0;
                break;
            }
        }
        cout << ev << endl;
    }
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3204
#pragma comment(linker, "/stack:640000000")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
//#include <unordered_map>
/// unordered map only when c++ 11 is ticked :p
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI=acos(-1.0);

#define    READ(f)       freopen(f, "r", stdin)
#define    WRITE(f)      freopen(f, "w", stdout)

#define    INF           999999999999999
#define    pii           pair<int, int>
#define    pdd           pair<double, double>
#define    pll           pair<long long int, long long int>
#define    ii            long long int
#define    uii           unsigned long long int
#define    ui            unsigned int
#define    bitCheck(a,k) ((bool)(a&(1<<(k))))
#define    bitOff(a,k)   (a&(~(1<<(k))))
#define    bitOn(a,k)    (a|(1<<(k)))
#define    bitFlip(a,k)  (a^(1<<(k)))
#define    iseq(a,b)     (fabs(a-b)<EPS)

template< class T > inline T _abs(T n) { return ((n) < 0 ? -(n) : (n)); }
template< class T > inline T _max(T a, T b) { return (!((a)<(b))?(a):(b)); }
template< class T > inline T _min(T a, T b) { return (((a)<(b))?(a):(b)); }
template< class T > inline T _swap(T &a, T &b) { a=a^b;b=a^b;a=a^b;}
template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }


///******************DELETE****************

#ifdef rafiul41
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
#else
    #define debug(args...)  // Just strip off all debug tokens
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;

int strToint(string x)
{
    stringstream ss(x);
    int i;
    ss>>i;
    return i; /// this int does not have any leading zeros !!!
}
///**************************************************

int main()
{
#ifdef rafiul41
//
//    READ("in.txt");
//    WRITE("out.txt");

#endif // rafiul41
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    scanf("%d",&n);
    ii ans;
    scanf("%lld",&ans);
    for(int i=1;i<n;i++)
    {
        ii x;
        scanf("%lld",&x);
        ans=lcm(x,ans);
    }
    cout<<ans<<endl;
    return 0;
}


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



int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i, n)  cin>>a[i];
    reverse(a.begin(), a.end());
    rep(i,n-1)  cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
  
}


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

int main(void){

    int a = 0;
    int b = 0;

    scanf("%d %d",&a,&b);


    int menseki = a*b;
    int syu = (a*2) + (b*2);
    printf("%d %d\n",menseki,syu);
    
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
d1 = 1
d2 = 1
d3 = 1
password = [d1,d2,d3]
counter = 0
while d3 <= n and d2 <= n and d1 <= n:
    if d3 == n and d2 != n:
        d2 += 1
        d3 = 1
    elif d2 == n and d3 == n:
        d1 += 1
        d2 = 1
        d3 = 1
    else:
        d3 += 1
    password = [d1, d2, d3]
    counter += 1
print(counter)


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
#define all(x) (x).begin(),(x).end()

vector<pll> func(ll n){
  vector<pll> res;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      pll p(i, n/i);
      res.push_back(p);
    }
  }
  return res;
}
//自然数nの桁数を返す
int digit(ll n){
  int res = 0;
  while(n>0){
    n /= 10;
    res++;
  }
  return res;
}

int main() {
    ll n;
    cin >> n;
    vector<pll> P = func(n);

    int ans = MOD;
    for(int i=0; i<P.size(); i++){
      int a = digit(P[i].first);
      int b = digit(P[i].second);
      ans = min(ans, max(a,b));
    }

    cout << ans << ln;
  }


Measured memory_bytes: 256
//It’s never too late to become what you might have been....
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 1000001

ll a[maxn],l[maxn],r[maxn];
int main()
{
	boost1;boost2;	
	ll i,j,n,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	a[0]=a[n+1]=-inf;
    for(i=2;i<=n;i++)
    {
        l[i]=i-1;
        while(a[l[i]]>=a[i])
        l[i]=l[l[i]];
    }
    for(i=n;i>=1;i--)
    {
        r[i]=i+1;
        while(a[r[i]]>a[i])
        r[i]=r[r[i]];
    }
   // for(i=1;i<=n;i++)
   //	cout<<l[i]<<" "<<r[i]<<endl;
    for(i=1;i<=n;i++)
    {
    	
    	l[i]++;
    	
    	r[i]--;
    	ans=ans+a[i]*(i-l[i]+1)*(r[i]-i+1);
    }
    cout<<ans;
	return 0;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  // vector<char> pixel(H)(W);
  vector<vector<char>> pixel(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++ ) {
      cin >> pixel.at(i).at(j);
    }
  }

  for (int i = 0; i < W+2; i++) {
    if (i == W+1) {
      cout << '#' << endl;
    } else {
      cout << '#';  
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++ ) {
      if ( W == 1 ) {
        cout << '#';
        cout << pixel.at(i).at(j);
        cout << '#' << endl;;
      } else if (j == 0) {
        cout << '#';
        cout << pixel.at(i).at(j);
      } else if (j == W-1) {
        cout << pixel.at(i).at(j);
        cout << '#' << endl;;
      } else {
        cout << pixel.at(i).at(j);
      }
    }
  }

    for (int i = 0; i < W+2; i++) {
    if (i == W+1) {
      cout << '#' << endl;
    } else {
      cout << '#';  
    }
  }
  
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;
using ll = long long int;


int main(int argc, char *argv[])
{
	ll n, a, b;

	//input
	cin >> n >> a >> b;


	//calc
	ll pairs = n / (a + b);
	ll remainder = n - pairs * (a + b);
	ll ans = pairs * a;
	ans += min(remainder, a);


	//ans
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())

x = [0] * N
y = [0] * N
a = [0] * N

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

X1 = 0
X2 = 0
Y1 = 0
Y2 = 0

x1, x2, y1, y2 = 0, 0, 0, 0

X = 0
Y = 0

entire = W * H

for i in range(N):
    if a[i]==1 and X1<x[i]:
        x1 = x[i] * H
        X1 = x[i]
    elif a[i]==2 and X2<(W-x[i]):
        x2 = (W-x[i]) * H
        X2 = W - x[i]
    elif a[i]==3 and Y1<y[i]:
        y1 = y[i] * W
        Y1 = y[i]
    elif a[i]==4 and Y2<(H-y[i]):
        y2 = (H-y[i]) * W
        Y2 = H - y[i]

if (X1 + X2) >= W or (Y1 + Y2) >= H:
    print('0')
else:
    entire = entire - (x1 + x2 + y1 + y2) + ((X1+X2) * (Y1+Y2))
    if entire<=0:
        print('0')
    else:
        print(entire)


Measured memory_bytes: 3064
import math

a, b, c = map(int, input().split())
ans = min(
    abs(a-b)+abs(b-c),
    abs(a-c)+abs(c-b),
    abs(b-a)+abs(a-c),
    abs(b-c)+abs(c-a),
    abs(c-a)+abs(a-b),
    abs(c-b)+abs(b-a),
)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<string>

using namespace std;

string s;
long long a,b,c,d,n;

signed main(){
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    a--,b--,c--,d--;

    for(int i=a;i<c;++i){
        if(s[i]=='#'&&s[i+1]=='#'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=b;i<d;++i){
        if(s[i]=='#'&&s[i+1]=='#'){
            cout<<"No"<<endl;
            return 0;
        }
    }

    if(d>c){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(int i=b;i<=d;++i){
        if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;



    return 0;
}

Measured memory_bytes: 640
//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=5005;
int p[N],n,A,B;ll dp[N],tmp;
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),A=read(),B=read();
	fp(i,1,n)p[i]=read();
	++n,p[n]=n;
	fp(i,1,n){
		dp[i]=1e18,tmp=0;
		fd(j,i-1,0)p[j]<p[i]?(cmin(dp[i],dp[j]+tmp),tmp+=B):tmp+=A; 
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;


int main()
{
	int A, B, ans = 0;
	vector<int>p, set;

	cin >> A >> B;

	ans = max(max(A + B, A - B), A * B);
	cout << ans;

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)

function main()
  N = readline() |> parseInt
  A = map(parseInt, split(readline()))

  # c = count(A .< 0)
  c = count(i -> i < 0, A)
  A_abs = map(abs, A)
  result = if c % 2 == 0
    sum(A_abs)
  else
    _, i = findmin(A_abs)
    sum(A_abs[1:i-1]) - A_abs[i] + sum(A_abs[i+1:end])
  end
  println(result)
end

main()

Measured memory_bytes: 124040
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

best_d = float('inf')
best_i = -1

for i,x in enumerate(H):
    t = T - x * 0.006
    d = abs(A - t)
    if d < best_d:
        best_d = d
        best_i = i
print(best_i + 1)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[][] b = new int[n][n];
        int[] wait = new int[n + 1];
        wait[n] = n;
        Deque<Integer>[] deque = new Deque[n];
        for (int i = 0; i < n; i++) {
            deque[i] = new ArrayDeque<>();
            wait[i] = scanner.nextInt() - 1;
            for (int j = 2; j < n; j++) {
                deque[i].add(scanner.nextInt() - 1);
            }
        }
        int[] lastMatch = new int[n];
        int rem = n;
        while (rem > 0) {
            boolean updated = false;
            for (int i = 0; i < n; i++) {
                if (wait[wait[i]] == i) {
                    lastMatch[wait[i]] = lastMatch[i] = Math.max(lastMatch[wait[i]], lastMatch[i]) + 1;
                    updated = true;
                    if (!deque[wait[i]].isEmpty()) {
                        wait[wait[i]] = deque[wait[i]].poll();
                    } else {
                        wait[wait[i]] = n;
                        rem--;
                    }
                    if (!deque[i].isEmpty()) {
                        wait[i] = n;
                        wait[i] = deque[i].poll();
                    } else {
                        rem--;
                    }
                }
            }
            if (!updated) {
                System.out.println(-1);
                return;
            }
        }
        Arrays.stream(lastMatch).max().ifPresent(System.out::println);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 72932
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define mod 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 92233720368547758070
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;

ll N,A,B,K,C[300001],ans;

ll pw(ll x, ll y){
	ll a=1;
	while(y){
		if(y%2)
			a=a*x%mod;
		y>>=1;
		x=x*x%mod;
	}
	return a;
}

ll modinv(ll x){
	return pw(x,mod-2);
}

int main(){
	cin>>N>>A>>B>>K;
	C[0]=1;
	for(int i=1;i!=N+1;++i){
		C[i]=C[i-1]*(N+1-i)%mod*modinv(i)%mod;
	}
	for(int i=0;i!=N+1;++i){
		if(A*i>K)break;
		if((K-A*i)%B==0){
			if((K-A*i)/B<=N){
				ans=(ans+C[i]*C[(K-A*i)/B])%mod;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  int n;
  cin >> n;
  vector<int> vec(n),vecori;
  REP(i,n) cin >> vec[i];
  copy(vec.begin(),vec.end(),back_inserter(vecori));
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int f = vec[0];
  int s = vec[1];
  int ans = f;
  REP(i,n){
    ans = f;
    if(vecori[i] == f)ans = s;
    cout << ans << endl;
  }

}

Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[5];
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<5;i++)cin>>a[i];
	sort(a,a+5);
	ll x=(n+a[0]-1)/a[0];
	cout<<x+4<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>

int64_t calc_lcm(int64_t a, int64_t b){
   int64_t small = std::min(a,b); 
   int64_t big = std::max(a,b); 
   while(big % small != 0){
       int64_t mod = big % small;
       big = small;
       small = mod;
   }
   int64_t gcd = small;
   //std::cout << "lcm(" << a << "," << b << ") = " << a/gcd*b << " , gcd = " << gcd << std::endl;
   return a * b / gcd;
}

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

    int32_t N;
    std::cin >> N;
    std::vector<int32_t> a(N);
    for(auto& i : a){
        std::cin >> i;
    }
    //int64_t lcm = a[0];
    //for(int32_t i = 1; i < N; i++){
    //    lcm = calc_lcm(lcm, (int64_t)a[i]);
    //}
    //int64_t mod = lcm - 1;
    //std::cout << "mod = " << mod << std::endl;
    int64_t sum = 0;
    for(int32_t i = 0; i < N; i++){
        sum += a[i] - 1;
    }

    std::cout << sum << std::endl;

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int bubble_sort(int *a, int m) {
    int i, j, tmp, n=0;

    for (i=0;i<m;i++) {
        for (j=m-1; j>i; j--) {
            if (a[j]<a[j-1]) {
                tmp=a[j];
                a[j]=a[j-1];
                a[j-1]=tmp;
                n++;
            }
        }
    }

    return n;
}

int main(void) {
    int i, n, count, arr[100];

    scanf("%d", &n);
    for (i=0; i<n; i++) scanf("%d", &arr[i]);
    count=bubble_sort(arr, n);
    for (i=0; i<n; i++) {
        printf("%d", arr[i]);
        if (i<n-1) printf(" ");
    }
    printf("\n");
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 2100
#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
#ifndef CrafterKolyan
#define endl '\n'
#endif

map<pair<string, string>, int> m[2];

void gen(const string &s, map<pair<string, string>, int> &m, int index, string &a, string &b, bool to_r) {
    if (index == s.size()) {
        if (to_r)
            reverse(a.begin(), a.end());
        else
            reverse(b.begin(), b.end());
        m[pair<string, string>{a, b}]++;
        if (to_r)
            reverse(a.begin(), a.end());
        else
            reverse(b.begin(), b.end());
        return;
    }
    a.push_back(s[index]);
    gen(s, m, index + 1, a, b, to_r);
    a.pop_back();
    b.push_back(s[index]);
    gen(s, m, index + 1, a, b, to_r);
    b.pop_back();
}

signed main() {
#ifndef CrafterKolyan
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    string s;
    cin >> s;
    string a, b;
    gen(s.substr(0, n), m[0], 0, a, b, false);
    gen(s.substr(n, string::npos), m[1], 0, a, b, true);
    ll ans = 0;
    for (const auto &cc : m[0]) {
        ll other = m[1][cc.first];
        ans += other * cc.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 100608
while(n = gets.chomp) != '0 0'
  a, b = n.split(' ').map(&:to_i)
  a.times do |x|
    if x == 0 || x == a - 1
      puts '#' * b
    else
      s = '.' * b
      s[0] = '#'
      s[s.size - 1] = '#'
      puts s
    end
  end
  puts ''
end

Measured memory_bytes: 8772
#include <iostream>
#include <stdio.h>

using namespace std;
struct node{
    node *parent;
    node *left;
    node *right;
    int key;
};

int main(){
    int n,tmp;
    cin >> n;
    int *l;
    l = new int[n+1];
    for(int i = 1; i <=n; ++i){
        cin >> tmp;
        l[i] = tmp;
    }
    for(int i = 1; i <=n; ++i){
        printf("node %d: key = %d, ",i,l[i]);
        if(i/2 > 0){
            printf("parent key = %d, ",l[i/2]);
        }
        if(n >= 2*i){
            printf("left key = %d, ",l[2*i]);
        }
        if(n >= 2*i+1){
            printf("right key = %d, ",l[2*i+1]);
        }
        printf("\n");
    }
}



Measured memory_bytes: 3212
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()

	if k == 1 {
		fmt.Println(0)
	} else {
		fmt.Println(n - k)
	}

}


Measured memory_bytes: 640
N,x = map(int,input().split())
A = list(map(int,input().split()))

AA = [0 for i in range(N-1)]
for i in range(N-1):
    AA[i] = A[i] + A[i+1]

cnt = 0

for i in range(N-1):
    aa = AA[i]
    diff = aa - x

    if aa > x:
        cnt += diff
        if A[i+1] >= diff:
            A[i+1] -= diff
        else:
            A[i]   -= diff - A[i+1]
            A[i+1]  = 0

        if i < N -2:
            AA[i] = A[i] + A[i+1]
            AA[i+1] = A[i+1] + A[i+2]
        else:
            AA[i] = A[i] + A[i+1]

print(cnt)


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = a * b;
  
  if (ans % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())
flag = False

l=[]
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k == K:
        m=[i, j, k]
        l.append(m)

for i in range(len(l)):
  m = l[i]
  a=A*(2**m[0])
  b=B*(2**m[1])
  c=C*(2**m[2])

  if a<b and b<c:
    flag = False
    print("Yes")
    break
  else:
    flag = True
if flag:
  print("No")

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 210;

int N;
string s[maxn];
bool e[maxn][maxn];
int col[maxn];

bool dfs(int v, int c) {
	col[v] = c;
	rep(u, N) if (e[v][u]) {
		if (col[u] == -1) {
			if (!dfs(u, c ^ 1)) {
				return false;
			}
		} else {
			if (col[u] != (c ^ 1)) {
				return false;
			}
		}
	}
	return true;
}

const int INF = 10000;

int main() {
	cin >> N;

	rep(i, N) {
		cin >> s[i];
		rep(j, N) e[i][j] = (s[i][j] - '0');
	}

	memset(col, -1, sizeof(col));

	if (!dfs(0, 0)) {
		puts("-1");
		return 0;
	}

	int ans = 0;

	rep(i, N) {
		vi d(N, INF);
		d[i] = 0;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int v = que.front(); que.pop();
			rep(u, N) if (e[v][u] && d[u] == INF) {
				d[u] = d[v] + 1;
				que.push(u);
			}
		}
		int t = 0;
		rep(j, N) chmax(t, d[j]);
		++t;
		chmax(ans, t);
	}
	cout << ans << endl;

	return 0;
}

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

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

    int ans = 0;
    int num = 1;

    while(num < b){
        num--;
        num += a;
        ans++;
    }

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

Measured memory_bytes: 256
N, M = map(int, input().split())

A, B = [0]*M, [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())


class UnionFind():
    def __init__(self, n):
        # 親要素の番号を格納。根の場合は-(その集合のsize)。
        # ノード番号とインデックスを対応させるためにn+1にした。0は無視。
        self.parent = [-1 for _ in range(n+1)]

    # 根ノードを検索
    def find(self, x):
        # 根ならその番号を返す
        if self.parent[x] < 0:
            return x
        # 根でないなら親の要素で再検索
        else:
            # 走査していく過程で親を書き換える
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    # 同じ集合に属するかチェック(根が同じか)
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 自分のいる集合のsizeを返す
    def size(self, x):
        y = self.find(x)  # xの根ノードを検索
        return -self.parent[y]  # 根ノードの番号には-(その集合のsize)があるので-1をかけて返す

    # 併合
    def union(self, x, y):
        # x, yの根ノードを検索
        x_root = self.find(x)
        y_root = self.find(y)

        # 同じ集合に属している場合(根が同じ場合)はそのまま
        if x_root == y_root:
            return False
        # 違う集合の場合(根が違う場合)、x_rootのsizeの方が大きいとしてx_rootにy_rootをつなげる
        else:
            # 大きい方に小さい方をつなげたいので、大小が違うなら入れ替える
            if -self.parent[x_root] < -self.parent[y_root]:
                x_root, y_root = y_root, x_root

            # x_rootのsizeを増やす
            self.parent[x_root] += self.parent[y_root]
            # y_rootの親をx_rootに変更する
            self.parent[y_root] = x_root
            return True


UnionFind = UnionFind(N)
ans = [0]*M
ans[M-1] = N * (N - 1) // 2

# 逆からつないでいき新しくつながった場合は不便さを減らしていく
for i in reversed(range(1, M)):
    a, b = A[i], B[i]
    # すでにつながっている場合
    if UnionFind.find(a) == UnionFind.find(b):
        ans[i-1] = ans[i]
    # 新しくつながった場合
    else:
        a_size = UnionFind.size(a)
        b_size = UnionFind.size(b)
        ans[i-1] = ans[i] - a_size * b_size
        UnionFind.union(a, b)

for i in ans:
    print(i)


Measured memory_bytes: 16956
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        mut a: [u64; n],
    }
    a.reverse();
    let mut b_f = VecDeque::new();
    let mut b_s = VecDeque::new();

    if n % 2 == 0 {
        let mut cnt = 0;
        while cnt + 1 < n {
            b_f.push_back(a[cnt]);
            cnt += 1;
            b_s.push_front(a[cnt]);
            cnt += 1;
        }
    } else {
        let mut cnt = 0;
        while cnt + 2 < n {
            b_f.push_back(a[cnt]);
            cnt += 1;
            b_s.push_front(a[cnt]);
            cnt += 1;
        }
        b_f.push_back(a[cnt]);
    }

    for b_ in b_f.iter() {
        print!("{} ", b_);
    }
    for b_ in b_s.iter() {
        print!("{} ", b_);
    }
    println!("");
}


Measured memory_bytes: 10364
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    double x;std::cin>>x;
    std::cout<<x*x*x/27<<'\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long a = scan.nextLong();
		long b = scan.nextLong();
		
		if(a % 2 == b % 2) {
			long d = Math.abs(b-a);
			System.out.println(d/2);
		}
		else {
			long ans = a-1;
			long bb = b-ans;
			if(bb % 2 != 1) {
				ans++;
				bb--;
			}
			ans += (bb-1)/2;
			
			long ans2 = n-b;
			long aa = a+ans2;
			if(aa % 2 != n % 2) {
				ans2++;
				aa++;
			}
			ans2 += (n-aa)/2;
			System.out.println(Math.min(ans, ans2));
		}
	}

}


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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
//using P = pair<double, double>;
using edge = struct {int to; ll cost;};

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1e9+100;
const ll INF64 = 7e18l;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};



void solve()
{
  priority_queue<int> x;
  rep(i, 3) {
    int _x;
    cin >> _x;
    x.push(_x);
  }
  int k;
  cin >> k;
  rep(i, k) {
    int a = x.top(); x.pop();
    x.push(a <<= 1);
  }
  int ans = 0;
  rep(i, 3) {
    ans += x.top(); x.pop();
  }
  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int input;//テ・ツ?・テ・ツ環崚ァツ板ィ
	int en[] = {500,100,50,10,5,1};//テァツ。ツャティツイツィテ」ツ?ョテァツィツョテゥツ。ツ?
	
	while(1){
		cin >> input;//テ・ツ?・テ・ツ環?
		
		if(input == 0) break;
		
		int cnt=0;
		int oturi=1000-input;
		
		for(int i=0;i<6;i++){
			cnt+=oturi/en[i];
			oturi=oturi%en[i];
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 2972
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s[s.length()-1] == 's') {
		s = s + "es";
	}
	else {
		s = s + "s";
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<vector>
using namespace std;
vector<int> v;
void rec(int n,int m){
	for(int i=m>n?n:m;i>0;i--){
		if(n-i==0){
			for(int j=0;j<v.size();j++)cout<<v[j]<<" "; cout<<i<<endl;
		}
		else v.push_back(i),rec(n-i,i),v.erase(v.end()-1);
	}
}
int main(){
	int n;
	while(cin>>n,n)rec(n,n);
	return 0;
}

Measured memory_bytes: 908
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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


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

	string s; cin >> s;
	ll p = 0, m = 0;
	for (char c : s) {
	 if (c == '+') p++;
	 else m--;
	}


	cout << p + m << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()

    a = a[n:]
    total = 0
    for i in range(n):
        total += a[i*2]

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 37084
#include <stdio.h>

int	main(void)
{
	int	A, B, C, D;

	scanf("%d %d %d %d", &A, &B, &C, &D);
	while (A > 0 && B > 0)
	{
		C -= B;
		if (C <= 0)
			break;
		A -= D;
	}
	if (A <= 0)
		printf("No\n");
	else if (C <= 0)
		printf("Yes\n");
	return (0);
}

Measured memory_bytes: 1648