akhauriyash/Code-Regression huggingface dataset:
// abc063_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int alpha[26] = {0};
  string s;
  cin >> s;
  rep(i,s.size()) {
    alpha[s[i] - 'a'] += 1;
    if (alpha[s[i] - 'a'] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;
  return 0;
}


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI c(n-1), s(n-1), f(n-1);
	rep(i, n-1) cin >>c[i] >>s[i] >>f[i];
	
	rep(i, n-1){
		int now=0;
		rep2(j, i, n-1){
			int tim = max(0, (now - s[j] + f[j] -1)/f[j]);
			now = s[j] + f[j] * tim +c[j];
		}
		cout <<now <<"\n";
	}
	cout <<"0\n";
	
	return 0;
}


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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    string s;
    cin >> s;
    if(s[s.size()-1] == 's') cout << s + "es" << endl;
    else cout << s + "s" << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

struct T { int x, y, d; };

int n;
int a[2][110];
int d[2][110];

int main()
{
	while (cin >> n, n){
		fill_n(*a, 220, 2);
		memset(d, -1, sizeof(d));
		rep(i, 2) rep(j, n) cin >> a[i][j];
		queue<T> q;
		rep(i, 2){
			int p = 0;
			while (a[i][p] == 1 && a[i][p + 1] == 1) p++;
			q.push({i, p, 0});
		}
		int res = -1;
		while (q.size()){
			T c = q.front(); q.pop();
			if (c.y == n - 1){
				res = c.d;
				break;
			}
			for (int k = 0; k <= 2; k++){
				int nx = c.x ^ 1;
				int ny = c.y + k;
				int nd = c.d + 1;
				while (a[nx][ny] == 1 && a[nx][ny + 1] == 1) ny++;
				while (a[nx][ny] == 2) ny--;
				if (d[nx][ny] == -1){
					d[nx][ny] = nd;
					q.push({nx, ny, nd});
				}
			}
		}
		if (res == -1) cout << "NA" << endl;
		else cout << res << endl;
	}
}

Measured memory_bytes: 1200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] n = line.split(" ");

		int x = Integer.parseInt(n[0]);
		int y = Integer.parseInt(n[1]);

		int z = Math.max(x, y) % Math.min(x, y);

		int gcd = 1;

		if (x == y) {
			gcd = x;
		} else {
			for (int i = 1; i <= z; i++) {
				if (x % i == 0 && y % i == 0) {
					gcd = i;
				}
			}
		}

		System.out.println(gcd);

	}

}

Measured memory_bytes: 26348
def need(x,y):
    if x%y==0:
        answer = x//y
    else:
        answer = x//y + 1

    return answer

n = int(input())
move_lst = [int(input()) for _ in range(5)]
min_move = min(move_lst)

answer = need(n, min_move) + 4
print(answer)

Measured memory_bytes: 3060
//بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ
#include <bits/stdc++.h>
using namespace std;
int n, a;
int arr[51]; long long memo[51][51][2501];

long long solve(int i, int x, int sum){
    if(memo[i][x][sum] > -1) return memo[i][x][sum];
    long long v;
    if(i == n){
        if(x && !(sum%x) && sum/x == a) v = 1;
        else v = 0;
    } else{
        v = solve(i+1, x, sum) + solve(i+1, x+1, sum+arr[i]);
    }
    memo[i][x][sum] = v;
    return v;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(memo, -1, sizeof(memo));
    cin >> n >> a;
    for(int i = 0; i < n; i++) cin >> arr[i];
    cout << solve(0, 0, 0);
}


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

int main()
{
		int a, b, c, n;
		cin >> a >> b >> c;
		if (a==b && c%a==0) cout << 1 << "\n";
		else {
				for (int i=a; i<=b; i++) {
						if (c%i==0) n++;
				}
				cout << n << "\n";
		}
}

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

int main() {
	int n;
	cin >> n;
	vector<ll>march(5, 0);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s.at(0) == 'M')march.at(0)++;
		else if (s.at(0) == 'A')march.at(1)++;
		else if (s.at(0) == 'R')march.at(2)++;
		else if (s.at(0) == 'C')march.at(3)++;
		else if (s.at(0) == 'H')march.at(4)++;
	}
	ll ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += march.at(i) * march.at(j) * march.at(k);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
  ll N;
  ll ans = 2;
  cin >> N;
  while(N > 1){
    N /= 2;
    ans *= 2;
  }
  ans -= 1;
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n;
   cin>>n;
   ll a[n];
   for(ll i=0;i<n;i++){
       cin>>a[i];
   }
   sort(a,a+n);
   reverse(a,a+n);
   ll ans=0;
   ans+=a[0];
   if(n>=2){
   ll p1=1,p2=2;
   while(p2!=n){
       if(n-p2-1>=1){
           p2+=2;
           ans+=2*a[p1];
           p1++;
       }else if(n-p2-1==0){
           p2+=1;
           ans+=a[p1];
           p1++;
       }else{
           break;
       }
   }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)

using ld = long double;
const ld pi = 3.14159265358979323846264338327950288419716939937510L;

int main(){
    int N;
    cin >> N;
    ld x[N], y[N];
    ld mx = 0, my = 0; // 重心
    rep(i, N){
        cin >> x[i] >> y[i];
        mx += x[i];
        my += y[i];
    }
    mx /= N;
    my /= N;
    ld a[N], b[N], c[N]; // 点iと点i+1の直線に関する不等式がax+by+c>=0
    rep(i, N){
        int i2 = (i + 1) % N;
        a[i] = -(y[i2] - y[i]);
        b[i] = (x[i2] - x[i]);
        c[i] = x[i] * y[i2] - x[i2] * y[i];
        //cout << a[i] << "x+" << b[i] << "y+" << c[i] << ">=0" << endl;
    }
    vector<pair<ld, pair<bool, int>>> point_atan;
    rep(i, N){
        ld theta = atan2(y[i] - my, x[i] - mx);
        point_atan.push_back({theta, {0, i}});
    }
    sort(all(point_atan));
    int now_vertex = point_atan[N - 1].second.second;
    int Q;
    cin >> Q;
    ld xa[Q], ya[Q];
    rep(i, Q){
        cin >> xa[i] >> ya[i];
        xa[i] *= 0.9999;
        ya[i] *= 0.9999;
        ld theta = atan2(ya[i] - my, xa[i] - mx);
        point_atan.push_back({theta, {1, i}});
    }
    int ans[Q];
    sort(all(point_atan));
    for(auto now: point_atan){
        int num = now.second.second;
        if(now.second.first == 0){
            now_vertex = num;
        }else{
            ans[num] = (xa[num] * a[now_vertex] + ya[num] * b[now_vertex] + c[now_vertex] >= 0);
        }
    }
    rep(i, Q){
        cout << ans[i] << endl;
    }
}





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

using namespace std;

int main()
{
    int n , m ;
    cin>>n>>m ;
    int ans = 1e9+2 ;
    int arr[n] ;
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    sort(arr , arr + n) ;
    for(int i = 0 ; i < n ; ++i)
    {
        if((i + m - 1) >= n)
            break;
        ans = min(ans , arr[i+m-1] - arr[i]);
    }
    return cout<<ans , 0 ;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

ll S;

int main()
{
	cin >> S;
	ll t = sqrt(S);
	while (t * t < S)
		t++;
	ll d = t * t - S;
	cout << 0 << ' ' << 0 << ' ' << t << ' ' << 1 << ' ' << d << ' ' << t << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

# 2 <= N <= 10^5
S = stdin.readline().rstrip()
N = len(S)

def run_length_compression(string):
    ret = []
    count = 1
    for i in range(len(string)-1):
        if string[i] == string[i+1]:
           count = count + 1
        else:
            ret.append((string[i], count))
            count = 1

    # 最後の文字セット
    ret.append((string[-1], count))

    return ret

run_length = run_length_compression(S)

ans = [0] * N

# ラングレス圧縮のデータのためのインデックスカーソル
cur = 0

for i in range(N):
    # RLの形の時だけを考えれば良い
    if S[i] == "R" and S[i+1] == "L":
        # 自分自身(1) + 偶数マス離れたものの数で考える
        # R
        ans[i] = 1 + (run_length[cur][1]-1)//2 + (run_length[cur+1][1])//2
        # L
        ans[i+1] = 1 + (run_length[cur][1])//2 + (run_length[cur+1][1]-1)//2

        # カーソルを進める
        cur += 2
        
#print(run_length)

print(*ans, sep=" ")


Measured memory_bytes: 83100
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
t = input()
n = len(s)
m = len(t)
ans = float("inf")
for i in range(n):
    if i+m>n:
        break
    val = sum((c!=c2) for c,c2 in zip(s[i:i+m], t))
    ans = min(ans, val)
#     print(val)
print(ans)

Measured memory_bytes: 67656
#include <bits/stdc++.h>
using namespace std;
int n;
long long a,sum[200000];
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(i)sum[i]=sum[i-1]+a;
    else sum[i]=a;
  }
  long long ans=20000000000;
  for(int i=0;i<n-1;i++){
    ans=min(ans,abs(sum[n-1]-2*sum[i]));
  }
  cout<<ans;
}

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

using namespace std;

struct unionfind {
	vector<int> data;
	unionfind(int size) : data(size, -1) { }
	bool Union(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y) {
			if (data[y] < data[x])
				swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	bool Find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};



int main()
{
	int n,q,com,x,y;
	cin >> n >> q;
	unionfind a(n);
	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com == 0) {
			a.Union(x,y);
		}
		else {
			cout << a.Find(x, y) << endl;;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String p = sc.nextLine();
		if(p.equals("AAA")||p.equals("BBB")){
				System.out.println("No");
			}else {
				System.out.println("Yes");
			}			
		
	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define debug(elem) foreach(e, elem){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
#define INF 1e+8
#define PI acos(-1)
#define MOD 100000009
using ll = long long;
using ull = unsigned long long;

map<string, int> mp;

int main(){
    int n;
    cin >> n;
    string s;
    rep(i, n){
        cin >> s;
        mp[s]++;
    }

    int mx = 0;
    foreach(e, mp){
        if(e.second >= mx){
            mx = e.second;
        }
    }

    foreach(e, mp){
        if(e.second == mx){
            println(e.first);
        }
    }
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    string a, b;
    cin >> a >> b;
    bool ok = false;
    for(int i=0;i<a.size();i++){
        int cnt = 0;
        for(int j=0;j<b.size();j++){
            if(i+j==a.size()){
                break;
            }
            if(a[i+j]==b[j] || b[j]=='_'){
                cnt++;
            }
            else{
                break;
            }
        }
        if(cnt==b.size()){
            ok = true;
        }
    }
    cout << (ok?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef float fl;
typedef long long ll;
const int INF = 1200001;
int a[12][12];


int main(){
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n,0);
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    int ans = INF;
    rep(i,1<<n){
        int cost = 0;
        vector<int> d(m,0);
        rep(j,n){
            if(i>>j&1){
                cost += c[j];
                rep(k,m) d[k] += a[j][k];
            }
        }
        bool ok = true;
        rep(j,m) if(d[j] < x) ok = false;
        if (ok) ans = min(cost, ans);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL<<30;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, 3) if (s[i] == t[i]) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
x,k,d = (int(x) for x in input().split())

if(x<0):
    x = -x

c = x%d
a = x//d

if(k<a):
    print(x-k*d)
else:
    if((k-a)%2 == 0):
        print(c)
    else:
        print(d-c)


Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define syn ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;}
const db eps=1e-8,PI=acos(-1.0);
const int N=4e3+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
int n,a[N],sum[3][N];
char s[N];
ll ans;
ll cal(int id,ll l,ll r){
	if(l>r)return 0;
	return sum[id][r]-sum[id][l-1];
}
int main(){
	sci(n);
	scanf("%s",s+1);
	rep(i,1,n){
		a[i]=(s[i]=='R'?0:(s[i]=='G'?1:2));
		rep(j,0,2){
			sum[j][i]=sum[j][i-1];
		}
		sum[a[i]][i]++;
	}
	rep(j,2,n-1){
		rep(i,1,j-1){
			if(a[i]==a[j])continue;
			ans+=cal(3-a[i]-a[j],j+1,n);
			if(2*j-i<=n && a[2*j-i]==3-a[i]-a[j])ans--;
		}
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
    using namespace std;
    #define FOR(i,n) for(int i=0;i<n;i++)
    #define why(n,x) int n;while(cin >>n,n!=x)
    #define iFOR(i,x,n)for(int i=x;i<n;i++)
    #define unless(flg) if ( !(flg) )
    #define read cin<<
    #define echo cout<<
    #define fin <<'\n'
    #define __ <<" "<<
    #define bash push_back
    #define alles(x) x.begin(),x.end()
    int dx[]={1,0,-1,0,1,1,-1,-1};
    int dy[]={0,-1,0,1,-1,1,-1,1};
    const int INF=1 << 30;
    bool inside(int x,int y,int w,int h){
    return (x>=0 && y>=0 && x<w && y<h);}
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef vector<int> vit;
    typedef map<string,int> mstit;
    typedef priority_queue<int> pqit;
    ll n,a[1000005];
    int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    cin >>n;
    FOR(i,n*3){
    cin >>a[i];
    }
    sort(a,a+n*3,greater<int>());
    ll ans=0;
    for(int i=1;i<=n*2;i+=2){
    ans+=a[i];
    }
    cout <<ans fin;
    return 0;
    }

Measured memory_bytes: 4352
from sys import stdin
import numpy as np
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 10**18
lcums = np.cumsum(data)
rcums = list(reversed(np.cumsum(list(reversed(data)))))
for i in range(0,N-1):
    ans = min(ans,abs(lcums[i]-rcums[i+1]))
print(ans)

Measured memory_bytes: 32968
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int x,y;
	scanf("%d%d",&x,&y);
	int ans=0;
	if(x==1){
		ans+=300000;
	}
	if(x==2){
		ans+=200000;
	}
	if(x==3){
		ans+=100000;
	}
	swap(x,y);
	if(x==1){
		ans+=300000;
	}
	if(x==2){
		ans+=200000;
	}
	if(x==3){
		ans+=100000;
	}
	if(x+y==2){
		ans+=400000;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
char s[maxn];
int c[maxn][26];
int min_from[maxn];
int vis[maxn];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n;
	cin >> s + 1, n = strlen(s + 1);
	for(int j = 0;j < 26;++j) c[n + 1][j] = n + 1;
	for(int i = n;i >= 0;--i) {
		for(int j = 0;j < 26;++j) c[i][j] = c[i + 1][j];
		if(i != n) c[i][s[i + 1] - 'a'] = i + 1;
	}
	std::queue<int> q;
	q.push(0); vis[0] = 1;
	for(;!q.empty();) {
		int x = q.front(); q.pop();
		for(int j = 0;j < 26;++j) {
			if(!vis[c[x][j]]) {
				vis[c[x][j]] = 1;
				min_from[c[x][j]] = x;
				q.push(c[x][j]);
			}
		}
	}
	std::string ans;
	for(int i = 0;i < 26;++i) if(c[min_from[n + 1]][i] == n + 1) { ans = char(i + 'a'); break; }
	for(int i = n + 1;i = min_from[i];) ans += s[i];
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
}


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

using namespace std;
const long long int big =998244353;
int main()
{
    int n,s;
    cin >> n >>s;
    int a[n+1];
    long long int table[n+1][s+1];
    long long int temp;
    for(int i=1;i<=s;i++){
        table[0][i]=0;
    }
    table[0][0]=1;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        for(int j=0;j<=s;j++){
            if(j<a[i]){
                table[i][j]=(2*table[i-1][j])%big;
            }else{
                table[i][j]=(((2*table[i-1][j])%big)+table[i-1][j-a[i]])%big;
                // cout <<","<< table[i-1][j-a[i]] << "," <<endl;
            }
            // cout << table[i][j] << " ";
        }
    // cout << endl;
    }
    cout << table[n][s] << endl;
    return 0;
}

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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(0)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)

int n;
ll dp[405][405], pref[405];
ll INF=(1e18);

int main()
{
	readUI(&n);
	for (int i=1; i<=n; ++i)
	{
		readUL(&dp[i][i]);
		pref[i]=pref[i-1]+dp[i][i];
	}
	for (int dl=2; dl<=n; ++dl)
	{
		for (int i=1; i<=n-dl+1; ++i)
		{
			int j=i+dl-1;
			dp[i][j]=INF;
			for (int k=i; k<=j; ++k)
			{
				dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+pref[j]-pref[i-1]);
			}
			debug
			{
				fprintf (err, "i=%d j=%d dp[i][j]=%lld\n", i, j, dp[i][j]);
			}
		}
	}
	fprintf (out, "%lld\n", dp[1][n]-pref[n]);
	return 0;
}
/*
*/




Measured memory_bytes: 1536
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
int z=0;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}//ここから始めよう
signed main(){
    int a,b;cin>>a>>b;
    vector<int>v;
    for(int i=1;i*i<=b;i++){
        if(b%i==0){
            v.ps(i);v.ps(b/i);
        }
    }
    sort(v.begin(),v.end(),greater<int>());
    for(auto x : v){
        if(a*x<=b){
         cout<<x<<endl;return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int main() {
    int n, m, x, gate[1000];
    
    mem( gate, 0);
    
    cin3(n,m,x);
    
    int c;
    rep(i,m) {
        scnd1(c);
        gate[c] = 1;
    }
    
    int minc = 1000000;
    c = 0;
    for ( int i = x; i <= n; i++ ) {
        c += gate[i];
    }
    minc = c;
    c = 0;
    for ( int i = x; i >= 0; i-- ) {
        c += gate[i];
    }
    minc = min( minc, c);
    
    cout1(minc);
}

Measured memory_bytes: 384
#include <stdio.h>
#include <limits.h>

#define NIL -1
#define WHITE 0
#define BLACK 1
#define MAX 100

int matrix[MAX][MAX];
int n;

void prim(){

    int i;
    int d[n],pi[n],color[n];
    int mincost;
    int u;
    int v;
    int sum = 0;

    for( i = 0 ; i < n ; i++ ){
        d[i] = INT_MAX;
        pi[i] = NIL;
        color[i] = WHITE;
    }

    d[0] = 0;
    pi[0] = NIL;

    while( 1 ){

        mincost = INT_MAX;

        for( i = 0 ; i < n ; i++ ){
            if( color[i] != BLACK && d[i] < mincost ){
                mincost = d[i];
                u = i;
            }

        }

        if( mincost == INT_MAX ){
            break;
        }

        color[u] = BLACK;

        for( v = 0 ; v < n ; v++ ){

            if( color[v] != BLACK && matrix[u][v] != INT_MAX ){
                
                if( matrix[u][v] < d[v] ){
                    
                    pi[v] = u;
                    d[v] = matrix[u][v];

                }
            }
        }

    }

    for( i = 0 ; i < n ; i++ ){
        sum += d[i];
    }

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

}

int main(){

    int i,j;
    scanf("%d",&n);

    for( i = 0 ; i < n ; i++ ){
        for( j = 0 ; j < n ; j++ ){
            scanf("%d",&matrix[i][j]);
            if( matrix[i][j] == NIL ){
                matrix[i][j] = INT_MAX;
            }
        }
    }

    prim();

    return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
int main()
{
    int y, m, d;
    scanf("%d/%d/%d",&y, &m, &d);
    if(y= 2019){
        if(m>4){
        printf("TBD");
        }else{
            printf("Heisei");
        }
    }else if(y > 2019){
        printf("TBD");
    }
    else{
        printf("Heisei");
    
    }
}

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

bool comp(pair<int,string>p1,pair<int,string>p2){

	if(p1.first > p2.first)return true;
  else if(p1.first < p2.first)return false;
  else{

  	  if(p1.second < p2.second)return true;
  	  return false;
  }
}

int main(){
    
    int n;
    cin>>n;
    
    map<string,int>mp;

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

    	string s;
    	cin>>s;

    	mp[s]++;
    }
    
    vector<pair<int,string>>v;
 
    for(auto i =mp.begin();i!=mp.end();i++){
          
          v.push_back({i->second,i->first});
    }

    sort(v.begin(),v.end(),comp);

    int cnt = v[0].first;

    for(int i=0;i<n;i++){
        
        if(v[i].first == cnt){
        	cout<<v[i].second<<endl;
        }else{
        	break;
        }
    }

	return 0;
}


Measured memory_bytes: 29552
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int min = 1;
		
		for(int i = 0; i < N; i++) {
			if(min + K > min * 2) {
				min *= 2;
			} else {
				min += K;
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define neko 200010
#define feko 800010
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
#define fe(i,a,b) for(register int i=(a);i<(b);i=-(~i))
#define rf(i,a,b) for(register int i=(a);i>=(b);i=~(-i))
int n,t,head[neko],siz[neko];
typedef long long arf[feko];
arf A,B,gi,rev;
typedef long long ll;
ll gpow[feko][2],F[neko],fac[neko],ifac[neko],mod=924844033;
struct edge
{int v,nex;}e[neko<<1];
namespace IO
{
	const unsigned int bufsize=1<<16,outsize=1<<24;
	static char ch[bufsize],*S=ch,*T=ch;
	inline char getc()
	{return ((S==T)&&(T=(S=ch)+fread(ch,1,bufsize,stdin),S==T)?0:*S++);}
	static char Out[outsize],*nowp=Out;
	inline void flush(){fwrite(Out,1,nowp-Out,stdout);nowp=Out;}
	template<typename T>
		void read(T &x)
		{
			char c=getc();x=0;
			for(;!isdigit(c);c=getc());
			for(;isdigit(c);x=(x<<1)+(x<<3)+(c^'0'),c=getc());
		}
	template<typename T>
		void write(T x,char c='\n')
		{
			if(!x)*nowp++='0';
			static unsigned int stk[50],tp=0;
			for(;x;x/=10)stk[++tp]=x%10;
			for(;tp;*nowp++=stk[tp--]^'0');*nowp++=c;
		}
}
ll ADD(ll x,ll y){return (x+=y)>=mod?x-mod:x;}
ll spow(ll m,ll n)
{
	ll b=1;
	for(;n;n>>=1,m=m*m%mod)if(n&1)b=b*m%mod;
	return b;
}
namespace Conv
{
	using std::swap;
	ll gen=5,igen=spow(5,mod-2);
	int n,m;
	void NTT(ll *p,int opt)
	{
		fe(i,0,n)if(i<rev[i])swap(p[i],p[rev[i]]);
		int hfi;
		ll u,v;
		for(register int i=2;i<=n;i<<=1)
		{
			hfi=i>>1;
			fe(j,1,hfi)gi[j]=gi[j-1]*gpow[i][opt]%mod;
			for(register int j=0;j<n;j+=i)
			{
				fe(k,0,hfi)
				{
					u=p[j+k],v=gi[k]*p[j+k+hfi]%mod;
					p[j+k]=ADD(u,v),p[j+k+hfi]=ADD(u,mod-v);
				}
			}
		}
		if(!opt)
		{
			int in=spow(n,mod-2);
			fe(i,0,n)p[i]=p[i]*in%mod;
		}
	}
	int solve(int n1,int n2,int opt)
	{
		m=n1+n2;int cnt=0;
		for(n=1;n<=m;n<<=1)++cnt;--cnt;
		fe(i,0,n)rev[i]=(rev[i>>1]>>1)|((i&1)<<cnt);
		NTT(A,1),NTT(B,1);
		if(opt==1)fe(i,0,n)A[i]=A[i]*B[i]%mod;
		if(opt==2)fe(i,0,n)A[i]=A[i]*B[i]%mod*B[i]%mod;
		NTT(A,0);return n;
	}
	void init(int x,int n)
	{
		fac[0]=ifac[0]=gi[0]=1;
		f(i,1,n+5)fac[i]=fac[i-1]*i%mod;
		ifac[n+5]=spow(fac[n+5],mod-2);
		rf(i,n+4,1)ifac[i]=ifac[i+1]*(i+1)%mod;
		for(register int i=2;i<=x;i<<=1)gpow[i][1]=spow(gen,(mod-1)/i),gpow[i][0]=spow(igen,(mod-1)/i);
	}
}
void dfs(int u,int fa)
{
	siz[u]=1;
	for(register int i=head[u],v=e[i].v;i;i=e[i].nex,v=e[i].v)if(v^fa)dfs(v,u),siz[u]+=siz[v];
	++F[siz[u]],++F[n-siz[u]];
}
void add(int x,int y)
{
	e[++t].v=y,e[t].nex=head[x],head[x]=t;
	e[++t].v=x,e[t].nex=head[y],head[y]=t;
}
int main()
{
	using namespace IO;
	int x,y;
	read(n);
	for(x=2;x<=n;x<<=1);
	Conv::init(x<<1,n);
	f(i,1,n-1)read(x),read(y),add(x,y);
	dfs(1,0);
	f(i,0,n-1)A[i]=fac[i]*(mod-F[i])%mod;
	A[n]=fac[n]*n%mod;
	f(i,0,n)B[i]=ifac[n-i];
	Conv::solve(n,n,1);
	f(i,1,n)printf("%lld\n",ADD(A[n+i]*ifac[i]%mod,mod));
	return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">:", debug_out(__VA_ARGS__)
#define INF LLONG_MAX


int main()
{
  ll n,x;
  cin >> n;
  x = n%10;
  if (x == 3) cout << "bon" << endl;
  else if(x == 0 or x==1 or x==6 or x==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();
		if(N >= M/2) {
			System.out.println(M/2);
			return;
		}
		System.out.println(N + (M-2*N)/4);
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>
#include<set>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){
    int N;
    cin>>N;
    map<string,int> M;
    vector <string> S(N);
    set <string> Sans;
    rep(i,0,N)cin>>S[i];
    rep(i,0,N){
        M[S[i]]++;
    }
    int Smax=0;
    rep(i,0,N){
        if(Smax<M[S[i]])Smax=M[S[i]];
    }
    rep(i,0,N){
        if(M[S[i]]==Smax){
            Sans.insert(S[i]);
        }
    }
    auto itr = Sans.begin();
    rep(i,0,Sans.size()){
        cout<<*itr<<endl;
        itr++;
    }
    return 0;
}

Measured memory_bytes: 36096
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

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

	long long ans = (x / 500) * 1000;

	x = x - (x / 500) * 500;

	ans += (x / 5) * 5;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      String s = in.next();
      boolean isEasy = true;

      for (int i = 0; i < s.length(); ++i) {
        if ((i + 1) % 2 == 1 && s.charAt(i) == 'L') {
          isEasy = false;
          break;
        } else if ((i + 1) % 2 == 0 && s.charAt(i) == 'R') {
          isEasy = false;
          break;
        }
      }

      if (isEasy) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 21716
import java.util.Scanner;

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

        int N = Integer.parseInt(sc.next());
        double sum = 0d;
        double tmp1;
        String tmp2;

        for (int i = 0; i < N; i++) {
            tmp1 = Double.parseDouble(sc.next());
            tmp2 = sc.next();

            if (tmp2.equals("JPY")) {
                sum += tmp1;
            } else if (tmp2.equals("BTC")) {
                sum += tmp1 * 380000;
            } else {

            }
        }

        System.out.print(sum);
    }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string L;
  cin >> L;
  ll ans = 0;
  ll count = 0;
  ll all1 = 0;

  REP(i, L.size()) {
    if (L[i] == '1')
      all1++;
  }
  ll N = L.size();

  REP(i, L.size()) {
    if (L[i] == '1') {
      ans += MODPOW(3, N - i - 1) * MODPOW(2, count);
      ans %= MOD;
      count++;
    }
  }
  ans += MODPOW(2, count);
  ans %= MOD;

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/





signed main() {
	string r,s,t;
	cin>>r; s=r+r;
	cin>>t;

	vector<vector<ll>> s_position(26,vector<ll>());
	vector<ll> t_num(26,0);
	rep(i,s.size()){
		ll ch=s[i]-'a';
		s_position[ch].push_back(i);
	}
	rep(i,t.size()){
		ll ch=t[i]-'a';
		t_num[ch]++;
	}
	rep(i,26){
		if(s_position[i].size()==0 && t_num[i]>0){
			cout<<-1<<endl;
			return 0;
		}
	}

	vector<vector<ll>> next(26,vector<ll>(s.size(),INF));
	ll ch=s[s.size()-1]-'a';
	next[ch][s.size()-1]=s.size()-1;
	for(ll i=s.size()-2;i>=0;i--){
		rep(j,26){
			next[j][i]=next[j][i+1];
		}
		ll ch=s[i]-'a';
		next[ch][i]=i;
	}

	ll ans=0;
	ll index=0;
	rep(i,t.size()){
		ll ch=t[i]-'a';
		ll nextindex=next[ch][index];
		ans+=nextindex-index+1;
		index=nextindex+1;
		if(index>=r.size())index-=r.size();
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 44928
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A,B,C;
  char X;
  cin>>A>>B>>C;
  X=A[0];
  A.erase(A.begin());
  while(1){
    if(X=='a'){
      if(A.size()==0) break;
      else{
        X=A[0];
        A.erase(A.begin());
      }
    }else if(X=='b'){
      if(B.size()==0) break;
        else{
        X=B[0];
        B.erase(B.begin());
        }
    }else{
      if(C.size()==0) break;
      else{
        X=C[0];
        C.erase(C.begin());
      }
    }
  }
  cout<<char(X-'a'+'A')<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String args[]) {
    final Scanner scanner = new Scanner(System.in);
    final String input = scanner.next();
    final int count0 = countChar(input, '0');
    final int count1 = countChar(input, '1');
    System.out.println(input.length() - Math.abs(count0 - count1));
  }
  private static int countChar(String str, char target){
    return str.length() - str.replace(String.valueOf(target), "").length();
  }
}

Measured memory_bytes: 33308
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

n, x = LI()
ls = LI()

ans = 1
l = 0
for i in ls:
    l = l + i
    if l <= x:
        ans += 1
    else:
        break

print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
 
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define debug(str,x) cout << str << ":" << x << endl
#define ll long long
#define int64 __int64
#define ui unsigned int

using namespace std;

const ll mod = 1e9 + 7;

//Date:2018-9-01
//Author：HarryBlackCat

int main() {
	//cin.sync_with_stdio(false);//降低cin，cout时间
	ll k;
	while(~rl(k)){
		ll odd = 0,even = 0;
		for(int i = 1;i <= k;i++){
			if(i % 2 == 0)
				even++;
			else
				odd++;
		}
		
		pr(odd * even);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define st first
#define sc second
#define arr array
#define yes cout << "Yes" <<"\n"
#define no cout << "No" <<"\n"
#define lb lower_bound
#define ub upper_bound
#define fast ios_base::sync_with_stdio(false)
#define out cin.tie(nullptr)
#define task "A"
#define open(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout);}
#define open_to_check(task)  if(fopen(task".inp", "r")){freopen(task".inp", "r", stdin);}

using namespace std;

const int maxn = 2e6 + 1;
const ll mod = 1e9 + 7;
const ll lim = 1e18;


int main()
{
    //open_to_check(task);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = ' ' + s;
    int dem = 0;
    for(int i=1; i<=n; i++){
        if(s[i] == 'R'){
            dem ++;
        }
    }
    int ans = dem;
    for(int i=1; i<=dem; i++){
        if(s[i] == 'R') ans --;
    }
    cout << ans;
}
/*
6 8
1 2
1 3
2 3
2 4
2 6
3 5
3 6
4 5

*/


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

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

int main(int argc, char **argv)
{
	string s; cin >> s;
	ll N = s.size();

	ll cnt{0};
	for (auto &c : s)
	{
		if (c == 'p')
			++cnt;
	}

	std::cout << N/2 - cnt << std::endl;
}

Measured memory_bytes: 512