akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int ordena(const void * a, const void * b){
    int x = *((int*) a);
    int y = *((int*) b);
    if(x < y){
        return -1;
    }
    else{
        return 1;
    }
    return 0;

}

int main(){
    int n;
    scanf("%d", &n);
    int total = 0;
    int v[n];

    for(int i = 0; i < n; ++i)
        scanf("%d", &v[i]);

    qsort(v, n, sizeof(v[0]), ordena);

    printf("%d\n", v[n/2]-v[(n/2)-1]);


    return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int n; cin >> n;
	vector<int>a(n);
	rep(i, n)cin >> a[i];
	vector<int>b(n);
	int x = 0, y = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			b[x] = a[n - 1 - i];
			++x;
		}
		else {
			b[n-1-y] = a[n - 1 - i];
			++y;
		}
	}
	rep(i, n)cout << b[i] << (i == n - 1 ? "\n" : " ");
	
		
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll H, W; cin >> H >> W;
    vvll v(H, vll(W));
    rep(i, H) rep(j, W) cin >> v[i][j];
    vector<pair<pair<ll, ll>, pair<ll, ll>>> op;

    rep(i, H) rep(j, W) {
        if (v[i][j] % 2 == 0) continue;
        if (i == H-1 && j == W-1) continue;

        v[i][j]--;
        pair<ll, ll> src = {i+1, j+1};
        pair<ll, ll> dst;
        if (j != W - 1) {
            dst = {src.first, src.second+1};
            v[i][j+1]++;
        } else {
            dst = {src.first+1, src.second};
            v[i+1][j]++;
        }
        op.push_back({src, dst});
    }

    //for (auto row : v) {
    //    for (auto elem : row) cout << elem << " "; cout << endl;
    //}

    cout << op.size() << endl;
    for (auto elem : op) {
        cout << elem.first.first << " " << elem.first.second << " " << elem.second.first << " " << elem.second.second << endl;
    }
    return 0;
}

Measured memory_bytes: 8432
#include<iostream>
#include <stdio.h>
#include<string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue> 
#include <map>
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
using namespace std;

int main(){

  string s;
  cin >> s;
  
  s[3] = '8';
  
  cout << s << endl;

 return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    bool flag = true;
    cin >> S;
    if (S[0] != 'Y') flag = false;
    if (S[1] != 'A') flag = false;
    if (S[2] != 'K') flag = false;
    if (S[3] != 'I') flag = false;

    cout << (flag ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	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;
	}

	return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

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(auto 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)
#define UNTIL(p) while(!(p))

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

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,H,W;
    cin>>N>>H>>W;
    int ans = 0;
    REP(i,N)REP(j,N){
        if(i + H <= N && j + W <= N){
            ans++;
        }
    }
    PUTS(ans);
}

Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
double cal(ll v) {

	double res = 0;
	while (v > 0)
	{
		res += v % 10;
		v /= 10;
	}
	return res;
}

void solv() {
	
	int n;
	ll v;

	cin >> n >> v;

	int p = -1;
	ll bef = 0;
	for (int i = 0; i < n; i++)
	{
		ll a;
		cin >> a;
		if (i > 0 && a + bef >= v) {
			p = i;
			break;
		}
		bef = a;
	}

	if (p == -1) {
		cout << "Impossible" << endl;
		return;
	}
	cout << "Possible" << endl;
	for (size_t i = 0; i < p - 1; i++)
	{
		cout << (i + 1) << endl;

	}

	for (int i = n; i > p; i--)
	{
		cout << (i - 1) << endl;
	}
}




int main() {
	solv();

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    string s;cin>>s;
    rep(i,0,26){
        int count=0;
        rep(j,0,s.size()){
            if(alph[i]==s[j])count++;
        }
        if(count%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, q int
	fmt.Scan(&n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	fmt.Scan(&q)
	cnt := 0
	for i := 0; i < q; i++ {
		var t int
		fmt.Scan(&t)
		for j := 0; j < n; j++ {
			if t == s[j] {
				cnt++
				break
			}
		}
	}
	fmt.Println(cnt)
}



Measured memory_bytes: 1688
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
import sys
input = sys.stdin.readline
from heapq import*


N,W=map(int,input().split())
WV=[list(map(int,input().split())) for i in range(N)]
dp=[[0 for i in range(301*(N+1))] for n in range(N)]
Z=WV[0][0]

for i in range(N):
    WV[i][0]-=Z
for n in range(N):
    for i in range(len(dp[0])):
        w,v=WV[n]
        if n==0:
            dp[n][w+301]=v
        else:
            dp[n][w+301]=max(dp[n-1][w+301],v)
            if i>=w+301:
                if dp[n-1][i-(w+301)]:
                    dp[n][i]=max(dp[n-1][i-(w+301)]+v,dp[n-1][i])
                else:
                    dp[n][i]=dp[n-1][i]
            else:
                dp[n][i]=dp[n-1][i]


print(max([max([dp[n][i] for i in range(len(dp[0])) if W>=i//301*Z+i%301]) for n in range(N)]))


Measured memory_bytes: 83420
n,*a=map(int,open(0).read().split())

ma=1001001
nums=[0]*ma

for i in a:
    nums[i]+=1
    if nums[i]==1: # 一回だけ出てきた場合
        for j in range(i+i,ma,i):
            nums[j]+=2
            
ans=nums.count(1)
print(ans)


Measured memory_bytes: 118724
from itertools import product

H,W=map(int,input().split())
S=[list(input()) for _ in range(H)]

G=[[0] * W for h in range(H)]
P=[(y,x) for y,x in product(range(-1,2),range(-1,2)) if not (y==0 and x==0)]

for x,y in product(range(W),range(H)):
    if S[y][x]=="#":
        G[y][x]="#"
        continue

    for p in P:
        c_y=y+p[0]
        c_x=x+p[1]
#         print(c_x,c_y)
        if c_x <0 or c_x>=W or c_y<0 or c_y>=H: 
            continue
#         print(c_x,c_y)
        if S[c_y][c_x]=="#":
            G[y][x]+=1

_=[print("".join(map(str,r))) for r in G]


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline T upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline T upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

char s1[100],s2[100]="AKIHABARA";
int main()
{
	scanf("%s",s1);
	int n=strlen(s1),m=strlen(s2),i,j;
	for (i=j=0;i<n;i++,j++) {
		while (s1[i]!=s2[j]&&s2[j]=='A') j++;
		if (s1[i]!=s2[j]) return puts("NO"),0;
	}
	while (s2[j]=='A') j++;
	puts(j<m?"NO":"YES");
	return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n;
int a[100];

int main(){

	cin >> n;
	int ma = -1000005;//
	int idx;
	FORI(1,n+1) {//
		cin >> a[i];
		if (abs(a[i]) > ma) {
			ma = abs(a[i]);
			idx = i;//
		}
	}

	cout << 2 * n - 1 << endl;
	FORI(1, n+1) {
		cout << idx << " " << i << endl;//		
	}
	if (a[idx] > 0) {
		FORI(1, n) {
			cout << i << " " << i+1 << endl;
		}
	}
	else {
		for(int i=n;i>=2;i--){
			cout << i << " " << i-1 << endl;
		}

	}
	return 0;
}


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

const int INF=1e9;
int N,M;

int K[200],S[200][200],H[200][200];
int X[200];
int sum[200][441];

int dp[2][201][21];

int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>K[i];
        int cur=0;
        for(int j=0;j<K[i];j++){
            cin>>S[i][j]>>H[i][j];
            int next=cur;
            while(next-cur<H[i][j]){
                sum[i][next]=S[i][j]+(next?sum[i][next-1]:0);
                next++;
            }
            cur=next;
            X[i]+=H[i][j];
        }
        sum[i][cur]=INF;
    }


    fill_n(**dp,2*201*21,INF);
    dp[0][0][0]=0;

    for(int i=0;i<N;i++){
        for(int j=0;true;j++){
            for(int k=0;k<=M;k++){
                int v=(j?sum[i][j-1]:0),s=sum[i][j]-(j?sum[i][j-1]:0);
                for(int l=0;l<=20;l++){
                    int t=(sum[i][j]==INF?l:(l?min(l,s):s));
                    if(k+j<=M)dp[(i+1)&1][k+j][t]=min(dp[(i+1)&1][k+j][t],dp[i&1][k][l]+v);
                }
            }
            if(sum[i][j]==INF)break;
        }

        for(int j=0;j<=M;j++){
            for(int k=0;k<=20;k++){
                dp[i&1][j][k]=INF;
            }
        }
    }

    double ans=0;

    for(int i=0;i<=M;i++){
        for(int j=0;j<=20;j++){
            if(dp[N&1][i][j]<=M){
                ans=max(ans,i+(j?min(1.0,1.0*(M-dp[N&1][i][j])/j):0.0));
            }
        }
    }

    printf("%.8lf\n",ans);
    return 0;
}

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    (u == s) ? a-- : b--;
    cout << a << " " << b << endl;
    return 0;
}


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

using namespace std;

int main(){

    int a,c,d,b;

    cin >> a >> b >> c >> d;

    int flag = 0;

    if(abs(a-c)<=d) cout << "Yes" << endl;

    else{

       if(abs(a-b)<=d && abs(b-c)<=d)

         cout << "Yes" << endl;

       else cout << "No" << endl;

    }

    return 0;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MAX 100

int N,ans=0;
int A[MAX],B[MAX];

int main(){
	cin >> N;
	for(int i=0;i<N-1;i++) cin >> B[i];
	B[N-1] = B[N-2];
	for(int i=0;i<N;i++){
		if(i==0) A[0] = B[0];
		else{
			if(B[i-1] <= B[i]) A[i] = B[i-1];
			else A[i] = B[i];
		}
	}  
	for(int i=0;i<N;i++) ans += A[i];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF 1e9
int main(){
	int dp[50010] = {0};
	int coin[21] = {0};
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i = 0; i < m; i++){
		scanf("%d",&coin[i]);
	}
	for(int i = 0; i < 50010; i++)dp[i] = INF;
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			int nx = coin[j] + i;
			if(nx <= n){
				dp[nx] = min(dp[nx],dp[i]+1);
			}
		}
	}
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1228
import numpy as np
from numba import njit
N, K = [int(_) for _ in input().split()]
A = np.array(sorted([int(_) for _ in input().split()]))


@njit
def solve(N, K, A):
    lb = -10**18 - 1
    rb = 10**18 + 1

    def check(x):
        #x以下の積がK個以上ある
        cnt = 0
        for i, a in enumerate(A):
            #区間i2∈[0,i) でA[i]*A[i2]<=xとなるようなi2の個数
            l = 0
            r = i
            if a > 0:
                l = -1
                r = np.searchsorted(A, x // a, side='right')
            elif a < 0:
                l = np.searchsorted(A, 0 - x // (-a), side='left')
                r = N + 1
            elif x < 0:
                r = 0
            l = min(max(l, 0), i)
            r = max(min(r, i), 0)
            cnt += r - l
        return cnt >= K

    # Min x for check(x) == True
    while rb - lb > 1:
        mid = (rb + lb) // 2
        if check(mid):
            rb = mid
        else:
            lb = mid
    print(rb)


solve(N, K, A)


Measured memory_bytes: 113752
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,A,B,C,D;
ll d[1001][1001];
ll fac[1001],inv[1001];
ll go(int N,int K)
{
	if(N==0)return fac[n];
	if(K>B)return 0;
	ll &ret=d[N][K];
	if(ret!=-1)return ret;
	ret=go(N,K+1);
	for(int i=C;i<=D && i*K<=N;i++)
	{
		ll tt=POW(inv[K],i);
		ll t=(tt*inv[i])%MOD;
		ret=(ret+t*go(N-i*K,K+1))%MOD;
	}
	return ret;
}
int main() {
	fac[0] = inv[0] = 1;
	fup(i, 1, 1000, 1)
		fac[i] = (fac[i - 1] * i) % MOD;
	inv[1000] = POW(fac[1000], MOD - 2);
	fdn(i, 999, 1, 1)
		inv[i] = (inv[i + 1] * (i+1)) % MOD;
	MEM_1(d);
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
	printf("%lld",go(n,A));
}

Measured memory_bytes: 8192
while True:
    list1=input().split('"')
    if list1[0]==".":
        break
    list2=input().split('"')
     
    cnt1=0
    cnt2=0
    flag=0
     
    if len(list1)!=len(list2):
        print("DIFFERENT")
    else:
        i=0
        while i<len(list1):
            if list1[i]==list2[i]:
                cnt1+=1
            elif i%2==0:	#[ " ~~~~~ " ]in ""
                print("DIFFERENT")
                flag=1
                break
            else:
                cnt2+=1
                if cnt2>1:
                    print("DIFFERENT")
                    break
            i+=1
                 
        if flag==0 and cnt2==1:
            print("CLOSE")
        if cnt1==len(list1):
            print("IDENTICAL")



Measured memory_bytes: 5576
//============================================================================
// Name        : alds1_3_d_areas_on_the_cross_section_diagram.cpp
// Author      : lovesaemi
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	stack<int> S1;
	stack<pair<int, int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++) {
		if (ch == '\\') {
			S1.push(i);
		} else if (ch == '/' && S1.size() > 0) {
			int j = S1.top();
			S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j) {
				a += S2.top().second;
				S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}
	vector<int> ans;
	while (S2.size() > 0) {
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++) {
		cout << " ";
		cout << ans[i];
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 3212
#include<iostream>
#include<algorithm>
#include<queue>
using lint=long long;
using namespace std;

const int dw[]={1,0,-1,0};
const int dh[]={0,-1,0,1};
const int inf=1e9;

int main()
{
	int H,W;
	char s[55][55];
	int wcnt=0;
	
	cin >> H >> W;
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			cin >> s[i][j];
			if(s[i][j]=='.')
				wcnt++;
		}
	}
	
	int dp[55][55]={};
	for(int i=0;i<=H;i++)
		for(int j=0;j<=W;j++)
			dp[i][j]=inf;
	dp[0][0]=1;
	
	queue<pair<int,int>> q;
	q.push(make_pair(0,0));
	while(!q.empty())
	{
		int ch=q.front().first;
		int cw=q.front().second;
		q.pop();
		
		s[ch][cw]='#';
		
		for(int i=0;i<4;i++)
		{
			int nh=ch+dh[i];
			int nw=cw+dw[i];
			
			if(nh<0 || nw<0 || nh>=H || nw>=W)continue;
			if(s[nh][nw]=='.' && dp[ch][cw]+1<dp[nh][nw])
			{
				dp[nh][nw]=dp[ch][cw]+1;
				q.push(make_pair(nh,nw));
			}
		}
	}
	
	if(dp[H-1][W-1]==inf)
		cout << -1;
	else
		cout << wcnt-dp[H-1][W-1];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define INF INT32_MAX

typedef struct Edge {
    int R;
    int D;
} Edge;
set<int> Node;
map<int, vector<Edge>> G;
vector<int> D;

void dfs(int cur, int prev) {
    for (auto e : G[cur]) {
        if (e.R == prev) continue;
        if (D[e.R] == INF) {
            D[e.R] = D[cur] + e.D;
            dfs(e.R, cur);
        }
        if (D[e.R] != D[cur] + e.D) {
            cout << "No" << endl;
            exit(0);
        }
    }
}

int main() {
    int N, M; cin >> N >> M;
    D.assign(N, INF);
    rep(i,M) {
        int L, R, D; cin >> L >> R >> D;
        L--, R--;
        Node.insert(L);
        Node.insert(R);
        G[L].push_back({R,D});
        G[R].push_back({L,-D});
    }
    
    for (auto x : Node) {
        if (D[x] != INF) continue;
        D[x] = 0;
        dfs(x, -1);
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 28224
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <set>

using namespace std;

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

	char op1, op2, op3;

	for (int i = 0; i < 8; i++) {
		int sum = S[0] - '0';
		if (i&(1 << 0))
			sum += S[1] - '0';
		else
			sum -= S[1] - '0';
		if (i&(1 << 1))
			sum += S[2] - '0';
		else
			sum -= S[2] - '0';
		if (i&(1 << 2))
			sum += S[3] - '0';
		else
			sum -= S[3] - '0';
		if (sum == 7) {
			if (i&(1 << 0))
				op1 = '+';
			else
				op1 = '-';
			if (i&(1 << 1))
				op2 = '+';
			else
				op2 = '-';
			if (i&(1 << 2))
				op3 = '+';
			else
				op3 = '-';
			break;
		}
	}
	cout << S[0] << op1 << S[1] << op2 << S[2] << op3 << S[3] << "=7" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool cmp(int a,int b)
{
    return a>b;
}
int s[1001],n,k1,k2;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    sort(s,s+n,cmp);
    for(int i=0;i<n;i++)
    {
        if(!(i%2))k1+=s[i];
        if(i%2)k2+=s[i];
    }
    cout<<k1-k2<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  long long x = 0;
  long long y = 0;
  long long ans = 0;
  rep (i, n) {
    long long j;
    cin >> j;
    y = x - j;
    if (y > 0) {
      ans += y;
    }
    x = max(j, x);
  }
  cout << ans << endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s, t;
	cin >> s;
	t = s;

	llong ans1 = 0, ans2 = 0;
	for (int i = 1; i < (int)s.size(); i++) {
		if (s[i] == s[i-1]) {
			ans1++;
			if (s[i] == '0')
				s[i] = '1';
			else
				s[i] = '0';
		}
	}

	for (int i = (int)t.size()-2; i >= 0; i--) {
		if (t[i] == t[i+1]) {
			ans2++;
			if (t[i] == '0')
				t[i] = '1';
			else
				t[i] = '0';
		}
	}

	cout << min(ans1, ans2) << endl;

	return 0;
}

Measured memory_bytes: 512
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("i8(i8,i8[:],i8[:])", cache=True)
def binary_search(K, A, F):
    """Meguru type binary search"""
    ng = -1
    ok = A[-1] * F[0]

    def is_ok(A, F, K, x):
        count = 0
        for a, f in zip(A, F):
            count += max(0, a - x // f)
        return count <= K

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(A, F, K, mid):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
    F = np.array(input().split(), dtype=np.int64)

    A.sort()
    F[::-1].sort()

    ans = binary_search(K, A, F)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 130568
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <cmath>
#include <cassert>
using namespace std;
typedef complex<double> P;

const int MAXN = 11;
const double eps = 1e-7;
const double inf = 1e100;
int N, M;
vector<P> Ds;
vector<double> V;
int num[MAXN];

bool equals(double a, double b) {
  return abs(a-b) < eps;
}

double getT(P p, P v, P d, double sp) {
  double a = v.real()*v.real() + v.imag()*v.imag() - sp*sp;
  double b = v.real()*(p.real()-d.real()) + v.imag()*(p.imag()-d.imag());
  double c = (p.real()-d.real())*(p.real()-d.real())
    + (p.imag()-d.imag())*(p.imag()-d.imag());
  double D = b*b - a*c;
  vector<double> t;
  if(equals(D, 0.0)) {
    assert(a != 0.0);
    t.push_back(-b/a);
  } else if(D > 0.0) {
    assert(a != 0.0);
    t.push_back((-b+sqrt(D))/a);
    t.push_back((-b-sqrt(D))/a);
  }
  double res = inf;
  for(int i = 0; i < t.size(); ++i) {
    if(t[i] < 0) continue;
    res = min(res, t[i]);
  }
  return res;;
}

void fly(P p, P v) {
  int getD = -1;
  double minT = inf;
  double t[MAXN];
  for(int i = 0; i < N; ++i) {
    t[i] = getT(p, v, Ds[i], V[i]);
    if(t[i] < minT) {
      getD = i;
      minT = t[i];
    }
  }
  ++num[getD];
  for(int i = 0; i < N; ++i) {
    if(t[i] == inf) continue;
    P endp = p + v*t[i];
    P base = endp - Ds[i];
    Ds[i] += base/abs(base)*V[i]*minT;
  }
}

int main() {
  while(cin >> N >> M && (N|M)) {
    Ds.resize(N);
    V.resize(N);
    for(int i = 0; i < N; ++i) {
      cin >> Ds[i].real() >> Ds[i].imag() >> V[i];
    }
    fill(num, num+MAXN, 0);
    while(M--) {
      P p, v;
      cin >> p.real() >> p.imag() >> v.real() >> v.imag();
      fly(p, v);
    }
    for(int i = 0; i < N; ++i) {
      if(i) cout << " ";
      cout << num[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <utility>
#include <functional>

using namespace std;
using ll = long long;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

struct brade{
    int a;
    int b;
    int num;
    brade(int _a,int _b,int _n): a(_a),b(_b),num(_n){

    };
};

int main(){
    int n,h,a,b;
    int turn_cnt=0,dmg=0,turn_cnt2=0,dmg2=0;
    int ans1 = 0, ans2= 0;
    cin >> n >> h;
    vector<brade> brade_a,brade_b;
    rep(i,n){
        cin >> a >> b;
        brade_a.push_back({a,b,i});
        brade_b.push_back({a,b,i});
    }

    sort(brade_a.begin(),brade_a.end(),
    [](brade &one,brade &two){return one.a > two.a;});

    sort(brade_b.begin(),brade_b.end(),
    [](brade &one,brade &two){return one.b > two.b;});

    for(auto elem:brade_b){
        if(elem.num != brade_a[0].num){
            if(elem.b >= brade_a[0].a){
                turn_cnt++;
                turn_cnt2++;
                dmg += elem.b;
                dmg2+=elem.b;
                if(dmg >= h){
                    cout << turn_cnt << endl;
                    return 0;
                }
                if(dmg2 >= h){
                    cout << turn_cnt2 << endl;
                    return 0;
                }
            }else{
                break;
            }
        }else{
            turn_cnt2++;
            dmg2 += elem.b;
            if(dmg2 >= h){
                cout << turn_cnt2 << endl;
                return 0;
            }
        }
    }

    turn_cnt++;
    int tmp = h - dmg - brade_a[0].b;
    
    if(tmp > 0){
        if(tmp % brade_a[0].a != 0)turn_cnt++;
        tmp /= brade_a[0].a;
    }else{
        tmp = 0;
    }
    cout << tmp + turn_cnt << endl;

    return 0;
}

Measured memory_bytes: 2868
#include <iostream>
#include <complex>
#include <cstdio>
#include <vector>
#include <utility>
#define X real()
#define Y imag()
#define EPS (1e-10)
#define INF (1e10)
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b-a) + EPS < abs(c-a) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  if(abs(a.first-b.first) < EPS ||
     abs(a.first-b.second) < EPS ||
     abs(a.second-b.first) < EPS ||
     abs(a.second-b.second) < EPS) return true;
  if(ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) <= 0 &&
     ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) <= 0) return true;
  return false;
}

P n_vector(P a){
  //a????????????????????´?????????????????????
  double l = abs(a);
  return P(-a.Y,a.X)/l;
}

L cpcc(C a, C b){
  //?????¨????????????
  double d = abs(a.first-b.first), ra = a.second, rb = b.second;
  double t = (ra*ra-rb*rb+d*d)/2/d, h = sqrt(ra*ra-t*t);
  P m = t/abs(b.first-a.first)*(b.first-a.first)+a.first;
  L cp;
  P n = n_vector(a.first-b.first);
  cp = L(m-n*h, m+n*h);
  return cp;
}

int main(){
  int n;
  while(cin >> n, n){
    double x, y, r;
    vector<C> Cs;
    vector<L> cps;
    vector<P> points;
    for(int i = 0; i < n; ++i){
      cin >> x >> y >> r;
      Cs.push_back(make_pair(P(x,y),r));
    }
    points.push_back(Cs[0].first);
    for(int i = 1; i < n; ++i){
      L cp = cpcc(Cs[i],Cs[i-1]);
      cps.push_back(cp);
      points.push_back(cp.first);
      points.push_back(cp.second);
    }
    points.push_back(Cs[n-1].first);
    vector< vector<double> > dist(2*n,vector<double>(2*n,INF));
    for(int i = 0; i < 2*n; ++i){
      for(int j = i; j < 2*n; ++j){
	if(i == j){
	  dist[i][j] = 0;
	  continue;
	}
	int s = min(max(0,i-1)/2,n-2), e = min(max(0,j-1)/2,n-2);
	//int s = (i-1)/2, e = (j-1)/2;
	bool f = true;
	for(int k = s; k <= e; ++k){
	  if(!is_cross(L(points[i],points[j]), cps[k])){
	    //cout << points[i] << points[j] << cps[k].first << cps[k].second << endl;
	    f = false;
	    break;
	  }
	}
	if(f){
	  dist[i][j] = abs(points[i]-points[j]);
	  dist[j][i] = abs(points[i]-points[j]);
	}
      }
    }
    /*
    for(int i = 0; i < 2*n; ++i)
      for(int j = 0; j < 2*n; ++j)
	cout << dist[i][j] << endl;
    */
    

    for(int k = 0; k < 2*n; ++k)
      for(int i = 0; i < 2*n; ++i)
	for(int j = 0; j < 2*n; ++j)
	  dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);

    printf("%.10f\n", dist[0][2*n-1]);
  }
  return 0;
}

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


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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = pi * r * r;
        double length = 2 * pi * r;
        System.out.printf("%f %f",area,length);
        sc.close();
    }
}


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

const double pi = acos(-1);

int main() {
    double a, b, x; cin >> a >> b >> x;
    if (2*x > a*a*b){
        double h = (2.0*(a*a*b - x)) / (a*a);
        //cout << h << endl;
        double rad = atan2(h, a);
        double ans = (rad*180.0) / acos(-1);
        printf("%.10f\n", ans);
    } else {
        double d = (2.0*x) / (a*b);
        //cout << d << endl;
        double rad = atan2(b, d);
        double ans = (rad / pi) * 180.0;
        printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){


int a,b,c,i;


int count;


scanf("%d %d %d\n",&a,&b,&c);


for(i=a,count=0;i<=b;i++){


if(c%i==0)count++;


}


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


return 0;


}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
    ll n;cin >> n;
    ll ans = n*(n-1)/2;
    cout << ans << endl;
}



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

int main() {
    int64_t a;
    cin >> a;
    int x=0;
    for(int i = sqrt(a); ; i--){
        if(a%i==0) {
            x=a/i;
            break;
        }
    }
    int cnt=0;
    while (x>0)
    {
        x/=10;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())
 
size = 1010000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))
 
ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)

Measured memory_bytes: 82932
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+7
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define max3(x, y, z) max(x, max(y, z))
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef pair<char, pair<int, int>> pcii;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;


int main() {
    int n, x;
    cin >> n >> x;
    cout << ((500*n) >= x ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a, b, c, d, x, y, z;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    x=a/d;
    if(a%d!=0) x+=1;
    y=c/b;
    if(c%b!=0) y+=1;
    if(x==y) printf("Yes\n");
    else if(x>y) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
int main(void)
{
	int n;
	int cnt;
	scanf("%d",&n);
	while(n!=0){
		cnt=0;
		while(n!=1){
			if(n%2==0){
				n=n/2;
				cnt++;
			}
			else{
				n=3*n+1;
				cnt++;
			}
		}
		printf("%d\n",cnt);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int input[3][3];

bool okay(int a,int b,int c, int d){
	if((a+c) == input[1][1] and (a+d) == input[1][2] and (b+c) == input[2][1] and (b+d) == input[2][2]){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	IOS;
	int a1,a2,a3,b1,b2,b3;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>input[i][j];
		}
	}
	bool flag=false;
	for(int i=0;i<=100;i++){
		a1=i;
		b1=input[0][0]-a1;
		b2=input[0][1]-a1;
		b3=input[0][2]-a1;
		a2=input[1][0]-b1;
		a3=input[2][0]-b1;
		if(okay(a2,a3,b2,b3)){
			flag=true;
			break;
		}
	}
	
	if(flag){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=5e5+5,M=2e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,m,bin[30]={1};
int head[N],cnt,lg[N];
struct edge{int t,ne;}e[N];
void adde(int a,int b){e[++cnt]=(edge){b,head[a]};head[a]=cnt;}
#define pw(a) (1<<(a))
int gao(int x,int f){
	int S=0,K=0,P=0,res=0;
	run(x)if(v!=f){
		K=gao(v,x);
		S|=K&P;
		P|=K;
	}
	res=(P|(pw(lg[S]+1)-1))+1;
	return res;
}
int main(){
	read(n);
	re(i,1,n){int a,b;read(a,b);adde(a,b);adde(b,a);}
	lg[0]=-1;rep(i,1,1<<17)lg[i]=lg[i>>1]+1;
	cout<<lg[gao(1,0)];
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

Int s[20];

string to_str(Int x) {
    string s = "";
    while (x > 0) {
        char a = '0' + (x % 10);
        s = a + s;
        x /= 10;
    }
    return s;
}

Int f(Int x) {
    Int ret = 0;
    string t = to_str(x);
    Int l = t.length();
    ret += s[l - 1];
    Int p = 1;
    while (p * 10 - 1 < x) {
        p *= 10;
    }
    x -= (p - 1);
    Int div3 = x / 3;
    Int div5 = x / 5;
    if (p > 1 and x % 5 >= 1) {
        div5++;
    }
    Int div15 = x / 15;
    if (p > 1 and x % 15 >= 6) {
        div15++;
    }
    ret += l * x - l * (div3 + div5 - div15) + 4 * (div3 + div5);
    return ret;
}

int main() {
    Int n;
    cin >> n;
    Int x = 9;
    for (Int i = 1; i <= 18; i++, x *= 10) {
        s[i] = i * x - i * (x / 3 + x / 5 - x / 15) + 4 * (x / 3 + x / 5);
    }
    for (Int i = 1; i < 18; i++) {
        s[i + 1] += s[i];
    }
    Int ok = 1;
    Int ng = 1e18 + 1;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        if (f(mid) <= n) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    string res = "";
    for (Int i = ok; i < ok + 30; i++) {
        if (i % 3 == 0) {
            res += "Fizz";
        }
        if (i % 5 == 0) {
            res += "Buzz";
        }
        if (i % 3 != 0 and i % 5 != 0) {
            res += to_str(i);
        }
    }
    // dump(res);
    // dump(f(ok));
    // dump(ok);
    string u = to_str(ok);
    Int cur = f(ok);
    Int ptr = 0;
    if (ok % 3 == 0 and ok % 5 == 0) {
        ptr = 7;
    }
    else if (ok % 3 == 0) {
        ptr = 3;
    }
    else if (ok % 5 == 0) {
        ptr = 3;
    }
    else {
        ptr = (Int)u.length() - 1;
    }
    while (cur < n) {
        cur++;
        ptr++;
    }
    for (int i = ptr; i < ptr + 20; i++) {
        cout << res[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3212
"use strict";
const main = arg => {
  let Nums = arg.split(" ").map(x=>x*1);
  let K = Nums[0];
  let X = Nums[1];
  let word ="";
  for(let i = X - K + 1; i < X + K; i++){
  	word = word + i + " ";
  }
  console.log(word);
}

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


Measured memory_bytes: 7372
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[] a = new long[n];
		
		for(int i = 0; i < n; i++) a[i] = sc.nextLong();
		
		int mincnt = 0;
		
		for(int i = 0; i < n; i++) {
			if(a[i] < 0) {
				mincnt++;
			}
		}
		
		long sum = Arrays.stream(a).map(Math::abs).sum();
		
		if(mincnt%2!=0) {
			long min = Arrays.stream(a).map(Math::abs).min().getAsLong();
			
			sum-=min*2;
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 59068
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
const ll MOD = 1e9+7;

int main()
{
	ll p = 0,q = 0,r = 0;
	int N;
	cin >> N;
	ll ans = 1;
	rep(i,N)
	{
		int A;
		cin >> A;
		bool flag = false;
		ll mul = 0;
		if (p == A)
		{
			if (!flag) p++;
			flag = true;
			mul++;
		}

		if (q == A)
		{
			if (!flag) q++;
			flag = true;
			mul++;
		}

		if (r == A)
		{
			if (!flag) r++;
			flag = true;
			mul++;
		}

		ans = ans * mul % MOD;
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,k,sum=0;
  cin >> n >> k;
  vector<ll> p(n);
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  sort(p.begin(),p.end());
  for(int i=0;i<k;i++){
    sum += p[i];
  }
  cout << sum << endl;
}


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

main()
{
    char w1[200200],w2[200200];
    scanf("%s %s",w1,w2);
    int ans=0;
    for(int i=0;w1[i];i++)
    {
        if(w1[i]!=w2[i])
            ans++;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 4112
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

// AtCoder Grand Contest 037
int main(){

    int N, K; cin >> N >> K;
    chmin(K, 15);

    string S; cin >> S; S += S;
    reverse(S.begin() + N, S.end());

    char need = 'z';
    rep(i, N)chmin(need, S[i]);

    string ans;
    rep(i, N)ans += 'z';

    function<void(string)> calc = [&](string s){
        reverse(all(s));
        int cnt = 0;
        rep(i, N){
            if(s[i] == need)cnt++;
            else break;
        }
        if(cnt == 0)return;
        if(((long long)cnt << (K - 1)) >= N){
            chmin(ans, string(N, need));
            return;
        } else {
            int sz = cnt << (K - 1);
            string tmp(sz, need);
            tmp += s.substr(cnt, N - sz);
            chmin(ans, tmp);
        }
    };

    rep(i, N + 1){
        string T = S.substr(i, N);
        calc(T);
    }

    cout << ans << endl;
    return 0;

}

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

int main() {
	int a, b;
	char x;
	while (1) {
		cin >> a >> x >> b;
		if (x == '?')break;
		if (x == '+')cout << a + b << endl;
		if (x == '-')cout << a - b << endl;
		if (x == '*')cout << a * b << endl;
		if (x == '/')cout << a / b << endl;
	}

}


Measured memory_bytes: 3112
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Console.WriteLine(
            n[0] <= n[2] && n[2] <= n[1] ?
            "Yes" : "No");
    }
}


Measured memory_bytes: 13268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 087
	// https://atcoder.jp/contests/abc087/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println((x - a) % b);
	}
	
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	int num[N] = {};
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == 'A'&&S[i + 1] == 'C') num[i + 1]++;
		num[i + 1] += num[i];
	}
	for (int i = 0; i < Q; i++) {
		int l, r;cin>>l>>r;
		cout << num[r-1] - num[l-1] << endl;
	}
}

Measured memory_bytes: 1408