akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
#define MAX 100010
#define NIL -1

struct Node {
    int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].p == NIL)
        cout << "root, ";
    else if (T[u].l == NIL)
        cout << "leaf, ";
    else
        cout << "internal node, ";

    cout << "[";

    for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

// 再帰的に深さを求める
void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) rec(T[u].r, p);  // 右の兄弟に同じ深さを設定
    if (T[u].l != NIL) rec(T[u].l, p + 1);  // 最も左の子に 自分の深さ+1 を設定
}

int main() {
    cin >> n;
    // 初期化
    for (int i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    int v, d, c, l, r;
    for (int i = 0; i < n; i++) {
        cin >> v >> d;
        for (int j = 0; j < d; j++) {
            cin >> c;
            if (j == 0)
                T[v].l = c;
            else
                T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }

    for (int i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
    rec(r, 0);

    for (int i = 0; i < n; i++) print(i);
}


Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{   
    int a,b; cin >> a >> b;
    cout <<(b%a==0?a+b:b-a) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <set>
using namespace std;
const int N=0;
const int E=1;
const int S=2;
const int W=3;
const int Z=4;
int rs[5][4]={{0,1,5,4},{0,3,5,2},{0,4,5,1},{0,2,5,3},{3,1,2,4}};
struct xai{
int ds[6];
void round(int n){
   int t=ds[rs[n][0]];
   for(int i=0;i<3;i++){
       ds[rs[n][i]]=ds[rs[n][i+1]];
   }
   ds[rs[n][3]]=t;
}
xai rounds(int n){
   xai e;
   for(int i=0;i<6;i++)e.ds[i]=ds[i];
    
   if(0<n){
       e.round(S);
   }
   if(1<n){
       e.round(E);
   }
   if(2<n){
       e.round(E);
   }
   if(3<n){
       e.round(E);
   }
   if(4<n){
       e.round(S);
   }
   return e;
}
void roundZ(){
   int cs[4];
   std::vector<int> vec;
   for(int i=0;i<4;i++){
       vec.push_back(ds[rs[Z][i]]);
   }
   for(int i=0;i<4;i++){
       round(Z);
       std::vector<int> vec2;
       for(int i=0;i<4;i++){
           vec2.push_back(ds[rs[Z][i]]);
       }
       if(vec<vec2)vec=vec2;
   }
   for(int i=0;i<4;i++){
       ds[rs[Z][i]]=vec[i];
   }
}
bool eq(xai e){
   for(int i=0;i<6;i++){
       if(ds[i]!=e.ds[i])return false;
   }
   return true;
}
bool operator<(const xai& e)const{
for(int i=0;i<6;i++){
	if(ds[i]!=e.ds[i])return ds[i]<e.ds[i];
}
return false;
}
};
 
int main() {
   xai es[101],e2;
   int n;
   scanf("%d",&n);
   for(int i=0;i<n;i++){
       for(int j=0;j<6;j++){
           scanf("%d",&es[i].ds[j]);
       }
   }
   bool hit=false;
   std::set<xai> sets;
   for(int i=0;i<n;i++){
       int min=es[i].ds[0];
       int top=0;
       for(int j=0;j<6;j++){
       	e2=es[i].rounds(j);
       	if(min>e2.ds[0]){
       		min=e2.ds[0];
       		top=j;
       	}
       }
       e2=es[i].rounds(top);
       e2.roundZ();
       sets.insert(e2);
   }
   printf("%s\n",sets.size()==n?"Yes":"No");
   return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; string s; cin>>n>>s;
	int R,G,B;
	R=G=B=0;
	for(auto&i:s){
		if(i=='R')++R;
		else if(i=='G')++G;
		else if(i=='B')++B;
	}
	int64_t ans=(int64_t)R*G*B,eq=0;
	for(int i=1;i<=n/2;++i){
		for(int j=0;j<n-2*i;++j){
			if(s.at(j)!=s.at(j+i)&&s.at(j+i)!=s.at(j+2*i)&&s.at(j+2*i)!=s.at(j)){
				++eq;
			}
		}
	}
	cout<<ans-eq<<"\n"s;
}

Measured memory_bytes: 3676
package main

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

/*********************************************************************
*  配列input: 入力配列を格納。添字0の箱は使わない。						 *
*  配列counting: inputに対して、添字i以下の要素の累積個数を格納。			 *
*  配列sorted: ソート済み配列。添字0の箱は使わない。						 *
*  																	 *
*  inputの各要素を後ろから調べていく。対象の数字を添字とする時に指定される	 *
*  countingに格納されている数字cは、対象の数字以下の数字がいくつあるかを		 *
*  表しているから、対象の数字の入るべきは、sortedの添字1から数えてc番目の箱。	 *
**********************************************************************/

const MAX_VALUE = 10000

func solve(reader io.Reader) string {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	input, sorted := make([]int, n+1), make([]int, n+1)
	counting := make([]int, MAX_VALUE+1)
	for i := 0; i < n; i++ {
		scanner.Scan()
		input[i+1], _ = strconv.Atoi(scanner.Text())
		counting[input[i+1]]++
	}
	countingSort(input, sorted, counting, n)
	return strings.Trim(fmt.Sprint(sorted[1:])[1:], "[]")
}

func countingSort(input, sorted, counting []int, n int) {
	for i := 1; i <= MAX_VALUE; i++ {
		counting[i] += counting[i-1]
	}
	for j := 1; j <= n; j++ {
		sorted[counting[input[j]]] = input[j]
		counting[input[j]]--
	}
}

func main() {
	fmt.Println(solve(os.Stdin))
}


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

using namespace std;
 
 main() {
   
 
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
 
    int dp[n][3]; 
 
    dp[0][0] = a[0]; 
    dp[0][1] = b[0]; 
    dp[0][2] = c[0]; 
 
    
    for (int i = 1; i < n; i++) { 
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]); 
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
 
  	
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); 
    
}

Measured memory_bytes: 5884
import sys

n, h = map(int, input().split())

max_a = 0
b = []
for i in range(n):
    x, y = map(int, input().split())
    max_a = max(max_a, x)
    b.append(y)

# 投げる価値がある刀を抜粋する
b = [x for x in b if x > max_a]

# 強い順に投げていく
b.sort(reverse=True)

i = 0
if len(b) > 0:
    for i, x in enumerate(b):
        i += 1
        h -= x
        if h <= 0:
            print(i)
            sys.exit()

# 投げ終わったら最強の刀で攻撃し続ける
print((h + max_a - 1) // max_a + i)

Measured memory_bytes: 13544
N = int(input())
# SP = sorted([list(input().split()) for _ in range(N)])
SP = {}
for i in range(N):
    city,score = input().split()
    if city in SP:
        SP[city].append([int(score),i])
    else:
        SP[city] = []
        SP[city].append([int(score),i])
# print(SP)


for city in sorted(SP.keys()):

    score = sorted(SP[city], reverse=True)
    for s in score:
        print(s[1]+1)


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000


//// mod power
ll mod_pow(ll x,ll n,ll mod){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}


int n;
int a[111111];
int cnt[111111];

int main(){
	cin.sync_with_stdio(false);
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		cnt[a[i]]++;
	}
	if(n%2==1&&cnt[0]!=1){
		cout<<0<<endl;
		return 0;
	}
	repl(i,1,n){
		if(cnt[i]!=0&&cnt[i]!=2){
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<mod_pow(2,n/2,1e9+7)<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int BE(int b,int e){
    if(e==0){
        return 1;
    }else{
        int sum = BE(b,e/2);
        if(e%2==0){
            return (sum*sum)%MOD;
        }else{
            return (((sum*sum)%MOD)*b)%MOD;
        }
    }
}

signed main(){
    int H,W,A,B;
    int Ans=0;
    cin >> H >> W >> A >> B;
    int fa[214514],fam[214514];
    fa[0]=1;
    REP(i,214513){
        fa[i+1]=(fa[i]*(i+1))%MOD;
    }
    REP(i,214514){
        fam[i]=BE(fa[i],MOD-2);
    }
    int x,y;
    for(int i=B;i<W;i++){
        x=(((fa[H-A+i-1]*fam[i])%MOD)*fam[H-A-1])%MOD;
        y=(((fa[A+W-i-2]*fam[W-i-1])%MOD)*fam[A-1])%MOD;
        Ans=(Ans+((x*y)%MOD))%MOD;
        //cout << x << " "<< y << " "<<x*y << endl;
    }
    cout << Ans << endl;
    return 0;
}   


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int nxt[100010];

int main(){
    ll n, x, m;
    cin >> n >> x >> m;
    ll a = x;
    rep(i, 100010) nxt[i] = -1;
    ll s, g;

    while(1){
        ll b = a * a % m;
        nxt[a] = b;
        if (nxt[b] != -1) {
            s = b;
            g = a;
            break;
        }
        a = b;
    }
    ll v = x;
    ll cnt_pre = 0;
    ll sum_pre = v;

    while(1){
        cnt_pre++;
        ll nv = nxt[v];
        if (nv == s) break;
        sum_pre += nv;
        v = nv;
    }

    ll cnt_loop = 1;
    v = s;
    ll sum_loop = v;
    while(1){
        cnt_loop++;
        ll nv = nxt[v];
        sum_loop += nv;
        if (nv == g) break;
        v = nv;
    }

    // cout << "s:" << s << " g:" << g << endl;
    // cout << "cnt_loop:" << cnt_loop << " cnt_pre:" << cnt_pre << endl;
    // cout << "sum_loop:" << sum_loop << " sum_pre:" << sum_pre << endl;

    ll ans = 0;
    v = x;
    if (n <= cnt_pre){
        while(n--){
            ans += v;
            v = nxt[v];
        }
        cout << ans << endl;
        return 0;
    }

    ll show = (n - cnt_pre) / cnt_loop;
    ll res = (n - cnt_pre) % cnt_loop;

    ans += sum_pre;
    ans += show * sum_loop;
    
    v = s;
    rep(i, res){
        ans += v;
        v = nxt[v];
    }

    cout << ans << endl;

    return 0;
}


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

int Func(int n) {
  int sum = 0;
  while(n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int total = 0;
  for(int i = 0; i <= N; i++) {
    int sum2 = Func(i);
    if(A <= sum2 && sum2 <= B) total += i;
  }
  
  cout << total << endl;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string s;
	cin >> s;
	map<char, int> M;
	for (auto a : s)
	{
		++M[a];
	}
	for (auto a : s)
	{
		if (M[a] % 2)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main() {
	int X, A;
	cin >> X >> A;
	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)
#define FE(i,n) for(int i = 0; i <= (n); i++)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const ll infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//

const int N = 3000;
vector<int> adj[N];
int a[N];
bool d[N];

void dfs(int u, int p = -1) {
	int m = inf; bool ex = false;
	for (auto &x : adj[u]) {
		if (x == p) continue;
		dfs(x, u);
		if (!d[x]) m = min(m, a[x]);
	}
	d[u] = (a[u] > m);
}

int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
#endif
	int n; ni(n);
	F(i, n)ni(a[i]);
	F(i, n - 1) {
		int u, v; nii(u, v); u--; v--;
		adj[u].push_back(v); adj[v].push_back(u);
	}

	F(i, n) {
		dfs(i);
		if (d[i])printf("%d ", i + 1);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 768
while 1:
    n,a,b,c,x=map(int,raw_input().split())
    if n==0:break
    reel=map(int,raw_input().split())
    roop,i=-1,0
    while i<n:
        roop+=1
        if roop>10000:
            roop=-1
            break
        if x==reel[i]:
            i+=1
        x=(a*x+b)%c
    print roop

Measured memory_bytes: 6208
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
    string S,T,U;
    int A,B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    map<string,int> m;
    m[S] = A;
    m[T] = B;
    m[U]--;
    cout << m[S] << " " << m[T] << endl;

    return 0;
}

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

int main()
{
  int n, m, sum = 0;
  vector<int> a;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
  {
    int t;
    cin >> t;
    a.push_back(t);
    sum += t;
  }
  sort(a.begin(), a.end(), greater<>());
  for (int i = 0; i < m; i++)
  {
    if (a[i] * 4 * m < sum)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
#define mod 1000000007

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n;
    cin>>n;
    map<ll,ll> mp;
    for(int i=2;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    for(int i=1;i<=n;i++) cout<<mp[i]<<endl;
    return 0;
}



Measured memory_bytes: 16112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
 

int main(){
	
	int n,a,b;cin>>n>>a>>b;
	int ans = 0;
	FOR(loop,1,n)
	{
		int num = loop;
		int cnt=0;
		while(num)
		{
			cnt +=num%10;
			num /=10;
		}
		if(a<=cnt and cnt <= b) ans+=loop;
	}
	cout << ans<< endl;
	
}

//cout << ans << endl;

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n : i64 = read();
    let v  = read_vec::<i64>();
    let sum = v.iter().fold(0,|y,x| y + x );
    let len = v.len() as i64;
    let ave = if sum % len == 0 {
        sum / len
    } else {
        (sum + sum % len ) / len
    };
    let ans = v.iter().map(|x| (x - ave) * (x - ave))
        .fold(0 , |y ,x | y + x );
    println!("{}",ans );

}

Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int r,D,x, ans;
	scanf("%d%d%d",&r,&D,&x);
	for(int i = 1;i <= 10;i++){
		x = r*x - D;
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;


int main(){
	int count1=0,count2=0;
	int sx[100],tx[100];
	string s,t;

	cin>>s>>t;
	for(int i=0;i<s.size();i++)
		sx[i]=s[i];
	for(int i=0;i<t.size();i++)
		tx[i]=t[i];
	sort(sx,sx+s.size());
	sort(tx,tx+t.size(),greater<>());
	for(int i=0;i<min(s.size(),t.size());i++){
		count1+=sx[i];
		count2+=tx[i];
//		cout<<"1,2="<<count1<<","<<count2<<endl;
		if(count1<count2){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(count1==count2&&s.size()<t.size()){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <map>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	int A = 0;
	int B = 0;
	rep(i, N)
	{
		int tmp;
		cin >> tmp;
		A += tmp;
		B += (tmp*tmp);
	}
	int ans = 100000000;
	for (int i = -100; i <=100; i++)
	{
		int x = N * i*i - 2 * A*i + B;
		ans = min(ans, x);
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  cin>>N;
  set<int> s;
  map<int,int> m;
  for(int i=0;i<N;i++){
    int L;
    cin>>L;
    m[L]++;
    s.insert(L);
  }
  vector<int> a;
  for(auto l:s){
    a.push_back(l);
  }
  sort(a.begin(),a.end());
  int n=a.size();
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(a[i]+a[j]>a[k]){
          ans+=m[a[i]]*m[a[j]]*m[a[k]];
        }
      }
    }
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
// #include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
// using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

typedef vector<int> vec;
typedef vector<vec> mat;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

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

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

long long d[301][301];
long long ans[301][301];

int main(void) {
    int N, M;
    long long L;
    cin >> N >> M >> L;
    long long inf = 1000000000000000;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            d[i][j] = inf;
            ans[i][j] = inf;
        }
        d[i][i] = 0;
        ans[i][i] = 0;
    }
    for (int i = 0; i < M; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        a--; b--;
        if (L < c) continue;
        d[a][b] = c;
        d[b][a] = c;
    }
    for (int k = 0; k < N; k++){
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][i] = d[j][j] = d[k][k] = 0;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        queue<int> q;
        for (int j = 0; j < N; j++) {
            if (d[i][j] <= L) ans[i][j] = 0;
            q.push(j);
        }
        while (!q.empty()) {
            int crt = q.front();
            q.pop();
            for (int j = 0; j < N; j++) {
                if (d[crt][j] <= L && ans[i][crt] + 1 < ans[i][j]) {
                    ans[i][j] = ans[i][crt] + 1;
                    q.push(j);
                }
            }
        }
    }
    
    int Q; cin >> Q;
    vector<long long> output(Q);
    for (int i = 0; i < Q; i++) {
        int s, t; cin >> s >> t;
        s--; t--;
        output[i] = ans[s][t];
    }
    for (int i = 0; i < Q; i++) {
        if (output[i] == inf) cout << -1 << endl;
        else cout << output[i] << endl;
    }
}

Measured memory_bytes: 2688
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin >> N;

    uint64_t T[100] = {0};
    for (int i=0; i < N; i++) {
        cin >> T[i];
    }

    uint64_t c = T[0];
    for (int i=1; i < N; i++) {
        c = c * (T[i] / __gcd(T[i], c));
    }

    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];

            var ahw = new List<string>();
            var igrow = new List<long>();
            var igcol = new List<long>();
            for (var i = 0; i < H; ++i)
            {
                var ah = ReadLine();
                if (ah.Contains('#'))
                    ahw.Add(ah);
            }
            for (var i = 0; i < W; ++i)
            {
                var ignore = true;
                for (var j = 0; j < ahw.Count(); ++j)
                {
                    if (ahw[j][i] == '#')
                    {
                        ignore = false;
                        break;
                    }
                }
                if (ignore)
                    igcol.Add(i);

            }
            foreach (var a in ahw)
            {
                for (var i = 0; i < W; ++i)
                {
                    if (!igcol.Contains(i))
                        Write(a[i]);
                }
                WriteLine();
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll sol(ll i,ll n,vector<ll> &v,vector<ll> &w,ll W,ll cw,vector<vector<ll> > &dp)
{
    if(cw>W)
    {
        return INT_MIN;
    }
    if(i==n)
    {
        return 0;
    }
    if(dp[i][cw]!=INT_MIN)
    {
        return dp[i][cw];
    }
    ll ans1=v[i]+sol(i+1,n,v,w,W,cw+w[i],dp);
    ll ans2=sol(i+1,n,v,w,W,cw,dp);
    return dp[i][cw]=max(ans1,ans2);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,W;
    cin>>n>>W;
    vector<ll> v(n);
    vector<ll> w(n);
    vector<vector<ll> > dp(n+1,vector<ll>(W+1,INT_MIN));
    for(ll i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    ll ans=sol(0,n,v,w,W,0,dp);
    cout<<ans;
    return 0;
}




Measured memory_bytes: 80256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	a, _ := strconv.Atoi(read())
	b, _ := strconv.Atoi(read())

	add := a + b
	sub := a - b
	mul := a * b

	ret := add
	if ret < sub {
		ret = sub
	}
	if ret < mul {
		ret = mul
	}

	fmt.Println(ret)
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <limits>
#include <iomanip>
using namespace std;
#define rad_to_deg(rad) (((rad)/2/3.1415926535)*360)

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

int main(){
    double a,b,x;
    cin >> a >> b >> x;
    double c=2*x/(a*a)-b;
    double ans;
    if(c>0){
        double d=b-c;
        ans=rad_to_deg(atan(d/a));
    }else{
        double e=2*x/a/b;
        ans=rad_to_deg(atan(b/e));        
    }
    std::cout<<std::fixed<<std::setprecision(10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
var print = console.log; // like python
var input_lines; // ?¨??????\????????????????????????????????????

function PreMain(input) {
    input_lines = input.split("\n");
    var f = function () {
        return input_lines.shift();
    };
    Main(f);
}

function IL(min1Flg) {
    var s = input_lines.shift().split(' ');
    var offset = min1Flg ? -1 : 0;
    var res = [];
    for (var i = 0; i < s.length; i++) {
        res.push(parseInt(s[i]));
    }
    return res;
}

/**
 * @return {number}
 */
Array.prototype.SUM = function SUM() {
    var sum = 0;
    this.forEach(function (elm) {
        sum += elm;
    });
    return sum;
};

/**
 * @return {string}
 */
Array.prototype.Format = function Format(split) {
    if (split === undefined) {
        split = " ";
    }
    return this.join(split);
};

Array.prototype.Copy = function Copy() {
    return [].concat(this);
};

/***
 * ??????Sort
 * <Array>.sort?????¨???(?????????)???????????????????????¨????????¨???
 * ??°????????????????????§?????°????????????????????????????????´??????????????????????????¨?????????
 * @constructor
 */
Array.prototype.Sort = function Sort() {
    this.sort(function (a, b) {
        if (a < b) return -1;
        if (a > b) return 1;
        return 0;
    });
    return this;
};

/*

(((???????????)??? ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

*/


function Main(input) {
    var dic = {};
    for (var i = 0; i < input_lines.length; i++) {
        var x = input_lines[i].split(' ');
        if (x.length <= 1) {
            continue;
        }

        if (x[0] in dic) {
            dic[x[0]].push(x[1]);
        } else {
            dic[x[0]] = [x[1]];
        }
    }
    var lst = [];
    for (var k in dic) {
        lst.push([k, dic[k].sort(function(a,b){return a-b;})]);
    }

    lst.sort();
    for (var i = 0; i < lst.length; i++) {
        print(lst[i][0]);
        print(lst[i][1].Format());
    }
}

 PreMain(require("fs").readFileSync("/dev/stdin", "utf8"));
//PreMain(require("fs").readFileSync("input.txt", "utf8"));

Measured memory_bytes: 16772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=b && c>=d){
        cout<<b+d<<endl;
    }
    else if(b>=a && d>=c){
        cout<<a+c<<endl;
    }
    else if(a>=b && c<=d){
        cout<<b+c<<endl;
    }
    else {
        cout<<a+d<<endl;
    }

    return 0;
}



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

using namespace std;


int main()
{
    int A,B,H,M;
    cin >> A >> B >> H >> M;

  


//    double time = round((H + M / 60.0) * 10000000000) / 10000000000;
    double time = H + M / 60.0;
    double h_time = 30.0 * time;
    double m_time = 360.0 * time;
    const double max_angle = 360.0;


    double h_angle = fmod(h_time,max_angle);
    double m_angle = fmod(m_time,max_angle);
    

    double angle = h_angle - m_angle;
    if(angle < 0){
        angle *= -1;
    }

    if(angle > 180){
        angle = 360 - angle;
    }

    double ans;

    //const double pi = 3.141592653589793;
    const double pi = acos(-1.0); 
    
    angle = angle / max_angle;
    angle = 2 * pi * angle;

    //ans = sqrt(A * A  + B * B - 2 * A * B * cos(angle));  変わらない
    ans = sqrt(pow(A,2)  + pow(B,2) - 2 * A * B * cos(angle));
    printf("%.32lf\n", ans); 

    //cout << ans << endl;

    return 0;
    

}

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

x = int(input())
if x <= 599:
    print(8)
elif x <= 799:
    print(7)
elif x <= 999:
    print(6)
elif x <= 1199:
    print(5)
elif x <= 1399:
    print(4)
elif x <= 1599:
    print(3)
elif x <= 1799:
    print(2)
else:
    print(1)

Measured memory_bytes: 9184
#include <iostream>
#include <vector>

static inline void swap(char *a,  char *b)
{
    char tmp0 = a[0];
    char tmp1 = a[1];
    char tmp2 = a[2];
    a[0] = b[0];
    a[1] = b[1];
    a[2] = b[2];
    b[0] = tmp0;
    b[1] = tmp1;
    b[2] = tmp2;
}

union input
{
    short s;
    char c[3];
};

int main(){
    int num;
    std::cin >> num;

    std::vector<union input> v1;
    std::vector<union input> v2;
    for(int i = 0; i < num; ++i){
        union input in;
        std::cin >> in.c;
        v1.push_back(in);
        v2.push_back(in);
    }

    for(int i = 0; i < num; ++i){
        int mini = i;
        for(int j = i + 1; j < num; ++j){
            if(v2[j].c[1] < v2[mini].c[1]){
                mini = j;
            }
            int k = num + i - j;
            if(v1[k].c[1] < v1[k-1].c[1]){
                swap(v1[k].c, v1[k-1].c);
            }
        }
        if(mini == i) continue;
        swap(v2[i].c, v2[mini].c);
    }
    for(int i = 0; i < num; ++i){
        std::cout << v1[i].c;
        if(i == num -1){
            std::cout << std::endl;
        } else {
            std::cout << ' ';
        }
    }
    std::cout << "Stable" << std::endl;

    bool isStable = true;
    for(int i = 0; i < num; ++i){
        std::cout << v2[i].c;
        if(i == num -1){
            std::cout << std::endl;
        } else {
            std::cout << ' ';
        }
        if(isStable && v2[i].c[0] != v1[i].c[0]){
            isStable = false;
        }
    }
    if(isStable){
        std::cout << "Stable" << std::endl;
    } else {
        std::cout << "Not stable" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3172
#include <iostream>
#include <stack>
#include <list>

using namespace std;


int main (int argc, char const* argv[]){
    stack<int> st;
    int n;
    int tmp;
    list<int> list1;
    
    while((cin >> n)){
        if(n == 0){ 
            list1.push_back(st.top());
            st.pop();
        }
        else st.push(n);
    }
    
    list<int>::iterator it = list1.begin();
    while(it != list1.end()){
        cout << *it << endl;
        it++;
    }
    
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string str, o, p, m, str2;
	int i, q, a, b, j, x, c;
	cin >> str >> q;
	for (i = 0; i<q; i++) {
		cin >> o;
		if (o == "print") {
			cin >> a >> b;
			for (j = a; j <= b; j++)
				cout << str[j];
			cout << endl;
		}
		else if (o == "reverse") {
			cin >> a >> b;
			reverse(str.begin()+a,str.begin()+b+1);
		}
        else if (o == "replace") {
			cin >> a >> b >> p;
			str.replace(a,b-a+1,p);
		}
	}
}

Measured memory_bytes: 1216
#include<iostream>
#define pb push_back
#define ll long long
#define mp std::make_pair
#include<cmath>

int main(){
int n,d;
 std::cin >> n >> d;
 int t=0;
 double x[n],y[n];
 for(int i=0;i<n;i++){
     std::cin >> x[i] >> y[i];
 }
 for(int i=0;i<n;i++){
    double res=(x[i]*x[i])+(y[i]*y[i]);
    if((sqrt(res))<=d)
        t++;
 }
 std::cout << t << std::endl;
 return 0;
}



Measured memory_bytes: 6960
#include <stdio.h>
int main(){
	int a, b, c, d, e;
	scanf("%d %d", &a, &b);
	c=a*b;
	d=a+b;
	e=a-b;
	if(c>d && c>e){
		printf("%d\n", c);
	}
	else if(d>c && d>e){
		printf("%d\n", d);
	}
	else if(e>c && e>d){
		printf("%d\n", e);
	}
	else if(d==c && e==c){
		printf("%d\n", c);
	}
	else if(d==c && d>e){
		printf("%d\n", d);
	}
	else if(e==d && e>c){
		printf("%d\n", e);
	}
	else if(e==c && c>d){
		printf("%d\n", c);
	}				
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
	int n,m,d,h,i,j,r,s;
	string str;
	for(;cin>>n,n;cout<<r<<endl){
		vector<int>monster(n);
		for(h=i=0;i<n;i++){
			cin>>monster[i];
			if(h<monster[i])h=monster[i];
		}
		vector<pair<int,int> >_all,_single;
		vector<int>all(h+1),single(h+1);
		for(cin>>i;i--;){
			cin>>str>>m>>str>>d;
			if(d){
				if(str[0]=='A')_all.push_back(make_pair(m,d));
				else _single.push_back(make_pair(m,d));
			}
		}
		for(i=1;i<=h;i++){
			all[i]=9999999;
			single[i]=9999999;
			for(j=0;j<_all.size();j++){
				all[i]=min(all[i],all[max(0,i-_all[j].second)]+_all[j].first);
			}
			for(j=0;j<_single.size();j++){
				single[i]=min(single[i],single[max(0,i-_single[j].second)]+_single[j].first);
			}
		}

		r=9999999;
		for(i=0;i<=h;i++){
			s=all[i];
			for(j=0;j<monster.size();j++)s+=single[max(0,monster[j]-i)];
			if(r>s)r=s;
		}
	}
}

Measured memory_bytes: 1948
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
double L,R,ans;
double p,e,t;
const double eps=1e-10;
void dfs(int k,double l,double r,double cur)
{
	if(k==0)
	{
		double mid=(l+r)/2;
		if(L-eps<mid&&mid<R+eps)
		{
		//cout <<k<<" "<<l<<" "<<r<<" mid:"<<mid<<" "<<l<<" "<<r<<" "<<cur<<endl;
			ans+=cur;
		}
	}
	else if(L-eps<l&&r<R+eps)
	{
		//cout <<k<<" "<<l<<" "<<r<<" "<<l<<" "<<r<<" "<<cur<<endl;
		ans+=cur;
	}
	else
	{
		double mid=(l+r)/2;
		if(L-eps<mid)
		{
			if(mid>t-eps)dfs(k-1,l,mid,cur*(1-p));
			else dfs(k-1,l,mid,cur*p);
		}
		if(R+eps>mid)
		{
			if(mid>t-eps)dfs(k-1,mid,r,cur*p);
			else dfs(k-1,mid,r,cur*(1-p));	
		}
	}
}
int main()
{
	int k,r,l;
	ans=0;
	scanf("%d%d%d",&k,&r,&l);
	scanf("%lf%lf%lf",&p,&e,&t);
	L=t-e;
	R=t+e;
	dfs(k,r,l,1);
	printf("%.9f\n",ans);
	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int ss(int m)
{
    int i;
    for(i=2;i<=sqrt(m);i++)
        if(m%i==0)
            return 0;
    return 1;
}
int main()
{
    int p,n,i;
    while(scanf("%d",&n)!=EOF)
    {
        p=0;
        for(i=2;i<=55555;i++)
        {
            if(ss(i)&&i%10==1&&p!=n)
            {
                cout<<i<<" ";
                p++;
            }
            if(p==n)
            {
                cout<<endl;
                break;
            }
        }
    }
    return 0;
}


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

int main()
{
    int N,L;
    cin >> N >> L;
    
    vector<string> s;
    
    for(int i = 0; i < N; ++i){
        string k;
        cin >> k;
        s.push_back(k);
    }
    
    sort(s.begin(),s.end());
    
    for(int i=0; i < N; ++i){
        cout << s.at(i);
    }
    cout << "" << endl;
    return 0;
}

Measured memory_bytes: 256
H,W = map(int,input().split())
A = [input() for i in range(H)]

tate = set(range(H))
yoko = set(range(W))

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            break
    else:
        tate.remove(i)

for i in range(W):
    for j in range(H):
        if A[j][i] == "#":
            break
    else:
        yoko.remove(i)

B=[[A[i][j] for i in tate] for j in yoko]
C=[""]*(len(list(tate)))

for i in range(len(list(tate))):
    for j in range(len(list(yoko))):
        C[i] += B[j][i]

for i in range(len(list(tate))):
    print(C[i])

Measured memory_bytes: 3188
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

double rnd(){
	const int INF=1e9;
	return (double)(rng()%INF)/INF;
}

int n;
ll c[26];
ll d[400][26];

void gen(){
	rep(x,0,26) c[x]=rng()%100;
	rep(x,0,n) rep(y,0,26) d[x][y]=rng()%20000;
}

ll calc(vector<int> &contest){
	ll last[26];
	
	memset(last,-1,sizeof(last));
	
	ll res=0;
	rep(x,0,n){
		res+=d[x][contest[x]];
		last[contest[x]]=x;
		
		rep(y,0,26) res-=c[y]*(x-last[y]);
	}
	
	return res;
}

//store curr best
ll best;
vector<int> ans;

ll test(double COOLING_RATE,double SCALE_FACTOR){
	vector<int> curr;
	rep(x,0,n){
		curr.push_back(0);
		
		rep(y,0,26) if (d[x][curr[x]]<d[x][y]) curr[x]=y;
	}
	
	ll val=calc(curr);
	
	best=val;
	ans=curr;
	
	double tempreture=1;
	
	auto begin_time=chrono::steady_clock::now().time_since_epoch().count();
	while (chrono::steady_clock::now().time_since_epoch().count()-begin_time<1950000000){
		int idx=rng()%n;
		int type=curr[idx];
		
		curr[idx]=rng()%26;
	
		ll temp=calc(curr);
		if (temp>val || rnd()<exp((temp-val)*SCALE_FACTOR/tempreture)){
			val=temp;
			
			if (best<val){
				best=val;
				ans=curr;
			}
		}
		else{
			curr[idx]=type;
		}
		
		tempreture*=COOLING_RATE;
	} 
	
	//pls uncomment later
	rep(x,0,n) cout<<ans[x]+1<<endl;
	
	return best;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	//freopen("sample2.in","r",stdin);
	
	cin>>n;
	rep(x,0,26) cin>>c[x];
	
	rep(x,0,n){
		rep(y,0,26) cin>>d[x][y];
	}
	
	test(0.99998,0.000005);
	return 0;
	
	for (double cool=0.99998;cool>=0.99997;cool-=0.000005){
		for (double scale=0.000001;scale<=0.00001;scale+=0.000001){
			ll curr=0;
			rep(x,0,20){
				gen();
				curr+=test(cool,scale);
			}
			
			cout<<cool<<" "<<scale<<" "<<curr<<endl;
		}
	}
}


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

int main(){
	int n,a;
	while(cin >> n && n){
		a = 0;
		while(n != 1){
			if(n % 2 == 1){
				n *= 3;
				++n;
			}
			else {
				n /= 2;
			}
			++a;
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  ll k,v1,v2;
  cin >> k;
  deque<pair<ll,ll>> v;
  v.push_back(make_pair(1,0));
  bool reached[100010]={0};
  while(!v.empty()){
    v1=v.front().first;v2=v.front().second;
    v.pop_front();
    if(v1==0){
      break;
    }
    reached[v1%k]=1;
    if(!reached[v1*10%k]){
      v.push_front(make_pair((v1*10)%k,v2));
    }
    if(!reached[(v1+1)%k]){
      v.push_back(make_pair((v1+1)%k,v2+1));
    }
  }
  cout << v2+1 << endl;
}

Measured memory_bytes: 1408
def main
  n = gets.to_i
  hash = { AC: 0, WA:0, TLE:0, RE:0 }
  n.times do
    s = gets.chomp.to_sym
    hash[s] += 1
  end
  puts "AC x #{hash[:AC]}"
  puts "WA x #{hash[:WA]}"
  puts "TLE x #{hash[:TLE]}"
  puts "RE x #{hash[:RE]}"
end

main



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

using namespace std;

int main()
{
    int a,b,c,temp=0;
    cin>>a>>b>>c;
    temp = a;
    a = b;
    b=temp;

    temp = a;
    a=c;
    c=temp;
    cout<<a<<" "<<b<<" "<<c;
}


Measured memory_bytes: 256
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll int

/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

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

// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1e9 + 7;
ll s[21][21],h,w;
vector<ll> mp(ll a,ll b,ll cnt) {
    vector<ll> tmp(3);
    tmp[0] = a;
    tmp[1] = b;
    tmp[2] = cnt;
    return tmp;
}
int bfs(ll hi, ll wi) {
    vector<vector<ll>> m;
	m.resize(21);
	for( int i=0; i < 21; i++ ){
		m[i].resize(21, -1);
	}
    ll cnt = 0;
    queue<vector<ll>> q;
    q.push(mp(hi,wi,0));
    while(!q.empty()) {
        vector<ll> p = q.front();
        q.pop();
        cnt = p[2];
        m[p[0]][p[1]] = cnt;
        ll x,y;
        
        x = p[0] - 1; y = p[1];
        if(x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1){
            m[x][y] = cnt + 1;
            q.push(mp(x, y, cnt + 1));  
        } 
        
        x = p[0] + 1; y = p[1];
        if(x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1){
            m[x][y] = cnt + 1;
            q.push(mp(x, y, cnt + 1));  
        } 
        
        x = p[0]; y = p[1] - 1;
        if(x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1){
            m[x][y] = cnt + 1;
            q.push(mp(x, y, cnt + 1));  
        } 
        
        x = p[0]; y = p[1] + 1;
        if(x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1){
            m[x][y] = cnt + 1;
            q.push(mp(x, y, cnt + 1));  
        } 
        
    }
    return cnt;
}
int main() {
    INIT();

    cin >> h >> w;
    REP(hi,h) {
        string row;
        cin >> row;
        REP(wi, w) {
            s[hi][wi] = row[wi] == '.' ? 0 : 1;
        }
    }
    ll ma = 0;
    REP(hi,h) {
        REP(wi, w) {
            if(s[hi][wi] == 0) {
                ll cost = bfs(hi, wi);
                chmax(ma, cost);
            }
        }
    }
    cout << fixed << ma;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))
d = dict()
c = 1
loop = False
k = 0
while(k<K):

    if not loop and str(c) in d:
        T = k-d[str(c)]
        #print ('K',k)
        a =  max((((K-k) // T)) - 1,0)
        #print(a)
        k += a*T
        #print ('K',k)
        loop = True
    d[str(c)] = k
    c = A[c]
    k+=1
print (c)

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

using namespace std;

int main(void)
{
	long long a,b,c; cin>>a>>b>>c;
	if(a+b >= c){
		cout<<"No"<<endl;
		return 0;
	}
	long long d = c - (a + b);
	if(4*a*b < d*d){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<map>  
#include<set>
#include<iterator>
#include<list>
#include<utility>
#include<cstdlib>
#include<queue>
#include<stack>
#include<bitset>
//#include<bits/stdc++.h>
#define PI  2*acos(0.0)
#define pb push_back

       
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;



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


ll m,n;
cin>>m>>n;
vector<string>v(m);
for(int i=0;i<m;i++)
{
	cin>>v[i];
}

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

/*while(!v.empty())
{
	cout<<*max_element(v.begin(),v.end())<<"\n";
	v.pop_back();
}
*/

for(int i=0;i<v.size();i++)
{
	cout<<v[i];
}






	
	
	return 0;
	
	
	       /***Israil Hosen
	            Computer Science & Engineering
	         University Of Rajshahi.
	         ***/
	
	
	
}

Measured memory_bytes: 3068
#include <stdio.h>

int main(void) {
	char str[1200];
	int i;
	
	gets(str);
	
	i = 0;
	while (str[i] != '\0') {
		if ('a' <= str[i] && str[i] <= 'z') putchar(str[i] - 'a' + 'A');
		else if ('A' <= str[i] && str[i] <= 'Z') putchar(str[i] - 'A' + 'a');
		else putchar(str[i]);
		
		i++;
	}
	puts("");
	
	return 0;
}

Measured memory_bytes: 524
#set
n = gets.chomp.to_i
hight_arr = gets.chomp.split(" ").map(&:to_i)
count = 0
zeros = 0

#main
loop do
  break if hight_arr.count(0) == n
  zeros_arr = hight_arr
  zeros = 1
  (n - 1).downto(1) do |i|
    zeros_arr.delete_at(i) if zeros_arr[i] == zeros_arr[i - 1]
    
  end
  zeros_arr.delete_at(0) if zeros_arr[0] == 0
  zeros_arr.delete_at(-1) if zeros_arr[-1] == 0
  zeros += zeros_arr.count(0)

  

  count += zeros
  hight_arr = hight_arr.map{|j| j - 1 if j != 0 }
  0.upto(n - 1) do |k|
    hight_arr[k] = 0 if hight_arr[k].nil?
  end
end

print ("#{count}\n")

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

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main() {
	string n;
	cin >> n;
	if ((n.at(0) == n.at(1) && n.at(1) == n.at(2)) || (n.at(3) == n.at(1) && n.at(1) == n.at(2))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	ll X, Y;
	cin >> X >> Y;
	cout << (abs(X-Y)>=2 ? "Alice" : "Brown") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

using namespace std;

int main() {
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
        return 0;
    }

    cout << R + 100 * (10 - N) << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

const ll MOD = 1e9+7;

map<pair<ll, ll> ,ll> ma;

ll func(ll S, ll X){
    pair<ll, ll> p = make_pair(S,X);
    if(ma.find(p) != ma.end()) return ma[p];
    if(S == 0) return 1;
    if(S == 1) return 2;
    ll ret = 0;
    ret += func(S/2, X/2) % MOD;
    ret += func((S-1)/2, (X-1)/2) % MOD;
    ret += func((S-2)/2, X/2) % MOD;
    ret %= MOD;
    ma[p] = ret;
    return ret;
}

int main(){
    ll N;
    cin >> N;
    ll ans = func(N, N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256