akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;

str sub_problem(str sub_t, ll mod_k, ll start){
    str sub_prob;
    for(ll i=start; i<sub_t.length(); i+=mod_k){
        sub_prob = sub_prob + sub_t[i];
    }
    return sub_prob;
}

int main(){
    ll n, k; cin >> n >> k;
    ll r, s, p; cin >> r >> s >> p;
    str t; cin >> t;
    ll ans = 0;
    str tmp;
    map<char, ll> point;
    point['r'] = p;
    point['s'] = r;
    point['p'] = s;
    map<char, char> rsp;
    rsp['r'] = 's';
    rsp['s'] = 'p';
    rsp['p'] = 'r';
    // 貪欲法
    for (ll i=0; i<k; i++){
        tmp = sub_problem(t, k, i);
        char memory = 'q';
        for(ll j=0; j<tmp.length(); j++){
            if(tmp[j] != memory){
                ans += point[tmp[j]];
                memory = tmp[j];
            }else if(j != tmp.length()){
                memory = rsp[tmp[j+1]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 968
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def fib_memo(n):
    if n <= 1:
        return 1
    memo = [0] * n
    memo[0] = 1
    memo[1] = 2
    for i in range(2, n):
        memo[i] = (memo[i - 1] + memo[i - 2]) % PRIME
    return memo[n-1]

PRIME = 10 ** 9 + 7
N, M = list(map(int, input().split()))
broken_stairs = []
for _ in range(M):
    broken_stairs.append(int(input()))

prev_broken = -1
cannot = False
ans = 1
for a in broken_stairs:
    if a - prev_broken == 1:
        cannot = True
        break
    ans *= fib_memo(a - prev_broken - 2)
    ans %= PRIME
    prev_broken = a

ans *= fib_memo(N - prev_broken - 1)
ans %= PRIME

if cannot:
    print(0)
else:
    print(ans)


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

#define rep(i,start,n) for(int i=start;i<(int)(n);i++)
#define rrep(i,n,end) for(int i=n-1;i>=end;i--)
#define each(it,v) for(auto it : v)
#define all(v) (v).begin(),(v).end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using vpii = vector<Pii>;
using vpll = vector<Pll>;

const ll mod=1e9+7;
const int intINF=INT_MAX;
const ll  longINF=LONG_LONG_MAX;

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

        ll ans=0;

        vi v(n);
        each(&it,v)cin>>it;

        rep(i,0,n-1)
        {
                if(v[i]%2==1)
                {
                        if(v[i+1]>0)
                        {
                                v[i]--;
                                v[i+1]--;
                                ans++;
                        }
                }
        }

        rep(i,0,n)
        {
                ans+=v[i]/2;
        }

        //each(it,v)cout<<it<<endl;

        cout<<ans<<endl;

}

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

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

    string s, t;
    cin>>s>>t;

    int ans = 0;

    for(int i=0;i<s.length();i++ ) {
        if(s[i] != t[i])
         ans++;
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int n;
  cin>>n;
  int k=1;
  for(int i=0;i<n;i++){
    k*=i+1;
    k%=1000000007;
  }
  cout<<k<<endl;
}


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





int main(){

    ll a,b,k;

    cin >> a >> b>> k;
    if(a>=k){
        a-=k;
        cout << a << endl;
        cout << b << endl;
        return 0;
    }
    else{
        k-=a;
        a=0;
        if(b>=k){
            b-=k;
        cout << a << endl;
        cout << b << endl;
        return 0;
        }
        b=0;
        cout << a << endl;
        cout << b << endl;
        return 0;

    }
    return 0;
}


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

int main() {
 int n,t,ans=100000;
  cin >> n >> t;
  vector<pair<int,int>> p(n);
  for(int i=0;i<n;i++){
  cin >> p[i].first >> p[i].second;
    if(p[i].second<=t){
    ans=min(ans,p[i].first);
    }
  }
  
  if(ans!=100000)cout << ans << endl;
  else cout << "TLE" << endl;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input())
a = list(map(int,input().split()))
count = i = 0


for i in range(200):
    hantei = True
    
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
        else :
            hantei = False
            break

    if hantei:
        count += 1
    else:
        break


print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
signed main(){
    int n,k;cin>>n>>k;
    string s;cin>>s;
    s[k-1]=((s[k-1]=='A')?'a':((s[k-1]=='B')?'b':'c'));
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

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

	if (b + c > a)
		cout << b + c - a;
	else
		cout << 0;
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
// Aizu 1125: Get Many Persimmon Trees
// 2017.9.15 bal4u@uu

#include <stdio.h>
#include <string.h>

char map[105][105];
int  sum[105][105];

int main()
{
	int n, w, h, x, y, s, t, i, k, ans;

	while (scanf("%d", &n) && n) {
		memset(map, 0, sizeof(map));
		scanf("%d%d", &w, &h);
		for (i = 0; i < n; i++) scanf("%d%d", &x, &y), map[y][x] = 1;
		for (y = 1; y <= h; y++) for (sum[y][0] = 0, x = 1; x <= w; x++)
			sum[y][x] = sum[y][x-1] + map[y][x];
		scanf("%d%d", &s, &t);
		for (ans = 0, y = 0; y <= h-t; y++) for (x = 0; x <= w-s; x++) {
			for (k = 0, i = 1; i <= t; i++) k += sum[y+i][x+s] - sum[y+i][x];
			if (k > ans) ans = k;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1796
#include<iostream>
#include<queue>

using namespace std;

int main()
{
	priority_queue<int> maxHeap;
	char s[10];
	int x;
	cin >> s;
	while (s[2] != 'd')
	{
		if (s[0] == 'i')
		{
			cin >> x;
			maxHeap.push(x);
		}
		if (s[0] == 'e')
		{
			cout << maxHeap.top() << endl;
			maxHeap.pop();
		}
		cin >> s;
	}
}


Measured memory_bytes: 6996
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64

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

  int cnt=0,ans=-1;
  for(auto &&mi: mp){
    cnt += mi.second;
    if(cnt>=k) {
      ans = mi.first;
      break;
    }
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  string s,t;
  cin >> s >> t;

  bool f; int index = -1;
  for(int i = s.size()-t.size(); i >= 0; i--){
    f = true;
    REP(j,t.size()){
      if(s[i+j] != '?' && s[i+j] != t[j]) f = false;
    }
    if(f){
      index = i;
      break;
    }
  }
  
  if(f){
    REP(i,t.size()){
      s[i+index] = t[i];
    }
    REP(i,s.size()){
      if(s[i] == '?') s[i] = 'a';
    }
    
    cout << s << endl;
  }
  
  else cout << "UNRESTORABLE" << endl;

 return 0;
}

Measured memory_bytes: 256
//stay hungry, stay foolish
//#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define loopi(stop) for(int i=0; i<stop; i++)
#define loopj(stop2) for(int j=0; j<stop2; j++)
#define loopk(stop3) for(int k=0; k<stop3; k++)
#define loopi1(stop) for(int i=1; i<=stop; i++)
#define loopj1(stop2) for(int j=1; j<=stop2; j++)
#define loopk1(stop3) for(int k=1; k<=stop3; k++)
#define loopse(kt,sstart, eend) for(int kt = sstart; kt<eend; kt++)
#define faster_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file_io_cf freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define p_b push_back
#define pii pair<int,int>
#define fi first
#define se second
#define prec_10 << fixed << setprecision(10)
#define DEB cout<<"DEBUG"<<'\n';
#define SRAND srand(time(0));
#define rev_comp  greater<int>()
using namespace std;

template <typename T>
void O(T x){
    cout<<x<<'\n';
}


vector <int> graph[100001];
int dp[100001] = {0};
int vis[100001] = {0};

int dfs(int src){

    if(vis[src] == 1){
        return dp[src];
    }

    vis[src]++;

    int maxl = 0;

    for(int child : graph[src]){
        maxl = max(maxl, dfs(child)+1);
    }

    dp[src] = maxl;

    return dp[src];
}


int32_t main(){
    
    faster_io
    // file_io_cf

    int n,m;cin>>n>>m;

    int a,b;
    loopi(m){
        cin>>a>>b;
        graph[a].p_b(b);
    }

    int maxl = 0;

    loopi1(n){
        maxl = max(maxl, dfs(i));
    }

    O(maxl);

    return 0;
}


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

const int N = 210;

char mat[N][N];
int color[N];
int n;
bool flag = true;
bool vis[N];

void dfs(int u){
    for (int i = 1; i <= n; ++ i){
        if (mat[u][i] == '1'){
            if (color[i] == -1){
                color[i] = color[u] ^ 1;
                dfs(i);
            }
            else{
                if (color[i] == color[u]){
                    flag = false;
                }
            }
        }
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i){
        scanf("%s", mat[i] + 1);
    }
    memset(color, -1, sizeof(color));
    color[1] = 0;
    dfs(1);
    if (!flag){
        puts("-1");
        return 0;
    }
    int max = 0;
    for (int i = 1; i <= n; ++ i){
        memset(vis, 0, sizeof(vis));
        int cnt = 0;
        vis[i] = true;
        std::vector <int> todo = {i};
        while (!todo.empty()){
            ++ cnt;
            std::bitset <N> tmp;
            for (auto u : todo){
                for (int j = 1; j <= n; ++ j){
                    if (mat[u][j] == '1' && !vis[j]){
                        tmp[j] = true;
                    }
                }
            }
            std::vector <int> ntodo;
            for (int j = 1; j <= n; ++ j){
                if (tmp[j]){
                    ntodo.push_back(j);
                    vis[j] = true;
                }
            }
            todo = ntodo;
        }
        max = std::max(max, cnt);
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
vector<long int> X;

int main(){
	int A[3];
	cin >> A[0] >> A[1] >> A[2];
	int ans = 3000;
	ans = min(abs(A[1] - A[0]) + abs(A[2] - A[1]), ans);
	ans = min(abs(A[2] - A[1]) + abs(A[0] - A[2]), ans);
	ans = min(abs(A[0] - A[2]) + abs(A[1] - A[0]), ans);
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <climits>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	string n;
	cin >> n;

	int sz = n.size();
	string out;
	for (int i = 0; i < sz; ++i) {
		if (n[i] == '1') {
			out.push_back('9');
		} else {
			out.push_back('1');
		}

	}

	cout << out << "\n";

	return 0;

}

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

int n;
int C=0;
vector<int> G[1000];

void find(int id,int &x,int &y){
  for(int i=0;i<C;i++){
    for(int j=0;j<(int)G[i].size();j++){
      if(G[i][j]==id){
        x=i;
        y=j;
        return;
      }
    }
  }
}

void init(){
  for(int i=0;i<1000;i++){
    G[i].clear();
  }
  C=0;
}

void solve(int A,int B){
  if(A==B)return;
  
  int ax,ay,bx,by;
  find(A,ax,ay);

  if(B==0){
    if(ay==0)return;
    for(int i=ay;i<(int)G[ax].size();i++){
      G[C].push_back(G[ax][i]);
      C++;
    }
    
    G[ax].erase( G[ax].begin()+ay , G[ax].end() );
    if(G[ax].empty()){
      C--;
      G[ax]=G[C];
      G[C].clear();
    }
    return;
  }
  
  find(B,bx,by);
  
  if(ax!=bx){
    for(int i=ay+1;i<(int)G[ax].size();i++){
      G[C].push_back(G[ax][i]);
      C++;
    }
    G[ax].erase( G[ax].begin()+ay , G[ax].end() );
    G[bx].push_back(A);
    if(G[ax].empty()){
      C--;
      G[ax]=G[C];
      G[C].clear();
    }
  }else{
    if(ay<by){
      for(int i=ay+1;i<(int)G[ax].size();i++){
        G[C].push_back(G[ax][i]);
        C++;
      }
      G[ax].erase( G[ax].begin()+ay , G[ax].end() );
      if(G[ax].empty()){
        C--;
        G[ax]=G[C];
        G[C].clear();
      }
      find(B,bx,by);
      G[bx].push_back(A);
    }
  }
  
}
      

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      G[i].push_back(i+1);
    }
    C=n;
    while(1){
      int A,B;
      cin>>A>>B;
      if(A==0&&B==0)break;
      solve(A,B);
    }
    vector<int> ans;
    for(int i=0;i<C;i++){
      ans.push_back( G[i].size() );
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++){
      cout<<ans[i]<<endl;
    }
    cout<<"end"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3156
import java.util.*;

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

        int h = S / 3600;
        int m = (S % 3600) / 60;
        int s = (S % 3600) % 60;

        System.out.println(h + ":" + m + ":" + s );
    }

}


Measured memory_bytes: 26288
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
int a[1010][8],n;char s[1010];std::map<int,int> d={{'J',0},{'O',1},{'I',2}};main(){scanf("%d%s",&n,s);a[0][1]=1;r(i,n)r(j,8)r(k,8)if(j&k&&k>>d[s[i]]&1)(a[i+1][k]+=a[i][j])%=10007;printf("%d\n",std::accumulate(a[n],a[n]+8,0)%10007);}

Measured memory_bytes: 1208
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

n,m = m()
a = list(input())

if a[m-1] == "A":
	a[m-1] = "a"
elif a[m-1] == "B":
	a[m-1] = "b"
else:
	a[m-1] = "c"
print("".join(a)) 


Measured memory_bytes: 3700
#include <stdio.h>

void main(){
	int n,m;
	int a[1000];
	int max,sum;
	int i,j;
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0 && m==0) break;
		for(i=0;i<n;i++){
			scanf("%d", &a[i]);
		}
		max = 0;
		for(i=0;i<n-1;i++){
			for( j=i+1; j<n ; j++){
				sum = a[i] + a[j];
				if( sum > max && sum <= m ){
					max = sum;
				}
			}
		}
		if(max != 0){
			printf("%d\n",max);
		}else{
			printf("NONE\n");
		}
	}			
}


Measured memory_bytes: 2040
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 500005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
char str[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    scanf("%d", &n);
    set<string> ss;
    for (int i = 0; i < n; i++) {
        scanf("%s", &str);
        ss.insert(str);
    }
    printf("%d", ss.size());
    return 0;
}

Measured memory_bytes: 19416
#include <iostream>
#include <cmath>

#define MOD (1000000007ULL)
using namespace std;

inline long long ApowBmodP(int a, long long b, long long p) {
	if (b==0) return 1;
	if (b%2==0) { //even
		long long d = ApowBmodP(a, b/2, p);
		return  (d % p) * d % p;
	} else { // odd
		return (a * ApowBmodP(a, b-1, p)) % p;
	}
}

long long combination(int n, int r, long long mod)
{
	if (n < r) return 0;
	if ((r*2) > n) r = n - r;

	long long ans = 1;
	for (int up = 1, down = n; up <= r; up++, down--) {
		ans = ans * down % mod;
		ans = ans * ApowBmodP(up, mod-2, mod) % mod;
	}
	return ans;
}

int main(void) {
	int X, Y;
	cin >> X >> Y;

	int max = std::max(X, Y);
	int min = std::min(X, Y);

	int stepA, stepB;
	bool f = false;
	for (int i = 0; i < max; i++) {
		stepB = i;
		stepA = min - stepB*2; // 一方 stepA*1 + stepB*2
		if (max == stepA*2+stepB) { // 他方 stepA*2 + stepB*1
			f = true;
			break;
		}
	}

	if (!f) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = combination(stepB+stepA, stepA, MOD);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import heapq

N,M = map(int, input().split())
jobs = [[] for _ in range(M)]
for _ in range(N):
    a,b = map(int, input().split())
    if a <= M: jobs[a-1].append(b)
h=[]
rsl=0
for i in range(M):
    for j in jobs[i]:
        heapq.heappush(h, -j)
    if len(h) > 0:
        rsl += -heapq.heappop(h)
print(rsl)


Measured memory_bytes: 18376
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		System.out.println((x-r<0)||(y-r<0)||(x+r>W)||(y+r>H) ? "No" : "Yes");
	}
}

Measured memory_bytes: 17324
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18

int main()
{
    int K, N;
    cin >> K >> N;
    vector<int> A(N, 0);
    vector<int> D(N, 0);
    cin >> A[0];
    for (size_t i=1; i<A.size(); i++) {
        cin >> A[i];
        D[i] = A[i] - A[i-1];
    }
    // 北端からA1 + Anから北端
    D[0] = A[0] + K - A[N-1];
    auto maxIter = max_element(D.begin(), D.end());
    int ans = K - *maxIter;
    cout << ans << endl;
}



Measured memory_bytes: 1792
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9+7;

void add_self(int& a, int b){
    a+=b;
    if(a >= mod) a-=mod;
}

void sub_self(int& a, int b){
    a-=b;
    if(a < 0) a+=mod;
}

int main()
{
    int n,K; cin >> n >> K;
    vector<int> dp(K+1);
    dp[0] = 1;
    
    for(int i = 0; i < n; i++){
        int upto; cin >> upto;
        vector<int> fake(K+1);
        for(int used = K; used >= 0; used--){
            int tmp = dp[used];
            int L = used+1;
            int R = used + min(upto, K - used);
            if(L <= R){
                add_self(fake[L],tmp);
                if(R+1 <= K)
                    sub_self(fake[R+1],tmp);
            }
        }
        int pr = 0;
        for(int i = 0; i <= K; i++){
            add_self(pr,fake[i]);
            add_self(dp[i],pr);
        }
    }
    
    printf("%d\n", dp[K]);
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int calc(int n, int k)
{
	if (n == 1) { return k; }

	else if (n % 2 == 0) { return calc(n / 2, k + 1); }

	else if (n % 2 == 1) { return calc(n * 3 + 1, k + 1); }
}

int main()
{
	const int DATASETS = 1000;

	int N[DATASETS], C = 0;

	while (true)
	{
		cin >> N[C];

		if (N[C] == 0) { goto Exit; }

		C++;
	}

Exit:;

	for (int i = 0; i < C; i++)
	{
		cout << calc(N[i], 0) << endl;
	}

	return 0;
}

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

vector<vector<ll>>dp;
void fill(vector<vector<ll>>&dp,ll W,ll n,vector<ll>&w,vector<ll>&v)
{
    for(ll i=1;i<=n;i++)
    {
      for(ll j=1;j<=W;j++)
      {
        if(w[i-1]<=j)
          dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
        else dp[i][j]=dp[i-1][j];
      }
    }
  cout<<dp[n][W];
}

int main()
{
 ll n,w1,v1,W;
  cin>>n>>W;
  vector<ll>v(n);
  vector<ll>w(n);
  for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
  dp.resize(n+1,vector<ll>(W+1));
  fill(dp,W,n,w,v);
  return 0;
}

Measured memory_bytes: 80256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
  if i == 0 and a[i] >= b[i]:
    res += b[i]
    b[i] = 0
  elif i == 0 and a[i] < b[i]:
    res += a[i]
    b[i] -= a[i]
  elif a[i] >= b[i] + b[i-1]:
    res += b[i] + b[i-1]
    b[i] = 0
  else:
    res += a[i]
    if b[i-1] >= a[i]:
      pass
    else:
      b[i] -= a[i] - b[i-1]
if a[-1] >= b[-1]:
  res += b[-1]
else:
  res += a[-1]
print(res)

Measured memory_bytes: 19156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int h, w;
    bool ans = true;
    cin >> h >> w;
    
    vector<vector<char>> vii(h+2, vector<char>(w+2, '.'));
        
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> vii[i][j];
        }
    }
    
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(vii[i][j] == '#' && vii[i][j+1]  == '.' && vii[i][j-1]  == '.' && vii[i+1][j]  == '.' && vii[i-1][j]  == '.'){
                ans = false;
                break;
            }
        }
        if(!ans){
            break;
        }
    }
    
    if(ans){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100001
#define MAX_LOG 30
vector<int>G[MAX];
int depth[MAX];
int parent[MAX_LOG][MAX];
int root;
void dfs(int v,int p,int d){
  parent[0][v]=p;
  depth[v]=d;
  for(int i=0;i<G[v].size();i++)
    if(G[v][i]!=p)dfs(G[v][i],v,d+1);
}
void init(int V){
  //parent???¨dfs??????????????????
  dfs(root,-1,0);
  //parent??????????????????
  for(int k=0;k+1<MAX_LOG;k++)
    for(int v=0;v<V;v++)
      if(parent[k][v]<0)parent[k+1][v]=-1;
      else parent[k+1][v]=parent[k][parent[k][v]];
}
int lca(int u,int v){
  if(depth[u]>depth[v])swap(u,v);
  for(int k=0;k<MAX_LOG;k++)
    if((depth[v]-depth[u])>>k&1)
      v=parent[k][v];
  if(u==v)return u;
  for(int k=MAX_LOG-1;k>=0;k--)
    if(parent[k][u]!=parent[k][v]){
    u=parent[k][u];
    v=parent[k][v];
  }
  return parent[0][u];
}
bool used[100001];
//int dep[100001];
int ans;
typedef pair<int,int>P;
main(){
  root=0;
  int n;
  cin>>n;
  for(int i=0;i<n-1;i++){
    int p;
    cin>>p;
    G[p-1].push_back(i+1);
  }
  init(n);
  vector<int>v;
  queue<P>q;
  used[0]=1;
  q.push(P(0,0));
  while(!q.empty()){
    P t=q.front();q.pop();
    int x=t.first;
    v.push_back(x);
    for(int i=0;i<G[x].size();i++){
      if(!used[G[x][i]]);
      used[G[x][i]]=1;
      q.push(P(G[x][i],t.second+1));
    }
  }
  for(int i=0;i<n-1;i++){
    int a=lca(v[i],v[i+1]);
    ans+=(depth[v[i]]-depth[a])+(depth[v[i+1]]-depth[a]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 38624
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    deque<char> deq;
    string s;
    int q;
    cin >> s >> q;
    int inv = 0;
    rep(i,s.size()) deq.push_back(s[i]);
    
    rep(i,q){
        int n;
        cin >> n;
        if(n==1){
            inv = 1 - inv;
        }else{
            int f;
            char ss;
            cin >> f >> ss;
            --f;
            if(inv==0){
                if(f==0) deq.push_front(ss);
                else deq.push_back(ss); 
            }else{
                if(f==0) deq.push_back(ss);
                else deq.push_front(ss);
            }
        }
    }
    //cout << deq.size() << endl;
    //cout << inv << endl;
    if(inv) reverse(deq.begin(),deq.end());
    for(int i=0;i<deq.size();i++) cout << deq[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  vector <pair <ll, ll>> v(n, pair <ll, ll> ());
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    v.at(i) = make_pair(a, b);
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    cout << v.at(i).first << ' ' << v.at(i).second << endl;
  }
}


Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890

int main(){
    ll i,j;
    ll n;
    string s;
    cin>>n>>s;
    n=2*n;
    ll v[n];
    for(i=0;i<n;i++){
        if(s[i]=='W') v[i]=1;
        else v[i]=0;
    }
    ll le=0;
    ll ans=1;
    for(i=0;i<n;i++){
        if(v[i]==le%2){
            le++;
        }
        else {
            ans=ans*le;
            ans%=Mod;
            le--;
        }
        if(le<0){
            cout<<0<<endl;
            return 0;
        }
    }

    if(le!=0) {
        cout<<0<<endl;
        return 0;
    }
    for(i=1;i<=n/2;i++){
        ans=ans*i;
        ans%=Mod;
    }
    cout<<ans<<endl;

    return 0;   
}

Measured memory_bytes: 2180
#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}
 
using namespace std;


#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int, int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int l = v[i].f;
		int r = v[i].s;

		auto it = mp.lower_bound(l);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			mini[it1->s]--;
			if(mini[it1->s]==0) mini.erase(it1->s);
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(mp.count(r+1) && mp[r+1] > mn) {
				mini[mp[r+1]]--;
				if(mini[mp[r+1]]==0) mini.erase(mp[r+1]);
				mini[mn]++;
				mp[r+1] = mn;
			}
			else if(!mp.count(r+1)){
				mp[r+1] = mn;
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}

Measured memory_bytes: 19300
program main
  implicit none
  integer(8) :: i, n, capacity(5), res

  read *, n
  do i = 1, 5
    read *, capacity(i)
  end do

  res = n / minval(capacity) + 5
  if (mod(n, minval(capacity)) == 0) then
    res = res - 1 
  end if
  print '(i0)', res
end program

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
double T;
/* function */
double calcMaxV(double l, double r, double x, double v) {
    if (0 <= x && x <= l) return v + (l - x);
    else if (l <= x && x <= r) return v;
    else if (r <= x && x <= T) return v + (x - r);
    return v + (x - r);
}
/* main */
int main(){
    int N;
    cin >> N;
    vector<double> v(N+2), t(N+2);
    for (int i = 1; i <= N; i++) cin >> t[i];
    for (int i = 1; i <= N; i++) cin >> v[i];
    T = accumulate(t.begin(), t.end(), 0);
    v[0] = 0;
    v[N+1] = 0;
    t[0] = 0;
    t[N+1] = T;
    vector<pdd> p(N+2);
    p[0] = pdd(0, 0);
    for (int i = 0; i < N; i++) { p[i+1] = pdd(p[i].second, p[i].second+t[i+1]); }
    p[N+1] = pdd(T, T);
    double D = 0.0;
    double vst = 0.0;
    for (double a = 0.0; a < T; a += 0.5) {
        double maxV = INF;
        for (int i = 0; i < N+2; i++) {
            maxV = min(maxV, calcMaxV(p[i].first, p[i].second, a+0.5, v[i]));
        }
        D += 0.25 * (vst + maxV);
        vst = maxV;
    }

    cout << setprecision(10) << D << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=505;

int main()
{
    IO;
    ll n,m;
    cin >> n >> m;
    cout<<abs((n*m)-((n+m-2)*2))<<endl;
    re 0;
}


Measured memory_bytes: 256
<?php
  list($sx, $sy, $tx, $ty) = explode(" ", trim(fgets(STDIN)));

  for($i=0; $i<$ty-$sy; $i++){
    echo "U";
  }
  for($i=0; $i<$tx-$sx; $i++){
    echo "R";
  }
  for($i=0; $i<$ty-$sy; $i++){
    echo "D";
  }
  for($i=0; $i<$tx-$sx+1; $i++){
    echo "L";
  }
  for($i=0; $i<$ty-$sy+1; $i++){
    echo "U";
  }
  for($i=0; $i<$tx-$sx+1; $i++){
    echo "R";
  }
  echo "D";
  echo "R";
  for($i=0; $i<$ty-$sy+1; $i++){
    echo "D";
  }
  for($i=0; $i<$tx-$sx+1; $i++){
    echo "L";
  }
  echo "U";


Measured memory_bytes: 16240
n,dp[1<<19],l;char s[1<<19]="0";i=2;j;
main()
{
	for(scanf("%d%s",&n,s+1);i++<n;dp[i]=fmax(dp[i],l?dp[l-3]+i-l+1:0))
	{
		dp[i]=dp[i-1];
		if(s[i]-s[i-1]==1&&s[i]==s[i-2])for(l=i,j=i-2;s[j]!=48;j--)dp[i]=fmax(dp[i],dp[j-1]+i-j-1);
		else if(s[i]==48)l=0;
	}
	printf("%d",dp[n]);
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
int main() {
  int n;cin>>n;
  string s,t;cin>>s>>t;
  string ans=s+t;
  REP(i,n){
    ans[i*2]=s[i];
    ans[i*2+1]=t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
  int h,w;
  int i,j;
  int a,b;
  int min[3];
  while(1){
    min[0] = 300*150;
    min[1] = 150;
    min[2] = 150;
    cin >> h >> w;
    if(h == 0)
      break;
    a = h*h+w*w;
    for(i = 1;i <= 150;i++){
      for(j = i+1;j <= 150;j++){
	b = i*i+j*j;
	if(b > a || (b==a&&i>h)){
	  if(min[0] > b || (min[0]==b&&min[1]>i)){
	    min[0] = b;
	    min[1] = i;
	    min[2] = j;
	  }
	}
      }
    }
    cout << min[1] << ' ' << min[2] << endl;
  }
  return 0;
}

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

int main(){
    long long N,K,MAX=100000000000000;
    cin>>N>>K;

    vector<long long> H(N),dp(N,MAX);
    dp[0] = 0;
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    for(int i =0;i<N-1;i++){
        for(int j=1;j<=K;j++){
            if(i+j>=N)break;
            dp[i+j] = min(dp[i+j],dp[i] + abs(H[i+j]-H[i]));
        }
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
  string s;
  cin >>s;
  if(s=="SUN")cout<<7;
  else if(s=="MON")cout<<6;
  else if(s=="TUE")cout<<5;
  else if(s=="WED")cout<<4;
  else if(s=="THU")cout<<3;
  else if(s=="FRI")cout<<2;
  else cout<<1;
  cout<<endl;
}


Measured memory_bytes: 256
a, b = gets.split.map(&:to_i)

def my_gcd(x, y)
  return x if y.zero?

  my_gcd(y, x % y)
end

def my_prime_division(n)
  res = Hash.new(0)
  i = 2
  while i * i <= n
    if n % i != 0
      i += 1
      next
    end

    while n % i == 0
      n /= i
      res[i] += 1
    end
    i += 1
  end
  if n != 1
    res[i] += 1
  end
  res
end

# require 'prime'
# puts Prime.prime_division(a.gcd(b)).size + 1
puts my_prime_division(my_gcd(a, b)).keys.size + 1


Measured memory_bytes: 1788
# Monoidクラスに+*/を定義するとLazySegmentTreeを使う時に便利？


# 1-indexed
class SegmentTree:
    '''
    SegmentTree(arr, e)
        arr : 配列,
        e : 単位元\n
    segment_tree[i] で取得、更新\n
    segment_tree.query(a,b) で区間[a,b)の計算結果を得る(a<bでなければ単位元が返ってくる)
    '''
    def __init__(self, arr, e):
        self.e = e
        self.len = len(arr)
        # 最下層の長さnの初期化(扱う配列の長さ以上の2冪のうち最も小さいもの)
        n = 2 ** (len(bin(self.len + 1)) - 2)
        self.n = n
        # nodeの初期化
        node = [e] * (2 * n)
        node[n: n + self.len] = arr
        for i in range(n - 1, 0, -1):
            node[i] = node[2 * i] + node[2 * i + 1]
        self.node = node

    def __setitem__(self, i, val):
        # 最下層からはじめる。それより上にはn-1個のノードがある
        i += self.n
        self.node[i] = val
        # 最上層に辿り着くまで
        while i > 1:
            # 親に移動
            i //= 2
            # 2つの子に対する計算結果
            self.node[i] = self.node[2 * i] + self.node[2 * i + 1]

    def __getitem__(self, i):
        return self.node[self.n + i]

    def query(self, a, b):
        a = self.trim(a, self.len)
        b = self.trim(b, self.len)

        # [a,b)が欲しい
        # k=0, [l=0,r=n)から始める
        # [l,r)が[a,b)の中に入るまで[l,mid), [mid,r)に分割して再帰
        def get(k, l, r):
            # そもそも[l,r)が[a,b)に入ってない時は計算に影響を与えない単位元を返す
            if r <= a or b <= l:
                return self.e
            if a <= l and r <= b:
                return self.node[k]
            m = (l + r) // 2
            return get(2 * k, l, m) + get(2 * k + 1, m, r)

        return get(1, 0, self.n)

    def getlist(self):
        return self.node[self.n:]

    def trim(self, i, n):
        i = max(i, -n)
        i = min(i, n)
        if i < 0:
            i += n
        return i

# https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/2/DSL_2_A

# 一例　([0..2^31-1],min)のモノイド
class Monoid:
    '''
    Monoid(val)\n
    演算は自分で定義する Monoid + Monoid
    ※単位元をクラス変数とし持たない
    '''

    def __init__(self, val):
        self.val = val
    def __repr__(self):
        return repr(self.val)

    # 以下自分で定義
    def __add__(self, other):
        return Monoid(min(self.val, other.val))

n, q = map(int, input().split())
A = [Monoid(2 ** 31 - 1)] * n
st = SegmentTree(A, Monoid(2 ** 31 - 1))
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        st[x] = Monoid(y)
    else:
        print(st.query(x, y + 1))



Measured memory_bytes: 38188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

int main()
{
    string str[2];
    cin >> str[0] >> str[1];
    for (int i = 0; i < (str[0].size() + str[1].size()); i++)
    {
        cout << str[i % 2][i / 2];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define MAX 16777217
#define L 14

int Hash[MAX];

int getChar(char);
int getKey(char*);
int find(char*);
int insert(char*);

int main(){
  int n, h;
  char com[7],str[L];

  scanf("%d" ,&n);
  while(n--){
    scanf("%s %s" ,com ,str);

    if(com[0] == 'i'){
      h = insert(str);
      Hash[h] = 1;
    }else{
      if(find(str)){
	puts("yes");
      }else{
	puts("no");
      }
    }
  }

  return 0;
}

int getChar(char ch){
  if(ch == 'A'){
    return 1;
  }else if(ch == 'C'){
    return 2;
  }else if(ch == 'G'){
    return 3;
  }
  return 4;
}

int getKey(char str[]){
  int sum = 0, p = 1, i;

  for(i = 0 ; i < (int)strlen(str) ; i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int find(char str[]){
  int key = getKey(str);

  if(Hash[key]){
    return 1;
  }
  return 0;
}

int insert(char str[]){
  return getKey(str);
}

Measured memory_bytes: 38620
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
int main() {
	int n, x, ans=1, d=0;
	cin >> n >> x;
	vector<int> l(n);
	REP(i, n)cin >> l[i];
	REP(i, n) {
		d += l[i];
		if (d > x)break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
    V n = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    
    int k; cin >> k;

    cout << n.at(k) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

n, m = map(int, raw_input().split())

aced = set()
d = defaultdict(int)
pen = 0
for i in xrange(m):
    p, s = raw_input().split()
    p = int(p)
    s = s.strip()

    if p in aced:
        continue

    if s == 'WA':
        d[p] += 1
    elif s == 'AC':
        aced.add(p)
        pen += d[p]
    else:
        assert False

print len(aced), pen


Measured memory_bytes: 18212
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans;
	if (b < c || a > d) {
		ans = 0;
	}
	else {
		ans = min(b, d) - max(a, c);
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
    int n = 0, ans = 0;
    cin >> n;
    if(n%10){
        while(n){
            ans += n%10;
            n /= 10;
        }
    }
    else ans = 10;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+50;
typedef pair<int, int> ii;
int solve(int K){
	deque<ii> dq;
	vector<int> vis(K, 0);
	dq.push_front(ii(1,1));
	while(!dq.empty()){
		ii p = dq.front(); dq.pop_front();
		int curr = p.first, cnt = p.second;
		if(curr == 0) return cnt;

		vis[curr] = 1;
		int next = (curr+1) % K;
		if(vis[next] == 0)
			dq.push_back(ii(next, cnt+1));

		next = (curr * 10) % K;
		if(vis[next] == 0)
			dq.push_front(ii(next, cnt));
	}
}
int main(){ 
	int K; cin >> K;
	cout << solve(K) << endl;
    return 0;
}

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

int main(int argc, char const *argv[]) {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long int health;
	long long int monsters = 1;
	long long int attacks = 0;
	cin>>health;
	while(health != 0){
		attacks += monsters;
		health /= 2;
		monsters *= 2;
	}
	cout<<attacks<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> 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;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

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 dfs(int cur, vvi& graph, vi& visit) {
    int rst = 0;
    for (int nxt : graph[cur]) {
        if (visit[nxt]) continue;
        visit[nxt] = 1;
        rst += dfs(nxt, graph, visit);
    }

    return rst+1;
}

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

    int N, M; cin >> N >> M;
    vvi graph(N+1);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int rst = 0;
    vi visit(N+1);
    for (int i = 1; i <= N; i++) {
        if (visit[i]) continue;
        visit[i] = 1;
        rst = max(rst, dfs(i, graph, visit));
    }

    cout << rst;
}

Measured memory_bytes: 24248
from sys import maxsize

WHITE = 0
GRAY = 1
BLACK = 2


def read_adj():
    n = int(input())
    adj_list = [[] for _ in range(n)]
    for i in range(n):
        u, _, *rest = [int(x) for x in input().split()]
        for i in range(0, len(rest) - 1, 2):
            adj_list[u].append((rest[i], rest[i + 1]))

    return n, adj_list


def shortest_path(n, adj_list):
    color = [WHITE] * n
    dist = [maxsize] * n

    dist[0] = 0
    color[0] = GRAY

    while True:
        minv = maxsize
        u = -1
        for i in range(n):
            if minv > dist[i] and color[i] != BLACK:
                u = i
                minv = dist[i]

        if u == -1:
            break
        color[u] = BLACK

        for v, c in adj_list[u]:
            if dist[u] + c < dist[v]:
                dist[v] = dist[u] + c
                color[v] = GRAY
                
    return dist


def print_dist(dist):
    for u, d in enumerate(dist):
        print(u, d)


def main():
    n, adj_list = read_adj()
    dist = shortest_path(n, adj_list)
    print_dist(dist)


if __name__ == '__main__':
    main()



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

using namespace std;

int lake_walk(vector<vector<int> >& lake, int startx, int starty, int m, int n) {
    int ans=1;
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};

    for(int i=0; i<4; ++i) {
        if(starty+dy[i]>=0 && starty+dy[i]<n &&
           startx+dx[i]>=0 && startx+dx[i]<m && lake[starty+dy[i]][startx+dx[i]]==1) {
            lake[starty][startx]=0;
            ans=max(ans,lake_walk(lake,startx+dx[i],starty+dy[i],m,n)+1);
            lake[starty][startx]=1;
        }
    }

    return ans;
}
int main()
{
    int m,n;

    cin >> m >> n;

    while(m!=0||n!=0) {
        vector<vector<int> > lake;

        for(int i=0; i<n; ++i) {
            vector<int> vtemp;

            for(int j=0; j<m; ++j) {
                int temp;

                cin >> temp;
                vtemp.push_back(temp);
            }
            lake.push_back(vtemp);
            vtemp.clear();
        }

        int ans=0;

        for(int i=0; i<n; ++i) {
            for(int j=0; j<m; ++j) {
                if(lake[i][j]==1) {
                    ans=max(ans,lake_walk(lake,j,i,m,n));
                }
            }
        }

        cout << ans << endl;

        cin >> m >> n;
    }
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007

using namespace std;
int main()
{    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     ll a,b;
     cin>>a>>b>>n;
     ll x=min(n,b-1);
     cout<<((a*x)/b)-(a*(x/b));
}  



Measured memory_bytes: 3628
function Main(input) {
    const x = input.split(" ");
    
    for(let i = 0; i < 5; i++){
        if(parseInt(x[i], 10) === 0){
            console.log(i+1);
        }
    }
}
 
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29488
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7 , MAX = 1e18 , k=1e9;
int main() 
{
	fast_io;
	ll n,m,s=0,a;
	cin>>n>>m;
	while(m--) cin>>a , s+=a;
	n-=s;
	if(n<0) n=-1;
	cout<<n;
	return 0;
}

Measured memory_bytes: 3688
<?php
fscanf(STDIN, '%s', $str);
$num = intval(substr($str, -1));
switch ($num) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        echo 'hon';
        break;

    case 0:
    case 1:
    case 6:
    case 8:
        echo 'pon';
        break;

    case 3:
        echo 'bon';
        break;
}

Measured memory_bytes: 16180