akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std ;
int n,k;
 const int I=2e9;
const int N=1e5+5;

int h[N];

int mem[N];

int dp(int i){

if(i == n-1) return 0;

if(mem[i] != -1) return mem[i];

int ans = I;

    for(int j = 1 ; j <= k ; j ++){
        if(i + j <= n-1){
            ans = min(ans , abs(h[i] - h[i + j]) + dp(i + j));
        }
    }

    mem[i] = ans;
    return mem[i];
}

int main(){

scanf("%d%d",&n,&k);


for(int i=0;i<n;i++)
{
    scanf("%d",&h[i]);
}

memset(mem , -1 , sizeof mem);

printf("%d\n",dp(0));

}



Measured memory_bytes: 5760
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	int pa[6] = { 2,3,-1,2,5,1 };
	int pb[6] = { 3,2,4,-1,1,3 };
	while (cin >> s){
		int mode = 0;
		//A:0 B:1 X:2 Y:3 Z:4 W:5
		if (s == "#")return 0;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '0')mode = pa[mode];
			else if (s[i] == '1')mode = pb[mode];
			if (mode == -1)goto missing;
		}
		if (mode == 1)cout << "Yes\n";
		else {
		missing:cout << "No\n";
		}
	}
}

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main() {
  string s;
  long k;
  cin >> s >> k;

  // 5000兆日後には少なくともある数値は5000兆個になってる
  
  int c = 0;
  for (int i=0; i<s.length(); i++) {
    if (s[i] != '1') break;
    c++;
  }

  if (c >= k) {
    cout << 1 << endl;
  } else {
    cout << s[c] << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const MAX = 1e5 + 50;
int arr[MAX];
int memo[MAX];
int n;

int dp(int i)
{
    if(i >= n) return 1e7;
	if(i == n - 1) return 0;
	int & ret = memo[i];
	if(ret != -1) return ret;
	int path1 = abs(arr[i + 1] - arr[i]) + dp(i + 1);
    int path2 = abs(arr[i + 2] - arr[i]) + dp(i + 2);
    //cout << path1 << " " << path2 << endl;
    return ret = min(path1, path2);
}


int main()
{
    memset(memo, -1, sizeof(memo));
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
    	scanf("%d", &arr[i]);
    }
    printf("%d", dp(0));

	return 0;
}


Measured memory_bytes: 4096
# -*- coding: utf-8 -*-
n=int(input())
v=input().split(" ")
c=input().split(" ")
v=[int(i) for i in v]
c=[int(j) for j in c]
count=0
for i in range(n):
  if v[i]-c[i]>=0:
    count=count+v[i]-c[i]
print(count)

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  string s;
  cin >> s;
  s[5] = s[13] = ' ';
  cout << s << endl;
}



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

typedef long long                   ll;
typedef long double                 ld;
typedef pair<ll,ll>                 pll;
typedef pair<ld,ld>                 pld;


#define all(x)          (x).begin(),(x).end()
#define Sort(x)         sort(all(x))
#define sep             ' '

#define endl            '\n'
#define tab             '\t'
#define X               first
#define Y               second
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random      mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll MOD = 1e9 + 7,
         MAXN= 1e6+10,
         INF=1e18;
ll n,x,l[110],d[110],ans;
int main()
{
    fast_io;
    cin>>n>>x;
    for(ll i=1;i<=n;i++){
        cin>>l[i];
    }
    d[1]=0;
    for(ll i=2;i<=n+1;i++){
        d[i]=d[i-1]+l[i-1];
        if(d[i]<=x)ans++;
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 256
import heapq
N, M = list(map(int, input().split()))
jobs = [[] for _ in range(M)]

for i in range(N):
    d, r = list(map(int, input().split()))
    if d-1 < M:
        jobs[d-1].append(-r) #マイナスにしている
heap = []
rewards = 0
for i in range(M):
    for reward in jobs[i]:
        heapq.heappush(heap,reward)
    if len(heap) != 0:
        r = heapq.heappop(heap)
        rewards += -r
print(rewards)

Measured memory_bytes: 23752
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
typedef long long ll;
ll a[200000];
int main(){
	cin>>N;
	rep(i,N) cin>>a[i];
	ll mn = 1e18;
	ll al = accumulate(a,a+N,0LL);
	ll sm = 0;
	rep(i,N-1){
		sm+=a[i];
		chmin(mn,abs(sm-(al-sm)));
	}
	cout<<mn<<endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(); in.nextLine();
		int[] ary = new int[N];
		
		for ( int i = 0; i < N; i++ ) {
			ary[i] = in.nextInt(); in.nextLine();
		}
		
		Arrays.sort(ary);
		
		int maxMochi = 101;
		int layers = 0;
		for ( int i = N-1; i >= 0; i-- ) {
			if ( ary[i] < maxMochi ) {
				layers++;
				maxMochi = ary[i];
			}
		}
		
		System.out.println(layers);
		
	}
}

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

int main(){
  int n;
  int i,j;
  int a[100005];
  int q[100005];

  scanf("%d", &n);

  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
    q[a[i] - 1] = i + 1;
  }

  for(i = 0;i < n - 1;i++){
    printf("%d ", q[i]);
  }

  printf("%d\n", q[n - 1]);
  return 0;
}


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

using namespace std;

long long comb2(int n){
    return (long long)n * (n - 1) / 2;
}

class UF{
public:
    int n;
    vector<int> parent;
    vector<int> size;
    long long sum;

    UF(int n){
        parent.resize(n);
        size.resize(n);
        for(int i = 0; i < n; i++){
            parent[i] = i;
            size[i] = 1;
        }
        sum = 0;
    }

    bool unite(int a, int b){
        int parentA = find(a);
        int parentB = find(b);

        if(parentA == parentB){
            return false;
        }
        else{
            int sizeA = size[parentA];
            int sizeB = size[parentB];
            if(sizeA < sizeB){
                parent[parentA] = parentB;
                size[parentB] += sizeA;
            }
            else{
                parent[parentB] = parentA;
                size[parentA] += sizeB;
            }
            int sizeAB = sizeA + sizeB;
            sum += (comb2(sizeAB) - comb2(sizeA) - comb2(sizeB));
            return true;
        }
    }

    int find(int node){
        int p = parent[node];
        if(p == node){
            return p;
        }
        else{
            int newP = find(p);
            parent[node] = newP;
            return newP;
        }
    }
};

int main(){

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v(M);

    int A, B;
    for(int i = 0; i < M; i++){
        cin >> A >> B;
        v[i] = make_pair(A - 1, B - 1);
    }

    UF uf(N);
    long long all = (long long)N * (N - 1) / 2;
    vector<long long> ans(M);

    for(int i = M - 1; i >= 0; i--){

        ans[i] = all - uf.sum;

        auto temp = v[i];
        uf.unite(temp.first, temp.second);
    }

    for(int i = 0; i < M; i++){
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
ll dp[200001][2][11];
ll OO = 2e15;
ll N = -2e16;
vector<int> arr;

ll solve(int in, int lst, int dif){
  int left = (in + dif) / 2;
  int taken = (in - dif) / 2;
  if(left + taken != in || dif < -1 || dif > 8)
    return -OO;

  if(in == n)
    return taken == n/2 ? 0 : -OO;

  ll& res = dp[in][lst][dif + 1];
  if(res != N)
    return res;
  res = 0;

  if(lst)
    res = solve(in + 1, 0, dif + 1);
  else
    res = max(
      solve(in + 1, 0, dif + 1),
      solve(in + 1, 1, dif - 1) + arr[in]
    );
  return res;
}
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  for(int i = 0;i < 200001;i++)
    for(int j = 0;j < 2;j++)
      for(int k = 0;k < 11;k++)
        dp[i][j][k] = N;
  cin >> n;
  arr.resize(n);
  for(auto& el : arr)
    cin >> el;
  cout << solve(0, 0, 0);
  return 0;
}


Measured memory_bytes: 53904
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
using ll=long long;
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(int a,int b){
    return (long long)a*(long long)b/gcd(a,b);
}
int main(){
    int a,b;
    cin>>a>>b;
    string s,t;
    cin>>s>>t;
    int na=0,nb=0;
    int g=gcd(a,b);
    int n=a/g,m=b/g;
    for(int i=0;i<g;i++){
        if(s[na]!=t[nb]){
            cout<<-1<<endl;
            return 0;
        }
        na+=n;
        nb+=m;
    }
    cout<<lcm(a,b)<<endl;
}


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

int main() {
	int a, b, c, d, l = 0;
	cin>>a>>b>>c>>d;
	while (a > 0 && c > 0)
	{
	    if (l % 2 == 0)
	    {
	        c = c - b;
	    }
	    else
	        a = a - d;
	    l++;
	}
	if ((l) % 2 == 0)
	    cout<<"No";
	else
	    cout<<"Yes";
	//cout<<"GfG!";
	return 0;
}

Measured memory_bytes: 3608
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 998244353
N, A, B, K = lr()
answer = 0
# A * x + B * y = K
# nCx * nCy

def F(x, y):
    return comb[x] * comb[y] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = N + 1 # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)
fact_N = fact[N]
comb = fact_N * fact_inv % MOD * fact_inv[::-1] % MOD

for x in range(N+1):
    temp = K-A*x
    q, r = divmod(temp, B)
    if r != 0:
        continue
    if q > N:
        continue
    if q < 0:
        break
    answer += F(x, q)

print(answer % MOD)


Measured memory_bytes: 26492
#include <iostream>
#include <cstdlib>
#define MAX_N 100
#define INF 1500000
using namespace std;
int t[MAX_N];
int m, n;

bool C(int x) {
	int i, sum, shelf = m;
	
	i = 0;
	while (shelf--) {
		sum = 0;
		while (i < n && sum + t[i] <= x) {
			sum += t[i];
			i++;
		}
	}
	return i == n;
}

int solve() {
	int ok = INF, ng = 0, mid;
	while (abs(ok - ng) > 1) {
		mid = (ok + ng) / 2;
		if (C(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {
	while (cin >> m, m) {
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> t[i];
		}
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n,a,b,c=gets.split.map &:to_i
l=(1..n).map{gets.to_i}
mp_m=43872038723
for bit in 0...4**n
    s=0
    t=0
    u=0
    mp=0
    bit.to_s(4).rjust(n,"0").split("").map(&:to_i).each_with_index{|e,i|
        if e==0
            mp+=10 if s>0
            s+=l[i]
        elsif e==1
            mp+=10 if t>0
            t+=l[i]
        elsif e==2
            mp+=10 if u>0
            u+=l[i]
        end
    }
    if s*t*u!=0
        mp_m=[mp_m,mp+(a-s).abs+(b-t).abs+(c-u).abs].min
    end
end
p mp_m

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

using namespace std;

struct segtree
{
	vector<int> t;
	segtree(int n) :t(n * 2 - 1, 0) {}
	void add(int a, int b, int o, int l, int r)
	{
		if (a >= r || b <= l)
			return;
		if (a <= l && b >= r) {
			t[o]++;
			return;
		}
		int m = (l + r) / 2;
		add(a, b, o + 1, l, m);
		add(a, b, o + (m - l) * 2, m, r);
	}
	int min(int o, int l, int r)
	{
		if (l + 1 == r)
			return t[o];
		int m = (l + r) / 2;
		int p = min(o + 1, l, m);
		int q = min(o + (m - l) * 2, m, r);
		return max(p, q) + t[o];
	}
};

pair<int, pair<int, int>> p[111111];
int main()
{
	int N, C;
	cin >> N >> C;
	for (int i = 0; i < N; i++)
		scanf("%d%d%d", &p[i].second.first, &p[i].second.second, &p[i].first);
	sort(p, p + N);
	segtree s(111000);
	int c = 0, d = 0;
	for (int i = 0; i < N; i++) {
		if (p[i].first != c || p[i].second.first != d) {
			c = p[i].first;
			s.add(p[i].second.first - 1, p[i].second.first, 0, 0, 111000);
		}
		d = p[i].second.second;
		s.add(p[i].second.first, p[i].second.second, 0, 0, 111000);
	}
	cout << s.min(0, 0, 111000) << endl;
	return 0;
}


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

using namespace std;

#define int long long

const int MAXN = 1.2e8 + 28;

const int INF = 8e18 + 118;

unordered_map<int, vector<pair<int, int>>> mod;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x, d;
    cin >> n >> x >> d;
    if (d < 0)
    {
        d = -d;
        x = -x;
    }
    if (d == 0)
    {
        if (x == 0)
        {
            cout << 1 << endl;
            return 0;
        }
        cout << n + 1 << endl;
        return 0;
    }
    int ans = 0;
    vector<int> a(n + 1);
    for (int i = 0; i <= n; ++i)
    {
        a[i] = i;
    }
    if (x < 0)
    {
        reverse(a.begin(), a.end());
    }
    for (auto i : a)
    {
        int l = (i * (i - 1ll)) / 2ll;
        int r = i * (n - 1ll) - l + 1ll;
        int ind = ((i * x) % d + d) % d;
        int st = ((i * x) - ((i * x) % d + d % d)) / d;
        int en = st + r;
        st += l;
        if (st > en)
        {
            swap(st, en);
        }
        mod[ind].push_back({st, -1});
        mod[ind].push_back({en, 1});
    }
    for (auto el : mod)
    {
        sort(el.second.begin(), el.second.end());
        int cur = 0;
        int pr = 0;
        int st = 0;
        for (auto e : el.second)
        {
            cur -= e.second;
            if (cur == 0)
            {
                ans += e.first - st;
            }
            if (pr == 0)
            {
                st = e.first;
            }
            pr = cur;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 22600
#include <iostream>
#include <queue>
#include <vector>
#include <tuple>

using namespace std;

const bool debug = false;

int main() {
    int n, m;
    cin >> n >> m;
    auto adj = new vector<int>[n];
    for (size_t i = 0; i < n; ++i) {
        adj[i] = vector<int>();
    }
    for (size_t i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    {
        int ones = 0;
        for (size_t i = 0; i < n; ++i) {
            if (adj[i].size() == 0) {
                cout << 0 << endl;
                return 0;
            }
            if (adj[i].size() == 1 && i != 0) {
                ++ones;
            }
        }
        if (ones > 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    int paths = 0;
    queue< tuple< int, int, vector<bool> > > q;
    vector<bool> initial;
    for (size_t i = 0; i < n; ++i) {
        initial.push_back(false);
    }
    initial[0] = true;
    q.push(make_tuple(1, 0, initial));
    while(!q.empty())
    {
        tuple< int, int, vector<bool> > f = q.front();
        if (debug) {
            cout << "Q " << get<0>(f) << ' ' << get<1>(f) << " [";
            for (size_t i = 0; i < n; ++i) {
                cout << get<2>(f)[i] << ',';
            }
            cout << "]\n";
        }

        int num_visit = get<0>(f);
        if (num_visit == n) {
            ++paths;
            q.pop();
        } else {
            int current_pos = get<1>(f);
            vector<bool> visited = get<2>(f);
            for (size_t i = 0; i < adj[current_pos].size(); ++i) {
                int next_pos = adj[current_pos][i];
                if (!visited[next_pos]) {
                    vector<bool> next_visited(visited);
                    next_visited[next_pos] = true;
                    q.push(make_tuple(num_visit+1, next_pos, next_visited));
        if (debug) {
            cout << "A " << num_visit+1 << ' ' << next_pos << " [";
            for (size_t i = 0; i < n; ++i) {
                cout << next_visited[i] << ',';
            }
            cout << "]\n";
        }
                }
            }
            q.pop();
        }
    }
    cout << paths << endl;
    return 0;
}


Measured memory_bytes: 640
a, b, c = map(int, input().split())
if a == b == c:
    ans = 1
else:
    ans = 1 << 31
    for x in [a - b, b - c, c - a]:
        if x != 0:
            tmp = 1
            while x % 2 == 0:
                tmp += 1
                x >>= 1
            ans = min(tmp, ans)

if a == b == c and b % 2 == 0:
    print(-1)
else:
    print(ans - 1)

Measured memory_bytes: 9028
while True:
    try:
        ax, ay, bx, by, cx, cy, px, py = map(float, input().split())
        a = (bx - ax) * (py - ay) - (by - ay) * (px - ax)
        b = (cx - bx) * (py - by) - (cy - by) * (px - bx)
        c = (ax - cx) * (py - cy) - (ay - cy) * (px - cx)
        if (a < 0 and b < 0 and c < 0) or (a > 0 and b > 0 and c > 0):
            print("YES")
        else:
            print("NO")
    except:
        break

Measured memory_bytes: 7340
#include <iostream>
#include <string>
#include <algorithm>
#include <chrono>

using namespace std;

#define ll long long;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int N,Y;
    int flag = 0;
    cin >> N >> Y;


    REP(i, N+1) {
        for(int j = 0; i + j <= N; ++j) {
            int k = N - i - j;
            int sum = i*10000 + j*5000 + k*1000;
            if(sum == Y && N ==(i+j+k) && flag == 0) {
                cout << i << " " << j << " " << k << endl;
                flag = 1;
            }
        }
    }

    if(flag == 0) cout << -1 << " " << -1 << " " << -1 << endl;

}


Measured memory_bytes: 256
//Doctor's Memorable Codes
#include<bits/stdc++.h>
using namespace std;

string into(string s){
  string ret="";
  for(int i=0; i<s.length(); i++){
    if(s[i]=='A')ret+="00000";
    if(s[i]=='B')ret+="00001";
    if(s[i]=='C')ret+="00010";
    if(s[i]=='D')ret+="00011";
    if(s[i]=='E')ret+="00100";
    if(s[i]=='F')ret+="00101";
    if(s[i]=='G')ret+="00110";
    if(s[i]=='H')ret+="00111";
    if(s[i]=='I')ret+="01000";
    if(s[i]=='J')ret+="01001";
    if(s[i]=='K')ret+="01010";
    if(s[i]=='L')ret+="01011";
    if(s[i]=='M')ret+="01100";
    if(s[i]=='N')ret+="01101";
    if(s[i]=='O')ret+="01110";
    if(s[i]=='P')ret+="01111";
    if(s[i]=='Q')ret+="10000";
    if(s[i]=='R')ret+="10001";
    if(s[i]=='S')ret+="10010";
    if(s[i]=='T')ret+="10011";
    if(s[i]=='U')ret+="10100";
    if(s[i]=='V')ret+="10101";
    if(s[i]=='W')ret+="10110";
    if(s[i]=='X')ret+="10111";
    if(s[i]=='Y')ret+="11000";
    if(s[i]=='Z')ret+="11001";
    if(s[i]==' ')ret+="11010";
    if(s[i]=='.')ret+="11011";
    if(s[i]==',')ret+="11100";
    if(s[i]=='-')ret+="11101";
    if(s[i]=='\'')ret+="11110";
    if(s[i]=='?')ret+="11111";
  }
  return ret;
}

string solve(string t){
  string s=into(t);
  string ret="";
  int l=0, r=0;
  for( ; r!=s.length(); r++){
    string tmp=s.substr(l, r-l+1);//文字列の切り出し
    if(tmp=="101"){ret+=" "; l=r+1;}
    if(tmp=="000000"){ret+="\'"; l=r+1;}
    if(tmp=="000011"){ret+=","; l=r+1;}
    if(tmp=="10010001"){ret+="-"; l=r+1;}
    if(tmp=="010001"){ret+="."; l=r+1;}
    if(tmp=="000001"){ret+="?"; l=r+1;}
    if(tmp=="100101"){ret+="A"; l=r+1;}
    if(tmp=="10011010"){ret+="B"; l=r+1;}
    if(tmp=="0101"){ret+="C"; l=r+1;}
    if(tmp=="0001"){ret+="D"; l=r+1;}
    if(tmp=="110"){ret+="E"; l=r+1;}
    if(tmp=="01001"){ret+="F"; l=r+1;}
    if(tmp=="10011011"){ret+="G"; l=r+1;}
    if(tmp=="010000"){ret+="H"; l=r+1;}
    if(tmp=="0111"){ret+="I"; l=r+1;}
    if(tmp=="10011000"){ret+="J"; l=r+1;}
    if(tmp=="0110"){ret+="K"; l=r+1;}
    if(tmp=="00100"){ret+="L"; l=r+1;}
    if(tmp=="10011001"){ret+="M"; l=r+1;}
    if(tmp=="10011110"){ret+="N"; l=r+1;}
    if(tmp=="00101"){ret+="O"; l=r+1;}
    if(tmp=="111"){ret+="P"; l=r+1;}
    if(tmp=="10011111"){ret+="Q"; l=r+1;}
    if(tmp=="1000"){ret+="R"; l=r+1;}
    if(tmp=="00110"){ret+="S"; l=r+1;}
    if(tmp=="00111"){ret+="T"; l=r+1;}
    if(tmp=="10011100"){ret+="U"; l=r+1;}
    if(tmp=="10011101"){ret+="V"; l=r+1;}
    if(tmp=="000010"){ret+="W"; l=r+1;}
    if(tmp=="10010010"){ret+="X"; l=r+1;}
    if(tmp=="10010011"){ret+="Y"; l=r+1;}
    if(tmp=="10010000"){ret+="Z"; l=r+1;}
  }
  return ret;
}

int main(){
  string s;
  while(getline(cin, s))cout<<solve(s)<<endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll N=2e5+5;
vector<ll>ans;
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<max(a*b,max(a+b,a-b));
   return 0;
}


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

bool check(string b, string n){
    int blen = b.length();
    int nlen = n.length();
    for(int i = 0; nlen+(nlen-1)*i <= blen; i++){
        for(int j = 0; j <= blen-(nlen+(nlen-1)*i); j++){
            int k;
            for(k = 0; k < nlen; k++){
                if(n[k] != b[j + k*(i+1)])  break;
            }
        
            if(k == nlen) return true;
        }
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    
    string name, board;
    cin >> name;

    int cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> board;
        if(check(board, name))  cnt++;
    }

    cout << cnt << endl;
    return 0;
}


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

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=100010;

vi graph[vmax],ord,low,scc,par;
stack<int>s;

void add_edge(int f,int t){ graph[f].pb(t);}
void add_both_edges(int f,int t){add_edge(f,t);add_edge(t,f);}

void dfs(int v,int p,int &k){
	ord[v]=k++;
	low[v]=ord[v];
	par[v]=p;
	s.push(v); // S
	for(auto &i:graph[v]){
		if(ord[i]==-1){
			dfs(i,v,k);
			low[v]=min(low[v],low[i]);
		//}else if(i!=p){    // B,A
		}else if(scc[i]==-1){ // S
			low[v]=min(low[v],ord[i]);
		}
	}
	if(ord[v]==low[v]){
		while(1){
			int u=s.top();s.pop();
			scc[u]=v;
			if(u==v) break;
		}
	}  //S
}

void lowlink(int n){
	int k=0;
	ord.assign(n,-1),low.resize(n);
	scc.assign(n,-1),par.resize(n);
	rep(i,n) if(ord[i]==-1) dfs(i,-1,k);
}

int main(void){
	int v,e;
	cin >> v >> e;
	rep(loop,e){
		int a,b;
		cin >> a >> b;
		// add_both_edges(a,b); // B,A
		add_edge(a,b); // S
	}
	lowlink(v);

/*	rep(i,v){
		cout << "ord[" << i << "]=" << ord[i]  << endl;
		cout << "low[" << i << "]=" << low[i]  << endl;
	}
*/

// Bridge
/*	vector<pii> bridge;
	rep(i,v){
		int j=par[i];
		if(j==-1)
			continue;
		if(ord[i] < low[j] || ord[j] < low[i] ){
			pii in(i,j);
			if(in.second<=in.first) swap(in.first,in.second);
			bridge.pb(in);
		}
	}
	sort(bridge.begin(),bridge.end());
	for(auto &i:bridge)
		cout << i.first << " " << i.second << endl;
*/

// Articulation Points
/*	vi articulation_point;
	rep(i,v){
		if(i){
			bool ok=false;
			for(auto &j:graph[i]){
				if(i==par[j]&&ord[i]<=low[j])
					ok=true;
			}
			if(ok) articulation_point.pb(i);
		}else{
			int d=0;
			rep(j,v) if(par[j]==0) d++;
			if(d>=2) articulation_point.pb(i);
		}
	}
	sort(articulation_point.begin(),articulation_point.end());
	for(auto &i:articulation_point)
		cout << i << endl;
*/
// Strongly Connected Components

	int q;
	cin >> q;
	rep(loop,q){
		int a,b;
		cin >> a >> b;
		cout << (scc[a]==scc[b]) << endl;
	}

	return 0;
}

Measured memory_bytes: 4684
#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>;

int main() {
  string s;
  int k;
  cin >> s >> k;

  int ls = 1;
  int ns = 0;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i-1]) ++ls;
    if (s[i] != s[i-1] || i == s.size() - 1) {
      ns += ls / 2;
      ls = 1;
    } 
  }

  int lf = 1, lb = 1;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i-1]) ++lf;
    else break;
  }
  for (int i = s.size() - 2; i >= 0; --i) {
    if (s[i] == s[i+1]) ++lb;
    else break;
  }

  ll min_ope;
  if (s[0] != s[s.size() - 1]) min_ope = (ll)k * ns;
  else if (lf == s.size()) min_ope = (ll)s.size() * k / 2;
  else {
    min_ope = (ll)k * ns + ((lf + lb) / 2 - lf / 2 - lb / 2) * (k - 1);
  } 
  cout << min_ope << endl;
  return 0;
}

Measured memory_bytes: 3632
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    if(s != 1000000000) {
        rep(i, k) {
            cout << s << (i == n-1?'\n':' ');
        }
        rep(i, n-k) {
            cout << s+1 << (i == n-1-k?'\n':' ');
        }
    } else {
        rep(i, k) {
            cout << s << (i == n-1?'\n':' ');
        }
        rep(i, n-k) {
            cout << 1 << (i == n-1-k?'\n':' ');
        }
    }
}

Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(2e5) + 17;

int n;
string s, t;

bool read() {
    if (!(cin >> s >> t))
        return false;

    return true;
}

void solve() {
    t += t;
    n = sz(s);

    forn (i, n)
        if (t.substr(i, n) == s) {
            cout << "Yes\n";
            return ;
        }

    cout << "No\n";
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int hoge;
    cin >> hoge;
    a.push_back(hoge);
    if (!mp.count(hoge))
      mp[hoge] = 1;
    else
      mp.at(hoge)++;
  }

  int64_t ans_all = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans_all += ((int64_t)(it->second) * (it->second - 1)) / 2;
  }

  int64_t ans;
  for (int i = 0; i < n; i++) {
    ans = ans_all - (mp.at(a.at(i)) - 1);
    cout << ans << endl;
  }
}

Measured memory_bytes: 8308
import java.util.Scanner;

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

		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0) {
				break;
			} else {
				for (int i = 0; i < H; i++) {
					for (int j = 0; j < W; j++) {
						System.out.print("#");
					}
					System.out.println("");
				}
				System.out.println("");
			}
		}
	}
}


Measured memory_bytes: 36560
#include <algorithm>
#include <iostream>
#include <map>
#include <cstdio>
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
using namespace std;

int main() {
	int N=0;
	
	SCD(N);
	int A[N+2];
	int ans = 0;
	FOR(i,0,N){SCD(A[i]);}
	sort(A,A+N);
	
	FOR(i,0,N){
		if (A[i] == A[i+1]) {
			i++;
		}else{
			ans++;
		}
	}
	
	PRINTD(ans);
}



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


int main(void) {
    int a,b,c,d;
    int l, r;
    cin >> a >> b >> c >> d;
    l = a + b;
    r = c + d;
    if (l == r) {
        cout << "Balanced";
    } else if(l > r) {
        cout << "Left";
    } else {
        cout << "Right";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0;
  int num[100];
  bool b=true;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  while(b){
    b=false;
    for(int i=n-1;i>=1;i--){
      if(num[i]<num[i-1]){
	swap(num[i],num[i-1]);
	b=true;
	cnt++;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(i==n-1) cout<<num[i];
    else cout<<num[i]<<" ";
  }
  cout<<endl;
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3116
#include <stdio.h>

int
main(int argc, char *argv[])
{
  long long x, y;
  scanf("%lld %lld", &x, &y);

  int cnt = 0;
  while(y >= x){
    x *= 2;
    cnt++;
  }

  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 128
n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i).sort
bc=[]
m.times do 
  b,c=gets.chomp.split.map(&:to_i)
  bc << [c,b]
end
bc.sort!
bc.reverse!
ans=a.inject(:+)
#puts ans
i=0
bc.each do |c,b|
  break if i == n
  break if a[i] > c
  b.times do
    if a[i] < c
      ans+=c-a[i]
      i+=1
      break if i == n
    else
      break
    end
  end
end
puts ans

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,V,P;
ll M;
ll A[101010];
ll B[101010];

int ok(int cur) {
	int i;
	if(cur<0) return 0;
	if(N-cur<=P) return 1;
	if(V<=P) {
		return (A[cur]+M>=A[N-P]);
	}
	else {
		int NN=N-(P-1);
		int NV=V-P;
		ll cand=A[cur]+M;
		vector<ll> B;
		ll dif=0;
		FOR(i,NN) if(i!=cur) {
			if(A[i]>cand) return 0;
			if(A[i]+M<=cand) {
				NV--;
			}
			else {
				dif+=cand-A[i];
			}
		}
		return (1LL*NV*M<=dif);
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>V>>P;
	FOR(i,N) cin>>A[i];
	int ret=N-1;
	sort(A,A+N);
	for(i=20;i>=0;i--) if(ok(ret-(1<<i))) ret-=1<<i;
	
	cout<<N-ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
import collections

def main():
    n = int(input())
    V = list(map(int, input().split()))
    if len(set(V)) == 1:
        print(n // 2)
        exit()
    evens = []
    odds = []
    for idx, v in enumerate(V, start=1):
        if idx % 2 == 0:
            evens.append(v)
        else:
            odds.append(v)
    c_even = collections.Counter(evens)
    c_odd = collections.Counter(odds)
    even_most_common = c_even.most_common()[0]
    odd_most_common = c_odd.most_common()[0]

    if even_most_common[0] != odd_most_common[0]:
        print(count_replace(c_even, even_most_common[0], c_odd, odd_most_common[0], n))
    else:
        even_second_most_common = c_even.most_common()[1]
        odd_second_most_common = c_odd.most_common()[1]
        vals = []
        vals.append(count_replace(c_even, even_most_common[0], c_odd, odd_second_most_common[0], n))
        vals.append(count_replace(c_even, even_second_most_common[0], c_odd, odd_most_common[0], n))
        print(min(vals))


def count_replace(c_even, even, c_odd, odd, n):
    return n - c_even[even] - c_odd[odd]


if __name__ == '__main__':
    main()


Measured memory_bytes: 111544
<?php

class Operator
{
    public $n_operations;
    public $operations;
    public $keys_operated = array();

    public function __construct()
    {
        fscanf(STDIN, '%d', $this->n_operations);
        $this->operations = new \SplDoublyLinkedList();
        while ($this->n_operations > 0) {
            $word = trim(fgets(STDIN));
            if ($word[0] === 'i') {
                $this->operations->unshift(substr($word, 7));
            } elseif ($word[6] === 'F') {
                $this->operations->shift();
            } elseif ($word[6] === 'L') {
                $this->operations->pop();
            } else {
                foreach ($this->operations as $key => $element) {
                    if ($element === substr($word, 7)) {
                        $this->operations->offsetUnset($key);
                        break;
                    }
                }
            }
            $this->n_operations -= 1;
        }
    }

    public function getAnswer()
    {
        while (1) {
            if (count($this->operations) > 0) {
                $keys_operated[] = $this->operations->shift();
            } else {
                break;
            }
        }
        echo implode(' ', $keys_operated), PHP_EOL;
    }
}

$operator = new Operator();
$operator->getAnswer();



Measured memory_bytes: 136152
#include <bits/stdc++.h>
using namespace std;
#define M 200010
int a[M];
int main() {
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) {
		int x; scanf("%d", &x);
		a[x] = i;
	}
	a[n + 1] = 0;
	int cnt = 0, Ans = 0;
	for(int i = 1; i <= n; ++ i) {
		if(a[i] < a[i + 1]) {
			++ cnt;
		}
		else {
			Ans = max(Ans, cnt + 1);
			cnt = 0;
		}
	}
	printf("%d\n", n - Ans);
}

Measured memory_bytes: 1024
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
#define INT_MAX 2147483647
#define _LIBCPP_DEBUG 0
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)	
using namespace std;

int max(int a,int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}

int main() {
	int n, l;
	cin >> n >> l;
	string s[110];
	string k;

	rep(i, n) {
		cin >> s[i];
	}

	sort(s, s + n);
	rep(i, n) {
		k += s[i];
	}
	cout << k << endl;
}

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, m, ans = 0;
    cin >> n >> m;
    if(n > 0) ans += n * (n - 1) / 2;
    if(m > 0) ans += m * (m - 1) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=55;
map<string,int>mp;
int n,t[N],i,ans;
string X,s;
int main(){
	cin>>n;
	for(i=1;i<=n;++i)cin>>s>>t[i],mp[s]=i;
	cin>>X;
	for(i=mp[X]+1;i<=n;++i)ans+=t[i];
	cout<<ans<<endl;
}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)
VI R, G, B;

char find_color(char c1, char c2) {
  vector<bool> flags(3);
  if (c1 == 'R' || c2 == 'R') {
    flags[0] = true;
  }
  if (c1 == 'G' || c2 == 'G') {
    flags[1] = true;
  }
  if (c1 == 'B' || c2 == 'B') {
    flags[2] = true;
  }

  if (!flags[0]) {
    return 'R';
  } else if (!flags[1]) {
    return 'G';
  } else if (!flags[2]) {
    return 'B';
  }
}

bool find(char ch, int key) {
  VI vec;
  if (ch == 'R') vec = R;
  if (ch == 'G') vec = G;
  if (ch == 'B') vec = B;
  return binary_search(vec.begin(), vec.end(), key);
}

int count_another_color(char ch, int key) {
  VI vec;
  if (ch == 'R') vec = R;
  if (ch == 'G') vec = G;
  if (ch == 'B') vec = B;
  int len = vec.size();
  auto iter_upper = upper_bound(vec.begin(), vec.end(), key);
  long idx_upper = distance(vec.begin(), iter_upper);
  return len - idx_upper;
}

VI char_to_vec(char ch) {
  VI vec;
  if (ch == 'R') vec = R;
  if (ch == 'G') vec = G;
  if (ch == 'B') vec = B;
  return vec;
}

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

  REP(i, n) {
    if (s[i] == 'R') {
      R.push_back(i);
    } else if (s[i] == 'G') {
      G.push_back(i);
    } else if (s[i] == 'B') {
      B.push_back(i);
    }
  }

  ll ans = 0;

  FOR(i, 0, n - 2) {
    FOR(j, i + 1, n - 1) {
      if (s[i] == s[j]) continue;
      char another_color = find_color(s[i], s[j]);
      // cout << another_color << " " << i << " " << j << " "
      //      << count_another_color(another_color, j) << endl;
      if (find(another_color, j + j - i)) {
        ans += count_another_color(another_color, j) - 1;
      } else {
        ans += count_another_color(another_color, j);
      }
    }
  }

  ANS(ans);

  return 0;
}


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

using namespace std;

void gen_comb(vector<int>& v, int N, vector<vector<int>>& comb) {
  if (v.size() == N) {
    comb.push_back(v);
    return;
  }

  if (v.size() > 0) {
    comb.push_back(v);
  }

  for (int i = 1; i <= N; i++) {
    if (v.size() == 0 || i > v[v.size() - 1]) {
      v.push_back(i);
      gen_comb(v, N, comb);
      v.pop_back();
    }
  }
}

int main() {
  const int C_MAX = 1200000 + 1;

  int N, M, X;
  cin >> N >> M >> X;
  int C[N + 1], A[N + 1][M + 1];

  for (int i = 1; i <= N; i++) {
    cin >> C[i];
    for (int j = 1; j <= M; j++) {
      cin >> A[i][j];
    }
  }

  vector<vector<int>> comb;
  vector<int> v;
  gen_comb(v, N, comb);

  int now_lvl[M + 1];
  int sol = C_MAX;
  for (auto now_comb = comb.begin(); now_comb != comb.end(); now_comb++) {
    int now_sol = 0;
    for (int i = 1; i <= M; i++) {
      now_lvl[i] = 0;
    }

    for (auto it = (*now_comb).begin(); it != (*now_comb).end(); it++) {
      now_sol += C[*it];
      for (int i = 1; i <= M; i++) {
        now_lvl[i] += A[*it][i];
      }
    }

    bool is_ok = true;
    for (int i = 1; i <= M; i++) {
      if (now_lvl[i] < X) {
        is_ok = false;
      }
    }

    if (is_ok && now_sol < sol) {
      sol = now_sol;
    }
  }

  if (sol == C_MAX) {
    sol = -1;
  }

  cout << sol << '\n';

  return 0;
}

Measured memory_bytes: 3880
#include<iostream>
#include<string>
#include<bitset>
using namespace std;
int main(){
    string s;cin>>s;
    long long ans=0;
    int n=(int)s.length();
    for(int bit=0;bit<(1<<n-1);++bit){
        long long buf=s[0]-'0';
        for(int i=0;i<n-1;i++){
            if(bit&(1<<i)){
                ans+=buf;
                buf=s[i+1]-'0';
            }
            else{
                buf*=10;
                buf+=s[i+1]-'0';
            }
        }
        ans+=buf;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline ll read() {
    ll res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n;
ll ans;
int buc[100][2];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        ll x;
        x = read();
        for (int j = 60; j >= 0; j--) {
            ll tmp = 1ll << j;
            if (x & tmp) buc[j][1]++;
            else buc[j][0]++;
        }
    }
    for (int j = 0; j <= 60; j++) {
        ll tmp = 1ll << j;
        tmp %= MOD;
        ans = (ans + tmp * buc[j][1] % MOD * buc[j][0] % MOD) % MOD;
    }
    printf("%lld\n", ans % MOD);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define prique priority_queue
signed main(){
    int n,k;
    cin>>n>>k;
    double ans=0.0000000000;
    if(n>=k)ans=1.0000000000*(n-k+1)/n;
    int d=min(n,k-1);
    for(int i=1;i<=d;i++){
        double db=1.0000000000/n;
        int j=i;
        while(j<k){
            j*=2;
            db/=2;
        }
        ans+=db;
    }
    printf("%.10LF",ans);
    cout<<endl;
    return 0;
}


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

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  unordered_map<int, int> cnt1, cnt2;
  for (int i = 0; i < n; i += 2) cnt1[v[i]] += 1;
  for (int i = 1; i < n; i += 2) cnt2[v[i]] += 1;
  vector<pii> v1, v2;
  for (auto p: cnt1) v1.push_back(p);
  for (auto p: cnt2) v2.push_back(p);
  sort(v1.begin(), v1.end(), [](pii a, pii b) { return a.second > b.second; });
  sort(v2.begin(), v2.end(), [](pii a, pii b) { return a.second > b.second; });

  if (v1.size() == 1 && v2.size() == 1) {
    if (v1[0].first == v2[0].first) {
      cout << n / 2 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }

  if (v1.size() == 1) {
    if (v1[0].first == v2[0].first) {
      cout << n / 2 - v2[1].second << endl;
      return 0;
    } else {
      cout << n / 2 - v2[0].second << endl;
      return 0;
    }
  }

  if (v2.size() == 1) {
    if (v1[0].first == v2[0].first) {
      cout << n / 2 - v1[1].second << endl;
      return 0;
    } else {
      cout << n / 2 - v1[0].second << endl;
      return 0;
    }
  }

  int ans = n;

  for (auto p1: v1) {
    for (auto p2: v2) {
      if (p1.first != p2.first) {
        ans = min(ans, n - p1.second - p2.second);
        break;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 5896
#include <iostream>
#include <algorithm>
using namespace std; long long int l[10000000][2]; long long int memo[102][1000002];long long int n,k;
long long int rek(long long int dosad, long long int dosad2, long long int mjesto){
	if (mjesto==n-1){
		if (dosad2+l[n-1][0]<=k) return memo[n-1][dosad2+l[n-1][0]]=l[n-1][1];
		else return 0;
	}
	if (memo[mjesto][dosad2]) return memo[mjesto][dosad2];
	long long int maxn=0;
	if (l[mjesto][0]+dosad2<=k && rek(dosad+l[mjesto][1],dosad2+l[mjesto][0], mjesto+1)+l[mjesto][1]>maxn) maxn=l[mjesto][1]+rek(dosad+l[mjesto][1], dosad2+l[mjesto][0], mjesto+1);
	if (rek(dosad,dosad2, mjesto+1)>maxn) maxn=rek(dosad,dosad2, mjesto+1);
	return memo[mjesto][dosad2]=maxn;
}
int main(){
	cin >> n >> k; int zb=0;
	for (int i=0; i<n; i++){
		int t,w; cin >> t >> w; l[i][0]=t; l[i][1]=w;
		zb+=t;
	}
	long long int maxn=0; rek(0,0,0);
	for (int j=0; j<zb+1; j++){
		//cout << memo[i] << endl;
		if (memo[0][j]>maxn) maxn=memo[0][j];
	}
	cout << maxn;
}


Measured memory_bytes: 284928
#include <bits/stdc++.h>
 
using namespace std;
const int Nmax = 101;
 
long long n, a[Nmax], ps[Nmax], x;
 
int main() {
    cin >> n >> x;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; ++i) {
        ps[i] = ps[i - 1] + a[i];
    }
    if (x > ps[n]) { cout << n - 1; return 0; }
    cout << upper_bound(ps, ps + n + 1, x) - ps - 1;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

typedef struct{
  int x;
  int y;
  int z;
}Cheeze;

double data[3];
Cheeze in;

void make(){
  data[0] = in.x*in.x + in.y*in.y;
  data[1] = in.y*in.y + in.z*in.z;
  data[2] = in.z*in.z + in.x*in.x;
}
int main(){
  
  while(cin >> in.x >> in.y >> in.z && in.z+in.y+in.z){
    make();
    int num;
    cin >> num;
    for(int i = 0; i < num; i++){
      int hole_r;
      cin >> hole_r;
      int status = 0;
      for(int i = 0; i < 3; i++){
	if(data[i] < 4*hole_r*hole_r) status = 1;
      }
      if(status) cout << "OK" << endl;
      else cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())

# TLE
#cnt = 0
#kei = [] 
#for _ in range(n):
#    tmp = input()
#    if not tmp in kei:
#        cnt += 1
#        kei.append(tmp)

s = set()
for _ in range(n):
    s.add(input())
cnt = len(s)

print(cnt)

Measured memory_bytes: 30920
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
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; }

long long Pow(long long x, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 1) return (x * Pow(x, n - 1));
    long long t = Pow(x, n / 2);
    return (t * t);
}

int main() {
    int N;
    cin >> N;
    long long ans = 0;
    map<pair<char, char>, int> A, B;
    for (int i = 1; i <= N; i++) {
        string S = to_string(i);
        int K = S.length();
        pair<char, char> p = make_pair(S[K-1], S[0]);
        if (A.count(p) == true) A[p] += 1;
        else A[p] = 1;
        if (B.count(p) == true) B[p] += 1;
        else B[p] = 1;
    }
    
    for (char i = '1'; i <= '9'; i++) {
        for (char j = '1'; j <= '9'; j++) {
            pair<char, char> p = make_pair(i, j), q = make_pair(j, i);
            if (A.count(p) && B.count(q)) ans += A[p]*B[q];
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int a, b;
int main() {
    cin>>a>>b;
    cout<<a*b-(a+b)+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define X real()
#define Y imag()

using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef complex<double> P;

const int INF = 1 << 24;

int main(void){
    string res;
    for(vector<P> p(4); cin >> p[0].X >> p[0].Y; cout << res << endl){
        COUNT(i, 3) cin >> p[i].X >> p[i].Y;
        
        vector<P> pos(2);
        rep(i, 2) pos[i].X = p[2 * i + 1].X - p[2 * i].X,
                  pos[i].Y = p[2 * i + 1].Y - p[2 * i].Y;

        res = (fabs(pos[0].X * pos[1].X + pos[0].Y * pos[1].Y) < 1e-10) ? "YES":"NO";
    }
 
    return 0;
}

Measured memory_bytes: 1220