akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll h; cin>>h;
	ll ans = 0, tmp = 1;
	while(h>=1){
		h /= 2;
		ans += tmp; tmp *= 2;
	}
	cout<<ans<<endl;	
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author P.Alizadeh
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll,ll>     pll;
typedef complex<ld>     cld;

#define all(x)          x.begin(),x.end()
#define Sort(x)         sort(all(x))
#define kill(x)         return cout << x << endl, 0;
#define Mp              make_pair
#define X               first
#define Y               second
#define sep             " "
#define endl            "\n"
#define fastio          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io         freopen("in.txt" , "r" , stdin) ; freopen("out.txt" , "w" , stdout);
#define ld_io           cout << setprecision(10) << fixed;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll pw(ll a, ll b, ll md) {
    if (!b)
        return 1;
    if (b & 1)
        return a * pw(a * a % md, b / 2, md) % md;
    return pw(a * a % md, b / 2, md) % md;
}

const ll MAXN = 1e5 + 10,
         INF  = 8e18,
         MOD  = 1e9 + 7,
         LOG  = 32;
//const ld PI   = M_PI;

ll n, dp[MAXN][2];
vector<ll> adj[MAXN];

void dfs(ll u, ll p = -1) {
    dp[u][0] = dp[u][1] = 1;
    for (ll v : adj[u]) {
        if (v != p) {
            dfs(v, u);
            dp[u][0] = (dp[u][0] * dp[v][1]) % MOD;
            dp[u][1] = (dp[u][1] * (dp[v][0] + dp[v][1])) % MOD;
        }
    }
}

int main()
{
    fastio;
    //ld_io;

    cin >> n;
    for (ll i = 0; i < n - 1; i++) {
        ll u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1);

    cout << (dp[1][0] + dp[1][1]) % MOD << endl;

    return 0;
}



Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int a[100005],b[100005];
int len;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	   cin>>a[i];

	b[1]=-a[1],len=1;

	for (int i=2;i<=n;i++)
		if (-a[i]>=b[len]) b[++len]=-a[i];
		else b[upper_bound(b+1,b+len,-a[i])-b]=-a[i];

	cout<<len<<endl;
}

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

int main() {
	string a;
    int ans; 
	cin >> a;
    if (a[0] == '1') {
      ans++;
    }
    if (a[1] == '1') {
      ans++;
    }
    if (a[2] == '1') {
      ans++;
    }
	cout << ans << endl;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vl a(3),b(2);
	cin>>a>>b;
	puta(min(a)+min(b)-50);
	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using Pair = pair<int, int>;

const int INF = 1e9;

int main() {
  int H, N;
  cin >> H >> N;
  vector<Pair> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i].first >> as[i].second;
  }
  vector<int> hs(H + 1, INF);
  hs[0] = 0;
  for(int h = 0; h < H; ++h) {
    for(int j = 0; j < N; ++j) {
      auto next = min(h + as[j].first, H);
      hs[next] = min(hs[h] + as[j].second, hs[next]);
    }
  }
  cout << hs[H] << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
    int r, d;
    vector<int> x(11);
    cin >> r >> d >> x[0];
    for (int i = 1; i < 11; i++){
        x[i] = x[i-1] * r - d;
        cout << x[i] << "\n";
    }
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,k,ans=0;
  std::cin >> n >> k;
  int x[200];
  for(int i=0; i<n; i++) std::cin >> x[i];
  for(int i=0; i<n; i++){
    if(x[i]<(abs(x[i]-k))) ans+=x[i]*2;
    else ans+=(abs(x[i]-k))*2;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	vector<ll> a(n);
	for (ll i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	if (n % 2 == 1)
	{
		a.push_back(0);
	}

	ll cnt = 0;
	for (ll i = 0; i < n + 1; i ++)
	{
		if (a[i] == i + 1)
		{
			ll buf = a[i];
			a[i] = a[i + 1];
			a[i + 1] = buf;

			cnt++;
		}
	}

	println(cnt);
}


Measured memory_bytes: 1792
import math

N = int(raw_input())

def genprimes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

primes = genprimes(55556)

ans = []
for p in primes:
    if str(p)[-1] == '1':
        ans.append(p)

print(' '.join(map(str, ans[:N])))


Measured memory_bytes: 5300
#include <stdio.h>

int main(){
  int n,A[101];
  int i,j,k=0,flag,a,cnt=0;

  scanf("%d",&n);

  if (n>=1 && n<=100){
    for (i=0; i<n; i++) scanf("%d",&A[i]);
    flag = 1;
    while(flag){
      flag = 0;
      for (j=n-1; j>0; j--){
	if (A[j] < A[j-1]){
	  a = A[j-1];
	  A[j-1] = A[j];
	  A[j] = a;
	  flag = 1;
	  cnt++;
	}
      }
    }
    for (i=0; i<n-1; i++) printf("%d ",A[i]);
    printf("%d\n",A[i]);
    printf("%d\n",cnt);
  }
  
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <cmath>
#define ll double
#define pi 3.1415926535897932384626433
#define l long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s>>t;
    l l1;
    l1=s.length();
    t.erase(l1);
    if(s.compare(t)==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}
    

Measured memory_bytes: 3640
/*#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define ll long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;*/

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define ll long long

const LL MOD=1e9+7;
const int maxn=1e5+10;

//const int INF=0x7ffffff;
//const int magic=348;
//const int zero=200;

int n;
//LL p,p1;
LL id1,id2;
LL a[100048];
int v[100048];
int cnt[100048];

LL fac[100048],finv[100048],inv[100048];

void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<100010;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int x,int y)
{
	if(x<y) return 0;
	return fac[x]*(finv[y]*finv[x-y]%MOD)%MOD;
}

int main ()
{
	//LL i;
	//cin>>n;
	/*memset(cnt,0,sizeof(cnt));
	for (i=1;i<=n+1;i++)
	{
		cin>>a[i];
		cnt[a[i]]++;
	}
	p=p1=0;
	for (i=1;i<=n+1;i++)
		if (cnt[a[i]]==2)
			if (p1==0) p1=i; else p=i;*/
	/*	memset(a, 0, sizeof(a));
    memset(v, 0, sizeof(v));
    for(ll i = 1; i <= n + 1; ++i){
        cin >> a[i];
        v[a[i]]++;
    }
    for(ll i = 1; i <= n + 1; ++i){
        if(v[a[i]] == 2 && !id1){
            id1 = i;
        }
        else if(v[a[i]] == 2) {
            id2 = i;
        }
    }
	LL ans;
	make();
	LL L=max(id1-1,0LL),R=max(n+1-id2,0LL);
	for (ll i=0;i<=n;i++)
	{
		ans=C(n+1,(i+1)*1LL);
		ans-=C(L+R,i*1LL);
		if (ans<0) ans+=MOD;
		cout<<ans<<endl;
	}
	return 0;*/
	ll n;
    make();
    ll id1 = 0, id2 = 0;
    cin >> n;
    memset(a, 0, sizeof(a));
    memset(v, 0, sizeof(v));
    for(ll i = 1; i <= n + 1; ++i){
        cin >> a[i];
        v[a[i]]++;
    }
    for(ll i = 1; i <= n + 1; ++i){
        if(v[a[i]] == 2 && !id1){
            id1 = i;
        }
        else if(v[a[i]] == 2) {
            id2 = i;
        }
    }
    ll L = max(id1 - 1LL, 0LL), /*M = id2 - id1 - 1LL*/ R = max(n + 1LL - id2, 0LL);
    ll res = 0;
    for(ll i = 1; i <= n + 1; ++i){
        res = C(n + 1, i * 1LL);
        res -= C(L + R, (i - 1) * 1LL);
        if(res < 0)res += MOD;
        cout << res << '\n';
    }
    return 0;
}

Measured memory_bytes: 4736
function main(K,S)
  
  count = 0
  
  for i in 0:K, j in 0:K
    
    if 0 <= S - (i+j) <= K
      
      count += 1
      
    end
    
  end
  
  println(count)
  
end

(K,S) = map(x -> parse(Int,x), split(readline()))
main(K,S)

Measured memory_bytes: 110444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    if(n%10==9 || n/10==9){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    int a[n + 1];
    for(int i = 0; i <= n; ++i) a[i] = -1;
    for(int i = 0; i < m; ++i) {
        int s, c;
        cin >> s >> c;
        if(a[s] != -1 && a[s] != c) {
            cout << -1 << endl;
            return 0;

        }
        a[s] = c;
    }

    if(n == 1) {
        if(a[1] != -1) {
            cout << a[1] << endl;

        } else {
            cout << 0 << endl;

        }
        return 0;

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

    }

    for(int i = 1; i <= n; ++i) {
        if(a[i] == -1) {
            if(i != 1) {
                cout << 0;

            } else {
                cout << 1;

            }
        } else {
            cout << a[i];

        }
    }
    cout << endl;
    return 0;
}



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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int nimber(int K, int A) {
    if (A < K) return 0;
    if (A % K == 0) return A / K;
    if (K == 1) return A;

    if (sqrt(A) > K) {
        int have = K + 1;
        vi stages = { K * K };
        do {
            int front = K - 1 - (stages.back() % K);
            int ins = 1 + (have - front) / (K - 1);
            have += ins;
            stages.push_back(stages.back() + have);
        } while (stages.back() < A);

        for (int s = sz(stages) - 1; s > 0; s--) {
            int back = stages[s] - A;
            int skip = stages[s] / K - A / K;

            A = stages[s-1] - back + skip;
            if (A % K == 0) return A / K;
        }
    }

    int last = A / K;
    while (A >= K) {
        int inx = (A - last * K) % (last + 1);
        if (inx == 0) return last;

        inx = (inx - 1 + K) % last;
        last--;
        A = last * K + inx;

        if (A % K == 0) return A / K;
    }

    return 0;
}

vi slow(int K, int A) {
    vi nim(A + 1);
    vi saw(A + 1, -1);

    for (int i = 0; i <= A; i++) {
        int lim = i / K;

        for (int take = 1; take <= lim; take++)
            saw[nim[i - take]] = i;

        while (saw[nim[i]] == i)
            nim[i]++;
    }

    return nim;
}

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

    /*for (int rep = 0; rep < 100000; rep++) {
        int A = rng() % int(1e9) + 1;
        int K = rng() % int(1e9) + 1;

        cout << "Nimber for A=" << A << " K=" << K << " is";
        cout.flush();
        cout << nimber(K, A) << endl;
    }
    return 0;*/

    /*for (int K = 1; K <= 10000; K++) {
        vi ans = slow(K, 10000);
        for (int A = 1; A <= 10000; A++) {
            if (int my = nimber(K, A); my != ans[A])
                cout << K << " " << A << " " << my << " " << ans[A] << endl;
        }
    }
    return 0;*/

    int N, res = 0;
    cin >> N;
    for (int i = 0, a, k; i < N; i++) {
        cin >> a >> k;
        res ^= nimber(k, a);
    }
    cout << (res ? "Takahashi": "Aoki") << endl;

    return 0;
}



Measured memory_bytes: 540
from copy import deepcopy
from collections import deque

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

cnt=0
for i in range(m):
  ll=deepcopy(l)
  del ll[i]

  tree=[[] for i in range(n)]
  for a,b in ll:
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)

    dist=[-1 for i in range(n)]

    s=ll[0][0]-1
    dist[s]=0
    dq=deque()
    dq.append(s)

    while dq:
      x=dq.popleft()
      for i in tree[x]:
        if dist[i]==-1:
          dq.append(i)
          dist[i]=dist[x]+1

  if -1 in dist:
    cnt+=1
print(cnt)

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

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

vector<vector<ll>> graph;
vector<ll> cnt;

void dfs(ll node, ll parent, ll sum) {
  for(ll n: graph[node]) {
    if (n != parent) dfs(n, node, sum + cnt[n]);
  }
  cnt[node] = sum;
}

int main() {
  ll input(n, q);
  graph = vector<vector<ll>>(n);
  REP(i, n - 1) {
    ll input(a, b);
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }

  cnt = vector<ll>(n);
  REP(i, q) {
    ll input(p, x);
    cnt[p - 1] += x;
  }

  dfs(0, -1, cnt[0]);
  REP(i, n - 1) {
    cout << cnt[i] << " ";
  }
  cout << cnt[n - 1] << endl;
}


Measured memory_bytes: 25128
#include <stdio.h>

int main(void)
{
	int in;
	int out[1000] = {0};

	int rem = 0;
	int rnd = 0;


	while(1)
	{
		scanf("%d",&in);

		if(in == 0)
			break;

		rem = 1000 - in;

		while(rem)
		{
			if(rem >= 500){
				rem -= 500;
				out[rnd]++;
				}else

			if(rem >= 100){
				rem -= 100;
				out[rnd]++;
				}else

			if(rem >= 50){
				rem -= 50;
				out[rnd]++;
				}else

			if(rem >= 10){
				rem -= 10;
				out[rnd]++;
				}else

			if(rem >= 5){
				rem -=5;
				out[rnd]++;
				}else

			if(rem >= 1){
				rem -= 1;
				out[rnd]++;
				}
		}

		rnd++;

	}



	for( in = 0 ; in < rnd ; in++){
		printf("%d\n",out[in]);}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 9;
 
int _;

//========================================================================
ll a[maxn],mp[maxn];
//========================================================================
int main()
{
    int n;
    ll ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        mp[a[i]]++;
        ans+=a[i];
    }
    int q;
    ll a,b;
    scanf("%d",&q);
    while(q--)
    {
        scanf("%lld%lld",&a,&b);
        ans+=mp[a]*(b-a);
        mp[b]+=mp[a];
        mp[a]=0;
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll N,x;cin >> N >> x;
  vector<ll> v(N);
  ll count = 0;
  ll pre = 0;
  rep(i,N){
    ll y;cin >> y;
    if(pre+y>x){
      count += pre+y-x;
      y -= pre+y-x;
    } 
    pre = y;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	char a[101];
	gets(a);
	int str=strlen(a);
	int i,top=0,minn=-1,j;
	for(i=0;i<str;i++)
	{
	   if(a[i]=='C')
	    {
	    	top++;
	    	j=i;
		}
	   if(a[i]=='F')
	   {
	      if(i>=minn)
		  {
		    minn=i;	
		  }	
	   }   	
	}
	if(top==0||minn==-1)
	  cout<<"No"<<endl;
	else
	{
	   if(j<minn)
	     cout<<"Yes"<<endl;
	   else
	     cout<<"No"<<endl;   	
	}
	return 0;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

template <typename T>
ll lcm(T a, T b){
  return (ll)a * (ll)b / (ll)__gcd(a, b);
}

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


  vll a(N);
  ll lcm1;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
    if(i == 0) lcm1 = a.at(0);
    else lcm1 = lcm(lcm1, a.at(i));
  }


  sort(ALL(a), greater<ll>());
  int minnum = -1;
  for(int i = a.at(0)/2; i <= M; i+= a.at(0)){
    bool flag = true;
    for(int j = 1; j < N; j++){
      if( (i-a.at(j)/2) % a.at(j) != 0 ){
        flag = false;
        break;
      }
    }
    if(flag){
      minnum = i;
      break;
    }    
  }
  if(minnum == -1) cout << 0 << endl;
  else{
    ll result = 1 + (M - minnum) / lcm1;
    cout << result << endl;
  }
}


Measured memory_bytes: 1024
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
using namespace std;
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
string s; 
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	ll j=0,ans=0;
	for (ll i=0;i<s.size();i++){
		if (s[i]=='W'){
			ans+=i-j;
			j++;
		}
	}
	cout<<ans<<endl;
	return 0;
}
/*
input:
*/


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstring>
#include<vector>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<functional>
#define io ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
#define ll long long
#define P pair<int,int>
#define lc rt*2
#define rc rt*2+1
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

using namespace std;

set<int> s;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if (s.count(x))
		{
			cout << "NO";
			return 0;
		}
		s.insert(x);
	}
	cout << "YES";
	return 0;
 }

Measured memory_bytes: 9600
import java.util.Scanner;
public class Main {
  enum Event {
  ARC,
  ABC
}
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		String h = in.nextLine();
      System.out.println(nextEvent(h));
    }
   static Event nextEvent(String event){
            if(Event.valueOf(event).equals(Event.ARC))
            {
              return Event.ABC ;
            }else{
                  return Event.ARC ;
            }
		}
	}

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

int n, m;
char grid[1005][1005];
int ans[1005][1005];
const int mod = 1e9 + 7;

int solve(int i, int j)
{
    if(i >= n || j >= m || grid[i][j] == '#')
        return 0;
    if(i == n - 1 && j == m - 1)
        return 1;
    int &ret = ans[i][j];
    if(~ret)
        return ret;
    ret = (solve(i + 1, j) + solve(i, j + 1)) % mod;
    return ret;
}

int main()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> grid[i][j];
    memset(ans, -1, sizeof ans);
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 5248
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int N;
int A[100];
int a, b;
string S;
string ans;

void _main() {
	cin >> a >> b;

	string stra = "";
	rep(i, 0, b) {
		 stra += to_string(a);
	}

	string strb = "";
	rep(i, 0, a) {
		strb += to_string(b);
	}

	ans = (stra < strb ? stra : strb);

	cout << ans << endl;
}

Measured memory_bytes: 256
K = int(input())
a = ["1","2","3","4","5","6","7","8","9"]
for i in range(K):
    if  a[i][-1] == "9":
        a.append(a[i]+str(int(a[i][-1])-1))
        a.append(a[i]+str(int(a[i][-1])))
    elif a[i][-1] == "0":
            a.append(a[i]+str(int(a[i][-1])))
            a.append(a[i]+str(int(a[i][-1])+1))
    else:
            a.append(a[i]+str(int(a[i][-1])-1))
            a.append(a[i]+str(int(a[i][-1])))
            a.append(a[i]+str(int(a[i][-1])+1))
print(a[K-1])

Measured memory_bytes: 23724
#include<stdio.h>

int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int sum=0,count=0;
    int a[1000];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    for(i=0;i<n;i++){
        if(a[i]*4*m>=sum)   count++;
    }
    if(count>=m)    puts("Yes");
    else    puts("No");
    return 0;

}

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

int main() {
  int count = 0;
  
  for (int i = 0; i < 3; i++) {
    char S;
    cin >> S;
    if (S == 'o') {
      count += 100;
    }
  }
  
  cout << 700 + count << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool safe(int x,int y){
  if(x<0||x>9) return false;
  if(y<0||y>9) return false;
  else return true;
}
int main(){
  int x,y,n,xy[10][10],memxy[10][10];
  while(cin>>x>>y){
    if(x==0&&y==0) break;
    cin >> n;
    int dx[n],dy[n];
    for(int i=0;i<n;i++) cin >> dx[i] >> dy[i];
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	xy[i][j] = -1;
	memxy[i][j] = 0;
      }
    }
    for(int i=-1;i<=1;i++){
      if(safe(x+2,y+i)) xy[x+2][y+i] = 0;
      if(safe(x-2,y+i)) xy[x-2][y+i] = 0;
      if(safe(x+i,y+2)) xy[x+i][y+2] = 0;
      if(safe(x+i,y-2)) xy[x+i][y-2] = 0;
    }
    /*for(int i=0;i<10;i++){
      for(int j=0;j<10;j++) cout << xy[j][i] << ' ';
      cout << endl;
      }*/
    //cout << endl;
    for(int i=0;i<n;i++){
      for(int j=-1;j<=1;j++){
	for(int k=-1;k<=1;k++){
	  if(safe(dx[i]+j,dy[i]+k)){
	    if(xy[dx[i]+j][dy[i]+k]==i){
	      for(int l=-1;l<=1;l++){
		if(safe(dx[i]+j+2,dy[i]+k+l)) memxy[dx[i]+j+2][dy[i]+k+l] = i+1;
		if(safe(dx[i]+j-2,dy[i]+k+l)) memxy[dx[i]+j-2][dy[i]+k+l] = i+1;
		if(safe(dx[i]+j+l,dy[i]+k+2)) memxy[dx[i]+j+l][dy[i]+k+2] = i+1;
		if(safe(dx[i]+j+l,dy[i]+k-2)) memxy[dx[i]+j+l][dy[i]+k-2] = i+1;
	      }
	    }
	  }
	}
      }
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++) xy[k][j] = memxy[k][j];
      }
      /*for(int j=0;j<10;j++){
	for(int k=0;k<10;k++) cout << xy[k][j] << ' ';
	cout << endl;
	}
	cout << endl;*/
      }
    //cout << "OK" << endl;
    bool ok = false;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++) if(xy[i][j]==n) ok = true;
    }
    if(ok) cout << "OK" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
n=int(input())
a=list(map(int,input().split()))
a.sort()
count=[0]*1000001
divisible=[False]*1000001
ans=0
for i in a:
    count[i]+=1
for i in a:
    if count[i]>=2:
        if divisible[i]:
            continue
        else:
            j=1
            while i*j<=1000000:
                divisible[i*j]=True
                j+=1
    elif count[i]==1:
        if divisible[i]:
            continue
        else:
            ans+=1
            j=1
            while i*j<=1000000:
                divisible[i*j]=True
                j+=1
print(ans)

Measured memory_bytes: 35344
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 100000

using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

#define MOD 1000000007
template<int mod>
struct ModInt{
	int x;
	ModInt():x(0){}
	ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=mod-p.x)>=mod)x-=mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1LL*x*p.x%mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inverse();
		return *this;
	}
	ModInt &operator^=(long long p){
		ModInt res = 1;
		for (; p; p >>= 1) {
			if (p & 1) res *= *this;
			*this *= *this;
		}
		return *this = res;
	}
	ModInt operator-()const{return ModInt(-x);}
	ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
	ModInt operator^(long long p)const{return ModInt(*this)^=p;}
	bool operator==(const ModInt &p)const{return x==p.x;}
	bool operator!=(const ModInt &p)const{return x!=p.x;}
	explicit operator int() const { return x; }						   // added by QCFium
	ModInt operator=(const int p) {x = p; return ModInt(*this);} // added by QCFium
	ModInt inverse()const{
		int a=x,b=mod,u=1,v=0,t;
		while(b>0){
			t=a/b;
			a-=t*b;
			std::swap(a,b);
			u-=t*v;
			std::swap(u,v);
		}
		return ModInt(u);
	}
	friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
		return os<<p.x;
	}
	friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
		long long x;
		is>>x;
		a=ModInt<mod>(x);
		return (is);
	}
};
typedef ModInt<MOD> mint;

mint nCx(int n, int x) {
    mint res = 1;
    for (int i = n; i > n-x; --i)
        res *= i;
    for (int i = x; i > 0; --i)
        res /= i;
    return res;
}

int main () {
    int X, Y;
    cin >> X >> Y;
	mint ans = 0;
	for (int a = 0; a <= X; ++a) {
		int b = X - a;
		if (b%2 == 1)
			continue;
		b /= 2;
		if (2*a + b == Y)
			ans += nCx(a + b, a);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
9
500
0
*/

fn read_line() -> String {
    let mut return_ = format!("");
    std::io::stdin().read_line(&mut return_).ok();
    return_.pop();
    return_
}

fn main() {
    let mut n;
    let mut tot;
    let mut tot_num;
    loop {
        n = read_line().parse().unwrap();
        if n == 0 {
            break;
        }
        tot_num = 0;

        for i in 1..(n / 2) + 1 {
            tot = 0;
            for j in i..n {
                tot = tot + j;
                if tot == n {
                    tot_num = tot_num + 1;
                    break;
                } else if tot > n {
                    break;
                }
            }
        }
        println!("{}", tot_num);
    }
}



Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    lint ret = 0;
    if (n % 2 == 0) {
        lint e = 0, o = 0;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == 0)
                e += a[i];
            else
                o += a[i];
        }
        ret = max(e, o);
    } else {
        lint o = 0;
        for (int i = 0; i < n; ++i) {
            if (i % 2 == 1)
                o += a[i];
        }
        ret = o;
    }
    vector<vector<lint>> dp(n + 2, vector<lint>(3, -inf));
    a.insert(a.begin(), 0);
    a.push_back(0);
    dp[0][0] = a[0];
    dp[1][0] = a[1];
    for (int i = 2; i <= n + 1; ++i) {
        chmax(dp[i][0], dp[i - 2][0] + a[i]);
        chmax(dp[i][1], dp[i - 2][1] + a[i]);
        chmax(dp[i][2], dp[i - 2][2] + a[i]);
        if (i >= 3) {
            chmax(dp[i][1], dp[i - 3][0] + a[i]);
            chmax(dp[i][2], dp[i - 3][1] + a[i]);
        }
        if (i >= 4) {
            chmax(dp[i][2], dp[i - 4][0] + a[i]);
        }
    }
    if (n % 2 == 0)
        chmax(ret, dp[n][1]);
    else {
        chmax(ret, max({dp[n - 1][1], dp[n][1], dp[n][2]}));
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 17084
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int x,y,a=-1,b=-1,c=-1;
	cin>>x>>y;
	for(int i=0;10000*i<=y;i++){
		for(int j=0;5000*j<=y;j++){
			if(i*10000+j*5000+(x-i-j)*1000==y&&x-i-j>=0){
				a=i;
				b=j;
				c=x-i-j;
			}
		}
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int isprime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0 && (i % 7 == 1 || i % 7 == 6) && (n / i % 7 == 1 || n / i % 7 == 6)) {
            return false;
        }
    }
    return true;
}

int toint(string s) {
    string b;
    copy_if(all(s), back_inserter(b), [] (char c) { return c != ':'; });
    return stoi(b);
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n; cin >> n;
        if (!n) break;
        vector<pii> v;
        rep(i, 0, n) {
            string a, b; cin >> a >> b;
            v.push_back({toint(a), toint(b)});
        }
        sort(all(v));
        multiset<int, greater<int>> ends;
        for (auto p : v) {
            int s, e; tie(s, e) = p;
            // cout << s << " " << e << ";; ";
            // for (int h : ends) cout << h << " ";
            // cout << endl;
            if (ends.empty()) ends.insert(e);
            else {
                // cout << "find: " << s << endl;
                auto it = ends.lower_bound(s);
            
                // if (it == ends.end()) cout << "NF" << endl;
                // else cout << *it << endl;

                if (it == ends.end()) ends.insert(e);
                else {
                    ends.erase(it);
                    ends.insert(e);
                }
            }
        }
        cout << ends.size() << endl;
    }
}



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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int a,b;cin>>a>>b;
  cout<<( ((a*b)%2) ? "Odd" : "Even" )<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

# sys.stdin = open('test_cases/abc158d/in/01.txt', 'r')
# sys.stdin = open('input.txt', 'r')

s = deque([s for s in input()])
q = int(input())
rev = False

for query in sys.stdin:
    if query.strip() == '1': # sys.stdin does not remove line breaks. (vs. input() removes line breaks)
        if rev:
            rev = False
        else:
            rev = True
    else:
        t,f,c = query.split()
        if f == '1':
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        elif f == '2':
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
if rev == True:
    s.reverse()
print(''.join(s))

Measured memory_bytes: 8548
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod009 = 1000000009;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, a[200000], b[200000], c[200000], d[400000];
ll rh[400001], rh2[400001];


int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < N - 1; i++) {
		c[i] = a[i] ^ a[i + 1];
		d[i] = b[i] ^ b[i + 1];
	}
	c[N - 1] = a[0] ^ a[N - 1];
	d[N - 1] = b[0] ^ b[N - 1];
	for (int i = N; i < N + N; i++) {
		d[i] = d[i - N];
	}
	ll RH, RH2;
	RH = RH2 = 0;
	for (int i = 0; i < N; i++) {
		RH = (RH*11113 + c[i]) % mod009;
		RH2 = (RH2*11117 + c[i]) % mod;
	}
	ll p11113, p11117;
	p11113 = p11117 = 1;
	for (int i = 0; i < N; i++) {
		p11113 *= 11113;
		p11113 %= mod009;
		p11117 *= 11117;
		p11117 %= mod;
	}
	for (int i = 0; i < N + N; i++) {
		rh[i + 1] = (rh[i] * 11113 + d[i]) % mod009;
		rh2[i + 1] = (rh2[i] * 11117 + d[i]) % mod;
	}
	for (int i = N; i > 0 ; i--) {
		if ((mod009 + rh[i + N] - rh[i] * p11113%mod009) % mod009 == RH && (mod + rh2[i + N] - rh2[i] * p11117%mod) % mod == RH2) {
			cout <<  N - i << sp << (a[0] ^ b[i%N]) << endl;
		}
	}
}

Measured memory_bytes: 13568
use proconio::{fastout, input};
use std::collections::BinaryHeap;
use ordered_float::NotNan;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: i64,
        a: [i64; n],
    }

    let mut q = BinaryHeap::new();
    // for a_i in a.iter().copied() {
    //     q.push((NotNan::new(a_i as f64).unwrap(), 1i64, a_i));
    // }

    let s: i64 = a.iter().sum();
    // let avg = s / (k + n);
    let mut cnt = 0i64;
    for a_i in a.iter().copied() {
        let m = a_i * (k + n as i64) / s;
        let m = if m == 0 { 1 } else { m };
        cnt += m;
        q.push((NotNan::new(a_i as f64 / m as f64).unwrap(), m, a_i));
    }

    for _ in 0..(k + n as i64 - cnt) {
        let (_, c, a_i) = q.pop().unwrap();
        let c = c + 1;
        q.push((NotNan::new(a_i as f64 / c as f64).unwrap(), c, a_i));
    }


    let (ans, _, _) = q.pop().unwrap();
    println!("{}", ans.ceil());
}


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

int main() {
	int N;
	int M;
	int A;
	unsigned int A_sum = 0;

	cin >> N >> M;

	for (int i = 0; i < M; i++) {
		cin >> A;
		A_sum += A;
	}

	if (N >= A_sum) {
		cout << N - A_sum;
	}
	else {
		cout << -1;
	}
  
	return 0;
}

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

int main(){
    ll X;
    cin >> X;
    vector<ll>n(1001);
    for(int i=0; i<=1000; ++i){
        n[i] = pow(i, 5);
    }
    for(int i=0; i<1001; ++i){
        for(int j=i; j<1001; ++j){
            if(n[j]-n[i]==X){
                cout << j <<" "<< i << endl;
                return 0;
            }
            else if(n[j]+n[i]==X){
                cout << j <<" "<< -(i) << endl;
                return 0;
            }
        }
    }

}


Measured memory_bytes: 4048
//01:20
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
struct T
{
	int v,id;
	bool operator<(T b)const 
	{return v<b.v;}
};
struct T1
{
	int v,id;
	bool operator<(T1 b)const 
	{return v>b.v;}
};
priority_queue<T>L;
priority_queue<T1>R;
bool vis[N];
struct G
{
	int l,r;
	bool In(int v)
	{
		if(l<=v&&v<=r)return true;
		else return false;
	}
}D[N];
int main()
{
	//freopen("/home/zz7/CFInput","r",stdin);
	int n;scanf("%d",&n);
	int a=0,b=0;
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		D[i]={l,r};
		T g={l,i};T1 g1={r,i};
		L.push(g);R.push(g1);
		if(l>0)a++;
		else if(r<0)b++;
	}
	int flag=0,ins=0;ll ans=0;
	if(a<b)flag=1;
	for(int i=0;i<2*n;i++){
		if(flag==1){
			//min
			T1 p=R.top();R.pop();
			if(vis[p.id])continue;
			vis[p.id]=true;
			if(!D[p.id].In(ins)){
				ans+=abs(ins-p.v);
				ins=p.v;
			}
		}else {
			//max
			T p=L.top();L.pop();
			if(vis[p.id])continue;
			vis[p.id]=true;
			if(!D[p.id].In(ins)){
				ans+=abs(ins-p.v);
				ins=p.v;
			}
		}flag=!flag;
	}cout<<ans+abs(ins)<<'\n';
}


Measured memory_bytes: 2924
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        Console.WriteLine("ABC" + Cin.Ni());
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,m=1000;
    cin>>n;

    if(n%m==0){
        cout<<0<<endl;
    }
    else cout<<1000-(n%m)<<endl;

    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P) {
	int i = 0;
	for ( int j = 0; j < k; j++ ) {
		llong s = 0;
		while( s + T[i] <= P ) {
			s += T[i];
			i++;
			if ( i == n ) return n;
		}
	}
	return i;
}

int solve() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while ( right - left > 1 ) {
		mid = (left + right) / 2;
		int v = check(mid);
		if ( v >= n ) right = mid;
		else left = mid;
	}
	
	return right;
}

main() {
	cin >> n >> k;
	for ( int i = 0; i < n; i++ ) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}


Measured memory_bytes: 3880
#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(){
   ll a,b,c,k; cin>>a>>b>>c>>k;
   ll ans=0;
   ll cnt=0;
   if(k>=a){
      ans=k-a;
      cnt+=a;
   }
   else{
      cout<<k<<endl;
      return 0;
   }
   if(ans>0){
      if(ans>=b) ans-=b;
      else{
         cout<<cnt<<endl;
         return 0;
      }
   }
   if(ans>0){
      cnt-=ans;
   }
   cout<<cnt<<endl;
   return 0;
}


Measured memory_bytes: 3632
#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;
int main(){
	int N;
	cin>>N;
	vector<bool> ok(N+1,false);
	rep(i,N){
		int x;
		cin>>x;
		x--;
		ok[i] = (x!=i);
	}
	int ans = 0;
	rep(i,N) if(!ok[i]){
		ans++;
		ok[i] = 1;
		ok[i+1] = 1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

using namespace std;

int main(void) {
	
	int a,b;
	cin >>a >>b;
	
	int ans;
	if (b%a==0) {
		ans=a+b;
	} else {
		ans=b-a;
	}
	cout <<ans <<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]#amari
B = [0 for _ in range(N)]
s =  N//2

B[s:] = A[s:]

for i in reversed(range(s)):
  k = i+1
 # print(k)
#  print(A[i])
#  print(sum(B[i::k])%2)
  if A[i] == sum(B[i::k])%2:
    B[i] = 0
  else:
    B[i] = 1
#  print("-----")
  
print(B.count(1))
for i in range(len(B)):
  if B[i] == 1:
      print(i+1)

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

int main() {
  long long A, B, V, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;
  bool b = false;
  if(abs(A-B) <= T * (V-W)) {
    b = true;
  }
  if(b) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long ans = LLONG_MIN;
	if((a<=0&&b>=0)||(c<=0&&d>=0))
		ans = 0;
	ans = max(ans,b*d);
	ans = max(ans,a*c);
	ans = max(ans,a*d);
	ans = max(ans,b*c);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660