akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    char number[1001];
    int i,num,sum=0;
     
    while(1) {
        scanf("%s",number);
        for(i=0;number[i]!='\0';i++){
            num=number[i]-'0';
            sum=sum+num;
        }
        if(sum==0) break;
        printf("%d\n",sum);
        sum=0;
        }
     
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "OK" << endl ; else cout << "NG" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
vll a ;

void DFS(vvll &g,vll &cnt,vll &ans,int n){
	if(ans.at(n)!=-1) return ;
	auto itr = lower_bound(all(cnt),a.at(n)) ;
	ll d = *itr ;
	*itr = a.at(n) ;
    ans.at(n) = lower_bound(all(cnt),INF)-cnt.begin() ;
	for(int i=0;i<g.at(n).size();i++){
		DFS(g,cnt,ans,g.at(n).at(i)) ;
	}
	*itr = d ;
}

int main(){
	ll n ; cin >> n ;
	for(int i=0;i<n;i++){
		ll sub ; cin >> sub ;
		a.emplace_back(sub) ;
	}
	vvll g(n,vll(0)) ;
	for(int i=0;i<n-1;i++){
		ll f,t ;
		cin >> f >> t ;
		f-- ; t-- ;
		g.at(f).emplace_back(t) ;
		g.at(t).emplace_back(f) ;
	}
	vll cnt(n+10,INF) ;
	cnt.at(0) = 0 ;
	cnt.at(1) = a.at(0) ;
	vll ans(n,-1) ;
	ans.at(0) = 2 ;
	for(int i=0;i<(int)g.at(0).size();i++){
		DFS(g,cnt,ans,g.at(0).at(i)) ;
	}
	for(int i=0;i<n;i++){
		cout << ans.at(i)-1 << endl ;
	}
}


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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  int n, k;
  cin >> n >> k;

  int now=1;
  rep(i,n){
    if(now*2>now+k) now+=k;
    else now *= 2;
  }
  prt(now);
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

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

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P & firstElof, const P & secondElof)
{
	return firstElof.second < secondElof.second;
}


signed main() {
	double thita = 0;
	
	double a, b, x;
	cin >> a >> b >> x;
	double pi = 3.1415926535;
	if (a * a * b / 2 <= x) {
		double joken = b / a - x / (a * a * a);
		joken *= 2;
		thita = atan(joken);
	}
	else {
		double joken = x / (a * b * b);
		joken *= 2;
		thita = atan(joken);
		thita -= pi / 2;
		thita *= -1;
	}
	thita = thita * 180 / pi;
	printf("%.10lf\n", thita);
}


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

using namespace std;

const int maxn = 100;
int n, d[maxn];

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<bitset>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<cstring>
#include<deque>
#include<chrono>
using namespace std;
#define pi 3.141592653589793238


#define MOD 1000000007
#define INF 999999999999999999 
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define f0 get<0>
#define f1 get<1>
#define f2 get<2>
typedef vector<ll> vi;
typedef vector<vi> vvi;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;
    
    
    //cin >> T;
    while (T--) {
        ll a;
        for(i = 1; i<= 5; i++){
            cin >> a;
            if(a == 0){
                cout << i;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3648
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <string.h>
#include <climits>
#include <map>
#include <stack>
#include <set>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> ii;

const int maxN = 1e6 + 2;

bool arr[26], ot[26];
string st;

bool chan(int w){
    string here = st.substr(0, w + 1);
    memset(ot, 0, sizeof(ot));
    for(char c: here){
        ot[c - 'a'] = 1;
    }
    int re = -1;
    for(int i = here.back() + 1 - 'a'; i < 26; i++){
        if(!ot[i]){
            re = i;
            break;
        }
    }
    if(re == -1) return false;
    here.back() = char('a' + re);
    cout << here << '\n';
    return true;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    cin >> st;
    
    int mi = 30;
    for(char c: st){
        arr[c - 'a'] = true;
    }
    
    for(int i = 0; i < 26; i++){
        if(!arr[i]){
            mi = i;
            break;
        }
    }
    if(30 == mi){
        for(int i = int(st.size() - 1); i >= 0; i--){
            if(chan(i))
                return 0;
        }
        cout << "-1\n";
    }
    else{
        cout << st << char(mi + 'a') << '\n';
    }
    
    
}


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

int main(){
    int N; cin >> N;
    vector <int> A(N+1);
    vector <int> B(N);
    rep(i,N+1) cin >> A[i];
    rep(i,N) cin >> B[i];
    
    long long ans=0;
    //N人の勇者チャレンジ
    rep(i,N){
        int sen=B[i]-A[i];
        if (B[i]>=A[i] && (sen < A[i+1])){//隣町の全ボスまでを倒す戦闘力がないとき
            ans=ans+A[i]+sen;
            A[i+1]-=sen;//隣町のボスにダメージを与えとく
        }
        else if (B[i]>A[i] && (sen >= A[i+1])){//隣町の全ボスも倒すことができるとき
            ans=ans+A[i]+A[i+1];
            A[i+1]=0;
        }else if (B[i]<A[i]){//最初の町の全ボスすらも倒せないとき
            ans+=B[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

x,y,z = inpm()

print(str(z) + " " + str(x) + " " + str(y))

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

int main(){
  int N;
  long long int S=0;
  cin>>N;
  vector<int> vec(N);
  
  for(int i=0;i<N;i++)
    cin>>vec.at(i);
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      S+= vec.at(i)*vec.at(j);
    }
  }
  cout<<S<<endl;
}


Measured memory_bytes: 892
from sys import stdin

N = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
A = [0] + a
B = [0]*(N+1)
putBall = []

for i in range(N, 0, -1):
    if sum(B[i::i])%2 != A[i]:
        B[i] = 1
        putBall.append("%d" % i)

print(sum(B))
print(*putBall)

Measured memory_bytes: 18480
s = input()
ans = 0
aaa = 0
for i in range(len(s)):
    if s[i] == 'A' or s[i] =='C' or s[i] == 'G' or s[i] == 'T':
        ans += 1
        aaa = max(aaa,ans)
    else:
        ans = 0
print(aaa)

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

int r,D,x;

int main(void){
    cin >> r>> D >> x;
    rep(i,10){
        x = x*r - D;
        cout << x << endl;
    }
}


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

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

int M, N;
char joi[1003][1003];
char c[2][2];
bool ok(int y, int x) {
    if (y + 1 >= M || x + 1 >= N) return 0;
    if (y < 0 || x < 0) return 0;
    int ys[] = {0, 0, 1, 1};
    int xs[] = {0, 1, 0, 1};
    rep(i, 4) {
        if (c[ys[i]][xs[i]] != joi[y + ys[i]][x + xs[i]]) {
            return 0;
        }
    }
    return 1;
}
void show() {
    rep(y, M) {
        rep(x, N) cout << joi[y][x] << " ";
        cout << endl;
    }
    cout << endl;
}
bool valid(int y, int x) {
    if (y < 0 || x < 0) return 0;
    if (y >= M || x >= N) return 0;
    return 1;
}
bool f[1003][1003];
int main() {
    cin >> M >> N;
    rep(i, M) rep(j, N) { cin >> joi[i][j]; }
    rep(i, 2) rep(j, 2) cin >> c[i][j];
    int ans = 0;
    rep(y, M) rep(x, N) {
        if (ok(y, x)) ans++;
        f[y][x] = ok(y, x);
        // printf("%d %d %d\n",y,x,ok(y,x));
    }

    string logo = "JOI";
    int maxi = 0;
    rep(y, M) rep(x, N) {
        char tmp = joi[y][x];
        rep(k, logo.size()) {
            int cnt = 0;
            joi[y][x] = logo[k];
            // show();
            for (int dy = -1; dy <= 1; dy++)
                for (int dx = -1; dx <= 1; dx++) {
                    if (!valid(y + dy, x + dx)) continue;
                    if (ok(y + dy, x + dx)) {
                        if (!f[y + dy][x + dx]) cnt++;
                    } else {
                        if (f[y + dy][x + dx]) cnt--;
                    }
                }
            //printf("%d %d %c: %d\n", y, x, logo[k], cnt);
            maxi = max(maxi, cnt);
            joi[y][x] = tmp;
        }
    }

    cout << ans + maxi << endl;
}

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1, dy = y2 - y1;
  printf("%d %d %d %d\n", x2 - dy, y2 + dx, x1 - dy, y1 + dx);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define Mod 1000000007

using namespace std;

int main() {
   ll n,k,q;cin>>n>>k>>q;
   ll a[n];
   for(ll i=0;i<n;i++)a[i]=k-q;
   while(q--){
       ll x;cin>>x;
       a[x-1]++;
   }
   for(ll i=0;i<n;i++){
       if(a[i]>0)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
   }
}

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

int main(){
    string s,t;
    cin >> s >> t;
    char tmp;
    string ans="No";

    for(int i=0; i<s.size(); i++){
        if(s==t){
            ans="Yes";
            break;
        }
        else{
            tmp=s.at(0);
            for(int j=0; j<s.size()-1; j++){
                s.at(j)=s.at(j+1);
            }
            s.at(s.size()-1)=tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N - R*i; j++) {
      int k = N - R*i - G*j;
      if (k >= 0 && k%B == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream> //JOI 2012 ???2
using namespace std;
int main(void) {
	int n, game[201][3], ten[201] = { 0 };
	cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> game[i][j];
		}
	}
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < n;j++) {
			for (int k = 0;k < n;k++) {
				if (k!=j){
					if (game[j][i] == game[k][i]) {
						break;
					}
				}
				if (k == n - 1) {
					ten[j] += game[j][i];
				}
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << ten[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3056
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] n = Console.ReadLine().Split();
        bool[] flag = new bool[4];
        for (int i = 0; i < 4; i++)
        {
            if (n[i] == "1") flag[0] = true;
            else if (n[i] == "9") flag[1] = true;
            else if (n[i] == "7") flag[2] = true;
            else if (n[i] == "4") flag[3] = true;
        }
        for (int i = 0; i < 4; i++)
        {
            if (!flag[i])
            {
                Console.WriteLine("NO");
                return;
            }
        }
        Console.WriteLine("YES");
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int N;
	scanf("%d", &N);
	PRINTD(0);
	fflush(stdout);
	char s[10],ts[10];
	scanf("%s", &s);
	strcpy(ts, s);
	int i = 0;
	int l = 1, r = N - 1;
	while (strcmp(s,"Vacant") != 0 && i < 20) {
		//printf("l=%d,r=%d\n", l, r);
		i++;
		int m = (l + r) / 2;
		PRINTD(m);
		fflush(stdout);
		scanf("%s", &s);
		if (((m-l+1)%2==0 && strcmp(s, ts) == 0) || ((m - l + 1) % 2 != 0 && strcmp(s, ts) != 0)) {
			l = m + 1;
			strcpy(ts, s);
		}
		else {
			r = m - 1;
		}
		//printf("s=%s ts=%s\n", s, ts);
	}
}

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

bool cmp(const pair<int,int> &f,const pair<int,int> &s)
{
	return f.second>s.second;
}

int main()
{
	int N;
	int v[100010]={};
	map<int,int> m;
	vector<pair<int,int>> even,odd;
	int f,s;
	int ans=0;
	
	cin >> N;
	for(int i=0;i<N;i++)
		cin >> v[i];
	
	//even
	for(int i=0;i<N;i+=2)
		m[v[i]]++;
	for(auto&& i:m)
		even.push_back({i.first,i.second});
	//odd
	m.clear();
	for(int i=1;i<N;i+=2)
		m[v[i]]++;
	for(auto&& i:m)
		odd.push_back({i.first,i.second});
	
	if(even.size()==1 && odd.size()==1)
	{
		if(even[0].first==odd[0].first)
			cout << N/2 << endl;
		else
			cout << 0 << endl;
		return 0;
	}
	
	sort(even.begin(),even.end(),cmp);
	sort(odd.begin(),odd.end(),cmp);
	
	for(int i=0,j=0;i<even.size() && odd.size();)
	{
		f=even[i].first;
		s=odd[j].first;
		if(f!=s)break;
		if(even[i].second>odd[j].second)
			j++;
		else if(even[i].second<odd[j].second)
			i++;
		else
		{
			if(even[i+1].second>=odd[j+1].second)
				i++;
			else
				j++;
		}		
	}
	
	//even
	for(int i=0;i<N;i+=2)
		if(v[i]!=f)ans++;
	for(int i=1;i<N;i+=2)
		if(v[i]!=s)ans++;
	
	cout << ans << endl;
	return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  vector<double> kakuritu(1010);
  vector<double> atai(n);
  for(int i=0;i<n;i++){
    cin >> atai.at(i);//値入力
  }
  int x = *max_element(atai.begin(),atai.end());
  for(int j=1;j<x+1;j++){
    kakuritu.at(j-1) = (1+j)/2.0;//各々の期待値をkakurituに収納
  }
  for(int i=0;i<n;i++){
    atai.at(i) = kakuritu.at(atai.at(i)-1);
  }
  double ans = 0;
  for(int i=0;i<k;i++){
    ans += atai.at(i);//先頭からkまでの足し算
  }
  double max1 = ans;
  for(int i=k;i<n;i++){
    ans = ans + atai.at(i) - atai.at(i-k);
    max1 = max(ans,max1);
  }
  cout << setprecision(10) << max1 << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::string s;std::cin>>s;
    s.pop_back();
    if(s.length()%2)s.pop_back();
    while(true){
        lint n=s.length()/2;
        for(lint i=0;i<=n;i++){
            if(i==n){
                std::cout<<2*i<<'\n';
                return 0;
            }
            if(s.at(i)!=s.at(n+i))break;
        }
        s.pop_back();
        s.pop_back();
    }
}


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

ll A,B,C,D;
map<ll,ll> memo;

ll dfs(ll x){
    if(x==0) return 0;
    if(x==1) return D;
    if(memo.count(x) ) return memo[x]; 
    ll res = 1e18+10;

    ll l2 = (x/2)*2;
    ll r2 = ((x+1)/2)*2;
    ll l3 = (x/3)*3;
    ll r3 = ((x+2)/3)*3;
    ll l5 = (x/5)*5;
    ll r5 = ((x+4)/5)*5;

    if(x < res/D) res = x*D;
    res = min(res, dfs(l2/2) + A + D * llabs(l2-x) );
    res = min(res, dfs(r2/2) + A + D * llabs(r2-x) );
    res = min(res, dfs(l3/3) + B + D * llabs(l3-x) );
    res = min(res, dfs(r3/3) + B + D * llabs(r3-x) );
    res = min(res, dfs(l5/5) + C + D * llabs(l5-x) );
    res = min(res, dfs(r5/5) + C + D * llabs(r5-x) );
    
    memo[x] = res;
    return res;
}

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

    vector<ll> ans;
    rep(i,T){
        memo.clear();
        ll N;
        cin >> N >> A >> B >> C >> D;
        ans.push_back(dfs(N) );
    }

    for(auto a : ans){
        cout << a << endl;
    }

}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int main() {
	int N, K;
	cin >> N >> K;
	vector<ll> A(N), B(N);
	ll sum = 0;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		sum += A[i];
	}
	vector<ll> Y;
	ll sq = sqrt(sum);
	for (int i = 1;i <= sq;i++) {
		if (sum%i == 0) {
			Y.push_back(i);
			Y.push_back(sum / i);
		}
	}
	sort(all(Y));
	reverse(all(Y));
	for (ll y : Y) {
		ll cnt = sum / y, ans = 0;
		for (int i = 0;i < N;i++) {
			cnt -= A[i] / y;
			B[i] = A[i] % y;
		}
		sort(all(B));
		reverse(all(B));
		for (int i = 0;i < cnt;i++) {
			ans += y - B[i];
		}
		if (ans <= K) {
			cout << y << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N,x = map(int,input().split())
    a = [0] + list(map(int,input().split()))
    
    ans = 0
    eat = 0
    for i in range(N):
        eat += a[i+1]
        if eat > x:
            a[i+1] -= eat-x
            ans += eat-x
            eat = x
        eat -= a[i]
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 58224
"""
References
----------
https://atcoder.jp/contests/abc149/submissions/9219652
"""
def solve(n, k, r, s, p, t):
    score = 0
    mapping = {"r": p, "s": r, "p": s}
    t = list(t)
    for i in range(k):
        score += mapping[t[i]]
    for i in range(k, n):
        if t[i] == t[i-k]:
            t[i] = "x"
        else:
            score += mapping[t[i]]
    return score

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
print(solve(n, k, r, s, p, t))

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

#define inRange(x,a,b) (a <= x && x < b)

typedef long long ll;

const ll mod = 1e9+7;
ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

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

void ng(){
    cout << 0 << endl;
    exit(0);
}

int main(){
    string zaki, o;
    int n;
    cin >> zaki >> o >> n;

    if(n <= o.length()){
        string hoge = o.substr(o.length()-n);
        reverse(hoge.begin(), hoge.end());
        string s = hoge + zaki + hoge + o;
        cout << isPalindrome(s) << endl;
        return 0;
    }

    map<int, char> ind;
    for(int i = 0; i < o.length(); i++) ind[i] = o[o.length()-1-i];

    ll len = n + zaki.length() + n + o.length();

    for(int i = 0; i < zaki.length(); i++){
        ll index = n + i;
        ll inv = len - 1 - index;
        if(inRange(inv, n, n+zaki.length()) && zaki[inv-n] != zaki[i]){
            ng();
        }else if(inRange(inv, n+zaki.length(), n+zaki.length()+n)){
            if(ind.count(inv-n-zaki.length()) == 1 && ind[inv-n-zaki.length()] != zaki[i]){
                ng();
            }
            ind[inv-n-zaki.length()] = zaki[i];
        }
    }

    ll ret = modpow(26, (n-ind.size()+1)/2);
    cout << ret << endl;
    return 0;
}


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

#define MAXN 5000
#define MAXM 1010
#define pos(x) (1<<((x)-1))

int n,m,f[MAXN],cost[MAXN],t[MAXN];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)
	{
		int x;
		scanf("%d%d",cost+i,&x);
		for(int j=1;j<=x;++j)
		{
			int p;
			scanf("%d",&p);
			t[i]|=pos(p);
		}
	}
	for(int i=1;i<(1<<n);++i)f[i]=1000000000;
	for(int i=0;i<(1<<n);++i)
		for(int j=1;j<=m;++j)
			f[i|t[j]]=min(f[i|t[j]],f[i]+cost[j]);
	printf("%d\n",f[(1<<n)-1]==1000000000?-1:f[(1<<n)-1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 200005;

int pos[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        --a;
        pos[a] = i;
    }
    set<int> st;
    ll ans = 0;
    rep(i,n){
        auto it = st.lower_bound(pos[i]);
        ll l,r;
        if(it == st.end()){
            if(it == st.begin()){
                ans += (ll)(i+1)*(pos[i]+1)*(n-pos[i]);
            }else{
                it--;
                l = *it;
                ans += (ll)(i+1)*(pos[i]-l)*(n-pos[i]);
            }
        }else if(it == st.begin()){
            r = *it;
            ans += (ll)(i+1)*(pos[i]+1)*(r-pos[i]);
        }else{
            r = *it;
            it--;
            l = *it;
            ans += (ll)(i+1)*(pos[i]-l)*(r-pos[i]);
        }
        st.insert(pos[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10368
#include <cstdio>
#define maxn 100005
#define ANS_MOD 1000000007ull
#define MOD 13
using namespace std;

typedef unsigned long long ULL;

char s[maxn];
ULL dp[maxn][MOD];

int main(int argc, char** argv)
{
	ULL res = 0ull;
	char c;
	dp[0][0] = 1ull;
	int i = 0;
	while((c = getchar()) != '\n')
	{
		int digit;
		if(c == '?') digit = -1;
		else digit = c - '0';
		for(int j=0; j<10; j++)
			if(digit == -1 || digit == j)
				for(int k=0; k<MOD; k++)
				{
					ULL& x = dp[i + 1][(k * 10 + j) % MOD];
					x += dp[i][k];
					x %= ANS_MOD;
				}
		i ++;
	}
	res = dp[i][5];
	printf("%llu\n", res);
	return 0;
}

Measured memory_bytes: 11732
import sys
from heapq import heappush
from heapq import heappop


# 入力
n_V, n_E, r = map(int, input().split())

E = [[] for _ in range(n_V)]
for i in range(n_E):
    v, e, c = map(int, input().split())
    E[v].append((e, c))


# 初期化
D = [sys.maxsize for _ in range(n_V)]
D[r] = 0

h = []
heappush(h, (D[r], r))


#　各頂点への最短距離を求める処理
while len(h) != 0:
    _, index = heappop(h)

    for e, c in E[index]:
        d = D[index] + c
        if D[e] > d:
            D[e] = d
            heappush(h, (d, e))


# 出力
for d in D:
    if d == sys.maxsize:
        print('INF')
    else:
        print(d)



Measured memory_bytes: 89288
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > piii;
#define pb push_back
#define debug(x) cout << x << endl
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define PI acos(-1)
#define all(c) c.begin(), c.end()
#define SET(x, y) memset((x), y, sizeof(x))
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const LL INF64 = 1e18;

const int N = 1e5 + 5;

int n, w;
LL val[105], wt[105];
LL dp[105][100005]; // N, val;

int main() {
    fastio;
    cin >> n >> w;
    for (int i = 1; i <= n; i++)
        cin >> wt[i] >> val[i];

    for (int i = 0; i < 100005; i++) {
        dp[0][i] = INF64;
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 100005; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - val[i] < 0)
                continue;
            dp[i][j] = min(dp[i][j], dp[i - 1][j - val[i]] + wt[i]);
        }
    }
    // debug("te");
    for (int i = 100004; i >= 0; i--) {
        if (dp[n][i] <= w) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}
        

Measured memory_bytes: 80128
package main

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

type bufReader struct {
	r   *bufio.Reader
	buf []byte
	i   int
}

var reader = &bufReader{
	bufio.NewReader(os.Stdin),
	make([]byte, 0),
	0,
}

func (r *bufReader) readLine() {
	if r.i < len(r.buf) {
		return
	}
	r.buf = make([]byte, 0)
	r.i = 0
	for {
		line, isPrefix, err := r.r.ReadLine()
		if err != nil {
			panic(err)
		}
		r.buf = append(r.buf, line...)
		if !isPrefix {
			break
		}
	}
}

func (r *bufReader) next() string {
	r.readLine()
	from := r.i
	for ; r.i < len(r.buf); r.i++ {
		if r.buf[r.i] == ' ' {
			break
		}
	}
	s := string(r.buf[from:r.i])
	r.i++
	return s
}

func (r *bufReader) nextLine() string {
	r.readLine()
	s := string(r.buf[r.i:])
	r.i = len(r.buf)
	return s
}

var writer = bufio.NewWriter(os.Stdout)

func next() string {
	return reader.next()
}

func nextInt64() int64 {
	i, err := strconv.ParseInt(reader.next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func nextInt() int {
	return int(nextInt64())
}

func nextLine() string {
	return reader.nextLine()
}

func out(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	return int(max64(int64(x), int64(y)))
}

func min64(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

func min(x, y int) int {
	return int(min64(int64(x), int64(y)))
}

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func abs(x int) int {
	return int(abs64(int64(x)))
}

func joinInt64s(a []int64, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.FormatInt(v, 10)
	}
	return strings.Join(b, sep)
}

func joinInts(a []int, sep string) string {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func divUp64(x, y int64) int64 {
	return (x + y - 1) / y
}

func divUp(x, y int) int {
	return int(divUp64(int64(x), int64(y)))
}

func gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func gcd(x, y int) int {
	return int(gcd64(int64(x), int64(y)))
}

func lcm64(x, y int64) int64 {
	return x * y / gcd64(x, y)
}

func lcm(x, y int) int {
	return int(lcm64(int64(x), int64(y)))
}

func pow64(x, y int64) int64 {
	return int64(math.Pow(float64(x), float64(y)))
}

func pow(x, y int) int {
	return int(pow64(int64(x), int64(y)))
}

func main() {
	solve()
	writer.Flush()
}

func solve() {
	out(strings.Replace(nextLine(), ",", " ", 2))
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  long a,b,c,d,e,n,k,t;
  cin >> n >> a >> b >> c >> d >> e;
  k=min({a,b,c,d,e});
  t=4+(n+k-1)/k;
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a, b, c, k;
	while(cin >> a >> b >> c >> k) {
		cout << (a >= k || a + b >= k ? min(a, k) : a - (k - (a + b))) << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
struct book{
    int wilde;
    int weight;
    void operator =(book a){
        wilde+=a.wilde;
        weight+=a.weight;
        return ;
    }
    void in(){
        scanf("%d%d",&wilde,&weight);
        return ;
    }
    book operator +(book a){
        return {wilde+a.wilde,weight+a.weight};
    }
    void init(){
        wilde=weight=0;
        return ;
    }
    void operator +=(book a){
        wilde+=a.wilde;
        weight+=a.weight;
        return ;
    }
    book operator -(book a){
        return {wilde-a.wilde,weight-a.weight};
    }
};
bool fitin(book b,book a){
    return a.weight>=b.weight&&a.wilde>=b.wilde;
}
const int N=2e5+10;
book s[N];
int n;
int find(int from,book shelf){
    if(!fitin(s[from]-s[from-1],shelf))return from-1;
    int r=n,mid,l=from;
    while(r-l>1){
        mid=(l+r)>>1;
        if(fitin(s[mid]-s[from-1],shelf))l=mid;
        else r=mid;
    }
    if(fitin(s[r]-s[from-1],shelf))return r;
    return l;
}
int max(int a,int b){return a>b?a:b;}
int main(){
    int m,top,dp[N];
    book shelf[20];
    scanf("%d%d",&n,&m);
    s[0].init();
    for(int i=1;i<=n;i++){
        s[i].in();
        s[i]+=s[i-1];
    }
    for(int i=0;i<m;i++)shelf[i].in();
    top=1<<m;
    dp[0]=0;
    for(int i=1;i<top;i++){
        dp[i]=0;
        for(int j=0;j<m;j++)if(i&(1<<j))dp[i]=max(dp[i],find(dp[i^(1<<j)]+1,shelf[j]));
    }
    printf("%d\n",dp[top-1]);
}


Measured memory_bytes: 4412
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod = 998244353

	pow := func(x, n int) int {
		x %= mod
		res := 1
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}
	inv := func(a int) int { return pow(a, mod-2) }
	const mx int = 3e5
	F := [mx + 1]int{1}
	invF := [mx + 1]int{inv(1)}
	for i := 1; i <= mx; i++ {
		F[i] = F[i-1] * i % mod
		invF[i] = inv(F[i])
	}
	comb := func(n, k int) int { return F[n] * invF[k] % mod * invF[n-k] % mod }

	var n, m, k, ans int
	Fscan(in, &n, &m, &k)
	for i := 0; i <= k; i++ {
		v := m
		v = v * comb(n-1, i) % mod
		v = v * pow(m-1, n-1-i) % mod
		ans = (ans +v) % mod
	}
	Fprint(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }


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


int main(){
  int a,b ;
  cin >> a >> b;
  if(a < b){
    for(int i = 0;i<b;i++){
      cout << a;
    }
    cout << endl;
  }else{
      
    for(int i = 0;i<a;i++){
      cout << b;
    }
    cout << endl;

  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 100010;

string n;
int32_t main() {
	cin >> n;
	
	int sum = 0;
	for (int i =0;i< (int) n.length();i++) {
		sum += (n[i] - '0');
	}
	
	if (sum % 9 == 0) cout << "Yes";
	else cout << "No";
}


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



int main(){
  int N;
  cin>>N;
  
  int64_t sum=0;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0) sum+=i;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    let ans: i32 = if a - b*2 > 0 {
        a - b*2
    } else {
        0
    };
    println!("{}", &ans);
}


Measured memory_bytes: 4352
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let n = get!(usize);
    let mut ds = get!([usize]);

    ds.sort();

    println!("{}", ds[n / 2] - ds[n / 2 - 1]);
}


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

int main(){

	int n, cnt;
	
	while(cin >> n){
		if(n == 0) break;
		cnt = 0;
		
		if(n == 1){
			cout << '0' << endl;
			continue;
		} 
		
		while(1){
			if(n % 2 == 0) n /= 2;
			else n = 3 * n + 1;
			cnt++;
			if(n == 1) break;
		}
		
		cout << cnt << endl;
	}

	return 0;

}

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

using namespace std;

const int N = 1000 * 100 + 10; 
int T[N];
int H[N];

#define INF 10000000001

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

	for(int i = 1; i <= n; i ++){
		T[i] = INF;
		int hi; 
		cin >> hi;
		H[i] = hi;
	}
	T[1] = 0;

	for(int i = 1; i <= n; i++){
		T[i+1] = min(T[i+1], abs(H[i +1] - H[i]) + T[i]);
		T[i+2] = min(T[i+2], abs(H[i +2] - H[i]) + T[i]);
	}

	cout << T[n];

	//int s; cin >> s;
	return 0;
}

Measured memory_bytes: 1024
<?php
fscanf(STDIN,"%d %d",$N,$K);
$S=strval(trim(fgets(STDIN)));
$length = strlen($S);
$array = [];

//1,0が何個連続するかの配列作成
while(substr($S,0,1) !== false){
  if(substr($S,0,1) === "1"){
    if(strpos($S,"0") === false){
      $array[] = strlen($S);//1
      $array[] = 0;//0
      break;
    }else{
      $S = substr($S,strpos($S,"0"),strlen($S)-1);
      $array[] = $length-strlen($S);//1
      $length = strlen($S);
    }
  }else{
    $array[] = 0;//1
  }
  if(substr($S,0,1) === "0"){
    if(strpos($S,"1") === false){
      $array[] = strlen($S);//0
      break;
    }else{
      $S = substr($S,strpos($S,"1"),strlen($S)-1);
      $array[] = $length-strlen($S);//0
      $length = strlen($S);
    }  
  }else{
    $array[] = 0;//0
  }
}

$size = count($array);
//配列の大きさの半分以上の回数指示できれば全員逆立ちできる
if($K>=$size/2){
  $max = $N;
}else{
  //初期値計算
  $value = 0;
  for($i=0;$i<$K*2+1;$i++){
    $value += $array[$i];
  }
  $max = $value;
  $value -= $array[0]+$array[1];
  //逆立ちの最大値を求める(尺取法)
  for($i=2;$i<$size-$K*2+1;$i+=2){
    //最後のみ次の値がないので足す回数が1回のみ
    if($i===$size-$K*2){
      $value += $array[$i+$K*2-1];
    //次の値を足す(尺の右側を進める)
    }else{
      $value += $array[$i+$K*2-1]+$array[$i+$K*2];
    }
    //最大値更新
    if($value > $max){
      $max = $value;
    }
    //尺の左側を進める
    $value -= $array[$i]+$array[$i+1];
  }
}
echo $max;

Measured memory_bytes: 19852
"""Partition."""

def partition(A, p, r):
    """Divide list A into A[p:q-1] whose elements aren't greater than A[q] and
    A[q+1:r] whose elements are greater than A[q].

    Default value of p is 0.
    The number as a refernce of the division is A[r].
    
    Return the index q.
    """

    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i + 1], A[r] = A[r], A[i + 1]
    return i + 1


r = int(input()) - 1

A = list(map(int, input().split()))

q = partition(A, 0, r)

print(*A[0:q], end = ' ')
print('[{0}]'.format(A[q]), end = ' ')
print(*A[q + 1:])

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

#define fi first
#define se second

typedef long long ll;


using namespace std;

void solve(){
  string t;
  bool n = 0, e = 0, w = 0, s = 0;
  cin >> t;

  for(int i=0;i<t.size();i++){
    if(t[i] == 'N')n = 1;
    if(t[i] == 'W')w = 1;
    if(t[i] == 'S')s = 1;
    if(t[i] == 'E')e = 1;
  }
  if(n == s && w == e){
    cout << "Yes";
  }
  else cout << "No";
}

int main(){
  int tt = 1;
  while(tt--){
    solve();
  }

return 0;
}


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

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

	for(int n, a, b; cin >> n >> a >> b && n;) {
		if(a < b) swap(a, b);

		int cnt = 0;
		int i = 1;
		vector<bool> ok(b, false);
		ok[0] = true;
		for(int x = 1; x <= n; ++x) {
			if(i * a <= x) {
				ok[(i * a) % b] = true;
				++i;
			}

			cnt += ok[x % b];
		}

		cout << n - cnt << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1192
import sys
input = lambda: sys.stdin.readline().rstrip() 
from collections import deque

def resolve():
    S = input()
    Q = int(input())
    Query = [input().split() for _ in range(Q)]

    S_deque = deque()
    for s in S:
        S_deque.append(s)
 
    is_reversed = False
    for q in Query:
        if q[0]=='1':
            is_reversed = not is_reversed
        elif q[0]=='2':
            if (not is_reversed and q[1]=='1') or (is_reversed and q[1]=='2'):
                S_deque.appendleft(q[2])
            else:
                S_deque.append(q[2])

    if is_reversed:
        S_deque.reverse()

    print(*S_deque, sep='')

if __name__ == '__main__':
    resolve()


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

const int MAX_N = 10100;
const int inf = 1e8;

int idx[MAX_N];


int main(){
 int N,M; scanf("%d %d", &N,&M);
 string S; cin >> S;
 
 vector<int> ans;
 
 int pos = N;
 
 while( pos > 0 ) {
  ans.push_back(pos);
  bool flag = true;
  for(int i = min(M,pos); i >= 1; i--){
   if( S[pos-i] == '0'){ pos -= i; flag = false; break;}
   }
   if(flag){ cout << -1 << endl; return 0;}
 }
 
 ans.push_back(0);
 
 reverse(ans.begin(),ans.end());
 
 for(int i = 0; i < (int)ans.size()-1; i++){
  printf("%d ", ans[i+1]-ans[i]);
  }
  
  cout << endl;
  
  return 0;
 }

Measured memory_bytes: 1144
import math

prime = [False] * (10 ** 6)
prime[0] = True
prime[1] = True

limit = int(math.sqrt(10 ** 6) + 1)

for i in range(2, limit):
    if prime[i] == False:
        for j in range(i * 2, 10 ** 6, i):
            prime[j] = True

while True:
    a, d, n = map(int, raw_input().split())

    if a == 0:
        break

    cnt = 0
    for i in range(a, 10 ** 6, d):
        if prime[i] == False:
            cnt += 1
        if cnt == n:
            print i
            break

Measured memory_bytes: 45892
(let ((n (read))
    (a 0)
    (ans "No"))

    (loop for i below n do
        (progn
            (if (= (read) (read))
                (incf a)
                (setq a 0)
            )
            (if (= a 3)
                (progn
                (setq ans "Yes")
                (return)
                )
            )
        )
    )
    (format t "~A~%" ans)
)

Measured memory_bytes: 23600
#include<stdio.h>

int main(){
  int i,j;
  char map[8][9];
  for(i=0;i<8;i++) scanf("%s",map[i]);
  printf("90\n");
  for(i=0;i<8;i++){
    for(j=7;j>-1;j--){
      printf("%c",map[j][i]);
    }
    printf("\n");
  }
  printf("180\n");
  for(i=7;i>-1;i--){
    for(j=7;j>-1;j--){
      printf("%c",map[i][j]);
    }
    printf("\n");
  }
  printf("270\n");
  for(i=7;i>-1;i--){
    for(j=0;j<8;j++){
      printf("%c",map[j][i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int s = S.size() - 1;
  if(S[s] == 's'){
    cout << S << "es" << endl;
  }
  else{
    cout << S << "s" << endl;
  }
}

Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	nums := map[int]bool{}
	var a int
	i := 0
	for i < n {
		i++
		fmt.Scan(&a)
		if _, ok := nums[a]; ok {
			delete(nums, a)
		} else {
			nums[a] = true
		}
	}
	fmt.Println(len(nums))
}

Measured memory_bytes: 5504
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a,b,c = sc.nextInt
  val res = if(a < b && b < c) "Yes"
  else "No"
  println(res)

// 結果
// List(List(123, 456, 789), List(111, 222, 333), List(1, 2, 3), List(63, 72, 81), List(100, 200, 300))
}


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

string s;
int sum;
int res;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		sum += s[i] - '0';
	}
	res = max(s[0] - '0' - 1 + ((int)s.size() - 1) * 9, sum);

	cout << res << endl;

}

Measured memory_bytes: 256
N = int(input())
NR = int(N**0.5)
count = 0
if int(N/2)-N/2 == 0:
    for i in range(1,int(N/2)):
        if int(N/i)-N/i == 0:
            count += int(N/i)-1
        else:
            count += int(N/i)
else:
    for i in range(1,int(N/2)+1):
        if int(N/i)-N/i == 0:
            count += int(N/i)-1
        else:
            count += int(N/i)

count += int(N/2)
print(count)

Measured memory_bytes: 9464
n = int(input())
b = list(map(int, input().split()))

ans = []
while True:
    num = 0
    for i in range(len(b)):
        if b[i] == i + 1:
            num = i + 1
    else:
        if num == 0:
            print("-1")
            quit()
        else:
            ans.append(b[num - 1])
            del b[num - 1]
    if b == []:
        break


for i in ans[::-1]:
    print(i)

Measured memory_bytes: 3064
x=[0,0,0]
for i in range(3):
    x[i]=list(map(int, input().split()))
    
l=abs(x[0][0]-x[1][0])
v=x[0][1]-x[1][1]
if l>v*x[2][0]:
    print('NO')
else:
    print('YES')

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

using namespace std;

int main()
{
	//
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	int st[n];
    for(int i=0; i<n; i++) cin>>st[i];
    vector<int> dp(n, 0);
	dp[0] = 0;
	dp[1] = abs(st[1] - st[0]);
	for(int i=2; i<n; i++){
		dp[i] = min((dp[i-1]+abs(st[i]-st[i-1])), (dp[i-2]+abs(st[i]- st[i-2])));
	}
	cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 4008