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

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

    long long n, p;
    cin >> n >> p;
    
    map<long long, long long> mp;

    // 素因数分解
    long long tmp = p;
    for(long long i = 2; i * i <= p; i++){
        // 素因数分解が終わっていたら抜ける
        //if(tmp == 1 || (long long)(sqrt(p)) > tmp) break;
        while(tmp % i == 0){
            mp[i]++;
            tmp /= i;
        }
    }

    // pの，pの(1/2)乗以下の最大の素因数をカウント
    // ここvalueは必ず1になる
    mp[tmp]++;

    long long ans = 1;
    for(auto x : mp){
        // pの素因数をn個に均等になるべく多く分配する
        for(int i = 0; i < x.second / n; i++){
            ans *= x.first;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int n,a[21],mini;

void rec(int idx,int sum1,int sum2){
  if(idx == n){
    if(mini > abs(sum1 - sum2)) mini = abs(sum1 - sum2);
    return;
  }
  rec(idx+1,sum1+a[idx],sum2); rec(idx+1,sum1,sum2+a[idx]);
}


int main(){
  while(cin >> n,n){
    mini = (2 << 28);
    for(int i=0;i<n;i++) cin >> a[i];
    rec(0,0,0);
    cout << mini << endl;
  }
}

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

int a, b, c, d;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> a >> b >> c >> d;
		if(a+b+c+d==0) return 0;
		cout << max(0, (b * c - a + d - 1) / d) << "\n";
	}
}


Measured memory_bytes: 3048
s = input()
t = input()
ans = len(t)

for i in range(len(s)):
    if i + len(t) -1  >= len(s): break
    diff = 0
    for j in range(len(t)):
        if s[i+j] != t[j]: diff += 1
    ans = min(ans, diff)
print(ans)



Measured memory_bytes: 67732
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(c >= (a - b)){
        cout << c - (a - b) << endl;
    } else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

constexpr int S = 51;
int N, M, a[60], b[60];
int suma[60], sumb[60];
// memo[s][t][u][v][turn][pass] :=
//      a ??????????????????????????? [s, t) ????????????
//      b ??????????????????????????? [u, v) ????????????
//      turn ??¨ pass ????????±
//      ???????????? point_a - point_b ??????
int memo[S][S][S][S][2][3];

// pass ?????£?¶?????????????????????°?????????
int dfs(int s, int t, int u, int v, int turn, int pass) {
    int& val = memo[s][t][u][v][turn][pass];
    if(val != -INF) return val;

    // ???????????????????????¶?????§??????????????????
    val =  suma[t] - suma[s];
    val -= sumb[v] - sumb[u];

    // ???????????¶??§???????????° pass ??????
    // ?????????????????¨????????£??????????????????????????????
    // ??\??????????????§????????????????????????????????£?????????
    if(!(s == t && u == v && pass == 1)) {
        if(s == t && u == v) val += dfs(t, t, v, v, turn^1, pass+1);
        else val += dfs(t, t, v, v, turn^1, 0);
    }

    // take (first)
    if(turn == 0) {
        if(t < N) {
            // ??¨??? -> ?????¨?????????????????????????????????????????¨????????????????????????
            //      -> ???????????????????????????????????????????????¨??????
            if(a[t] == -1) chmax(val, dfs(s, t+1, v, v, turn^1, 0));
            else           chmax(val, dfs(s, t+1, u, v, turn^1, 0));
        }
    }
    // take (second)
    else {
        if(v < M) {
            if(b[v] == -1) chmin(val, dfs(t, t, u, v+1, turn^1, 0));
            else           chmin(val, dfs(s, t, u, v+1, turn^1, 0));
        }
    }
    return val;
}

signed main() {
    rep(i,0,S) rep(j,0,S) rep(k,0,S) rep(l,0,S) rep(t,0,2) rep(p,0,3)
        memo[i][j][k][l][t][p] = -INF;

    cin >> N >> M;
    rep(i,0,N) cin >> a[i];
    rep(i,0,M) cin >> b[i];

    // 1-indexed
    rep(i,0,N) suma[i+1] = (a[i] == -1 ? suma[i] : suma[i] + a[i]);
    rep(i,0,M) sumb[i+1] = (b[i] == -1 ? sumb[i] : sumb[i] + b[i]);
    cout << dfs(0, 0, 0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 320220
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        int A = input.nextInt();
        int B = input.nextInt();
        if (N+A+B > 21){
            System.out.println("bust");
        }else {
            System.out.println("win");
        }

//        for (int i = 0; i < N; i++){
//            for (int j = 0; j < A; j++){
//
//            }
//        }
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string> 
#include <vector> 
using namespace std;

int main(){
	int n;
	while(cin >> n){
	if(n == 0){break;}
	int t[100],tt[200],i,ii;
	string ans[1000];
	i = 1;
	for(i = 1;n >= i;i++){
			//cout << i << endl;
			cin >> t[1] >> t[2] >> t[3];
			tt[1] = ( t[1] + t[2] ) / 2;
			tt[2] = ( t[1] + t[2] + t[3]) / 3;
			if(t[1] == 100 or t[2] == 100 or t[3] == 100 or  tt[1] >= 90 or tt[2] >= 80){
				ans[i] = "A";
			}else if(tt[2] >= 70){
				ans[i] = "B";
			}else if(tt[2] >= 50 and t[1] >= 80 or tt[2] >= 50 and t[2] >= 80){
				ans[i] = "B";
			}else{
				ans[i] = "C";
			}
	}
	ii = 1;
	//cout << "OK" << endl;
	for(ii = 1;n >= ii;ii++){
		cout << ans[ii] << endl;
	}
}
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m;
	cin>>n>>m;
	vector<vint> vv;
	initvv(vv,n,m);
	rep(i,n){
		rep(j,m){
			char t;
			cin>>t;
			vv[i][j]=t-'0';
		}
		// cout<<endl;
	}
	rep(i,n){
		rep(j,m){
			if(i==0&&j==0){
				continue;
			}
			if(i==0){
				vv[i][j]+=vv[i][j-1];
			}
			else if(j==0){
				vv[i][j]+=vv[i-1][j];
			}
			else{
				vv[i][j]+=min(vv[i-1][j],vv[i][j-1]);
			}
			// cout<<vv[i][j]<<" ";
		}
		// cout<<endl;
	}
	cout<<vv[n-1][m-1]<<endl;
}

Measured memory_bytes: 1228
n = gets.to_i
h = gets.split.map(&:to_i)
h << 0
dp = Array.new(n + 1) { Float::INFINITY }
dp[0] = 0

0.upto(n - 2) do |i|
  dp[i + 1] = [dp[i] + (h[i] - h[i + 1]).abs, dp[i + 1]].min
  dp[i + 2] = [dp[i] + (h[i] - h[i + 2]).abs, dp[i + 2]].min
end

puts dp[n - 1]


Measured memory_bytes: 20928
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1000;
vector<int>G[N];
int n,m,u,v;
int vis[N];

struct node {
	int step;
	int u;
	node(int s,int _){
		step = s;
		u = _;
	}
	node(){
	}
};

int bfs(int st,int ed) {
	memset(vis,0,sizeof(vis));
	node q[N];
	int l = 0, r = 1;
	vis[st] = 1;
	q[l] = node(0,st);
	while(l < r) {
		node now = q[l++];
		int u = now.u;
		if(now.step <= 2 && u == ed)return 1;
		if(now.step >= 2)continue;
		for(int i=0;i<G[u].size();i++) {
			int v = G[u][i];
			if(vis[v])continue;
			vis[v] = 1;
			q[r++] = node(now.step+1,v);
		} 
	}
	return 0;	
}

int main() {
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++) {
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}	
	
	if(bfs(1,n))puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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


int main(){
	int n;
	cin>>n;
	int x=0,y=0;

	bool flag=true;
	int time=0;
	for (int i = 0; i < n; i++){
		int a,b,t;
		cin>>t>>a>>b;
		int ti=t-time;
		int on=abs(a-x)+abs(b-y);
		if(on<=ti&&ti%2==on%2){
			x=a;
			y=b;
			time=t;
		}else{
			flag=false;
		}
	}

	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}
	

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

int topological_sort(int V_num,vector<vector<int>> &edge){
	int num[V_num]={};
	for(int i=0;i<edge.size();i++){
		for(int j=0;j<edge[i].size();j++){
			num[edge[i][j]]++;
		}
	}
	
	vector<int> check;
	for(int i=0;i<V_num;i++){
		if(num[i]==0)check.push_back(i);
	}
	
	vector<int> ans(V_num,0);
	while(check.size()!=0){
		int a = check[check.size()-1];
		check.pop_back();
		for(int i=0;i<edge[a].size();i++){
			num[edge[a][i]]--;
			if(num[edge[a][i]]==0)check.push_back(edge[a][i]);
			ans[edge[a][i]]=max(ans[edge[a][i]],ans[a]+1);
		}
	}
	int maxi = 0;
	for(int i=0;i<V_num;i++){
		maxi=max(ans[i],maxi);
	}
	
	return maxi;
}




int main(){
	int V,E;
	cin>>V>>E;
	
	vector<vector<int>> edge(V);
	
	for(int i=0;i<E;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		edge[a].push_back(b);
	}
	
	int ans = topological_sort(V,edge);
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <vector>
#include <stack>

#define MAX_V 55 

using namespace std;

bool is_visited[MAX_V];

void dfs(int n, int u, int v, vector<int> *graph, int cur) {
  is_visited[cur] = true;
  for (int i = 0; i < graph[cur].size(); i++) {
    int next_v = graph[cur][i];
    // 辺を使わない処理
    if (cur == u && next_v == v) { continue; }
    if (cur == v && next_v == u) { continue; }

    if ( !is_visited[next_v] ) {
      dfs(n, u, v, graph, next_v);
    }
  }
}

int main() {
  int n, m;
  int aa[MAX_V], bb[MAX_V];
  vector<int> graph[MAX_V];

  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;

    aa[i] = a; bb[i] = b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    int u = aa[i], v = bb[i];
    for (int i = 0; i < MAX_V; i++) {
      is_visited[i] = false;
    }
    dfs(n, u, v, graph, 0);
    bool f = true;
    for (int i = 0; i < n; i++) {
      if ( !is_visited[i] ) {
        f = false;
      }
    }
    if (!f) { ans++; };
  }

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

  return 0;
}

Measured memory_bytes: 256
class UF():
  def __init__(self, N):
    self.par = [-1] * N

  def find(self, n):
    if self.par[n] < 0:
      return n
    else:
      self.par[n] = self.find(self.par[n])
      return self.par[n]

  def union(self, x,y):
    p1,p2 = self.find(x), self.find(y)
    if p1 == p2: return
    if p1 > p2:
      p1,p2 = p2,p1
    self.par[p1] += self.par[p2]
    self.par[p2] = p1

  def same(self, x,y):
    return self.find(x) == self.find(y)

N,M = map(int,input().split())
A = list(map(int,input().split()))
uf = UF(N+1)
for _ in range(M):
  u,v = map(int,input().split())
  uf.union(u,v)

res = 0
for i in range(N):
  if i+1 == A[i] or uf.same(i+1, A[i]):
    res += 1

print(res)


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

int main(){
    long long int N=0,A=0,B=0;
    cin>>N>>A>>B;
    long long int count=0;
    count=(N/(A+B))*A;
    if(N%(A+B)>A){
        count=count+A;
    }
    else{
        count=count+N%(A+B);
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int H,W,h,w;
while(1){
  scanf("%d%d",&H,&W);
  if(H == 0 && W == 0)break;
  for(w = 0;w < W;w++)putchar('#');
  putchar('\n');
  for(h = 2;h < H; h++){
    putchar('#');
    for(w = 2; w < W;w++)putchar('.');
    putchar('#');
    putchar('\n');}
  for(w = 0;w < W; w++)putchar('#');
  putchar('\n');
  putchar('\n');}
return 0;
}



Measured memory_bytes: 2068
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ld long double
#define F first
#define S second
//
#define int long long
#define ll long long
#define db(x)                cerr<<#x<<": "<<x<<endl
#define db2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define db3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define db5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define db6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
//
#define mem(x,y) memset(x,y,sizeof(x))
#define bitcount    __builtin_popcount
//
#define pii pair<int, int>
#define all(v) v.begin(),v.end()
//
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define vi vector<int>
#define vvi vector< vector<int> >
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define mk make_pair
const int N=1e5+5;
const int mod=1e9+7;
const int mod1=998244353;
const int inf=1e16+7;
using namespace std;
vector<int> adj[N];
int dp[N];
int rec(int u){
   
    if(dp[u]!=-1) return dp[u];
    int &ans=dp[u];
    ans=0;
    for(int v:adj[u]){
        ans=max(ans,rec(v)+1);
    }
    return  ans;
    
}
void solve(){
    memset(dp,-1,sizeof(dp));
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
      //  adj[v].pb(u);
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,rec(i));
    }
    cout<<ans;
    
}


int32_t main() {
    IOS;
    
    int t;
    //cin>>t;
    t=1;
    for(int i=1;i<=t;i++){
       solve();
    }
   
}

















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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<double, double> pd;
typedef pair<int, int> pi; typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;  typedef pair<ll, pi> plp;
typedef pair<int, pi> pip; typedef tuple<int, int, int> ti;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e5 + 100;

int N, Nr[MAX_N], Temp[MAX_N];
int maxL[MAX_N], maxR[MAX_N];
int getAns(int st, int en) {
	int cnt = 0;
	for(int i=st; i<=en; i++) Temp[i] = Nr[i];
	for(int i=st; i<=en; i++) {
		int now = 0;
		if(Nr[i] == 1) cnt++;
		else if(cnt >= 1) {
			if(Nr[i+1] == 1) {
				now = cnt;
				if(cnt == 1) Nr[i] = 1, Nr[i+1] = 0, cnt = 1;
				else Nr[i] = Nr[i+1] = 0, cnt = 0;
			}else cnt = 0;
		}
		maxL[i+1] = maxL[i] + now;
	}
	cnt = 0;
	for(int i=st; i<=en; i++) Nr[i] = Temp[i];
	for(int i=en; i>=st; i--) {
		int now = 0;
		if(Nr[i] == 1) cnt++;
		else if(cnt >= 1) {
			if(Nr[i-1] == 1) {
				now = cnt;
				if(cnt == 1) Nr[i] = 1, Nr[i-1] = 0, cnt = 1;
				else Nr[i] = Nr[i-1] = 0, cnt = 0;
			}else cnt = 0;
		}
		maxR[i-1] = maxR[i] + now;
	}
	int res = 0;
	for(int i=st-1; i<=en; i++) {
		res = max(res, maxL[i] + maxR[i+1]);
	}
	
	for(int i=st; i<=en; i++) Nr[i] = Temp[i];
	
	return res;
}
int main() {
	cin >> N;
	for(int i=1; i<=N; i++) scanf("%1d", &Nr[i]);
	
	bool zz = true;
	int st = -1, en = -1;
	int ans = 0;
	for(int i=1; i<=N; i++) {
		if(zz) {
			if(Nr[i] == 0) continue;
			else{
				zz = false; st = i;
			}
		}
		if(zz == false) {
			if(Nr[i+1] == 0 && Nr[i+2] == 0) {
				en = i;
				ans += getAns(st, en);
				zz = true;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>

int arr[100005];

int main()
{
	int n;
	std::cin >> n;
	for (int i = 0; i <= n; ++i)
		std::cin >> arr[i];
	long long num = 0;
	for (int i = 0; i < n; ++i)
	{
		int h;
		std::cin >> h;
		if (h >= arr[i])
		{
			num += arr[i];
			h -= arr[i];
			arr[i] = 0;
			if (h >= arr[i + 1])
			{
				num += arr[i + 1];
				h -= arr[i + 1];
				arr[i + 1] = 0;
			}
			else
			{
				num += h;
				arr[i + 1] -= h;
				h = 0;
			}
		}
		else
		{
			num += h;
			arr[i] -= h;
			h = 0;
		}
	}
	std::cout << num << '\n';
	return 0;
}

Measured memory_bytes: 640
n = int(input())
arr = [int(n1) for n1 in input().split()]

flg = True
count1 = 0
con1 = 0
i = 0

while flg == True:
    
    for num in arr:
        if int(num) % 2 == 0:
            arr[i] = num / 2
        else:
            flg = False
            break
        i += 1
        
    if flg == True:
        con1 += 1
        i = 0

print(con1)

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

int main()
{
    int H,W,N,i;
    cin>>H;cin>>W;cin>>N;


    if(H>=W)
    {
    for(i=1;i<=H;i++)

    if(i*H>=N)
    break;

    }
    else
    {
    for(i=1;i<=W;i++)

    if(i*W>=N)
    break;

    }
    cout<<i;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char s;
	int sum = 0;
	while(cin>>s){
		sum = sum +(s-'0');
		sum%=9;
	}
	if(sum == 0){
		cout<<"Yes";
	} else{
		cout<<"No";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<algorithm>
using std::cin;
using std::cout;
int father[1000010], size[1000010], n, m;
int getfather(int x) {
    int ancesstor = x;
    for (; father[ancesstor] != ancesstor; ancesstor = father[ancesstor]);
    for (int tmp; x != ancesstor; x = tmp) {
        tmp = father[x];
        father[x] = ancesstor;
    }
    return ancesstor;
}

void merge(int x, int y) {
    x = getfather(x); y = getfather(y);
    if (x == y) return;
    if (size[x] > size[y]) {
        father[y] = x;
        size[x] += size[y];
    }
    else {
        father[x] = y;
        size[y] += size[x];
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //cout << std::setiosflags(std::ios::fixed) << std::setprecision(3);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        father[i] = i;
        size[i] = 1;
    }
    for (int i = 1; i <= m; ++i) {
        int x, y;
        cin >> x >> y;
        merge(x, y);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = std::max(ans, size[i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5068
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int N,M,C;
  cin >> N >> M >> C;
  
  vector<int> B(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  
  int ans = 0;
  for (int i = 0; i < N; i++){
    int tmp = 0;
    for (int j = 0; j < M;j++){
      int A;
      cin >> A;
      tmp += A * B[j];
    }
    
    tmp += C;
    
    if (tmp > 0){
      ans++;
    }
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

#define rep(i,x,y) for(int (i)=(x);(i)<(y);(i)++)

int string_to_int(string s){
  int res=0;
  for(char ch:s){
    res*=10;
    res+=ch-'0';
  }
  return res;
}

void solve(string s,int l){
  if(s.size()<l){
    string hoge;
    rep(j,0,l-s.size()) hoge+='0';
    s=hoge+s;
  }
  vector<bool> done(1000000);
  vector<int> idx(1000000,-1);
  {
    int tmp=stoi(s);
    done[tmp]=true;
    idx[tmp]=0;
  }
  rep(i,1,100000000){
    string a=s,b=s;
    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());
    int tmp=string_to_int(b)-string_to_int(a);
    stringstream ss;
    ss << tmp;
    s=ss.str();
    if(s.size()<l){
      string hoge;
      rep(j,0,l-s.size()) hoge+='0';
      s=hoge+s;
    }
    if(done[tmp]){
      cout << idx[tmp]  << " " << tmp << " " << i-idx[tmp] << endl;
      return;
    }
    done[tmp]=true;
    idx[tmp]=i;
  }
}

int main(){
  while(true){
    string s;
    int l;
    cin >> s >> l;
    if(s=="0" and l==0) break;
    solve(s,l);
  }
}

Measured memory_bytes: 7188
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
#include <cmath>
#include <vector>

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

typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main() {
    ll n, k;
    cin >> n >> k; 

    int digits = 1;
    while (n >= k)
    {
        /* code */
        n = n/k;
        digits++;
    }
    cout << digits << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

import Queue

N = int(raw_input())
tree = [[] for _ in xrange(N)]

for i in range(N-1):
    a, b, c = map(int, raw_input().split())
    a -= 1; b -= 1;
    tree[a].append((b, c))
    tree[b].append((a, c))

Q, K = map(int, raw_input().split())
K -= 1

depth = [0 for _ in xrange(N)]

def bfs(v, p = -1, d = 0):
    q = Queue.Queue()
    q.put([v, p, d])
    while not q.empty():
        cur = q.get()
        depth[cur[0]] = cur[2]
        for i, j in tree[cur[0]]:
            if i == cur[1]:
                continue
            q.put([i, cur[0], cur[2] + j])

bfs(K)

for i in range(Q):
    x, y = map(int, raw_input().split())
    x -= 1; y -= 1;
    print depth[x] + depth[y]


Measured memory_bytes: 49708
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, k;
	cin >> n >> k;
	if(n%k==0){
		cout << 0 << endl;
	} else {
		cout << 1 << endl;
	}

	return 0;
}

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

int main()
{
    string S;
    cin>>S;
    string T= S;
    reverse(S.begin(),S.end());
    if(S!=T)
    {
        cout<<"No";
        return 0;
    }
    string X= S.substr(0,(S.length()-1)/2);
    string X1 = X;
    reverse(X.begin(),X.end());
    if(X1!=X)
    {
        cout<<"No";
        return 0;
    }
    string Y=S.substr((S.length()+2)/2,(S.length()-1)/2);
    string Y1=Y;
    reverse(Y.begin(),Y.end());
    if(Y!=Y1)
    {
        cout<<"No";
        return 0;
    }
    
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



LL snum[4001];
int main(){
	LL N;
	vector<string>res;
	while(1){
		cin>>N;
		if(N==0)break;
		CLR(snum);
		vector<LL>vn;
		REP(i,N){
			LL num,tanka,suryo;
			cin>>num>>tanka>>suryo;
			vn.PB(num);
			snum[num]+=tanka*suryo;
		}
		bool c=false;
		set <LL>sl;
		REP(i,SZ(vn)){
			if(snum[vn[i]]>=1000000&&sl.find(vn[i])==sl.end()){
				c=true;
				sl.insert(vn[i]);
				res.PB(toString(vn[i]));
			}
		}
		if(!c)res.PB("NA");
	}
	REP(i,SZ(res)){
		cout<<res[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1360
#include<stdio.h>
int main()
{
  int A,B;
  scanf("%d %d",&A,&B);
  int i;
  int flag=-1;
  int C,D;
  for(i=0;i<1000000;i++)
  {
    C=i*0.08;
    D=i*0.1;
    if((C==A)&&(D==B)){
      flag=i;
      break;
    }
  }
  printf("%d",flag);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
list_a = [int(input()) for i in range(N)]

next = list_a[0]
ans = 1

for i in range(1,N+1) :
    if next == 2 :
        print(ans)
        exit()
    next = list_a[next-1]
    ans += 1

print(-1)


Measured memory_bytes: 7084
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> hogee;
	REP(i, n) {
		int a;
		cin >> a;
		hogee.push_back(make_pair(a, i));
	}
	int ans = 0;
	sort(hogee.begin(), hogee.end());
	REP(i, n) {
		if (hogee[i].second % 2 != i % 2) {
			ans++;
		}
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 1400
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
    l := getStdinIntArr()
    x, y := l[0], l[1]
    if y%2 == 0 && y >= 2*x && y <= 4*x {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}

// slice[start:end+1] = val
func fill(slice []int, val, start, end int) ([]int, error) {
    if len(slice) < start || len(slice) < end {
        return nil, fmt.Errorf("Error")
    }
    for i := start; i < end; i++ {
        slice[i] = val
    }
    return slice, nil
}

func getStdin() string {
    return readLine()
}
func getStdinInt() int {
    str := getStdin()
    res, _ := strconv.Atoi(str)
    return res
}
func getStdinIntArr() []int {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.Atoi(v)
    }
    return res
}
func getStdinArr() []string {
    str := getStdin()
    list := strings.Split(str, " ")
    return list
}
func getStdinIntArr64() []int64 {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int64, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.ParseInt(v, 10, 64)
    }
    return res
}
func readLine() string {
    buf := make([]byte, 0, 0)
    for {
        l, p, e := sc.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N;
  cin>>N;
  vector<ll>A(N);
  vector<ll>B(N);
  vector<pair<ll,ll>>C(N);  
  rep(i,N){
    cin>>A[i]>>B[i];
    C[i].first=B[i];
    C[i].second=A[i];
  }
  
  sort(all(C));
  
  ll now=0;
  bool flag=true;
  for(ll i=0;i<N;i++){
    now+=C[i].second;
    if(C[i].first<now){
flag=false;
      break;
    }
  }

  if(flag){
cout<<"Yes"<<endl;
  }
else{
  cout<<"No"<<endl;
}
}


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

using namespace std;

int main() {
    int c;
    cin >> c;
    if (c >= 30 && c <= 40)
    {
        cout << "Yes";
    }
    else if (c >= -40 && c < 30)
        cout << "No";
}

Measured memory_bytes: 3592
def is_ok(a, b, k, val):
    for i in range(val + 1):
        a_val = i
        b_val = val - a_val
        if a_val > len(a) or b_val > len(b):
            continue
        ret = 0
        if a_val > 0:
            ret += a[a_val-1]
        if b_val > 0:
            ret += b[b_val-1]
        if ret <= k:
            return True
    return False


n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

for i in range(1, len(a)):
    a[i] += a[i-1]

for i in range(1, len(b)):
    b[i] += b[i-1]

ok = 0
ng = 400001
while ng - ok > 1:
    mid = (ok + ng) // 2
    if is_ok(a, b, k, mid):
        ok = mid
    else:
        ng = mid

print(ok)


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

N = int(input())

def F(N):
    if N == 3:
        return [2,5,63]
    A2 = [x for x in range(2,30001,2) if x%6 != 0]
    A3 = [x for x in range(3,30001,6)]
    A6 = [x for x in range(6,30001,6)]
    x2 = min(10000,(N-2)//2*2)
    N -= x2
    x3 = min(5000,N//2*2)
    x6 = N - x3
    return A2[:x2] + A3[:x3] + A6[:x6]

answer = F(N)

print(' '.join(map(str,answer)))

Measured memory_bytes: 5084
// author: vanilla
#include<bits/stdc++.h>

using namespace std;

// 用意した竹の本数, 竹Aの長さ, 竹Bの長さ, 竹Cの長さ, 用意した竹の長さ
int N, A, B, C, l[8], ans = (int)1e9;

// 深さ優先探索
void dfs(int depth, int nA, int nB, int nC, int nowA, int nowB, int nowC){
    // まだ探索しきれてない場合
    if(depth < N){
        // i番目の竹をA, B, Cのそれぞれに合成。またはどれにも合成しない。
        dfs(depth + 1, nA + 1, nB, nC, nowA + l[depth], nowB, nowC);
        dfs(depth + 1, nA, nB + 1, nC, nowA, nowB + l[depth], nowC);
        dfs(depth + 1, nA, nB, nC + 1, nowA, nowB, nowC + l[depth]);
        dfs(depth + 1, nA, nB, nC, nowA, nowB, nowC);
    }else{
        if(nA == 0 || nB == 0 || nC == 0) return;
        // コストを求める
        int cost = (max(nA-1,0)+max(nB-1,0)+max(nC-1,0))*10+abs(A-nowA)+abs(B-nowB)+abs(C-nowC);
        ans = min(ans, cost);
    }
}

int main(){
    // 入力
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; ++i) cin >> l[i];
    dfs(0, 0, 0, 0, 0, 0, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;

int main() {
  int n,m;
  cin >> n >> m;
  vector<P> v[n];
  for(int i=0; i<m; i++) {
    int x,y,z;
    cin >> x >> y >> z;
    x--,y--;
    v[x].push_back(P(y,z));
    v[y].push_back(P(x,z));
  }
  int M=0,cnt=0;
  bool u[n];
  memset(u,0,sizeof(u));
  for(int k=0; k<n; k++) {
    int d[n];
    fill(d,d+n,1<<29);
    d[k]=0;
    vector<int> w[n];
    priority_queue<P,vector<P>,greater<P> > que;
    que.push(P(0,k));
    while(!que.empty()) {
      P p=que.top();que.pop();
      int x=p.S,c=p.F;
      if(d[x]<c) continue;
      if(c>M) {
        M=c;
        memset(u,0,sizeof(u));
      }
      for(int i=0; i<v[x].size(); i++) {
        int y=v[x][i].F,cc=v[x][i].S;
        if(d[y]>d[x]+cc) {
          d[y]=d[x]+cc;
          que.push(P(d[y],y));
          w[y].clear();
        }
        if(d[y]==d[x]+cc) w[y].push_back(x);
      }
    }
    bool uu[n];
    memset(uu,0,sizeof(uu));
    queue<int> q;
    for(int i=0; i<n; i++) {
      if(d[i]==M) {
        uu[i]=1;
        q.push(i);
      }
    }
    while(!q.empty()) {
      int x=q.front();q.pop();
      for(int i=0; i<w[x].size(); i++) {
        int y=w[x][i];
        if(uu[y]) continue;
        uu[y]=1;
        q.push(y);
      }
    }
    for(int i=0; i<n; i++) u[i]|=uu[i];
  }
  for(int i=0; i<n; i++) if(!u[i]) cnt++;
  cout << cnt << endl;
  for(int i=0; i<n; i++) if(!u[i]) cout << i+1 << endl;
  return 0;
}


Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

vector<vector<int>> g;
vector<bool> v;
vector<int64_t> c;
map<int, int64_t> p;

void dfs(const int s, int64_t x) {
    if(v[s]) return;
    v[s] = true;
    x += p[s];
    c[s] += x;

    for (int elm : g[s]) {
        if(not v[elm]) dfs(elm, x);
    }
}

int main(){
    int n, q;
    cin >> n >> q;

    g.assign(n, vector<int>(0));
    for (auto i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    for (auto i = 0; i < q; i++) {
        int a, b; cin >> a >> b;
        p[a - 1] += b;
    }

    v.assign(n, false);
    c.assign(n, 0);
    dfs(0, 0);

    for (auto i = 0; i < n; i++) {
        cout << c[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 39936
fun main(args: Array<String>)
{
    val n = readInt()
    val arr = Array<String>(n, { readString().toList().sorted().joinToString("") } )

    val mm = mutableMapOf<String, Long>()
    for (s in arr)
    {
        val v = if (mm.containsKey(s)) mm[s]!!.plus(1L) else 0L
        mm.put(s, v)
    }

    println(mm.values.map{ it * (it + 1) / 2 }.reduce{ acc, item -> acc + item })
}

// Read an integer
// Usage: val a = readInt()
fun readInt() = readLine()!!.toInt()

// Read a string
// Usage: val a = readString()
fun readString() = readLine()!!


Measured memory_bytes: 77484
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> squares;
int dp[100001];

int DynamicSolve(int k)
{
	if (k == squares.size())
		return 0;

	if (dp[k] != -1)
		return dp[k];

	int res = 0;
	if (k != squares.size() - 1 && squares[k] >= squares[k + 1])
		res += DynamicSolve(k + 1) + 1;
	else
		DynamicSolve(k + 1);
	dp[k] = res;
	return res;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int square;
		scanf("%d", &square);
		squares.push_back(square);
	}
	DynamicSolve(0);
	int maxLandCnt = 0;
	for (int i = 0; i < 100001; i++)
	{
		maxLandCnt = max(maxLandCnt, dp[i]);
	}
	cout << maxLandCnt;
}

Measured memory_bytes: 2680
/*  ex3_3
    Graku   */
#include <stdio.h>
#include <math.h>

int main(void) {
    int n, k; //declaration
    scanf("%d %d", &n, &k);

    /*
    write n in k base, and divide n by k.
    this operation mean remove ones place.
    */
    int count = 0; //initialized
    do {
        count++;
    } while (n /= k);

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

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

using namespace std;
#define ll long long int
vector<vector<ll>>v;
map<pair<int,int>,int>mp;
ll f(int c,int i){
    if(i==v.size()) return 0;
    if(mp.find({c,i})!=mp.end()) return mp[{c,i}];
    ll x = 0;
    ll ans = 0;
    if(c == 1){
        x = v[i][0];
        ans =  x+max(f(2,i+1),f(3,i+1));
        mp[{c,i}] = ans;
        return ans;
    }
    else if(c == 2){
        x = v[i][1];
        ans = x+max(f(1,i+1),f(3,i+1));
        mp[{c,i}] = ans;
        return ans;
    }
    x = v[i][2];
    ans = x+max(f(1,i+1),f(2,i+1));
    mp[{c,i}] = ans;
    return ans;
}
int main() {
    int n,k;
    cin>>n;
    
    for(int i=1;i<=n;i++){
        ll x,y,z;
        cin>>x>>y>>z;
        v.push_back({x,y,z});
        //cout<<a[i]<<"\n";
    }
    
    cout<<max(f(1,0),max(f(2,0),f(3,0)))<<"\n";
    return 0;
    
}

Measured memory_bytes: 34480
#include<iostream>
#include<vector>
#define N 500000
#define INF 2000000000
using namespace std;
int c;

void merge(int *A,int l,int m,int r){
  vector<int> L,R;
  for(int i=l;i<m;i++)L.push_back(A[i]);
  for(int i=m;i<r;i++)R.push_back(A[i]);  
  int i=0,j=0;
  L.push_back(INF);
  R.push_back(INF);
   for(int k=l;k<r;k++){
     if(R[j]>L[i])A[k]=L[i++];
     else A[k]=R[j++];
     c++;
  }
}

void mergesort(int *A,int l,int r){
  if(l+1<r){
    int m=(l+r)/2;
    mergesort(A,l,m);
    mergesort(A,m,r);
    merge(A,l,m,r);
  }
}
 
 
int main(){
  int n,S[N];
  cin>>n;
  for(int i=0;i<n;i++)cin>>S[i];
  mergesort(S,0,n);
  for(int i=0;i<n-1;i++)cout<<S[i]<<" ";
  cout<<S[n-1]<<endl<<c<<endl;
  return 0;
}


Measured memory_bytes: 7276
#include <iostream>
#include <string>
namespace Mylib{
    using namespace std;
    
}
int main(void){
    using namespace std;
    int A,B;
    
    cin >> A >> B;
    
    string Astr="";
    string Bstr="";
    
    for(int i=0;i<B;i++)Astr+=to_string(A);
    for(int i=0;i<A;i++)Bstr+=to_string(B);
    
    if(Astr<Bstr){
        cout << Astr << endl;
    }else if(A>=B){
        cout << Bstr << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007

/* add vars here */

int d;
ll g;

/* add your algorithm here */

int main() {
  cin >> d >> g;

  ll p[d], c[d];

  rep(i,d) cin >> p[i] >> c[i];
  ll ans = 100 * d + 1;

  for (int i = 0; i < (1 << d); ++i) {

    bool check[d];
    rep(i,d) check[i] = false;

    ll ts, tc;
    ts = tc = 0;
    
    for (int j = 0; j < d; ++j) {
      if (i >> j & 1) {
        check[j] = true;
        ts += p[j] * (j + 1) * 100 + c[j];
        tc += p[j];
      }
    }

    if (ts >= g) {
      ans = min(ans, tc);
      continue;
    }

    for (int j = d-1; j >= 0; --j) {
      bool flag = false;
      if (check[j]) continue;

      if (ts + ((j + 1) * 100) * p[j] + c[j] < g) {
        ts += ((j + 1) * 100) * p[j] + c[j];
        tc += p[j];
        continue;
      }

      if (ts >= g) {
        ans = min(ans, tc);
        break;
      }

      for (int k = 1; k <= p[j]; ++k) {
        ts += (j + 1) * 100;
        if (k == p[j]) ts += c[j];
        tc++;
        if (ts >= g) {
          flag = true;
          break;
        }
      }

      if (flag) {
        ans = min(ans, tc);
        break;
      }
    }
  }

  cout << ans << endl;
}


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

int main(){
  long n, a, b, c, d, e, m;
  cin >> n >> a >> b >> c >> d >> e;

  m = min({a, b, c, d, e});
  // cout << "min:" << m << endl;
  cout << setprecision(16) << ceil((double)n/m) + 4  << endl;

  return 0;
}

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

using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

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

    int64_t k, a, b;
    cin >> k >> a >> b;

    int64_t res = 1, cnt = 0;
    while (cnt < k) {
        if (b - a > 2 && k - cnt >= 2 && res >= a) {
            res += b - a;
            cnt += 2;
        } else {
            res++;
            cnt++;
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int n;
    cin >> n;

    vi v(n);
    iota(ALL(v), 1);

    string p, q;
    REP(_, n) { char c; cin >> c; p += c;}
    REP(_, n) { char c; cin >> c; q += c;}

    vs dic;
    do {
        string s;
        for (int num : v) s += to_string(num);
        dic.emplace_back(s); 
    } while (next_permutation(ALL(v)));

    sort(ALL(dic));

    int a, b, cnt = 0;
    for (string d : dic) {
        if (d == p) a = cnt;
        if (d == q) b = cnt;
        cnt++;
    }

    cout << abs(a-b) << endl;

    return 0;
}


Measured memory_bytes: 2552
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	hs := make([]int, n)
	for k := range hs {
		fmt.Fscan(r, &hs[k])
	}

	var ans int
	for sk := 0; sk < n; sk++ {
		for hs[sk] > 0 {
			for ek := sk; ek < n; ek++ {
				if hs[ek] == 0 {
					break
				}
				hs[ek]--
			}
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if((a-2*b) > 0) {
        printf("%d\n",a-2*b);
    }
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<iomanip> 
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define pb push_back
#define mp make_pair 
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %I64d\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
#define MAXN (100000+10)
int a[100000+10];
int main()
{
//	freopen("B.in","r",stdin);
//	freopen(".out","w",stdout);
	int n=read();
	For(i,n) cin>>a[i];
	ll ans=0;
	For(i,n) if (i<a[i]&&a[a[i]]==i) ++ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3

def main():
    A,B,C= map(int, input().split())
    youki1_capa = A - B
    youki2_zan = C - youki1_capa
    if youki2_zan > 0:
        print(youki2_zan)
    else:
        print(0)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940