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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> g (n);
    vector<vector<int>> edge (n-1);
    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
        edge.at(i).push_back(a);
        edge.at(i).push_back(b);
    }
    int k = 0;
    map<vector<int>,int> m;
    queue<int> q;
    vector<int> color (n,0);
    vector<int> used (n,0);
    used.at(0) = 1;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(k < g.at(v).size()) k = g.at(v).size();
        int c = 1;
        for(int u: g.at(v)){
            if(used.at(u)) continue;
            if(color.at(v) == c) c++;
            m[{v,u}] = c; m[{u,v}] = c;
            color.at(u) = c;
            c++;
            used.at(u) = 1;
            q.push(u);
        }
    }
    cout << k << endl;
    for(int i=0; i<edge.size(); i++){
        int a,b;
        a = edge.at(i).at(0); b = edge.at(i).at(1);
        cout << m[{a,b}] << endl;
    }
}

Measured memory_bytes: 34176
import numpy as np

N,M=map(int,input().split())
P=[]
Y=[]
for i in range(M):
    p,y=map(int,input().split())
    P.append(p)
    Y.append(y)

Y_arg=np.argsort(Y)

Ans=[0 for j in range(M)]
count=[0 for k in range(N)]

for ya in Y_arg:
    p_id_6='{0:06d}'.format(P[ya])
    c_id=count[(P[ya]-1)]+1
    count[P[ya]-1]+=1
    c_id_6='{0:06d}'.format(c_id)
    Ans[ya]=str(p_id_6)+str(c_id_6)

for a in Ans:
    print(a)

Measured memory_bytes: 30612
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    A, B, C, D = map(int, input().split())

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

    d = C*D//gcd(C, D)

    dividable = (B//C + B//D - B//d) - (A-1)//C - (A-1)//D + (A-1)//d
    print(B-A+1 - dividable)



# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc131","c",main)

Measured memory_bytes: 3064
n = int(input())
d = list(map(int,input().split()))

d = sorted(d)

if d[len(d)//2-1] == d[len(d)//2]:
    print(0)
else:
    dif =  d[len(d)//2] - d[len(d)//2-1]
    print(dif)


Measured memory_bytes: 14396
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int n;

void bfs(vector< vector<int> > T, vector<int>& odl, int start)
{
    vector<bool> odw(n, false);
    queue<int> Q;
    odw[start] = true;
    Q.push(start);
    while (!Q.empty())
    {
        int akt = Q.front();
        Q.pop();
        for (int i = 0; i < T[akt].size(); ++i)
        {
            if (!odw[T[akt][i]])
            {
                odw[T[akt][i]] = true;
                Q.push(T[akt][i]);
                odl[T[akt][i]] = odl[akt] + 1;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> n >> b >> a;
    --a;
    --b;
    vector< vector<int> > T(n);
    for (int i = 0; i < n - 1; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        T[x].push_back(y);
        T[y].push_back(x);
    }
    vector<int> odlA(n, 0), odlB(n, 0);
    bfs(T, odlA, a);
    bfs(T, odlB, b);
    int odp = 0;
    for (int i = 0; i < n; ++i)
        if (odlB[i] < odlA[i] && T[i].size() == 1 && i != a)
            odp = max(odp, odlA[i] - 1);
    cout << odp;
    return 0;
}


Measured memory_bytes: 12248
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int m, n; cin >> m >> n;
  vector<lint> p(m);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  vector<lint> c(n);
  vector<lint> e(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> e[i];
  }

  vector<vector<lint>> dp(n + 1, vector<lint> (m + 1, INF));
  dp[0][0] = 0; 

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      if (dp[i][j] == INF) continue;
      
      // not
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);

      // take
      lint nCap = min(j + c[i], (lint)m);
      dp[i + 1][nCap] = min(dp[i + 1][nCap], dp[i][j] + e[i]);
    }
  }

  sort(RALL(p));
  vector<lint> acc(m + 1, 0);
  for (int i = 1; i <= m; i++) {
    acc[i] = p[i - 1];
    acc[i] += acc[i - 1];
  }

  lint ans = 0;
  // 饅頭 i こ販売
  
  for (int i = 1; i <= m; i++) {
    lint cost = dp[n][i];
    lint score = acc[i];
    ans = max(ans, score - cost);
  }

  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 42200
N = int(input())
C = list(input().strip())
count = 0
j = N - 1
for i in range(N):
  if C[i] == "W":
    while i < j:
      if C[j] == "R":
        C[i], C[j] = C[j], C[i]
        count += 1
        break
      else:
        j -= 1

print(count)

Measured memory_bytes: 10556
#include<bits/stdc++.h>
#define reg register
#define ll long long
using namespace std;
vector<int>g[505];
int dfn[505],low[505],n,m,u,v,depth,ans;
inline void tarjan(reg int u,reg int fa)
{
    dfn[u]=low[u]=++depth;
    for(reg int i=0;i<g[u].size();i++)
	{
        reg int v=g[u][i];
        if(!dfn[v])
		{
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ans++;
        }
		else if(v!=fa)low[u]=min(low[u],dfn[v]);
    }
}
int main()
{
    while(cin>>n>>m)
    {
        depth=ans=0;
    	memset(dfn,0,sizeof(dfn));
    	memset(low,0,sizeof(low));
    	for(reg int i=0;i<=n;i++)g[i].clear();
        for(reg int i=0;i<m;i++)
		{
            cin>>u>>v;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        tarjan(1,-1);
        cout<<ans<<endl;
    }
    return 0;
}

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

import sys
import os
import math

N, P = map(int, input().split())

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Combination(n, m):
    #print(str(n) + "C" + str(m))
    f = math.factorial
    return f(n) // f(m) // f(n - m)

combination_for_one = 0
if P == 0:
    for i in range(0, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
else:
    for i in range(1, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  string s;
  cin >> s;

  puts(regex_match(s, regex("(dream(er)?|eraser?)*")) ? "YES" : "NO");
}

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

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

int N;
vector<pair<int,int>> E[202020];
vector<pair<ll,ll>> S[202020];
ll ret;

int ok(ll v) {
	int i;
	for(i=N-1;i>=0;i--) {
		if(E[i].empty()) {
			S[i]={{0,0}};
		}
		else {
			int d1=E[i][0].second;
			int d2=E[i][1].second;
			vector<pair<ll,ll>>& s1=S[E[i][0].first];
			vector<pair<ll,ll>>& s2=S[E[i][1].first];
			vector<pair<ll,ll>> T;
			
			if(s2.size()<s1.size()) swap(s1,s2), swap(d1,d2);
			
			/*
			_P("S1(%d)[%d]:",E[i][0].first,s1.size());
			FORR(r,s1) _P("(%lld,%lld) ",r.first,r.second);
			_P("\nS2(%d)[%d]:",E[i][1].first,s2.size());
			FORR(r,s2) _P("(%lld,%lld) ",r.first,r.second);
			_P("\n");
			*/
			int R=0;
			FORR(r1,s1) {
				ll d=v-(r1.second+d1+d2);
				while(R<s2.size()-1&&s2[R+1].first<=d) R++;
				while(R>=0&&s2[R].first>d) R--;
				//_P("A(%lld,%lld)=%d  ",r1.first,r1.second,R);
				if(R>=0) T.push_back({r1.first+d1,s2[R].second+d2});
			}
			R=s2.size()-1;
			FORR(r1,s1) {
				ll d=v-(r1.first+d1+d2);
				while(R>=1&&s2[R-1].second<=d) R--;
				while(R<s2.size()&&s2[R].second>d) R++;
				//_P("B(%lld,%lld)=%d  ",r1.first,r1.second,R);
				if(R<s2.size()) T.push_back({s2[R].first+d2,r1.second+d1});
			}
			
			sort(ALL(T));
			S[i].clear();
			FORR(t,T) if(S[i].empty() || S[i].back().second>t.second) S[i].push_back(t);
			/*
			_P("%d(%lld) : ",i,v);
			FORR(t,S[i]) _P("(%lld,%lld) ",t.first,t.second);
			_P("\n");*/
		}
	}
	return S[0].size();
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back({i+1,y});
	}
	
	ret=(1LL<<40)-1;
	for(i=39;i>=0;i--) if(ok(ret-(1LL<<i))) ret-=1LL<<i;
	cout<<ret<<endl;
	
}


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


Measured memory_bytes: 38788
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N, M;
	string S;
	cin >> N >> M >> S;
	vector<int> ans;
	int i = N;
	while (i > 0) {
		//cout << i << endl;
		bool out = true;
		if (i - M <= 0) {
			ans.push_back(i);
			break;
		}
		for (int j = M; j > 0; j--) {
			if (S[i - j] == '0') {
				out = false;
				ans.push_back(j);
				i -= j;
				break;
			}
		}
		if (out) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define print(val) print_helper(#val, val);
#define bg begin
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int32_t,int32_t>
#define loop(i,n) for(int64_t i=0; i<n; i++)
#define loop1(i,a,b) for(int64_t i=a; i<=b; i++)
#define rloop(i,n) for(int64_t i=n-1; i>=0; i--) 
#define rloop1(i,a,b) for(int64_t i=a; i>=b; i--) 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
void err() {cout << "-1\n";}
template <typename T>
void print_c(T & a) {
for_each(begin(a),end(a),[](auto & i){cout << i << " ";}); cout << "\n"; }
template <typename T, typename V>
void fill(T & collection, V val) {fill(begin(collection),end(collection),val);}
template <typename T>
void print_helper(string name, T val) {cout << name << ": " << val << "\n";}

int main() {
  fast_io
  int n,k; cin >> n >> k;
  vector<ll> vec(n+1);
  iota(vec.begin(),vec.end(),0);
  vector<ll> prefix_sum(n+1);
  vector<ll> suffix_sum(n+1);
  prefix_sum[0] = 0;
  suffix_sum[0] = n;
  loop1(i,1,n) {
    prefix_sum[i] = prefix_sum[i-1] + vec[i];
    suffix_sum[i] = suffix_sum[i-1] + vec[n-i];
  }
  ll total = 0;
  loop1(i,k,n+1) {
    total = ( total + (suffix_sum[i-1]-prefix_sum[i-1]+1) )%mod;
  }
  cout << total << "\n";
}


Measured memory_bytes: 7924
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define ll long long
const long long INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}//約数求める


ll kaijou(int n) {
	ll temp = 1;
	for (int i = 2; i <= n; i++) {
		temp *= i;
		temp %= MOD;
	}
	return temp;
}


int main() {
	string s, t;
	cin >> s >> t;
	string seq[2];
	seq[0].push_back(s[0]);
	seq[1].push_back(t[0]);
	for (int i = 1; i < s.size(); i++) {
		if (!((s[i] == s[i - 1]&&t[i]==t[i-1])||(s[i] != s[i - 1] && t[i] != t[i - 1]))) {
			cout << "No";
			return 0;
		}
		else if (s[i] != s[i - 1] ) {
			int num = -1;
			for (int j = 0; j < seq[0].size(); j++) {
				if (s[i ] == seq[0][j]) {
					
					num = j;
					break;
				}
			}
			if (num == -1)seq[0].push_back(s[i ]);
			int temp = -1;
			for (int j = 0; j < seq[1].size(); j++) {
				if (t[i ] == seq[1][j]) {

					temp = j;
					break;
				}
			}
			if (temp == -1)seq[1].push_back(t[i]);
			if (num != temp) {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 776
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())

s = ns()
mm = s[5:7]
dd = s[8:10]

if int(mm) < 4:
    print("Heisei")
elif int(mm) == 4 and int(dd) < 31:
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 3064
// ABC154D3.cpp
//#include "pch.h"
#include <iostream>
#include<vector>
using namespace std;
int main()
{
    long long N,K;
    cin >> N >> K;
    vector<long long>p(N);
    long long ans2=0;
    for (int i = 0; i < N; i++)
    {
        cin >> p.at(i);
        ans2+=p.at(i);
    }
    if (K==N) {
        printf("%.10lf\n", (double)(ans2+K)/2.0);
        return 0;
    }else{
        long long max = 0;
        long long tmp = 0;
        for (long long i = 0; i < K; i++)
            {
                tmp += p.at(i);
            }
        long long left = 0;
        long long right = K;
        while (right < N) {
            tmp = tmp + p.at(right) - p.at(left);
            if (tmp > max) {
                max = tmp;
            }
            left++;
            right++;
        }
            printf("%.10lf\n", (double)(max+K)/2.0);
        return 0;
        }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lid id << 1
#define rid id << 1 | 1

using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 1e9;

int h, w, a[MAXN], L[MAXN], R[MAXN], ans[MAXN];

template <class T>
void read(T &x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

// a[i] = a[i-1]  i∉[L,R]
// a[i] = a[L-1] -L + 1 + i  i∈[L,R];

struct Node {
    int l, r, mi, lval;
    bool tag;
    Node() { mi = lval = 0, tag = 0; }
    // mi denotes the minimum a in [l,r]
    // lval denotes the value of the left end point of [l,r]
} tr[MAXN * 4];

void update(int id) {
    tr[id].mi = min(tr[lid].mi, tr[rid].mi);
    tr[id].lval = tr[lid].lval;
}

void pushdown(int id) {
    if (tr[id].tag) {
        tr[lid].tag = 1;
        tr[lid].lval = tr[lid].mi = tr[id].lval;
        tr[rid].tag = 1;
        tr[rid].lval = tr[rid].mi = tr[id].lval + tr[rid].l - tr[lid].l;
        tr[id].tag = 0;
    }
}

void build(int id, int l, int r) {
    tr[id].l = l, tr[id].r = r;
    if (l == r) return;
    int mid = l + r >> 1;
    build(lid, l, mid);
    build(rid, mid + 1, r);
}

void modify(int id, int l, int r, int val) {
    if (tr[id].l == l && tr[id].r == r) {
        tr[id].mi = tr[id].lval = val;
        tr[id].tag = 1;
        return;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        modify(lid, l, r, val);
    else if (l > mid)
        modify(rid, l, r, val);
    else {
        modify(lid, l, mid, val);
        modify(rid, mid + 1, r, val + mid + 1 - l);
    }
    update(id);
}

int query(int id, int l, int r) {
    if (r < 1) return INF;
    if (tr[id].l == l && tr[id].r == r) {
        return tr[id].mi;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        return query(lid, l, r);
    else if (l > mid)
        return query(rid, l, r);
    else
        return min(query(lid, l, mid), query(rid, mid + 1, r));
}

int main() {
    read(h), read(w);
    for (int i = 1; i <= h; i++) read(L[i]), read(R[i]);
    fill(ans + 1, ans + h + 2, -1);
    build(1, 1, w);
    for (int i = 2; i <= h + 1; i++) {
        int tmp = query(1, L[i - 1] - 1, L[i - 1] - 1);
        modify(1, L[i - 1], R[i - 1], tmp + 1);
        int mi = query(1, 1, w);
        if (mi >= INF) break;
        ans[i] = mi + i - 1;
    }
    for (int i = 2; i <= h + 1; i++) printf("%d\n", ans[i]);
    return 0;
}

Measured memory_bytes: 21688
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 100005
#define BLOCK 555
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
inline ll myceil(ll a, ll b) { if (a % b == 0)	return (a / b);	return (a / b + 1);}
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

ll n, m, k;
vvl pres;
vector<vvl> dp(3005, vvl(3005, vl(3, -1)));
ll solve(ll i, ll j, ll lim)
{
	if (i > n || j > m || lim < 0)
		return 0;
	if (dp[i][j][lim] != -1)
		return dp[i][j][lim];
	ll res1 = 0, res2 = 0;
	// Take
	if (pres[i][j])
	{
		res1 = pres[i][j] + max(solve(i, j + 1, lim - 1), solve(i + 1, j, 2));
	}
	// Leave
	res2 = max(solve(i, j + 1, lim), solve(i + 1, j, 2));
	return dp[i][j][lim] = max(res1, res2);
}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	cin >> n >> m >> k;
	pres = vvl(n + 1, vl(m + 1, 0));
	loop(i, k)
	{
		ll x, y, v;
		cin >> x >> y >> v;
		pres[x][y] = v;
	}
	cout << solve(1, 1, 2) << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 568104
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, K; cin >> N >> K;
    vector<Int> A(N); for (auto &a : A) cin >> a;
    Int ans = 1e18;
    for (int bits = 0; bits < (1 << N); bits++) {
        if (__builtin_popcount(bits) < K) continue;
        Int curr = 0, cost = 0;
        for (int i = 0; i < N; i++) {
            if (bits & (1 << i)) {
                int next = max(curr + 1, A[i]);
                cost += next - A[i];
                curr = next;
            } else {
                curr = max(curr, A[i]);
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  if (a < b) {
    cout << "a < b" << endl;
  }
  else if(a > b) {
    cout << "a > b" << endl;
  }
  else {
    cout << "a == b" << endl;
  }
}



Measured memory_bytes: 3084
from collections import Counter
from itertools import accumulate
from bisect import bisect_right


def factor(n):
    res = []
    for i in range(2, int(n ** .5) + 1):
        while n % i == 0:
            res.append(i)
            n //= i
    if n > 1:
        return res + [n]
    else:
        return res


stairs = list(accumulate(i for i in range(1, 64)))
N = int(input())
factors = factor(N)
ans = 0
for cnt in Counter(factors).values():
    ans += bisect_right(stairs, cnt)
print(ans)


Measured memory_bytes: 9728
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::VecDeque;
use std::collections::BinaryHeap;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}
//03:48
fn main(){
    let n: usize = read_as_vec()[0];
    let a = read_as_vec::<i64>();

    let mut half1 = a.clone().into_iter().take(n).map(|x| -x).collect::<BinaryHeap<i64>>();
    let mut half2 = a.clone().into_iter().skip(2*n).collect::<BinaryHeap<i64>>();
    let middle = a.into_iter().skip(n).take(n).collect::<VecDeque<i64>>();

    let mut answers: Vec<i64> = vec![0;middle.len()+1];

    let mut half1_sum = -half1.iter().sum::<i64>();
    answers[0] = half1_sum;
    for i in 0..middle.len(){
        half1.push(-middle[i]);
        half1_sum += middle[i];

        let half1_min: i64 = -half1.pop().unwrap();
        half1_sum -= half1_min;
        answers[i+1] = half1_sum;
    }
    let mut half2_sum: i64 = half2.iter().sum::<i64>();
    *answers.last_mut().unwrap() -= half2_sum;
    for i in (0..middle.len()).rev(){
        half2.push(middle[i]);
        half2_sum += middle[i];

        let half2_max:i64 = half2.pop().unwrap();
        half2_sum -= half2_max;

        answers[i] -= half2_sum;
    }
    let mut ans = std::i64::MIN;
    for tmp in answers{
        ans = cmp::max(ans, tmp);
    }

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


Measured memory_bytes: 14196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  vll ans(1000);
  ll ANS = 1;
  for(int i = 2;i <= n;i++){
    ll num = i;
    for(int j = 2;j <= i;j++){
      if(num == 1) break;
      if(num % j == 0){
        ans[j]++;
        num /= j;
        j = 1;
      }
    }
  }
  for(int i = 2;i<= 1000;i++){
    ANS *= ans[i]+1;
    ANS %= 1000000007;
  }
  cout << ANS << endl;
}

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

#define ll long long 

const ll MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  vector<ll> count(30, 0);
  
  for (int i = 0; i < N; i++) {
    count[S[i] - 'a']++;
  }
  
  ll ans = 1;
  for (int i = 0; i < 26; i++) {
    ans *= count[i]+1;
    ans %= MOD;
  }
  
  ans--;
  
  cout << ans << endl;
}

Measured memory_bytes: 3732
from bisect import bisect_left, bisect_right

N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

A.sort()
C.sort()

result = 0

for i in B:
    a = bisect_left(A,i)
    c = bisect_right(C,i)
    result += a * (N - c)

print(result)



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

int main(){
  long long A, B, K;
  cin >> A >> B >> K;
  A -= K;
  
  if (A < 0){
    B += A;
    A = 0;
    
    if (B < 0){
      B = 0;
    }
  }
  
  
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
s = input()
s = s.replace("RL", "*")
i = 0
rls = []
n = 0
m = 0
for c in s:
  if c == "R":
    n += 1
  if c == "*":
    r = (n + 1) // 2
    l = n + 1 - r
    rls.append([l, r])
    n = 0
m = 0
i = 1
for c in reversed(s):
  if c == "L":
    m += 1
  if c == "*":
    l = (m + 1) // 2
    r = m + 1 - l
    rls[-i][0] += l
    rls[-i][1] += r
    i += 1
    m = 0
ans = []
i = 0
for c in s:
  if c == "*":
    ans.extend(rls[i])
    i += 1
  else:
    ans.append(0)
print(" ".join([str(c) for c in ans]))

Measured memory_bytes: 53620
#include <iostream>
#include <cstdio>
using namespace std;
int main (){

double r;

scanf ("%lf",&r);

double m=r*r*3.1415926535897932384626433832795;
double e=r*2*3.1415926535897932384626433832795;
printf ("%lf %lf\n",m,e);

return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,ans;
  ans=0;
  cin >> N;
  vector<int> a1(100);
  vector<int> a2(100);
  if (N==1) {
    cout << 1;
  } else {
    for (int i = 0;i<N;i++) {
      string i2 = std::to_string(i+1);
      char i3 = i2[0];
      char i4 = i2[i2.length()-1];
      a1.at((i3-48)*10+(i4-48))++;
      a2.at((i4-48)*10+(i3-48))++;
   };
     for (int i = 1;i<10;i++) {
      for (int j = 1;j<10;j++) {
        ans = ans + a1.at(i*10+j) * a2.at(i*10+j);
      };
    };
    cout << ans;
  };
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
  string s;
  cin >> s;
  ll N=s.size();
  ll i;
  char cb,cn;
  ll Rpos,Lpos;
  ll even,odd;
  ll ans[N];
  cb='R';
  even=1;
  odd=0;
  for(i=1;i<N;i++){
    cn=s[i];
    if(cb=='R'){
      even+=(i+1)%2;
      odd+=i%2;
      if(cn=='R'){
        ans[i-1]=0;
      }
      if(cn=='L'){
        Rpos=i-1;
        Lpos=i;
      }
    }
    if(cb=='L'){
      if(cn=='L'){
        ans[i]=0;
        even+=(i+1)%2;
        odd+=i%2;
      }
      if(cn=='R'){
        if(Rpos%2==0){
          ans[Rpos]=even;
          ans[Lpos]=odd;
        }else{
          ans[Rpos]=odd;
          ans[Lpos]=even;
        }
        even=(i+1)%2;
        odd=i%2;
      }
    }
    if(i==N-1){
      if(Rpos%2==0){
        ans[Rpos]=even;
        ans[Lpos]=odd;
      }else{
        ans[Rpos]=odd;
        ans[Lpos]=even;
      }
    }
    cb=cn;
  }
  for(i=0;i<N-1;i++){
    cout << ans[i]<<" ";
  }
  cout << ans[N-1];
  return 0;
}


Measured memory_bytes: 1536
import java.util.*;

public class Main{
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a-b*2<0)System.out.println(0);
		else System.out.println(a-b*2);
	}
}

Measured memory_bytes: 23252
#include <stdio.h>

int main(){

  int s,h,w,i,j,min=45000,a,b;
  int s2[151][151]={{}};


  for(;;){
    scanf("%d %d",&h,&w);
    if(h==0&&w==0){
      break;
    }
    s=h*h+w*w;

    for(i=1;i<=150;i++){
      for(j=i+1;j<=150;j++){
	s2[i][j]=i*i+j*j;
	if(s2[i][j]>s){
	  if(min>s2[i][j]){
	    min=s2[i][j];
	    a=i;
	    b=j;
	  }
	}
	else if(s2[i][j]==s){
	  
	  if(i>h){
	    a=i;
	    b=j;
	    printf("%d %d\n",a,b);
	    break;
	  }
	}
      }
      if(s2[i][j]==s&&i>h){
	break;
      }
    }
    if(s2[i][j]>s)printf("%d %d\n",a,b);
    min=45000;
    for(i=1;i<=150;i++){
      for(j=1;j<=150;j++){
	s2[i][j]=0;
      }
    }
  } 
  
  return 0;
}
	
    

Measured memory_bytes: 696
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>


string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 


int main(){
    int N;
    cin >> N;
    ll A[N];

    ll Amin=10000000000;
    int i_Amin;
    ll sum = 0;
    rep(ni,N){
        cin >> A[ni];
        if(ni % 2 == 0 ) sum+=A[ni] * 2;
        else sum -= A[ni] * 2;
    }

    ll ans[N];
    ans[0] = sum/2;
    for( int ni = 1 ; ni < N ; ni++ ){
        ans[ni] = ( A[ni-1] - ans[ni-1]/2 ) * 2;
    }

    rep(ni,N){
        cout << ans[ni];
        cout << " ";
    }
}

Measured memory_bytes: 2944
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
ans = 1
s = 0
q = 0
for i in range(n-1):
    s += a[i]
    if 2*s >= a[i+1]:
        q += 1
    else:
        q = 0
    if i == n-2:
        ans += q
print(ans)

Measured memory_bytes: 20372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    
    vector<int> a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    
    set<int> st;
    rep(i,b.size())st.insert(b[i]);
    
    if(st.size()==n){
        cout<<"Yes"<<endl;
        return 0;
    }else{
        cout<<"No"<<endl;
        int bx = -1;
        for(int i=1;i<=n;i++){
            if(st.count(i)==0){
                bx = i;
            }
        }
        int p = -1;
        rep(i,a.size()){
            if(a[i]==bx){
                p = i;
                break;
            }
        }
        rep(i,n){
            if(i)cout<<" ";
            if(i==p)cout<<1;
            else cout<<i+1;
        }
        cout<<endl;

        rep(i,n){
            if(i)cout<<" ";
            if(i==p)cout<<2;
            else cout<<i+1;
        }
        cout<<endl;
}
}



Measured memory_bytes: 8372
#include <stdio.h>
int main(void){
    int N;
    int a[30];
    int b[30];
    int c[30];
    int sum=0;

scanf("%d",&N);
for(int i=0;i<N;i++){
    scanf("%d",&a[i]);
}

for(int i=0;i<N;i++){
    scanf("%d",&b[i]);
}

for(int i=0;i<N-1;i++){
    scanf("%d",&c[i]);
}
    
for(int i=0;i<N;i++){
   sum=sum+b[i];
if(i!=N-1){
   if(a[i]==a[i+1]-1){
       sum=sum+c[a[i]-1];
   } 
}

}
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    l=[]
    ans='yes'
    for i in s:
        l.append(i)
    l.sort()
    for i in range(len(l)-1):
        if l[i]==l[i+1]:
            ans='no'
            break
    print(ans)
resolve()

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    int a[5];
    for(int i=0;i<5;++i) cin >> a[i];
    cout << min(a[0],min(a[1],a[2]))+min(a[3],a[4])-50 << endl;
}

Measured memory_bytes: 1160
# ABC152F

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



from collections import defaultdict
from queue import deque
import itertools
import functools
def find(start,goal):
    q = deque([start])
    seen = [None] * n
    seen[start] = -1
    while q:
        u = q.pop()
        d = seen[u]
        if u==goal:
            break
        for v in ns[u]:
            if seen[v] is None:
                seen[v] = u
                q.appendleft(v)
    u = goal
    es = 0
    while True:
        t = (min(u, seen[u]), max(u, seen[u]))
        es |= 1<<uv2e[u,seen[u]]
        if seen[u]==start:
            break
        u = seen[u]
    return es

n = int(input())
ns = defaultdict(set)
uv2e = {}
for i in range(n-1):
    u,v = map(int, input().split())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1, u-1] = i
ans = 0
m = int(input())
paths = [None] * m
for i in range(m):
    u, v = map(int, input().split())
    paths[i] = find(u-1,v-1)

ans = 0

def dfs(ind, s, ans):
    if len(ind)==m:
        if True in ind:
            tmp = 0
            for i in range(n-1):
                tmp += (s & 1<<i)>0
            ans += 2**(n-1-tmp) * (-1)**((sum(ind)+1)%2)
        return ans
    ans = dfs(ind + [True], s | paths[len(ind)], ans)
    ans = dfs(ind + [False], s, ans)
    return ans
        
# for ind in itertools.product(*[(False, True) for _ in range(m)]):
#     num = sum(ind)+1
#     if num==1:
#         continue
#     c = 2**(n - 1 - len(functools.reduce(lambda x,y: x|y, (paths[i] for i in range(m) if ind[i]), set())))
#     ans += (-1)**num * c
ans = dfs([], 0, 0)
print(2**(n-1) - ans)

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

int main(){
  int a[5];
  int b[5];
  for(int i=0;i<5;i++){
    cin >> a[i];
    b[i]=0;
    if(a[i]%10!=0){
      b[i] = 10-(a[i]%10);
      a[i] = a[i]+b[i];
    }
  }

  int ans = a[0]+a[1]+a[2]+a[3]+a[4];
  sort(b,b+5);
  cout << ans-b[4] << endl;


}


Measured memory_bytes: 256
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;
int dp[1001][10100];
pair < int , int > arr[2000];
int n;

int solve(int i , int sum){
    //cout << i << " " << sum << endl;
    if(sum <= 0)return 0;
    if(i >= n)return 1e8;
    int &ret = dp[i][sum];
    if(ret != -1)return ret;
    ret = 0;
    ret = min(arr[i].second + solve(i,sum-arr[i].first) , solve(i+1,sum));
    return ret;
}

int main()
{
    fast;
    int m;
    memset(dp,-1,sizeof dp);
    cin >> m >> n;
    for(int i = 0; i<n; i++){
        cin >> arr[i].first >> arr[i].second;
    }
    cout << solve(0,m) << endl;
    return 0;
}
/*



*/



Measured memory_bytes: 40448
n = int(input())
H1 = list(map(int,input().split()))
H2 = list(map(lambda x: x - 1, H1))

ans = "Yes"
prev = H2[0]
for i in range(1,n):
    if H2[i] > prev:
        prev = H2[i]
    if prev > H1[i]:
        ans = "No"
        break

print(ans)

Measured memory_bytes: 14396
N = int(input())
A = sorted(list(map(int,input().split())))
G = {i:0 for i in range(9)}
for i in range(N):
    if A[i]<=399:
        G[0] += 1
    elif A[i]<=799:
        G[1] += 1
    elif A[i]<=1199:
        G[2] += 1
    elif A[i] <= 1599:
        G[3] += 1
    elif A[i] <= 1999:
        G[4] += 1
    elif A[i] <= 2399:
        G[5] += 1
    elif A[i] <= 2799:
        G[6] += 1
    elif A[i] <= 3199:
        G[7] += 1
    else:
        G[8] += 1
cnt = 0
for i in range(8):
    if G[i] > 0:
        cnt += 1
if cnt==0:
    cmin = 1
    cmax = G[8]
else:
    cmin = cnt
    cmax = cmin+G[8]
print(cmin,cmax)

Measured memory_bytes: 3064
import java.io.*;

class Main {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int x = 0;
            int y = 0;
            int max = 0;
            boolean end = false;

            while (!end) {
                String ex = br.readLine();
                String[] numbers = ex.split(" ");
                x = Integer.parseInt(numbers[0]);
                y = Integer.parseInt(numbers[1]);

                if ((x < 0 && y > 10000) || (x == 0 && y == 0) || max > 3000) {
                    end = true;
                } else if (x > y || x == y) {
                    System.out.println(y + " " + x);
                } else if (x < y) {
                    System.out.println(x + " " + y);
                }
                max++;
            }

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

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

int main(){
    int x,y;
    long long ans;

    cin>>x>>y;

    if(x > 0 && y > 0){
        if(x > y){
            ans = x - y +2;
        }else{
            ans = y - x;
        }
    }

    else if(x > 0 && y <0){
        ans = abs(x+y)+1;
    }

    else if(x < 0 && y>0){
        ans = abs(y+x)+1;
    }

    else if(x < 0 && y < 0){
        if(x > y){
            ans = abs(y-x)+2;
        }else{
            ans = abs(x-y);
        }
    }

    else if(x == 0 || y == 0){
        if(x == 0 && y > 0){
            ans = y-x;
        }

        else if(x == 0 && y < 0){
            ans = abs(y)+1;
        }

        else if(y == 0  && x > 0){
            ans = x + 1;
        }

        else if( y == 0 && x < 0){
            ans = abs(x);
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[]
ans=1e12
l=int(n**0.5)+2
for i in range(1,l):
  if n%i==0 and i not in a:
    a.append(i)
    a.append(n//i)
    ans=min(ans,(i+n//i-2))
print(ans) 

Measured memory_bytes: 3276
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long n = sc.nextLong();
        StringBuilder sb = new StringBuilder();
        long now = 2;
        if(n == 0){
            System.out.println(0);
            return;
        }
        while(n != 0){
            if(n % now != 0){
                //System.out.println(n + " " + now + " " + (n%now));
                sb.append('1');
                n -= now/2;
            }else{
                sb.append('0');
            }
            now *= -2;
        }
        System.out.println(sb.reverse().toString());
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  ll n, ans = 0;
  vector<double> t(5);
  cin >> n;
  REP(i, 5) {
    cin >> t[i];
  }
  cout << (ll)ceil((double)n / *min_element(ALL(t))) + 4 << endl;
  return 0;
}


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

typedef long long LL;

const int N = 2e5 + 5;

int A[N];
LL csum[N];

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

    LL sum = 0, ans = LLONG_MAX;
    for(int i = 1; i <= n; i++)
    {
        cin>>A[i];
        sum += A[i];
        csum[i] = sum;
    }

    for(int i = 1; i < n; i++)
    {
        LL x = csum[i];
        LL y = sum - x;
        ans = min(ans, abs(x - y));
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#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))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;

signed main(){
    string S; cin>>S;
    int N = S.size();
    bool ans = true;
    REP(i,N){
        REP(j,i){
            if(S[i]==S[j]){
            ans = false;
            }
        }
    }
    if(ans) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
} 

Measured memory_bytes: 256
import sys
input=sys.stdin.readline

def main():
    H, N = map(int, input().split())
    AB = [tuple(map(int, input().split()))for _ in range(N)]
    DP = [10**10] * (H+1)
    DP[H] = 0
    for h in range(H, 0, -1):
        for a, b in AB:
            x = max(0, h - a)
            DP[x] = min(DP[x], DP[h] + b)
    print(DP[0])

if __name__ == "__main__":
    main()

Measured memory_bytes: 40432
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string c;
    bool ans = true;
    cin >>c;
    rep(i,c.size()-1){
        if(c[i]== c[i+1]){
            ans = false;
        }
    }
    if(ans){
        cout << "Good" << endl; 
    }else{
        cout << "Bad" << endl;
    }
}

Measured memory_bytes: 256