akhauriyash/Code-Regression huggingface dataset:
//25
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int n,t,s;
  cin>>n>>t>>s;
  int dp[3001]={};
  while(n--){
    int a,b;
    cin>>a>>b;
    for(int i=t;i-b>=0;i--){
      if(s<=i-b||i<=s){
	dp[i]=max(dp[i],dp[i-b]+a);
      }
    }
    for(int i=0;i<t;i++){
      dp[i+1]=max(dp[i+1],dp[i]);
    }
  }
  cout<<dp[t]<<endl;
  return 0;
}
    

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n, m; scanf("%d%d", &n, &m);
	std::vector<i64> a(m), b(m);
	std::vector<std::vector<int>> c(m);
	for(int i = 0; i < m; i++) {
		scanf("%d%d", &a[i], &b[i]);

		for(int j = 0; j < b[i]; j++) {
			int a; scanf("%d", &a);

			c[i].push_back(a - 1);
		}
	}

	auto dp = make_v<i64>(1 << n);
	for(int i = 0; i < dp.size(); i++) dp[i] = 1LL << 60; dp[0] = 0;
	for(int i = 0; i < m; i++) {
		for(int j = 0; j < (1 << n); j++) {
			if(dp[j] == 1LL << 60) continue;

			int to = j;
			for(auto v: c[i]) to |= (1 << v);
			dp[to] = std::min(dp[to], dp[j] + a[i]);
		}
	}
	if(dp[(1 << n) - 1] == 1LL << 60) printf("-1\n");
	else printf("%lld\n", dp[(1 << n) - 1]);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define PUT(x) cout << x << endl;
#define DPUT(x) printf("%.15lf\n",x);
#define GET(x,y) std::get<x>(y) 


using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

int main(void) {

	int a, b;
	cin >> a >> b;

	cout << (a + b + 1) / 2 << endl;

	return 0;

}

Measured memory_bytes: 256
T = int(input())

def floor_sum(n, m, a, b):
    result = 0
    if a >= m:
        result += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        result += n * (b // m)
        b %= m

    yMax = (a * n + b) // m
    xMax = yMax * m - b
    if yMax == 0:
        return result
    result += (n - (xMax + a - 1) // a) * yMax
    result += floor_sum(yMax, a, m, (a - xMax % a) % a)
    return result
  
  
for _ in range(T):
  n, m, a, b = map(int,input().split())
  print(floor_sum(n, m, a, b))

Measured memory_bytes: 76084
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

typedef long long ll;

bool has_smaller_first(const std::pair<ll, ll>& a, const std::pair<ll, ll>& b)
{
  return a.first < b.first;
}

int main()
{
  int nstores, ndrinks;
  std::cin >> nstores >> ndrinks;
  std::vector<std::pair<ll, ll>> store;
  for (int i = 0; i < nstores; i++) {
    ll price, limit;
    std::cin >> price >> limit;
    store.emplace_back(price, limit);
  }
  std::sort(store.begin(), store.end(), has_smaller_first);
  ll cost = 0;
  for (const auto& p : store) {
    if (p.second <= ndrinks) {
      cost += p.first * p.second;
      ndrinks -= p.second;
    } else {
      cost += p.first * ndrinks;
      break;
    }
  }
  std::cout << cost << '\n';
  return 0;
}


Measured memory_bytes: 3444
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			int k = sc.nextInt();
			
			int[] m = new int[n];
			for(int i=0;i<n;i++){
				m[i] = sc.nextInt();
			}
			
			ArrayDeque<String> que = new ArrayDeque<String>();
			StringBuffer sb;
			String s;
			
			for(int a=0;a<n;a++){
				for(int b=0;b<n;b++){
					if(a!=b){
						if(k==2){
							sb = new StringBuffer();
							s = sb.append(m[a]).append(m[b]).toString();
							if(que.contains(s)==false) que.add(s);
						}else{
							for(int c=0;c<n;c++){
								if(a!=c && b!=c){
									if(k==3){
										sb = new StringBuffer();
										s = sb.append(m[a]).append(m[b]).append(m[c]).toString();
										if(que.contains(s)==false) que.add(s);
									}else{
										for(int d=0;d<n;d++){
											if(a!=d && b!=d && c!=d){
												sb = new StringBuffer();
												s = sb.append(m[a]).append(m[b]).append(m[c]).append(m[d]).toString();
												if(que.contains(s)==false) que.add(s);
											}
										}
									}
								}
							}
						}
					}
				}
			}
			System.out.println(que.size());
		}	
	}	
}

Measured memory_bytes: 25556
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int a,b,c;
    int k;
    scanf("%d %d %d", &a,&b,&c);
    scanf("%d", &k);
   // printf("%d %d %d   %d",a,b,c,k);
    
    while(k>0){
        if(a>=b){b*=2;k--;}
        else if(b>=c){c*=2;k--;}
        else{k=0;}
     //   printf("%d %d %d   %d",a,b,c,k);
    }
    
    
    if(a<b&&b<c){printf("Yes");}
    else{printf("No");}
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" \
						  << " = " << a[i] << endl;
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define PI 3.141592654
#define all(v) v.begin(), v.end()
using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
using pi = pair<int, int>;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; }return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll& x, ll v)
{
	x = (x + v) % MOD;
	if (x < 0)
		x += MOD;
}
//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


const int mxN = 2e5;
ll a[mxN];

void test_case() {

}


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

	sort(a, a + n);

	if (a[n - 1] == 0 && (k & 1)) {
		cout << 0;
		return 0;
	}

	if (a[n - 1] < 0 && (k & 1)) {
		ll ans = 1;
		for (int i = n - k; i < n; ++i)
			ans = (ans * a[i]) % MOD;
		while (ans < 0) ans += MOD;
		cout << ans;
		return 0;
	}
	ll ans = 1;
	int i = 0, j = n - 1;
	if (k & 1) {
		ans = ans * a[j];
		ans %= MOD;
		--j;
		--k;
	}

	k /= 2;
	for (int itr = 0; itr < k; ++itr) {
		ll left = a[i] * a[i + 1];
		ll right = a[j] * a[j - 1];

		if (left > right) {
			ans *= a[i];
			ans = ans % MOD;
			ans *= a[i + 1];
			ans = ans % MOD;
			i += 2;
		}
		else {
			ans *= a[j];
			ans = ans % MOD;
			ans *= a[j - 1];
			ans = ans % MOD;
			j -= 2;
		}
	}

	
	while (ans < 0)
		ans += MOD;
	cout << ans;
	return 0;
}


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

static const int mod = 1000000007;

inline void inc(int &x, int y) { (x += y) >= mod && (x -= mod); }
inline int mul(int x, int y) { return 1LL * x * y - 1LL * x * y / mod * mod; }
inline int modpower(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = mul(res, x);
    y >>= 1, x = mul(x, x);
  }
  return res;
}

int n, k, ans;
int F[10000];
int main() {
  scanf("%d %d", &n, &k);
  vector<int> factor;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      factor.push_back(i);
      if (i * i != n) factor.push_back(n / i);
    }
  }
  sort(factor.begin(), factor.end());
  ans = 0;
  for (int i = 0; i < (int)factor.size(); ++i) {
    int x = factor[i];
    F[i] = modpower(k, (x + 1) / 2);
    for (int j = 0; j < i; ++j)
      if (x % factor[j] == 0) inc(F[i], mod - F[j]);
    inc(ans, mul(F[i], (x & 1) ? x : x / 2));
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    int i = 1;
    ll ans;
    bool single = s1[0] == s2[0];
    if (single) ans = 3;
    else {
        ans = 6;
        single = false;
        i++;
    }
    
    while (i < n) {
        if (s1[i] == s2[i]) {
            if (single) ans *= 2;
            single = true;
            i++;
        } 
        else {
            if (single) ans *= 2;
            else ans *= 3;
            single = false;
            i += 2;
        }
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {
	ll M, N;
	cin >> N >> M;

	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	ll s = 0;
	repn(i, N) s += A[i];

	
	ll pop = 0;
	repn(i, N) {
		if (A[i] * 4 * M >= s) { pop++; }
	}

	if (pop >= M) { cout << "Yes"; }
	else { cout << "No"; }

	system("PAUSE");
}


Measured memory_bytes: 504
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()



int main(void){
    int N;
    cin >> N;
    int A[N+1],B[N];
    rep(i,N+1){
        cin >> A[i];
    }
    rep(i,N){
        cin >> B[i];
    }

    ll sum = 0;

    REP(i,N){
        if(B[i] - A[i+1] - A[i] <= 0){
            sum += B[i];
            if(A[i+1]-B[i]<0){
                A[i] -= -(A[i+1]-B[i]);
            }            
        }else{
            sum += A[i+1] + A[i];
            A[i] = 0;
        }

        
        
    }

    cout << sum << endl;
	
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#define MAXN 100+10
int main (void)
{
	int n;
	int a[MAXN];
	scanf("%d",&n);
	double sum = 0;
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]),sum+=a[i];
	sum/=(double) n;
	double min = 1e9;
	int t;
	for(int i=0;i<n;i++)
	{
		if(fabs(a[i]-sum)<min)
		{
			min = fabs(a[i]-sum);
			t = i;
		}
	}
	printf("%d\n",t);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
num = 0
min_temp = 10000000
for i in range(n):
    temp = t - (0.006*h[i])
    temp_diff = abs(a - temp)
    if temp_diff < min_temp:
        min_temp = temp_diff
        num = i

print(num+1)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))
D = {}
res = 0
for a in A:
    if a in D.keys():
        D[a] += 1
    else:
        D[a] = 1
    res += a
Q = int(input())
BC = []
for _ in range(Q):
    b,c = map(int,input().split())
    BC.append([b,c])

for bc in BC:
    if bc[0] in D.keys():
        res += D[bc[0]]*(bc[1]-bc[0])
        if bc[1] in D.keys():
            D[bc[1]] += D[bc[0]]
        else:
            D[bc[1]] = D[bc[0]]
        D[bc[0]] = 0
    print(res)

Measured memory_bytes: 32096
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

string s;

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

  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
using namespace std;
int main()
{
    int n;
    cin >> n;
    string str[55];
    /*
    string TempStr;
    int len = 10000;
    REP(i, 0, n){
       cin >> str[i];
       string t = str[i];
       if( t.size() < len){
           TempStr = t;
           int l = t.size();
           len = min(len, l);
       }
    }
    string ans = "";
    for(int i = 0; i < len; i++){
       bool flag = true;
       for(int j = 0; j < n; j++){
           if(str[j].find(TempStr[i]) == -1){
               flag = false;
           }
       }
       if(flag){
           ans += TempStr[i];
           //cout << TempStr[i] << endl;
       }
    }
    */

    int t;
    REP(i, 0, n)
        cin>>str[i];
    REP(i, 0, 26)
    {
        t = 0x7fffffff;
        REP(j, 0, n)
        {
            t = min(t, (int) count(begin(str[j]), end(str[j]),(char)i+97));
        }
        REP(j, 0, t) cout <<(char)(i+97);
    }

    cout << endl;
    /*
    sort(ans.begin(),ans.end());
    if(ans == ""){
       cout << "The answer is an empty string." <<'\n';
    }
    else{
       cout << ans << '\n';
    }*/


}


Measured memory_bytes: 256
M=10**9+7
n,s=open(0)
n=int(n)
a=l=s[0]<'W'>s[-2]
r=f=0
for b,c in zip(s,s[1:-1]):f^=b==c;a=a*(l-r)**f%M;r+=f;l+=f^1
while n:a=a*n%M;n-=1
print(a*(l==r))

Measured memory_bytes: 3508
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline


def dfs(now):
    seen[now] = True
    for next in branch[now]:
        if seen[next] is False:
            score[next] += score[now]
            dfs(next)


N, Q = map(int, input().split())
branch = [set() for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    branch[a - 1].add(b - 1)
    branch[b - 1].add(a - 1)
score = [0] * N
for _ in range(Q):
    p, x = map(int, input().split())
    score[p - 1] += x

seen = [False] * N
for i in range(N):
    if seen[i] is False:
        dfs(i)

print(*score)


Measured memory_bytes: 251956
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>

using LL = long long;
using namespace std;

int N;
int A[123456];


int main() {
	while (cin >> N, N) {
		for (int i = 0; i < N; ++i) {
			cin >> A[i];
		}
		sort(A, A + N);
		int ans = 123456789;
		for (int i = 1; i < N; ++i) {
			ans = min(ans, A[i] - A[i - 1]);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3152
#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/STACK: 20000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vec vector
#define all(x) x.begin(), x.end()
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
    set<ll> correct;
    map<ll,ll> penalties;
    ll pen = 0;
    ll n,m;cin>>n>>m;
    while(m--){
        ll t; cin>>t; string s; cin>>s;
        if(s=="WA" && correct.count(t)==0 ) penalties[t]++;
        else if(s=="AC" && correct.count(t)==0 ) correct.insert(t), pen+=penalties[t];
    }
    cout<<correct.size()<<" "<<pen<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;




int main() {
	
	int N, K;
	cin >>N >> K;
	char s[200000];

	for (int i = 1; i <= N; i++) {
		cin >> s[i];
	}

	int hp = 0;

	for (int i = 1; i < N; i++) {
		if (s[i] == s[i + 1]) { hp++; }
	}

	hp = min(N-1, hp + 2 * K);

	cout << hp;

	system("PAUSE");
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a % 2 || b % 2 || c % 2)
    {
        cout << 0 << endl;
        return 0;
    }
    if (a == b && b == c)
    {
        cout << -1 << endl;
        return 0;
    }

    int cnt = 0;
    while (!(a % 2 || b % 2 || c % 2))
    {
        int a_ = a / 2;
        int b_ = b / 2;
        int c_ = c / 2;
        a = b_ + c_;
        b = a_ + c_;
        c = a_ + b_;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#ABC122-D
MOD = 1000000007
n = gets.to_i
cnt = 1
map = ["A","G","C","T"]
hash = Hash.new(0)
map.repeated_permutation(3) do |x|
  str = x[0] + x[1] + x[2]
  if str =~ /GAC/ || str =~ /ACG/ || str =~ /AGC/
    hash[str] = 0
  else
    hash[str] = 1
  end
end
4.upto(n) do |i|
  hash2 = Hash.new(0)
  hash.each do |k,v|
    map.each do |s|
      str = k[0]+k[1]+k[2] + s
      if str =~ /GAC/ || str =~ /ACG/ || str =~ /AGC/ || str =~ /A.GC|AG.C/
        next
      else
        hash2[k[1]+k[2]+s] += v
        hash2[k[1]+k[2]+s] %= MOD
      end
    end
  end
  hash = hash2
end
puts hash.each_value.inject(:+) % MOD

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

using namespace std;

typedef long long ll;

#define min(a, b) ((a) < (b)? (a):(b))
#define max(a, b) ((a) > (b)? (a):(b))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(int i=(a); i<(n); i++)
#define pb push_back

int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    
    int ans = 700;
    if(s[0] == 'o') ans+= 100;
    if(s[1] == 'o') ans+= 100;
    if(s[2] == 'o') ans+= 100;
    
    cout << ans << endl;
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
 
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    ll a, b, k; cin >> a >> b >> k;
    ll cpy = a;
    a -= k;
    if(a < 0){
        k -= cpy;
        a = 0;
        b -= k;
        if(b < 0) b = 0;
    }
    return cout << a << ' ' << b << '\n', 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    int N; cin >> N;
    vi P(N); for (int i = 0; i < N; i++) cin >> P[i];

    ll rst = 9876543219876543;
    for (int x = 1; x <= 100; x++) {
        ll sub = 0;
        for (int p : P) {
            sub += (p - x) * (p - x);
        }
        rst = min(rst, sub);
    }
    cout << rst;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <functional>
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin >> n;
    ll mn = 100*100*100+10;
    vector<ll> x(n);
    for(int i = 0;i < n;i++)cin >> x[i];
    for(ll now = 1;now <= 100;now++){
        ll sum_now = 0; 
        for(int i = 0;i < n;i++){
            sum_now += (x[i] - now) * (x[i] - now);
        }
        mn = min(sum_now,mn);
    }

    cout << mn << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
struct weight_unionfind {
    vi par,rank;
    vector<T> diff_weight;
public:
    weight_unionfind(int n):par(n,-1),rank(n,0),diff_weight(n,0) {}
    int root(int x) {
        if(par[x] < 0) return x;
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    T weight(int x) {
        root(x);
        return diff_weight[x];
    }
    bool same(int x,int y) { return root(x) == root(y); }
    bool merge(int x,int y,T w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x,y),w = -w;
        if(rank[x] == rank[y]) rank[x]++;
        par[x] += par[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    T diff(int x,int y) {
        assert(same(x,y));
        return weight(y)-weight(x);
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    weight_unionfind<int> uf(n);
    rep(_,m) {
        int l,r,d;
        cin >> l >> r >> d;
        l--; r--;
        if(!uf.same(l,r)) uf.merge(l,r,d);
        else {
            if(uf.diff(l,r) == d) continue;
            Yes(0);
            return 0;
        }
    }
    Yes(1);
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

ll dp[101010];
int bad[101010];

int main(){
  int N,M; cin>>N>>M;
  rep(i,M){
    int A; cin>>A;
    bad[A]=1;
  }
  dp[0]=1;
  rep(i,N){
    if(bad[i+1]==0) (dp[i+1]+=dp[i])%=MOD;
    if(bad[i+2]==0) (dp[i+2]+=dp[i])%=MOD;
  }
  cout<<dp[N]<<endl;
  return 0;
}


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

n, a, b, c, d = map(int, input().split())
s = input()
if '##' in s[a:c-1] or '##' in s[b:d-1]:
    ans = 'No'
elif c > d:
    if '...' in s[b-2:d+1]:
        ans = 'Yes'
    else:
        ans = 'No'
else:
    ans = 'Yes'
print(ans)

Measured memory_bytes: 3572
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr int INF = 1e9;
constexpr ll BIGINF = 1e18;
constexpr double EPS = 1e-16;
constexpr int MOD = 1e9 + 7;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

string s;

void input() {
  cin >> s;
}

void solve() {
  int ans = INF;

  int sz = 3;

  for (int i = 0; i < (int)s.size() - sz + 1; ++i) {
    int sub = atoi(s.substr(i, sz).c_str());

    ans = min(ans, abs(753 - sub));
  }

  cout << ans << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve();
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int M = sc.nextInt();

    sc.close();

    int X = 1900 * M + 100 * (N - M);

    int rate = 1;

    for (int i = 1; i <= M; i++){
      rate *= 2;
    }

    System.out.println(rate * X);

  }

}

Measured memory_bytes: 23764
from collections import deque
H, W = map(int, input().split())
H += 2
W += 2
maze = '#' * W
for _ in range(H-2):
  maze += '#' + input() + '#'
maze += '#' * W
 
def bfs(root):
  if maze[root] == '#':
    return -1
  dist = [-1] * (H*W)
  dist[root] = 0
  q = deque([root])
  while q:
    x = q.popleft()
    for d in [1, -1, W, -W]:
      if maze[x+d] == '.' and dist[x+d] == -1:
        q.append(x+d)
        dist[x+d] = dist[x] + 1
  return max(dist)
 
ans = max(bfs(i) for i in range(H*W))
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;main(int N){cin>>N;int A[N],B[N],c[N+1]={};rep(i,N)cin>>A[i];rep(i,N)cin>>B[i];rep(i,N)c[A[i]]++,c[B[i]]++;if(*max_element(c,c+N+1)>N)printf("No");else{printf("Yes ");queue<int> s;rep(i,N)if(A[i]==B[i])s.push(i);while(!s.empty()){int n=s.front(),t=rand()%N;s.pop();if(A[n]!=B[t]&&A[t]!=B[n])swap(B[n],B[t]);else s.push(n);}rep(i,N)cout<<B[i]<<" ";}}

Measured memory_bytes: 6796
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  while(1){
    ll n,m;
    cin>>n>>m;
    if(n==0&&m==0) return 0;
    vector<P> v;
    ll dsum=0;
    for(int i=0;i<n;i++){
      ll d,atk;
      cin>>d>>atk;
      dsum+=d;
      v.push_back(P(atk,d));
    }
    sort(v.begin(),v.end());
    m=dsum-m;
    if(m<=0){
      cout<<0<<endl;
      continue;
    }
    ll ps=0,ans=0;
    while(m>0){
      if(v[ps].second<=m){
        m-=v[ps].second;
        ans+=v[ps].first*v[ps].second;
        ps++;
        continue;
      }
      else{
        ans+=v[ps].first*m;
        break;
      }
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3260
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Buffer(make([]byte, 0), 1000000009)

	for {
		var s string
		s = nextString()
		if s == "." {
			break
		}
		var st []byte
		is_valid := true

		for _, value := range s {
			if value == '(' {
				st = append(st, byte(value))
			}
			if value == '[' {
				st = append(st, byte(value))
			}
			if value == ')' {
				if len(st) == 0 || st[len(st)-1] != '(' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
			if value == ']' {
				if len(st) == 0 || st[len(st)-1] != '[' {
					is_valid = false
					break
				} else {
					st = st[:len(st)-1]
				}
			}
		}
		if len(st) != 0 {
			is_valid = false
		}
		if is_valid {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}


Measured memory_bytes: 1376
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
int n,a[233333],qz[233333];
int main() {
	read(n);rep(i,1,n)read(a[i]); //,qz[i]=qz[i-1]+(a[i]==0);
	rep(i,1,n) if (a[i]>=i) {puts("-1"); return 0;} ll res=0;
	rep(i,1,n) if (a[i]) {
		int j; for (j=i+1; j<=n; j++) if (a[i]-i!=a[j]-j) break; //[i,j-1]
		if (!a[i-1]&&a[i]>1||a[i-1]<a[i]-1){puts("-1"); return 0;} res+=a[j-1]; i=j-1;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 1024
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){
            long[] nd = ILongs();

            long[][] x = ILongLongs(nd[0]);

            long ans = 0;

            for(long i=0;i<nd[0]-1;i++){
                for(long j=i+1;j<nd[0];j++){
                    long d2 = 0;
                    for(int d=0;d<nd[1];d++){
                        d2 += (x[i][d]-x[j][d])*(x[i][d]-x[j][d]);
                    }

                    for(long r=0;r<=(long)Math.Sqrt(d2);r++){
                        if(r*r==d2){
                            ans ++;
                            break;
                        }
                    }
                    
                }
            }

            Console.WriteLine(ans);
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 13268
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>
#include <iostream>

using namespace std;

int main() {
	long long int n, k;
	long long int ans=0,tmp=0,sum=0;
	cin >> n >> k;

	do {
		if (ans == 0) {
			tmp = 1;
		}
		else {
			tmp *= k;
		}
		ans++;
	} while (tmp<= n);
	ans--;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int maxn=1e5;
using namespace std;
int main(){
    std::ios::sync_with_stdio(false);
    int n,flag=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a%2==0){
            if(a%3!=0&&a%5!=0)
                flag=1;
        }
    }
    if(flag) puts("DENIED");
    else puts("APPROVED");
    return 0;
}


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

namespace StringWithTheSameLength
{
    class Program
    {
        static void Main(string[] args)
        {
            var len = int.Parse(Console.ReadLine());
            var texts = Console.ReadLine().Split(' ');
            var sb = new StringBuilder();
            for (int i = 0; i < len; i++)
            {
                sb.Append(texts[0][i]);
                sb.Append(texts[1][i]);
            }

            Console.WriteLine(sb);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 5010;

int z[N];
string s;

int main()
{
	ios_base::sync_with_stdio(false);
	
  int n;
  
  cin >> n >> s;
  
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    int l = -1, r = -1;
    for(int j = i + 1; j < n; ++j) {
      int k = (j > r ? 0 : min(z[j - l + i], r - j + 1));
      while(j + k < n && s[i + k] == s[j + k]) ++k;
      z[j] = k;
      if(j + k - 1 > r) l = j, r = j + k - 1;
      ans = max(ans, min(z[j], j - i));
    }
  }
  
  cout << ans << '\n';
	return 0;
}



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

using vi = vector<int>;

int main()
{
    ios_base::sync_with_stdio(0);

    int n; cin >> n;

    vi v(256, INT_MAX);

    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;

        vi w(256, 0);

        for(auto x : s) w[x]++;

        for(int j = 0; j < 256; j++)
            v[j] = min(v[j], w[j]);
    }

    for(int i = 0; i < 256; i++)
    for(int j = 0; j < v[i]; j++)
        cout << char(i);

    cout << endl;
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

long long gcd( long long m, long long n ){
    if ( n == 0) return m;
    return gcd(n,m%n);
  }//最大公約数

  long long lcm( long long m, long long n ){
  // 引数に０がある場合は０を返す
  if ( ( 0 == m ) || ( 0 == n ) ) return 0;

  return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//最小公倍数

VLL prime;
bool ok[(ll)(2*1e6)];

void makePrime(){
  memset(ok,true,sizeof(ok));
  ok[0] = false;
  ok[1] = false;
  for(ll i = 2; i*i <= 1e12; i++){
    if(ok[i] == false) continue;
    ll x = 2;
    prime.push_back(i);
    while(x*i <= 2*1e6 - 1){
      ok[x*i] = false;
      x++;
    }
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;
  cin >> a >> b;
  a = gcd(a,b);
  // cout << a << endl;
  makePrime();
  ll ans = 0;
  for(ll x : prime){
    bool flag = false;
    while(a%x == 0){
      a/= x;
      flag = true;
    }

    if(flag) ans += 1;
  }

  // cout << a << endl;
  if(a == 1) ans++;
  else ans += 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(double i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int const INF = 1000000;
int main(){
  
    ll n,T;
    cin>>n>>T;
    ll ans=0;
    ll pretime = 0;
    rep(i,n){
        ll t;
        cin>>t;
        if(t!=0){
            if(t<pretime+T){
                ans+=t-pretime;
                pretime=t;
            }else{
                ans+=T;
                pretime=t;
            }
        }
    }
    
    ans+=T;
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
# 12月30日の M 時から次の年になるまでは何時間か、求めてください。

# 制約
# 1 ≦ M ≦ 23
# 入力は全て整数

# 標準入力から Mの値を取得し、出力する
m = int(input())

# 残り何時間か計算し、出力する
result = 48 - m
print(result)


Measured memory_bytes: 9028
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
bool ok[1000005];
int gu(int s){
	return s/2;
}
int ki(int s){
	return 3*s+1;
}

int main(){
	int s;cin>>s;
	int ans=1,temp=s;
	while(ok[temp]==false){

		ok[temp]=true;
		if(temp%2==0)temp=gu(temp);
		else temp=ki(temp);
		++ans;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 888
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
ll A, B, C, K;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>A>>B>>C>>K;

    ll ans = 0;

    if(K % 2 == 0){
        ans = A - B;
    }else{
        ans = -A + B;
    }

    if(abs(ans) > 1000000000000000000LL){
        cout<<"Unfair"<<endl;
    }else{
        cout<<ans<<endl;
    }

    return 0;
}


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

int main() {
    int N,c;
  	cin >> N;
  	
  	c = N%10;
  	/*cout << c << endl;*/
  	if ((c==2)||(c==4)||(c==5)||(c==7)||(c==9)){
      cout << "hon" << endl;
    }else if((c==0)||(c==1)||(c==6)||(c==8)){
      cout << "pon" << endl;
    }else{
      cout << "bon" << endl;
    }
  return 0;
   
}

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

int main() {
    int N, K;
    cin >> N >> K;
    int l[N];
    for (int i = 0; i < N; i++) {
        cin >> l[i];
    }
    sort(l, l + N);
    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += l[N - 1 -i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

std::unordered_map<int, int> memo;

int get_mininum_count(int N) {
    std::vector<int> withdrawals = {59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1};

    if (N == 0) {
        return 0;
    }
    if (memo.count(N) == 1) {
        return memo[N];
    }

    int min_count = N;
    for (int n : withdrawals) {
        if (n <= N) {
            min_count = std::min(min_count, get_mininum_count(N - n) + 1);
        }
    }
    memo[N] = min_count;
    return min_count;
}

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

    std::cout << get_mininum_count(N) << std::endl;
}


Measured memory_bytes: 4388
import java.util.*;

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0) break;

			Year[] y = new Year[n];
			for(int i=0;i<n;i++){
				y[i] = new Year(sc.next(),sc.nextInt(),sc.nextInt());
			}
			Arrays.sort(y);

			for(int i=0;i<m;i++){
				int q = sc.nextInt();
				int j;
				for(j=0;j<n && y[j].y<q;j++);

				int ans = 0;
				if(j >= n || (ans=y[j].y-q) >= y[j].b){
					System.out.println("Unknown");
					continue;
				}
				System.out.println(y[j].name + " " + (y[j].b - ans));
			}
		}
	}
}

class Year implements Comparable<Year>{
	String name;
	int b,y;

	Year(String name,int b,int y){
		this.name = name;
		this.b = b;
		this.y = y;
	}

	public int compareTo(Year year){
		return y - year.y;
	}
}

Measured memory_bytes: 14000
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define FOR(i,s,n) for(ll i = s; i < (n); ++i)

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(5);
	ll n;
	string s;
	cin >> n >> s;

	vl alp(27, 0);
	REP(i, s.size()) if(i%2==0) alp[s[i] - 'a']++;
	
	vl alp_inv(10, 0);
	REP(i, 27) alp_inv[alp[i]]++;

	ll cnt = 0;
	ll sum = 0;
	if (alp_inv[1]!=0) {
		sum += alp_inv[1] * 2 - 1;
		cnt++;
	}
	FOR(i, 2, 10) if (alp_inv[i]!=0){
		sum += alp_inv[i] * 2 - 1;
		sum += 4;
		if (alp_inv[i] == 1) sum -= 2;
		cnt++;
	}

	cout << sum + cnt - 1 << endl;
}

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

public class Main {

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

        int n = sc.nextInt();
        String[] s = new String[n];
        int[] p = new int[n];
        Pair[] pairs = new Pair[n];
        for (int i = 0 ; i < n ; i++) {
            s[i] = sc.next();
            p[i] = sc.nextInt();
            Pair pp = new Pair();
            pp.from = s[i];
            pp.end = p[i];
            pp.num = i + 1;
            pairs[i] = pp;
        }

        Arrays.sort(pairs);

        for (int i = 0 ; i < n ; i++ ) {
            System.out.println(pairs[i].num);
        }



    }



}

class Pair implements Comparable {
    String from;
    int end;
    int num;
    @Override
    public int compareTo(Object other) {
        Pair otherpair = (Pair) other;
        int aa = from.compareTo(otherpair.from);
        if (aa != 0) {
            return from.compareTo(otherpair.from);
        } else {
            return otherpair.end - end;
        }


    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(all(a)); }
template<class T> inline auto min(const T& a){ return *min_element(all(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define HERE  cout<<"Here"<<endl;

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  double a,b,x,h,ans;cin>>a>>b>>x;
  // h=3.0*x/(a*b);
  if(a*a*b>=2*x){
    ans=atan((a*b*b)/(2.0*x));
    ans*=180/M_PI;
  }
  else{
    x=(a*a*b)-x;
    ans=atan(a*a*a/(2.0*x));
    ans=90-ans*180/M_PI;
  }
  print(ans)
  return 0;

}


Measured memory_bytes: 384
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i).sort
ai = a[-1]
aj = a[0]
(n-1).times do |i|
  if (ai-aj*2).abs >= (ai-a[i]*2).abs
    aj = a[i]
  end
end
print ai,"\s",aj,"\n"

Measured memory_bytes: 11008