akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> va(a);
    vector<int> vb(b);
    vector<tuple<int, int, int>> vc(m);
    int a_min = 1e8;
    int b_min = 1e8;
    rep(i, a) {
        cin >> va[i];
        a_min = min(a_min, va[i]);
    }
    rep(i, b) {
        cin >> vb[i];
        b_min = min(b_min, vb[i]);
    }
    rep(i, m) {
        int tmp_x, tmp_y, tmp_c;
        cin >> tmp_x >> tmp_y >> tmp_c;
        --tmp_x, --tmp_y;
        vc[i] = make_tuple(tmp_c, tmp_x, tmp_y);
    }
    sort(vc.begin(), vc.end());
    reverse(vc.begin(), vc.end());
    int ans = 1e8;
    bool flg = false;

    rep(i, m) {
        if ( get<1>(vc[i]) >= a || get<2>(vc[i]) >= b ) continue;
        ans = min(ans, va[get<1>(vc[i])] + vb[get<2>(vc[i])] - get<0>(vc[i]));
        flg = true;
    }
    if ( !flg ) cout << a_min + b_min << endl;
    else        cout << min(ans, a_min + b_min ) << endl;
    return 0;
}

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


int main(){
    string s;cin>>s;
    
    rep(i,3){
        cout<<s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
using System;
using System.Linq;

namespace AtCoder2
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			var l = s.Length;
			var b = Enumerable.Repeat(1, l).ToList();

			for (int i = 0; i < l - 2; i++)
			{
				if (s[i] == 'R' && s[i + 1] == 'R')
				{
					b[i + 2] += b[i];
					b[i] = 0;
				}
			}

			for (int i = l - 1; i > 0; i--)
			{
				if (s[i] == 'L' && s[i - 1] == 'L')
				{
					b[i - 2] += b[i];
					b[i] = 0;
				}
			}

			Console.WriteLine(String.Join(' ', b));
		}
	}
}


Measured memory_bytes: 28316
#include<iostream>
#include<stdlib.h>
#include<math.h>
#define EPS (1e-10)
using namespace std;
struct Point{
  double x,y;
  Point(){};
  Point(double x,double y):x(x),y(y){}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
};
double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}
int main(){
  Point p[4];
  while(cin>>p[0].x>>p[0].y){
    int i,j,k;
    for(i=1;i<4;i++) cin>>p[i].x>>p[i].y;
    if(p[0].y>p[3].y||p[2].y>p[1].y||p[2].x>p[1].x||p[0].x>p[3].x)
      cout << "NO" << endl;
    else cout << "YES" << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N, A;
    cin >> N >> A;
    cout << N*N - A << "\n";
}


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

using namespace std;
typedef long long LL;

int main(){
  LL ans=0;
  LL dp[110][100010];
  int N, W;
  cin >> N >> W;
  int w[110];
  LL v[110];
  for(int i=0; i<N; i++) cin >> w[i] >> v[i];
  for(int i=0; i<=N; i++){
    for(int j=0; j<=W; j++) dp[i][j]=0;
  }
  for(int i=0; i<N; i++){
    for(int j=0; j<=W; j++){
      if(j>=w[i]) dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout << dp[N][W] << endl;
  
  return 0;
}

Measured memory_bytes: 81024
a,b = map(int,input().split())
ar = []
br = []
while a % 2 == 0:
    a /= 2
    ar.append(2)
f = 3
while a > 1:
    if(a % f == 0):
        a /= f
        ar.append(f)
    else:
        f += 2
while b % 2 == 0:
    b /= 2
    br.append(2)
f = 3
while b > 1:
    if(b % f == 0):
        b /= f
        br.append(f)
    else:
        f += 2

y = list(set(ar + br))
s = []
for i in y:
    s.append(i**max([ar.count(i),br.count(i)]))
p = 1
for i in s:
  p *= i
print(p)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        long[] A = new long[N];

        for (int i=0; i<N; i++) {
            A[i] = sc.nextLong();
        }

        System.out.println(solve(N, A));
    }

    private static long solve(int N, long[] A) {
        boolean contain0 = false;
        int minusCount = 0;
        long minAbs = Long.MAX_VALUE;
        long sum = 0;

        for (int i=0; i<N; i++) {
            sum += Math.abs(A[i]);

            if (A[i] == 0) contain0 = true;
            if (A[i] < 0) minusCount++;
            minAbs = Math.min(minAbs, Math.abs(A[i]));
        }

        if (!contain0 && minusCount%2 != 0) {
            sum -= minAbs*2;
        }

        return sum;
    }
}


Measured memory_bytes: 50664
n = int(input())
arr =[]
for _ in range(n):
    a,b=[int(c) for c in input().split()]
    if a == b:
        arr.append(1)
    else:
        arr.append(0)

arr.append(0)
arr.append(0)

for i in range(n):
    if arr[i]+arr[i+1]+arr[i+2] == 3:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 9196
#include <stdio.h>

int main(void)
{
    int a, b, c, d, n;
    int count;

    while (scanf("%d", &n) != EOF) {
        count = 0;
        for (a = 0; a < 10; a++)
            for (b = 0; b < 10; b++)
                for (c = 0; c < 10; c++)
                    for (d = 0; d < 10; d++)
                        if (a + b + c + d == n)
                            count++;
        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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 namespace std;

int N, A[16][16];
ll dp[1 << 16];
ll cst[1 << 16];
int main (){
    cin >> N;
    rep(i, N){
        rep(j, N){
            cin >> A[i][j];
        }
    }

    rep(msk, 1 << N){
        rep(i, N){
            REP(j, i+1, N){
                if (msk & (1 << i)) if (msk & (1 << j)) cst[msk] += A[i][j];
            }
        }
    }

    rep(msk, 1 << N){
        for (int msk2 = msk; msk2 > 0; msk2 = (msk2 - 1) & msk){
            ll nxt = dp[msk - msk2] + cst[msk2];
            chmax(dp[msk], nxt);
        }
    }

    cout << dp[(1 << N) - 1] << endl;
}


Measured memory_bytes: 1280
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

void Main() {
  int n, k, s; cin >> n >> k >> s;
  int o = s + 1;
  if(o > 1000000000) o = s - 1;
  for(int i = 0; i < k; i++) {
    cout << s << " ";
  }
  for(int i = 0; i < n - k; i++) {
    cout << o << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 1280
#include<stdio.h>
int main()
{
	int a, b;
	char op;
	while(scanf("%d %c %d", &a, &op, &b))
	{
		if(op =='?')
		{
			break;
		}
		switch(op)
		{
			case '+':
				printf("%d\n", a+b);
				break;
			case '-':
				printf("%d\n", a-b);
				break;
			case '*':
				printf("%d\n", a*b);
				break;
			case '/':
				printf("%d\n", a/b);
				break;
		}
	}
	return 0;
}


Measured memory_bytes: 2088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var n = int.Parse(ReadLine());
		var a = new long[n].Select(x => long.Parse(ReadLine())).ToArray();
		WriteLine(LCM(a));
	}

	public static long LCM(long a, long b)
	{
		return a / GCD(a, b) * b;
	}

	public static long LCM(params long[] a)
	{
		if(a.Length <= 0)
		{
			return -1;
		}
		var work = new long[a.Length];
		Copy(a, work, a.Length);
		for(long i = 1; i < a.Length; i++)
		{
			work[0] = LCM(work[0], work[i]);
		}
		return work[0];
	}

	public static long GCD(long a, long b)
	{
		if(a == 0 || b == 0)
		{
			return -1;
		}
		while(b != 0)
		{
			long temp = a % b;
			a = b;
			b = temp;
		}
		return Abs(a);
	}

}


Measured memory_bytes: 18808
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll>C(N-1);
    vector<ll>S(N-1);
    vector<ll>F(N-1);

    rep(i,N-1){
        cin>>C[i]>>S[i]>>F[i];
    }

    rep(i,N){
        ll t=0;
        rep3(j,i,N-1){
            if(t<S[j]){
                t=S[j];
            }else if(t%F[j]!=0){
                t += F[j]-t%F[j];
            }
            t+=C[j];
            
        }
        cout<<t<<endl;
    }



    return 0;
    

}

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

int m1, m2, d1, d2;

int main(){
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(d2 == 1){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}		

Measured memory_bytes: 256
// コンテスト後に自力AC
// コンテスト中に考えていた方針は正しかったが実装が間に合わず
//
// N人のゲストの組合せはN * N通り。

#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

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

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll N, M;
vector<ll> As;
vector<ll> sumA;

// 値がsum以上の組合せは何個あるか？
ll count_pair_num(ll sum) {
    ll ret = 0;
    for(auto a: As) {
        auto it = lower_bound(ALL(As), sum - a);
        ret += N - (it - As.begin());
    }
    return ret;
}

// 値がsum以上の組合せはpair_num個以上あるか？
bool check(ll sum, ll pair_num) {
    return count_pair_num(sum) >= pair_num;
}

// 値がsum以下の組合せの値の合計を求める
// 事前に累積和の計算が必要
ll count_sum(ll num) {
    ll ret = 0;
    // e.g.  a = 5
    // 例えばAs = [1 3 3 5 5 21 24 34 110], num = 26のとき
    // 26以上になる組合せは(5, 21), (5, 24), (5, 34), (5, 110)
    // 値の合計は、(5 * 4) + (21 + 24 + 34 + 110)
    // この第二項の計算には累積和を使う
    for(auto a: As) {
        auto it = lower_bound(ALL(As), num - a);
        if (it != As.end()) {
            auto tmp1 = sumA[it - As.begin()];
            auto tmp2 = (As.end() - it);
            ret += tmp1 + a * tmp2;
        }
    }
    return ret;
}

int main(void)
{
    cin.sync_with_stdio(false);

    cin >> N >> M;
    As.resize(N);
    REP(n, N) cin >> As[n];
    sort(ALL(As));

    // 累積和
    sumA.resize(N);
    REP(n, N) {
        if (n == 0) sumA[N - n - 1] = As[N - n - 1];
        else sumA[N - n - 1] = sumA[N - n] + As[N - n - 1];
    }

    // 「X以上の組合せの数」がM以上となる最大のXを二分探索で求める
    ll ok = 0;
    ll ng = As[N-1] * 2 + 1; // 最初 As[N-1] * 2 にしててエラー; 確実に境界をみつけるためには+1が必要
    while (ng - ok > 1) {
        auto mid = (ok + ng) / 2;
        if (check(mid, M)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    // 値がok以上の組合せの数を求める
    // この組合せの数はM以上である
    auto pair_num = count_pair_num(ok);

    // 値がok + 1以上の組合せの数を求める
    // この組合せの数は必ずMより小さいことが保証される
    auto pair_num2 = count_pair_num(ok + 1);

    // 値がok + 1以上の組合せの数の和を求める
    ll ans = count_sum(ok + 1);

    // この時点で、(M - pair_num2)個の組合せの分がまだansに反映されていない
    // この組合せは、すべて値がokであることが保証される
    ans += (M - pair_num2) * ok;

    cout << ans << endl;

    return 0;
}



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

using namespace std;

int n,k;
const int MOD=1e9+7,N=4e5+5;


long long poww(long long b,long long p)
{
	if(p==0) return 1;
	if(p&1) return (b*poww(b,p-1))%MOD;
	return poww((b*b)%MOD,p/2);
}

long long fac[N],infac[N];

long long nck(int n,int k)
{
	return (((fac[n]*infac[k])%MOD)*infac[n-k])%MOD;
}

int main()
{
	fac[0]=infac[0]=1;
	for(int i=1;i<N;i++)
	{
		fac[i]=(i*fac[i-1])%MOD;
		infac[i]=poww(fac[i],MOD-2);
	}
	cin >> n >> k;
	long long ans=1;
	for(int i=1;i<=min(n-1,k);i++)
	{
		// i zeros
		ans+=nck(n,i)*nck((n-i)+i-1,i);
		//cout << nck(n,i) << " " << nck((n-i)+i-1,i) << endl;
		ans%=MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6528
import java.util.*;
// cin=sc.nextInt();
// List<Integer> a = new ArrayList<Integer>(n);
 
public class Main {
    public static void main(String args[]){
		    Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            double b = a/1.08;
            int c = (int)b;
            int d = c+1;
            if((int)(c*1.08) == a){
                System.out.println(c);
            }
            else if((int)(d*1.08) == a){
                System.out.println(d);
            }
            else{
                System.out.println(":(");
            }
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  if(c>=a&&c<=b){
    print("Yes");
  }
  else{
    print("No");
  }
}

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

int main() {
  long long S; cin >> S;
  int x2 = 1000000000;
  int x3 = (x2 - S % x2) % x2;
  int y3 = (S + x3) / x2;
  cout << "0 0 1000000000 1 " << x3 << " " << y3 << endl;
}

Measured memory_bytes: 256
require 'prime'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
s=gs
q=gi
fl=0
pfix=[]
sfix=[]

q.times do
  inp=gets.chomp.split
  if inp[0]=="1"
    fl=(fl+1)%2
  else
    f=inp[1].to_i
    c=inp[2]
    if f==1
      if fl==0
        pfix.unshift c
      else
        sfix<<c
      end

    else
      if fl==0
        sfix<<c
      else
        pfix.unshift c
      end
    end
  end
end

if fl==0
  puts pfix.join<<s<<sfix.join
else
  puts sfix.join.reverse<<s.reverse<<pfix.join.reverse
end

Measured memory_bytes: 17020
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)


function main()
	n,p = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	k = 0
	for i in 1:n
		if a[i]%2 == 1
			k += 1
		end
	end
	if p == 0
		t = 0
		for i in 0:2:k
			t += binomial(k,i)
		end
		println(2^(n-k)*t)
	else
		t = 0
		for i in 1:2:k
			t += binomial(k,i)
		end
		println(2^(n-k)*t)
	end
end
 
main()

Measured memory_bytes: 112976
use std::collections::BinaryHeap;
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut m: usize = 1 << n;
    let mut a: Vec<i32> = sc.vec(m);
    a.sort();
    let mut s = vec![];
    s.push(a[m - 1]);
    a[m - 1] = -1;

    for _ in 0..n {
        let mut p = s.clone();
        p.sort();
        let mut ai = m - 1;
        while p.len() > 0 {
            if a[ai] == -1 {
                if ai == 0 {
                    break;
                }
                ai -= 1;
                continue;
            }

            if a[ai] < p[p.len() - 1] {
                s.push(a[ai]);
                p.pop().unwrap();
                a[ai] = -1;
            }
            if ai == 0 {
                break;
            }
            ai -= 1;
        }
        if p.len() > 0 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12668
N = int(input())
S = input()
sum = 0
for i in range(N):
  if S[i] == "R":
    sum += S[i+1:].count("G")*S[i+1:].count("B")
  elif S[i] == "G":
    sum += S[i+1:].count("R")*S[i+1:].count("B")
  elif S[i] == "B":
    sum += S[i+1:].count("G")*S[i+1:].count("R")
for a in range(N):
  for b in range(a+1, N):
    if S[a] == S[b] or 2*b-a >= N:
      pass
    elif S[b] != S[2*b-a] and S[2*b-a] != S[a]:
      sum -= 1
print(sum)

Measured memory_bytes: 68148
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

unsigned long long int X,Y;

int main(){
	cin>>X;
	Y=X/11;
	X=X%11;
	if(X==0){
		cout<<2*Y<<endl;
	}else if(X<=6){
		cout<<2*Y+1<<endl;
	}else{
		cout<<2*Y+2<<endl;
	}
}

Measured memory_bytes: 256
'use strict'
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var H=input;
  var ans=0;
  var max=H[0];
  for(let i=0;i<N;i++){
    if(H[i]>=max)
      ans++;
    max=Math.max(H[i],max);
  }
  console.log(ans);
}

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


Measured memory_bytes: 7372
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long Maxn=200000+10;
bool vis[Maxn];
long long a[Maxn];
long long n,k,tot,cnt;
int main()
{
//	freopen("in.txt","r",stdin);
	scanf("%lld%lld",&n,&k);
	for(long long i=1;i<=n;++i)
	scanf("%lld",&a[i]);
	long long x=1;
	while(!vis[x])
	vis[x]=1,x=a[x];
	memset(vis,0,sizeof(vis));
	while(!vis[x])
	vis[x]=1,++tot,x=a[x];
	long long pos=x;
	x=1;
	while(x!=pos)x=a[x],++cnt;
	x=1;
	if(k>cnt+1)k=(k-cnt)%tot,k+=cnt;
	while(k--)x=a[x];
	printf("%lld\n",x);
	return 0;
}

Measured memory_bytes: 5516
N, M  = map(int,input().split())
s = [-1]*M
c = [-1]*M
for i in range(M):
  s[i],c[i] = map(int,input().split())
if N==1 and M==0:
  print(0)
  exit()
if N==1 and s[0]==1 and c[0]==0:
  print(0)
  exit()
arr_ans = [-1]*(N+1)
for i in range(M):
  if arr_ans[s[i]] == -1 or arr_ans[s[i]] == c[i]:
    arr_ans[s[i]] = c[i]
  else:
    print(-1)
    exit()
    
if arr_ans[1] == 0:
  print(-1)
  exit()
for i in range(1,N+1):
  if arr_ans[i] == -1:
    if i == 1:
      arr_ans[i] = 1
    else:
      arr_ans[i] = 0

_ans = [str(arr_ans[i]) for i in range(N+1)]
ans = ''.join(_ans[1:])
print(ans)
  

Measured memory_bytes: 9256
a = $stdin.gets.chomp.to_i
b = $stdin.gets.chomp.to_i
c = $stdin.gets.chomp.to_i
d = $stdin.gets.chomp.to_i

if
  a <= b
  train = a
elsif
  b < a
  train = b
end

if
  c <= d
  bus = c
elsif
  d < c
  bus = d
end

x = train + bus
puts x

Measured memory_bytes: 1788
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let c: i64 = input();
    let d: i64 = input();
    let e: i64 = input();
    let f: i64 = input();

    let mut ans = (0, 0);
    for ia in 0.. {
        if 100 * a * ia > f {
            break;
        }

        for ib in 0.. {
            if 100 * a * ia + 100 * b * ib > f {
                break;
            }
            if ia == 0 && ib == 0 {
                continue;
            }

            for ic in 0.. {
                if 100 * a * ia + 100 * b * ib + c * ic > f {
                    break;
                }
                if c * ic > (a * ia + b * ib) * e {
                    break;
                }

                for id in 0.. {
                    if 100 * a * ia + 100 * b * ib + c * ic + d * id > f {
                        break;
                    }
                    if c * ic + d * id > (a * ia + b * ib) * e {
                        break;
                    }

                    let w = 100 * a * ia + 100 * b * ib;
                    let s = c * ic + d * id;

                    if ans.0 == 0 {
                        ans = (w + s, s);
                    } else {
                        if s * ans.0 > ans.1 * (w + s) {
                            ans = (w + s, s);
                        }
                    }
                }
            }
        }
    }

    println!("{} {}", ans.0, ans.1);
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  int L = A + B;
  int R = C + D;
  
  if (L < R) {
    cout << "Right" << endl;
  }
  else if (L > R) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((a / b) + " " + (a % b) + " " + String.format("%.8f", (double)(a) / b));
	}
}



Measured memory_bytes: 26504
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  int sum_ame = 0;

  rep(i, n){
    int ame;
    cin >> ame;
    a[i] = ame;
    sum_ame += ame;
  }

  int x[n];

  int sum_ame_even = 0;
  for(int i = 1; i < n; i += 2){
    sum_ame_even += a[i];
  }

  x[0] = sum_ame - 2 * sum_ame_even;

  for(int i = 1; i < n; ++i){
    x[i] = a[i - 1] * 2 - x[i - 1];
  }

  rep(i, n){
    cout << x[i] << " ";
  }
  cout << "\n";

  return 0;
}


Measured memory_bytes: 2176
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Hitachi String
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

char s[16];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  if (! (n & 1)) {
    bool ok = true;
    for (int i = 0; i < n; i += 2)
      if (s[i] != 'h' || s[i + 1] != 'i') {
	ok = false;
	break;
      }

    if (ok) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
  return 0;
}


Measured memory_bytes: 256
def split(word): 
    return [char for char in word]  

s=input()
t=input()
a = split(s)
b = split(t)
count=0
for i in range(len(a)):
	if a[i]==b[i]:
		count=count+1
if ((count==len(a)) and (len(b)==len(a)+1)):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
const int N = 1e5+5;
ll ans[N];
const ll mod = 1e9+7;
ll po(ll a, ll b){
    if(b==0)return 1;
    ll x = po(a,b/2);
    x = (x*x)%mod;
    if(b&1)x = (x*a)%mod;
    return x;
}
void solve(){
    int n,k;
    cin>>n>>k;
    ll ret = 0;
    for(ll i=k;i>=1;i--){
        ll trt = 0;
        ll cnt = 1;
        for(ll j=i+i;j<=k;j+=i){
            trt+=ans[j];
            cnt++;
        }
        ans[i] = po(cnt,n)-trt;
        ans[i]  = (ans[i]%mod+mod)%mod;
        ret+=i*ans[i];
        ret%=mod;
    }
    cout<<ret<<endl;

}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4352
"""
可変長データの読み込み
"""
t = []
x = []
y = []

t.append(0)
x.append(0)
y.append(0)

for i in (range(0, 1000000, 1)):
  try:
    c = input()
    if i == 0:
      N = int(c)
    else:
      t.append(int(c.split(" ")[0]))
      x.append(int(c.split(" ")[1]))
      y.append(int(c.split(" ")[2]))
  except:
    break

for i in range(0, len(t) - 1, 1):
  
  con1 = t[i + 1] >= (x[i + 1] + y[i + 1]) 
  dt = t[i+1] - t[i]
  dist = (x[i+1]-x[i]) + (y[i+1] - y[i]) 

  if con1 is True and (dt - dist) %2 == 0:
    ans = "Yes"
  else:
    ans = "No"
    break
    
print(ans)
  
  
    
  
  
  

Measured memory_bytes: 11844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())


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

    ll n,i;
    cin>>n;
    set<string> st;
    while(n--)
    {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<sz(st);
}

Measured memory_bytes: 19244
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int mod=1e9+7;
const int MAXN=1e6+10;

char str[MAXN];
int cnt[26];
int main() {
	int N; 
	while(~scanf("%d%s",&N,str)) {
		memset(cnt,0,sizeof(cnt));
		for(int i=0;i<N;++i) {
			cnt[str[i]-'a']++;
		}
		LL ans=1;
		for(int i=0;i<26;++i) {
			ans=ans*(cnt[i]+1)%mod; 
		}
		ans=((ans-1)%mod+mod)%mod;
		printf("%lld\n",ans);
	}
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
const long long MOD = 1000000007LL;
int main(){
    int n;
    cin >> n;
    int k = 1;
    bool fl = true;
    rep(i,500){
        if(i*(i+1) == 2*n){
            k = i;
            fl = false;
            break;
        }
    }
    int a[k+1][k];
    rep(i,k){
        a[0][i] = i+1;
    }
    int p = k+1;
    if(fl){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
        cout << k+1 << endl;
        cout << k << " ";
        rep(i,k){
            cout << a[0][i] << " ";
        }
        cout << endl;
        for(int i = 1;i<=k;i++){
            cout << k << " ";
            rep(j,k){
                if(i>j){
                    a[i][j] = a[j][i-1];
                }
                else{
                    a[i][j] = p;
                    p++;
                }
                cout << a[i][j] << " ";
            }
            cout << endl;
        }

    }
}

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

using namespace std;

long long n, m, p, wa[100005], corr, pena;
string s;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	while (m--) {
		cin >> p >> s;
		if (s == "WA") {
			if (wa[p] >= 0) wa[p]++;
		}
		else {
			if (wa[p] >= 0) {
				corr++;
				pena += wa[p];
				wa[p] = -1;
			}
		}
	}
	cout << corr << " " << pena << endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N),K(N);
    rep(i,N) cin >> A[i] >> K[i];

    int g = 0;
    rep(i,N) {
        int val = 0;
        while (true) {
            int p = A[i]/K[i];
            int q = A[i]%K[i];
            if (p==0) {
                val = 0;
                break;
            }
            if (q==0) {
                val = p;
                break;
            }
            int r = (A[i]+K[i]-1)/K[i];
            int s = (q+r-1)/r*r;
            A[i] -= s;
        }
        g ^= val;
    }

    cout << (g ? "Takahashi" : "Aoki") << ln;
}

Measured memory_bytes: 256
from queue import deque
from copy import deepcopy

    
H, W = map(int, input().split())
S = [['#'] * (W + 2)]
cnt = []
Checked = [[0 for _ in range(W+2)] for _ in range(H+2)]


for _ in range(H):
    S.append(['#'] + [i for i in input()] + ['#'])
S.append(['#']*(W + 2))

for start_h in range(1, H+1):
    for start_w in range(1, W+1):
        if S[start_h][start_w] == '#':
            continue
        q = deque([[start_h, start_w]])
        checked = deepcopy(Checked)
        c = 0
        tmp = []
        while q:
            h, w = q.popleft()
            if checked[h][w]:
                 continue
            checked[h][w] = 1
                    
            for dw, dh in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                next_h, next_w = h + dh, w + dw
                if S[next_h][next_w] == '#':
                    continue
                if [next_h, next_w] in tmp or checked[next_h][next_w]:
                    continue
                tmp.append([next_h, next_w])
            if not q:
                q.extend(tmp)
                tmp = []
                c += 1
        cnt.append(c-1)
            
print(max(cnt))

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

using namespace std;
#define ll long long


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

    ll a,b;
    cin>>a>>b;

    unordered_map<int,int> hmap;

    for(int i=0;i<b;i++)
    {
        int c = 0; cin>>c;
        hmap[c]++;
    }

    for(int l = 0 ; l <= b;l++)
    {
        if(hmap.find(a-l) == hmap.end())
        {
            cout<<(a-l)<<endl;
            return 0;
        }

        if(hmap.find(a + l) == hmap.end())
        {
            cout<<(a+l)<<endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,A,B,C,D; cin>>N>>A>>B>>C>>D;
    string s="r",t; cin>>t;
    s+=t;
    bool ans=true;
    
    //独立
    if(C<D){
        //A->C
        FOR(i,A,C){
            if(s[i]=='#' && s[i+1]=='#') ans=false;
        }
        //B->D
        FOR(i,B,D){
            if(s[i]=='#' && s[i+1]=='#') ans=false;
        }
    }
    //B~Dどこかで止まる
    else{
        ans=false;
        //追い越せる場所
        FOR(i,B,D+1){
            if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') ans=true;
        }
        //A->C
        FOR(i,A,C){
            if(s[i]=='#' && s[i+1]=='#') ans=false;
        }
    }
    
    if(ans) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
}



Measured memory_bytes: 3720
#include<bits/stdc++.h>
using   namespace   std;
#define N  200010
#define LL  long    long
char    a[N];
int main()
{
    int i,j,k;
    LL  s1,s2,s3,s4,s;
    scanf("%s",a+1);
    k=strlen(a+1);
    s=0;
    s1=0;
    for(i=1;i<=k;i++)
    {
        if(a[i]=='B')
            s++;
        else
            s1=s1+s;
    }
    printf("%lld\n",s1);
    return  0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define output(x) cout<<x<<endl;
#define fre(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define frd(i, a, b) for (int i = (int)(a); i >= b; --i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int,int> > vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

const int maxn = 3010;

ll a[maxn],dp[maxn][maxn];

ll f(int x,int y){
	if(x==y) return a[x];
	if(dp[x][y]!=-1) return dp[x][y];
	dp[x][y]=max(a[x]-f(x+1,y) , a[y]-f(x,y-1));
	return dp[x][y];
}

int main(){
	cin.tie(0);ios_base::sync_with_stdio(0);	
	int n;
	cin>>n;
	fre(i,1,n) cin>>a[i];
	fre(i,0,maxn-1) fre(j,0,maxn-1) dp[i][j]=-1;
	output(f(1,n));
	return 0;
}

Measured memory_bytes: 71296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned int a, b, c, temp;
  int count = 0;
  string s;
  cin >> s;
  if(s[0] == '1'){
    count++;
  }
  if(s[1] == '1'){
    count++;
  }
  if(s[2] == '1'){
    count++;
  }
    cout << count << endl;
  
  return 0;
}

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

int main(){
string S;
  cin>>S;
  
  int count=0, M=0;
  for(int i=0; i<S.size(); i++){
   if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
     count++;
     M=max(M, count);}
   else{count=0;} 
  }
  
  cout<<M<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] Input = Console.ReadLine().Split(' ');

            List<int> Inputnum = new List<int>();

            //??\??????????????????int???????????????add??????
            for (int i = 0; Input.Length > i; i++)
            {
                Inputnum.Add(int.Parse(Input[i]));
            }

            Console.WriteLine(Judge(Inputnum));

        }

        private static string Judge(List<int> list)
        {
            string result = "No";

            if (list[0] <= list[2] && list[1] <= list[3])
            {
                return result;
            }

            if( list[2] < 0 || list[3] < 0)
            {
                return result;
            }

            int wideradius = list[0] - list[2];
            int hightradius = list[1] - list[3];

            if (wideradius >= list[4] && hightradius >= list[4])
            {
                result = "Yes";
                return result;
            }

            return result;
        }



    }

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);

    int max_1 = 0, max_2 = 0;
    rep(i, N) {
        cin >> A[i];
        if (A[i] > max_2) {
            max_2 = min(max_1, A[i]);
            max_1 = max(max_1, A[i]);
        }
    }

    rep(i, N) {
        if (A[i] == max_1) cout << max_2 << endl;
        else cout << max_1 << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
def q1():
    a,b,c = map(int, input().split(" "))
    r = int(a*b/2)
    print(r)

def q2():
    def f(n):
        if n%2 == 0:
            return n//2
        else:
            return 3*n+1
    def solver(v):
        ary = []
        for i in range(10**6):
            if i == 0:
                ary.append(v)
            else:
                v = f(ary[-1])
                if v in ary:
                    return i+1
                else:
                    ary.append(v)
    s = int(input())
    print(solver(s))


"""
1. 最低値を数える (1)
2. 配列全体から最低値を減算する
3. 0で配列を分割する
4. 分割した配列に1～の処理を行う
5. 配列の長さが0になったら終わる
6. 全ての最低値を足した値が答え
"""
n = int(input())
h = list(map(int, input().split(" ")))

def water(ary):
    # 5
    if len(ary) == 0:
        return 0
    elif len(ary) == 1:
        return ary[0]

    # 1
    m = min(ary)
    #print("min = %d" % m)
    # 2
    new_ary = list(map(lambda x:x-m, ary))
    # 3
    tmp = []
    multi_ary = []
    for n in new_ary:
        if n != 0:
            tmp.append(n)
        else:
            multi_ary.append(tmp)
            tmp = []
    else:
        multi_ary.append(tmp)
    #print("%s -> %s -> %s" % (ary, new_ary, multi_ary))
    # 4
    cnt = sum(map(water, multi_ary))
    # 6
    #print("%d + %d" % (cnt,m))
    return cnt +m

print(water(h))


Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public struct Pair { public int x, y; public Pair(int a, int b) { x = a; y = b; } }
    public static void Solve()
    {
        int N = NextInt();
        int M = NextInt();
        Console.WriteLine(N == M ? "Yes" : "No");
    }
    public static long GCD(long a, long b)
    {
        if (a < b) GCD(b, a);
        long d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(long a, long b)
    {
        return a / GCD(a, b) * b;
    }

    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


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

using namespace std;

int main(){
    while(true) {
        int n = 0;
        cin >> n;
        if(n == 0) break;
        vector<int> v(n);
        int x;
        for(int i = 0; i < n; ++i){
            cin >> v[i];
        }
        cin >> x;
        int left = 0;
        int right = n - 1;
        int cnt = 0;
        while(true){
            int pivot = (right + left) / 2;
            int elem = v[pivot];
            if(left > right) break;
            cnt++;
            if( elem < x ){
                left = pivot + 1;
            } else if ( elem > x ) {
                right = pivot - 1;
            } else {
                break;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int a,b,c,d,e,k;
    cin>>a>>b>>c>>d>>e>>k;
    if(abs(a-b)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(a-c)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(a-d)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(a-e)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(b-c)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(b-d)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(b-e)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(c-d)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(c-e)>k){
        cout<<":("<<endl;
        return 0;
    }
    else if(abs(d-e)>k){
        cout<<":("<<endl;
        return 0;
    }
    cout<<"Yay!"<<endl;
    return 0;
}

Measured memory_bytes: 256
inf = 10 ** 18
P = 10 ** 9 + 7

S = input()
N = len(S)

tmp = 1
modrow = [1] * 6
for i in range(5):
    tmp = (tmp * 10) % 13
    modrow[1 + i] = tmp

modtab = [[None] * 10 for i in range(6)]
for i in range(6):
    for j in range(10):
        modtab[i][j] = (modrow[i] * j) % 13

# for modcol in modtab:
#     print("#", sorted(modcol))

# X + question === 5 (mod 13)
X = 0
q_idx = []
for i, Si in enumerate(S[::-1]):
    if Si == '?':
        q_idx.append(i)
    else:
        X = (X + modtab[i % 6][int(Si)]) % 13


M = len(q_idx)
ans_tab = [[0] * 13 for _ in range(M + 1)]

ans_tab[0][0] = 1
for i, idx in enumerate(q_idx):
    for src in range(13):
        for coeff in range(10):
            dst = (src + modtab[idx % 6][coeff]) % 13
            ans_tab[1 + i][dst] = (ans_tab[1 + i][dst] + ans_tab[i][src]) % P
        
# print("#", ans_tab[-1])
idx_ans = (5 - X) % 13
print(ans_tab[-1][idx_ans])

Measured memory_bytes: 63392
/* dp[c3][c2][c1] = 
(n - c1 - c2 - c3) / n * (1 + dp[c3][c2][c1]) // eat disk with 0 sushi -> probability = 1 - (c1 + c2 + c3) / n
+ (c3 / n) * (1 + dp[c3 - 1][c2 + 1][c1]) // eat disk with 3 sushi -> probability = c3 / n
+ (c2 / n) * (1 + dp[c3][c2 - 1][c1 + 1]) // eat disk with 2 sushi -> probability = c2 / n
+ (c1 / n) * (1 + dp[c3][c2][c1 - 1]) // eat disk with 1 sushi -> probability = c1 / n
*/
#include <bits/stdc++.h>
using namespace std;
 
const int N = 303;

int n, C[4];
double dp[N][N][N];

signed main() {
	cin >> n;
	for (int i = 1, x; i <= n; i++) {
		cin >> x;
		C[x]++;
	}
	for (int c3 = 0; c3 <= n; c3++) {
		for (int c2 = 0; c2 <= n; c2++) {
			for (int c1 = 0; c1 <= n; c1++) {
				if (c1 + c2 + c3 > n) continue;
				int k = c1 + c2 + c3;
				if (k) dp[c3][c2][c1] = 1.0 * n / k;
				if (c3) dp[c3][c2][c1] += 1.0 * c3 / k * dp[c3 - 1][c2 + 1][c1];
				if (c2) dp[c3][c2][c1] += 1.0 * c2 / k * dp[c3][c2 - 1][c1 + 1];
				if (c1) dp[c3][c2][c1] += 1.0 * c1 / k * dp[c3][c2][c1 - 1];
			}
		}
	}
	printf("%.9f\n", dp[C[3]][C[2]][C[1]]);
}

Measured memory_bytes: 217344
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }
    let mut acc = vec![0; n + 1];
    for i in 0..n {
        acc[i + 1] = acc[i] + a[i];
    }
    let mut b = vec![];
    for i in 1..=n {
        for j in 0..i {
            b.push(acc[i] - acc[j]);
        }
    }
    let mut result = 0;
    for i in (0..=40).rev() {
        let x = result | 1 << i;
        if b.iter().filter(|&bi| bi & x == x).count() >= k {
            result = x;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 6116