akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include<set>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll npk(ll n, ll k) {
	ll ret = 1;
	if (n < k || n < 0)return 0;
	rep(i, 0, k) {
		ret *= (n - i);
		ret %= MOD;
	}
	if (ret < 0) ret = 0;
	return ret;
}

//136C
int main(void) {
	map<string, ll> mp = map<string, ll>();
	ll n;
	cin >> n;
	rep(i, 0, n) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	ll ans = 0;
	auto iter = mp.begin();
	rep(i,0,mp.size()) {
		ll value = iter->second;
		ans += value * (value - (ll)1) / (ll)2;
		iter = next(iter, 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using Real = long double;

template<class T>
T sq(T x) { return x * x; }

constexpr Real EPS = 1e-10;
constexpr Real INF = 1e10;

int compare(Real X, Real Y) {
	return abs(X - Y) < EPS ? 0 : (X < Y ? -1 : 1);
}

struct Pos {
	Real x, y, z;
	Pos(Real x = 0, Real y = 0, Real z = 0) 
		: x(x), y(y), z(z) {}
};

Real norm(Pos X) {
	return sq(X.x) + sq(X.y) + sq(X.z);
}

Real dot(Pos X, Pos Y) {
	return X.x * Y.x + X.y * Y.y + X.z * Y.z;
}

Real calc(Pos X, Pos V, Real R, Real RV) {
	Real A = sq(RV) - norm(V);
	Real B = R * RV + dot(X, V);
	Real C = sq(R) - norm(X);

	assert(compare(C, 0) < 0);

	Real t;
	Real D = sq(B) - A * C;
	if (compare(A, 0) == 0) {
		if (compare(B, 0) == 0) {
			t = INF;
		} else {
			t = C / (B * 2);
		}
	} else if (compare(A, 0) > 0) {
		assert(compare(D, 0) > 0);
		t = (B + sqrtl(D)) / A;
	} else {
		if (compare(D, 0) < 0 || compare(B / A, 0) < 0) {
			t = INF;
		} else {
			t = (compare(A, 0) > 0) ? (B - sqrtl(D)) / A : (B + sqrtl(D)) / A;
		}
	}

	if (compare(t, 0) < 0) t = INF;
	return t;
}

bool solve() {
	int N;
	cin >> N;
	if (N == 0) return false;

	vector<Pos> X(N), V(N);
	vector<Real> R(N), RV(N);
	for(int i = 0; i < N; ++i) {
		cin >> X[i].x >> X[i].y >> X[i].z;
		cin >> V[i].x >> V[i].y >> V[i].z;
		cin >> R[i] >> RV[i];
	}

	vector<Real> ans(N);
	set<int> panished;
	while(panished.size() < N) {
		vector<Real> tmpans(N, INF);
		for(int i = 0; i < N; ++i) {
			if (panished.count(i)) continue;

			tmpans[i] = R[i] / RV[i];
			for(int j = 0; j < N; ++j) {
				if (i == j || panished.count(j)) continue;
				Pos DX, DV;
				DX.x = X[i].x - X[j].x;
				DX.y = X[i].y - X[j].y;
				DX.z = X[i].z - X[j].z;
				DV.x = V[i].x - V[j].x;
				DV.y = V[i].y - V[j].y;
				DV.z = V[i].z - V[j].z;
				Real SR, SRV;
				SR = R[i] + R[j];
				SRV = RV[i] + RV[j];
				Real t = calc(DX, DV, SR, SRV);
				if (compare(t, R[i] / RV[i]) > 0) t = INF;
				if (compare(t, R[j] / RV[j]) > 0) t = INF;
				// cerr << i << " " << j << ":" << t << endl;
				tmpans[i] = min(tmpans[i], t);
			}
		}
		// cerr << endl;
		Real mi = *min_element(tmpans.begin(), tmpans.end());
		for(int i = 0; i < N; ++i) {
			if (compare(mi, tmpans[i]) == 0) {
				ans[i] = mi;
				panished.insert(i);
			}
		}
	}

	for(auto t : ans) {
		cout << fixed << setprecision(10) << t << endl;
	}

	return true;
}

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


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n, k; ll x, y;
	cin >> n >> k;
	ll X[50], Y[50]; pair<ll, ll> sta[50];
	int i,j,a,b;
	for (i = 0; i < n; i++) {
		cin >> x >> y;
		X[i] = x; Y[i] = y; sta[i] = make_pair(x, y);
	}
	int count[51][51];
	for (i = 0; i < n+1; i++) {
		count[i][0] = 0; count[0][i] = 0;
	}
	sort(X, X + n); sort(Y, Y + n);
	for (i = 1; i < n+1; i++) {
		for (j = 1; j < n+1; j++) {
			count[i][j] = count[i - 1][j] + count[i][j - 1] - count[i - 1][j - 1];
			for (a = 0; a < n; a++) {
				if (sta[a].first == X[i-1] && sta[a].second == Y[j-1]) {
					count[i][j]++;
				}
			}
		}
	}
	ll mi = INF*4;
	for (i = 1; i < n+1; i++) {
		for (j = i + 1; j < n + 1; j++) {
			for (a = 1; a < n + 1; a++) {
				for (b = a + 1; b < n + 1; b++) {
					if (k <= count[j][b] - count[i - 1][b] - count[j][a - 1] + count[i - 1][a - 1]) {
						mi = min(mi, (X[j - 1] - X[i - 1])*(Y[b - 1] - Y[a - 1]));
					}
				}
			}
		}
	}
	cout << mi << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

ll a,b;
ll ans;
int main(){
	scanf("%lld%lld",&a,&b);
	if(a>b){
		ll t=a;
		a=b;
		b=t;
	}
	if(a==1){
		if(b==1)puts("1");
		else printf("%lld\n",b-2);
	}else{
		printf("%lld\n",(a-2)*(b-2));
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i = 0;i<n;i++)cin >> a[i];

	cout<<((n-1+k-1-1)/(k-1))<<endl;
}

Measured memory_bytes: 640
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e4+10,M=105,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

string n;
int d;
int x[N];
int sz;

int cache[N][M][2];

int dp(int idx, int rem, int less){
    if(idx==sz+1){
        return (rem==0);
    }
    int &ans=cache[idx][rem][less];
    if(ans!=-1) return ans;
    ans=0;
    if(!less){
        for(int i=0; i<=x[idx]; i++){
            ans+=dp(idx+1,(i+rem)%d,less|(i<x[idx]));
            ans%=mod;
        }
    }
    else{
        for(int i=0; i<=9; i++){
            ans+=dp(idx+1,(rem+i)%d,less);
            ans%=mod;
        }
    }
    return ans;
}

int f(string &s){
    sz=s.size();
    for(int i=0; i<sz; i++) x[i+1]=s[i]-'0';
    mst(cache,-1);
    return dp(1,0,0);
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cin >> d;
    int res=f(n);
    res-=1;
    res+=mod;
    res%=mod;
    cout << res;
    return 0;
}

Measured memory_bytes: 17408
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();

		int max;
		max = Math.max(a+b, a-b);
		max = Math.max(max, a*b);

		// 出力
		System.out.println(max);
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000

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

    ll n, mx = 0, ans = 0;
    cin >> n;
    rep(i, n){
        ll p;
        cin >> p;
        mx = max(mx, p);
        ans += p;
    }
    cout << ans - mx / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int a;
    cin>>a;
    if(a==0) cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3632
using namespace std;
#include <iostream>
int gcd(int l,int m){
    if (m==0) {
        return l;
    }
    return gcd(m, l%m);
}
int main() {
    // insert code here...
    int p,r;
    cin>>p>>r;
    cout<<gcd(p,r)<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;



int main(){
  string s,t;
  cin >> s >> t;
  ll a=s.size();
  ll ans=0;
  rep(i,a){
    if(s[i]!=t[i])ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3920
#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;
  int ans=0;
  int k[n];
  int y[n];
  rep(i,n)cin >> k[i];
  rep(i,n)cin >> y[i];
  rep(i,n){
    ans+=max(0,k[i]-y[i]);
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
    int N, M ,C;
    cin >> N >> M >> C;
    int B[M];
    int a;
    int sum;
    int count = 0;

    for (int i = 0; i < M; i++) cin >> B[i];

    for (int i = 0; i < N; i++)
    {
        sum = 0;
        for (int j = 0; j < M; j++)
        {
            cin >> a;
            sum += a * B[j];
        }
        if(sum > -C) count++;
    }        
    cout << count << "\n";
}


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

int main(){
    int x;
    cin >> x;
    int sum = 0;
    for(int i=1; i<= (int)1e6; i++){
        sum += i;
        if(sum >= x){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {

string S; cin >> S ;

int ans=1000;

for(int i=0;i<S.size()-2;i++){
  string T=S.substr(i,3);

  int X=atoi(T.c_str());

  ans=min(ans,abs(X-753));

}

cout << ans << endl;


return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FSelectHalf {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      ll dp[n+1][5][4];
      rep(i, n+1) rep(j, 5) rep(k, 4) {
        dp[i][j][k] = LLONG_MIN/2;
      }
      dp[0][2][1] = 0;
      for(int i=0; i<n; i++) {
        if (i%2==0) {
          // not take
          for(int j=0; j<5; j++) {
            for(int k=0; k<3; k++) {
              chmax(dp[i+1][j][k+1], dp[i][j][k]);
            }
          }
          // take
          for(int j=0; j<4; j++) {
            for(int k=1; k<4; k++) {
              chmax(dp[i+1][j+1][0], dp[i][j][k] + a[i]);
            }
          }
        } else {
          // not take
          for(int j=1; j<5; j++) {
            for(int k=0; k<3; k++) {
              chmax(dp[i+1][j-1][k+1], dp[i][j][k]);
            }
          }
          // take
          for(int j=0; j<5; j++) {
            for(int k=1; k<4; k++) {
              chmax(dp[i+1][j][0], dp[i][j][k] + a[i]);
            }
          }
        }
      }

      ll ans = LLONG_MIN;
      rep(k, 4) {
        chmax(ans, dp[n][2][k]);
      }

      cout << ans << endl;

    }
};

signed main() {
  FSelectHalf solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 35960
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {

	string O,E;

	cin >> O >> E;

	for (int i = 0; i < O.length(); i++) {
		cout << O[i];
		if((O.length()-1 == i) && (O.length() > E.length())){
             // NOP
		}else{
			cout << E[i];
        }
	}

	cout << endl;

	return 0;
}



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

int N;

int main(){
  cin >> N;

  int shou = 0;
  for(int i = N;N > 0; N--)
  {
    int res = 0;
    int n = N;
    while(n){
      if(n % 2 != 0) break;
      n /= 2;
      ++res;
    }
    
    if(shou < res) shou = res;
  }
  
  int seikai = 1;
  for(int i = 0;i < shou; i++){
  	seikai = seikai * 2;
  }
  cout << seikai << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
// greater<int>()
typedef long long ll;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }

using namespace std;
int main() {

	int n;
	string s;

	bool onazi = true;

	cin >> n >> s;

	int ans = 0;
	for (int i = 0; i < n - 1; i++)
	{
	/*	if (onazi) {*/
			if (s[i] == s[i + 1]) {
				onazi = true;
			}
			else {
				false;
				ans++;
			}
		//}

		
	}


	cout << ++ans << endl;
	



}


Measured memory_bytes: 512
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"
#include "map"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;

int main()
{
  bool check = true;
  int n, m;
  cin >> n >> m;
  int s[10], c[10];
  string st;
  for (int i = 0; i < n; i++)
  {
    st[i] = 'a';
  }
  if (n != 1)
  {
    for (int i = 0; i < m; i++)
    {
      cin >> s[i] >> c[i];
      s[i]--;
      if (s[i] == 0 && c[i] == 0)
      {
        check = false;
      }
      if ((st[s[i]] != 'a') && (st[s[i]] != c[i] + '0'))
      {
        check = false;
      }
      st[s[i]] = c[i] + '0';
    }

    if (!check)
    {
      cout << -1 << "\n";
    }
    else
    {
      if (st[0] == 'a')
      {
        cout << '1';
      }
      else
      {
        cout << st[0];
      }
      for (int i = 1; i < n; i++)
      {
        if (st[i] == 'a')
        {
          cout << 0;
        }
        else
        {
          cout << st[i];
        }
      }
      cout << "\n";
    }
  }
  else
  {
    for (int i = 0; i < m; i++)
    {
      cin >> s[i] >> c[i];
      if ((st[0] != 'a') && (st[0] != c[i] + '0'))
      {
        check = false;
      }
      st[0] = c[i] + '0';
    }
    if (!check)
    {
      cout << -1 << "\n";
    }
    else
    {
      if (m == 0)
      {
        cout << 0 << "\n";
      }
      else
      {
        cout << st[0] << "\n";
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    rep(i, h)
    {
        cin >> g[i];
    }
    rep(i, h)
    {
        rep(j, w)
        {
            if (g[i][j] == '#')
            {
                cout << "#";
            }
            else
            {
                int num = 0;
                rep(dx, -1, 2)
                {
                    rep(dy, -1, 2)
                    {
                        int cx = j + dx;
                        int cy = i + dy;
                        if (0 <= cx && cx < w && 0 <= cy && cy < h)
                        {
                            num += (g[cy][cx] == '#' ? 1 : 0);
                        }
                    }
                }
                cout << num;
            }
        }
        cout << 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);
		int A = sc.nextInt();
		int cnt = 1;
		for (int i = 0;;i++) {
			if(A == 4 || A == 2 || A == 1) {
				break;
			}
			if(A % 2 == 0) {
				A = A / 2;
				cnt = cnt + 1;
			}else {
				A = (A * 3) + 1;
				cnt = cnt + 1;
			}
		}
		cnt = cnt + 3;
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout.precision(10);
    int n;
    cin >> n;
    string s;
    cin >> s;
    bool sol = true;
    if(n & 1)
    {
        cout << "No\n";
        return 0;
    }
    for(int i = 0; i < n/2; i++)
    {
        if(s[i] != s[n/2 + i])
        sol = false;
    }
    if(sol)
    cout << "Yes\n";
    else
    cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long UCLN(long long a, long long b)
   {
   	if (b==0) return a;
   	return UCLN(b,a%b);
   }
int main()
{
  long long i,a,b,demc=0,demd=0,demboi=0,boi=0;
  long long c,d,uoc;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
  if (c<d) uoc = UCLN(c,d);
   else uoc = UCLN(d,c);
  boi=(c*d)/(double)uoc;
  demc=b/c-a/c;
  if (a%c==0) demc++;
  demd=b/d-a/d;
  if (a%d==0) demd++;
  demboi=b/boi-a/boi;
  if (a%boi==0) demboi++;
 // printf("%lld %lld %lld ", demc, demd, demboi);
  printf("%lld", (b-a+1)-(demc+demd-demboi));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
 
int run_test(){
      ll n, k;
      cin >> n >>k;
      int arr[n + 1];
      for(int i=1; i<n + 1; i++){
            cin >> arr[i];
      } 
      int visited[n + 1], index = 1, t;
      fill(visited, 0);
      vector<int> ans;
      ans.pb(1);
      visited[1] = 1;
      while(true){
            if(!visited[arr[index]]){
                  ans.pb(arr[index]);
                  visited[arr[index]] = 1;
                  index = arr[index];
            }
            else{
                  t = arr[index];
                  break;
            }
      }
      for(int i=0; i<ans.size(); i++){
            if(ans[i] == t){
                  t = i;
                  break;
            }
      }
      if(k <= t){
            cout << ans[k];
      }
      else{
            while(t--){
                  k--;
                  ans.erase(ans.begin());
            }
            cout << ans[(k) % ans.size()];
      }
      return 0;
}

int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

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

string input; 

bool checking(string s){
	for(int i=0; i<s.length(); i++){
		if(s[i]!=s[0])return true;
	}
	return false;
}

int main(){
	cin>>input;
	int minim=1e9; char nummax;
	for(int i=0; i<26; i++){
		string s=input;
		int total=0;
		char nummax=i+'a';
		while(checking(s)){
			total++;
			string t=""; bool fin=true;
			for(int i=0; i<s.length()-1; i++){
				if(s[i]!=nummax&&s[i+1]!=nummax){
					t+=s[i]; fin=false;
				}
				if(s[i]==nummax||s[i+1]==nummax)t+=nummax;
			}
			s=t; 
		}
		minim=min(total,minim);
	}
	cout<<minim<<'\n';
}

Measured memory_bytes: 3608
def primes(n,default=2):
    if n<3:return []
    sievebd=n//2-1
    sieve=[True]*sievebd
    limit=(int((n-1)**.5)-1)//2
    for i in range(limit):
        if sieve[i]:
            for j in range(2*i**2+6*i+3,sievebd,2*i+3):
                sieve[j]=False
    return [2]*(default==2)+[2*i+3 for i in range(default//2-1,sievebd) if sieve[i]]
P=primes(55555)
l=[]
n=int(input())
i=0
while len(l)<n:
    if P[i]%5==1:l.append(P[i])
    i+=1
print(*l)

Measured memory_bytes: 3444
#include<stdio.h>
#include<limits.h>

int main(void)
{
    int n;

    int max=INT_MIN;int min=INT_MAX;long long sum=0;int i;
    int temp=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
    	scanf("%d\n",&temp);
    	if(temp>max)max=temp;
    	if(temp<min)min=temp;
    	sum+=temp;
    }
    printf("%d %d %lld\n",min,max,sum);
return 0;
}


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

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll ans = 0;
  map<ll,ll> m;
  rep(i,n) {
    ans += m[i-a[i]];
    m[a[i]+i]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 27880
#include <stdio.h>

int pnum[1000000];
int psum[1000000];

int main(){
	int n;
	int i,j;
	for(i=0;i<1000000;i++){
		pnum[i]=1;
		psum[i]=0;
	}
	pnum[0]=0;pnum[1]=0;
	for(i=2;i*i<1000000;i++){
		if(pnum[i]!=0){
		for(j=i*i;j<1000000;j+=i){
			pnum[j]=0;
		}
		}
	}
	for(i=1;i<1000000;i++){
		psum[i] = psum[i-1] + pnum[i];
	}
	while(scanf("%d",&n)!=EOF){
		printf("%d\n",psum[n]);
	}
	return 0;
	}

Measured memory_bytes: 8404
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }
struct UnionFind{
    vector<int> par;
    vector<int> siz;
    int c;//親の個数(グループ数)
    void init(int n){
        c=n;
        for(int i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    UnionFind(int n){
        init(n);
    }
    int root(int x){
        //根を返す
        return(par[x]==x?x:(par[x]=root(par[x])));
    }
    bool sameParent(int x,int y){
        return(root(x)==root(y));
    }
    void unite(int x, int y){
        x=root(x);y=root(y);
        if(x==y)    return;
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];par[y]=x;c--;
    }
    int size(int x){
        return siz[root(x)];
    }
};
//一番上の親探るときはparじゃなくてroot使え

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

    int n,m;cin>>n>>m;
    int need=2*(n-m-1);
    if(need==0){
        cout<<0<<endl;
        return 0;
    }
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    UnionFind uf(n);
    rep(i,m){
        int x,y;cin>>x>>y;
        uf.unite(x,y);
    }
    vector<vector<ll>> g(n);
    rep(i,n){
        g[uf.root(i)].push_back(a[i]);
    }

    ll ans=0;
    priority_queue<ll,vector<ll>,greater<ll>> q;
    
    rep(i,n){
        if(g[i].empty()) continue;
        sort(ALL(g[i]));
        ans+=g[i][0];
        need--;
        for(int j=1;j<g[i].size();j++){
            q.push(g[i][j]);
        }
    }
    while(need>0 and !q.empty()){
        ans+=q.top();q.pop();
        need--;
    }
    if(need>0){
        cout<<"Impossible"<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 7284
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    if (u == s) {
        a--;
        cout << a << ' ' << b << endl;
    } else {
        b--;
        cout << a << ' ' << b << endl;
    }
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
 
using namespace std;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni(!=) cerr << boolalpha << i; ris; }
    eni(==) ris << range(begin(i), end(i)); }
    sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
    }
    sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
    }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
# define forn(i, n) for (ll i = 0; i < int(n); i++)
# define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
# define all(V) V.begin(), V.end()
# define rall(V) V.rbegin(), V.rend()
# define len(V) (int)V.size()
# define ll long long
# define ld long double
# define ff first
# define ss second
# define pb push_back
# define mp make_pair
# define endl '\n'
# define M_PI 3.14159265358979323846

void solve()
{
        int a, b; cin >> a >> b;
        int r = 0;
        int c = 1;
        while(c < b)
        {
                c += a;
                c--;
                r++;
        }
        cout << r;
}
 
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        solve();
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vvi edges(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }
    vi grundy(n, -1);
    function<int(int, int)> dfs = [&](int c, int p) {
        int child = 0;
        for (auto &v : edges[c]) {
            if (v == p)
                continue;
            else
                child ^= dfs(v, c);
        }
        return grundy[c] = child + 1;
    };
    dfs(0, -1);
    int gs = 0;
    for (auto &v : edges[0]) {
        gs ^= grundy[v];
    }
    if (gs == 0)
        cout << "Bob"
             << "\n";
    else
        cout << "Alice"
             << "\n";
    return 0;
}

Measured memory_bytes: 15488
#include<stdio.h>
int main(){
  int r,c,i,j,ans=0;
  scanf("%d %d",&r,&c);
  int a[r+1][c+1];
  for(i=0;i<=r;i++)
  a[i][c]=0;
  
  for(j=0;j<=c;j++)
  a[r][j]=0;
//初期化完了

  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
      scanf("%d",&a[i][j]);
    }
  }
  
  for(i=0;i<r;i++)
  {
    for(j=0;j<c;j++)
    {
      a[i][c]+=a[i][j];
      a[r][j]+=a[i][j];
      ans+=a[i][j];
    }
  }
  a[r][c]=ans;
  for(i=0;i<r+1;i++)
  {
    for(j=0;j<c+1;j++)
    {
      if(j==c)printf("%d\n",a[i][j]);
      else printf("%d ",a[i][j]);
    }
  }
  return 0;
}



Measured memory_bytes: 2032
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, m;
    std::cin >> n >> m;
    vec<std::string> a(n), b(m);
    for (auto&& s: a) std::cin >> s;
    for (auto&& s: b) std::cin >> s;

    for (usize si=0; si<=n-m; si++) for (usize sj=0; sj<=n-m; sj++) {
        bool ng = false;
        for (usize i=0; i<m; i++) for (usize j=0; j<m; j++) {
            if (a.at(si+i).at(sj+j)!=b.at(i).at(j)) {
                ng = true;
                break;
            }
        }
        if (!ng) {
            std::cout << "Yes" << '\n';
            return 0;
        }
    }
    std::cout << "No" << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	vector<int>V(5);
	rep(i, 5) {
		cin >> V[i];
	}
	int K;
	cin >> K;
	if (V[4] - V[0] > K) {
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
}

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

int a[110],b[110];

int main(void){
	int n,m;
	while(1){
		cin >> n >> m;
		if(n==0&&m==0) break;

		int asum=0,bsum=0;

		for(int i=0;i<n;++i) cin >> a[i];
		for(int i=0;i<m;++i) cin >> b[i];

		for(int i=0;i<n;++i) asum+=a[i];
		for(int i=0;i<m;++i) bsum+=b[i];

		int aidx=-1,bidx=-1;
		int cmin=100010;

		for(int i=0;i<n;++i){
			for(int j=0;j<m;++j){
				if(asum-a[i]+b[j]==bsum-b[j]+a[i]){
					int cur=a[i]+b[j];
					if(cur<cmin){
						cmin=cur;
						aidx=i,bidx=j;
					}
				}
			}
		}

		if(aidx==-1&&bidx==-1)
			cout << -1 << endl;
		else
			cout << a[aidx] << " " << b[bidx] << endl;
	}
	return 0;
}

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

#include <iomanip>
int main() {
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int>>> vs(n);
    for (int i = 0; i < m; i++) {
        int p, y; cin >> p >> y, p--;
        vs[p].emplace_back(y, i);
    }
    vector<pair<int, int>> res(m);
    for (int i = 0; i < n; i++) {
        sort(begin(vs[i]), end(vs[i]));
        for (int j = 0; j < (int)vs[i].size(); j++) {
            res[vs[i][j].second] = {i + 1, j + 1};
        }
    }
    for (auto &p: res) {
        cout << setfill('0') << setw(6) << p.first;
        cout << setfill('0') << setw(6) << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define oo 2000000000
const int N = 200010;
int main(){
	int n , m , k;
	cin >> n >> m >> k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if((i * m) + (j * n) - 2 * (i * j) == k){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
n=int(input())
arr=list(map(float,input().split()))
dp=[1]*(n+1)
dp[0]=(1-arr[0])
dp[1]=arr[0]
for i in range(1,n):
  for j in range(i+2):
    if j==0:
      dp[i+1-j]=dp[i-j]*arr[i]
    elif j==i+1:
      dp[i+1-j]=dp[i+1-j]*(1-arr[i])
    else:
      dp[i+1-j]=dp[i-j]*arr[i]+dp[i+1-j]*(1-arr[i])
ans=0
for i in range(int(n/2)+1,n+1):
  ans+=dp[i]
print(ans)

Measured memory_bytes: 43612
import sys
n, y = map(int, input().split())

for a in range(n + 1):
    for b in range(n - a + 1):
        c = n - a - b
        if 10000*a + 5000*b + 1000*c == y:
            print(a, b, c)
            sys.exit(0)
print(-1,-1,-1)

Measured memory_bytes: 3060
/*input
314159265 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=5e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main(){
    int n,k;
    cin>>n>>k;
    int cnt=0;
    while(n>0){
        ++cnt;
        n/=k;
    }
    cout<<cnt;
}

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

int main() {
    char S[4];
    cin >> S;
    sort(S, S + 4);
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
cnt = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

for _ in range(n):
  b, f, r, v = map(int, input().split())
  cnt[b-1][f-1][r-1] += v
  
for i in range(4):
    for j in range(3):
      print(' ' + ' '.join(map(str, cnt[i][j])))
    if i != 3:
      print('#'*20)


Measured memory_bytes: 5608
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let num: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    let mut adj = vec![Vec::new(); n];

    for _ in 0..n - 1 {
        let u = sc.ne::<usize>() - 1;
        let v = sc.ne::<usize>() - 1;
        // 自分より大きいのに動かしたら負け
        if num[u] > num[v] {
            adj[u].push(v);
        }
        if num[v] > num[u] {
            adj[v].push(u);
        }
    }
    fn dfs(cur: usize, adj: &Vec<Vec<usize>>) -> bool {
        let mut res = false;
        for &nxt in &adj[cur] {
            if dfs(nxt, &adj) == false {
                res = true;
            }
        }
        res
    }
    for i in 0..n {
        if dfs(i, &adj) {
            print!("{} ", i + 1);
        }
    }
    println!("");
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 764
using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int N;
    long[] x;
    long[] y;
    long[] r;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        double[,] d = new double[N+2,N+2];
        for(int i=0;i<N+2;i++){
            for(int j=0;j<N+2;j++){
                d[i,j] = Distance(i,j);
            }
        }
        Dijkstra D = new Dijkstra(d,N,N+2);
        sb.Append(D.GetCost(N+1)+"\n");

    }
    double Distance(int i,int j){
        return (x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]) > (r[i]+r[j])*(r[i]+r[j]) ? Math.Sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])) - (r[i]+r[j]) : 0;
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(Console.ReadLine());
        x = new long[N+2];
        y = new long[N+2];
        r = new long[N+2];
        x[N] = Int64.Parse(str[0]);
        x[N+1] = Int64.Parse(str[2]);
        y[N] = Int64.Parse(str[1]);
        y[N+1] = Int64.Parse(str[3]);
        r[N] = 0;
        r[N+1] = 0;
        for(int i=0;i<N;i++){
            str = Console.ReadLine().Split(' ');
            x[i] = Int64.Parse(str[0]);
            y[i] = Int64.Parse(str[1]);
            r[i] = Int64.Parse(str[2]);
        }
    }    
}
class Dijkstra{
	int N;
	int start;
	double[,] distance;
	double[] cost;
	public Dijkstra(double[,] d,int s,int n){
		N = n;
		distance = d;
		start = s;
		Calc();
	}
	void Calc(){
		bool[] finished = new bool[N];
		cost = new double[N];
		for(int i=0;i<N;i++){
			finished[i] = false;
			cost[i] = i == start ? 0 : -1;
		}
		while(true){
			int min = -1;
			for(int i=0;i<N;i++){
				if(!finished[i] && cost[i] != -1 && (min == -1 || cost[min] > cost[i])){
					min = i;
				}
			}
			if(min == -1){
				break;
			}
			finished[min] = true;
			for(int i=0;i<N;i++){
				if(!finished[i] && distance[min,i] != -1 && (cost[i] == -1 || cost[i] > cost[min] + distance[min,i])){
					cost[i] = cost[min] + distance[min,i];
				}
			}
		}
	}
	public double GetCost(int p){
		return cost[p];
	}
}

Measured memory_bytes: 11096
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

ll N, X, M;
int main() {
  cin >> N >> X >> M;
  vi a;
  vi id(M, -1);
  int len = 0;
  ll tot = 0;
  while (id[X] == -1) {
    a.pb(X);
    id[X] = len;
    len++;
    tot += X;
    X = (X * X) % M;
  }
  ll sum = 0;
  for (int i = id[X]; i < len; ++i) {
    sum += a[i];
  }
  int c = len - id[X];
  ll ans = 0;
  if (len < N) {
    ans += tot;
    N -= len;
    ans += sum * (N / c);
    N %= c;
    rep(i, N) ans += a[id[X] + i];
  } else {
    rep(i, N) ans += a[i];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3964
import math
n,d = map(int,input().split())
X = []
for j in range(n):
    X.append([int(i) for i in input().split()])
tmp,cnt = 0,0
for i in range(0,n):
    for k in range(i+1,n):
        for j in range(d):
            tmp += (abs(X[k][j]-X[i][j]))**2
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            cnt += 1
        tmp = 0
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <assert.h>

using namespace std;
typedef long long LL;
LL l,r,ans;

void print(LL w) {
	if (!w) cerr<<"0";
	else {
		print(w>>1);
		cerr<<(w&1);
	}
}
int main()
{
	#ifdef Amberframe
		freopen("agc015d.in","r",stdin);
		freopen("agc015d.out","w",stdout);
	#endif
	scanf("%lld %lld",&l,&r);
	if (l==r) {printf("1");return 0;}
	if (l+1==r) {printf("%d",2+((l|r)!=r));return 0;}
	int p=60;while ((r>>p)-(l>>p)<=0) --p;
	int q=p;while ((r>>q)-(l>>q)<=1) --q;
	if (q==p-1) {
		if ((r>>q)&1) {
			r|=(1ll<<q)-1;
			printf("%lld",r-l+1);
		}
		else {
			int t=q;while (t&&!((r>>t)&1)) --t;
			r|=(1ll<<t)-1;
			if ((r&((1ll<<p)-1))>=(l&((1ll<<p)-1))) {
				r|=(1ll<<p)-1;
				printf("%lld",r-l+1);
			}
			else {
				LL ans=r-l+1;
				ans+=(1ll<<p)-(l&((1ll<<p)-1));
				printf("%lld",ans);
			}
		}
	}
	else {
		int t=q;while (t&&!((r>>t)&1)) --t;
		r|=(1ll<<t)-1;
		LL ans=r-l+1;
		ans+=(1ll<<p)-(l&((1ll<<p)-1));
		printf("%lld",ans);
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from string import ascii_lowercase

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    ans = []
    while N:
        N, r = (N - 1) // 26, (N - 1) % 26
        ans.append(ascii_lowercase[r])

    print(''.join(reversed(ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9776
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int main(void) {
	int num, m, i, j, a, b, c, ans = 0;
	cin >> num >> m;
	vector<vector<int>> d(m, vector<int>(100001, 0));
	for (i = 0; i < num; i++) {
		scanf("%d%d%d", &a, &b, &c);
		d[c - 1][a]++;
		d[c - 1][b]--;
	}
	for (i = 0; i < m; i++) {
		for (j = 1; j < 100000; j++) {
			if (d[i][j] > 0) {
				d[i][j - 1] += 1;
				d[i][j] = 0;
			}
		}
	}
	for (a = 0, i = 0; i < d[0].size(); i++) {
		for(j = 0; j < m; j++)
			a += d[j][i];
		ans = max(ans, a);
	}
	cout << ans << "\n";
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  rep(i,N) cin >> P[i];
  int ans = 0;
  int curMin = 1e9;
  rep(i,N) {
    curMin = min(curMin, P[i]);
    if (curMin == P[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int A, B, A1;
    cin >> A >> B;
    A1 = 1;
    int cnt = 0;
    while (A1 < B) {
        A1 += (A - 1);
        cnt ++;
    }
    cout << cnt << endl;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  string o;
  for (size_t i = 0; i < s.size(); ++i) {
    if (s[i] == 'B' && 0 < o.size()) {
      o.pop_back();
    } else if (s[i] == '1' || s[i] == '0') {
      o.push_back(s[i]);
    }
  }
  cout << o << "\n";
}


Measured memory_bytes: 256