akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <string>
using namespace std;
typedef long long LL;
const LL N = 998244353;

map <string,LL> mp[2];
string u;

LL f(LL id,string s){
	if(mp[id].find(s) != mp[id].end()) return mp[id][s];
	LL ret = 0,len;
	len = s.length();
	if(id){
		for(LL i = 0;i < len;i ++) ret = (ret + f(1,s.substr(0,i)) * f(0,s.substr(i,len))) % N;
		mp[id][s] = ret; return ret;
	}
	else{
		for(LL i = 1;i < len;i ++){
			if(len % i) continue;
			string t = "";
			for(LL j = 0;j < i;j ++) t += '1';
			for(LL j = 0;j < len;j += i){
				for(LL k = 0;k < i;k ++){
					if(s[j + k] == '0') t[k] = '0';
				}
			}
			ret += f(1,t); ret %= N;
		}
		mp[id][s] = ret; return ret;
	}
}

int main(){
	mp[0][""] = mp[1][""] = 1;
	mp[0]["0"] = 1; mp[0]["1"] = 2;
	mp[1]["0"] = 1; mp[1]["1"] = 2;
	cin >> u;
	cout << f(1,u) << '\n';
	return 0;
}

Measured memory_bytes: 14208
#include<iostream>
#include<algorithm>
using namespace std;
int a[123456];
int flag[123456];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i==0)
			flag[0]=0;
		else
		{
			if(a[i]<=a[i-1])
				flag[i]=flag[i-1]+1;
			else
				flag[i]=0;
		}
	}
	sort(flag,flag+n);
	cout<<flag[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

struct edge {
    ll to;
    ll cost;
    ll dist;
};

struct state {
    ll node;
    ll coin;
    ll total;
    
    bool operator<(const state& other) const {
        if (total > other.total) return true;
        else return false;
    }
};

int main() {
    ll N, M, S;
    cin >> N >> M >> S;
    vector< vector<edge> > edges(N, vector<edge>());
    vector<ll> A(M), B(M), C(N), D(N);

    ll a_max = 0;

    REP(i, M) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        edge e1 = {b, c, d}, e2 = {a, c, d};
        edges[a].push_back(e1);
        edges[b].push_back(e2);
        if(a > a_max) a_max = a;
    }

    REP(i, N) {
        cin >> C[i] >> D[i];
    }

    S = min(S, 2500ll);
    vector< vector<ll> > dp(N, vector<ll>(2501, INF));

    priority_queue<state> pq;
    pq.push(state{0, S, 0});
    dp[0][S] = 0;

    while(!pq.empty()) {
        state v = pq.top();
        pq.pop();

        for(edge n: edges[v.node]) {
            int next_cost = min(2500ll, v.coin - n.cost);
                if(next_cost >= 0 && dp[n.to][next_cost] > dp[v.node][v.coin] + n.dist) {
                    dp[n.to][next_cost] = dp[v.node][v.coin] + n.dist;
                    state next_state = {n.to, next_cost, dp[n.to][next_cost]};
                    pq.push(next_state);
                }
        }

        int next_cost = min(2500ll, v.coin + C[v.node]);
        if(dp[v.node][next_cost] > dp[v.node][v.coin] + D[v.node]) {
            dp[v.node][next_cost] = dp[v.node][v.coin] + D[v.node];
            state next_state = {v.node, next_cost, dp[v.node][next_cost]};
            pq.push(next_state);
        }
    }

    FOR(i, 1, N-1) {
        ll ans = INF;
        REP(cost, 2501) if(ans > dp[i][cost]) ans = dp[i][cost];
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
  int n,k,a,ans=0;cin>>n>>k;
  REP(i,n){
    cin>>a;
    ans+=min(a,abs(k-a))*2;
  }
  cout<<ans;
}

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    int x;
    cin>>x;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    ll res=0;
    rep(i,1,n){
        int sum=a[i]+a[i-1];
        if(sum>x){
            res+=sum-x;
            a[i]=max(0,a[i]-(sum-x));
        }
    }
    cout<<res<<endl;
    return 0;
}




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

int main()
{
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)cin>>s[i];
    int a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)a[i][j]=0;
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#') a[i][j]=0;
            else{
               if(i==0&&j==0)a[i][j]=1;
               else{
                if(j>0){
                    a[i][j]=a[i][j-1];
                }
                if(i>0)a[i][j]=(a[i][j]+a[i-1][j])%1000000007;
               }
            }
        }
    }
    cout<<a[h-1][w-1];
	return 0;
}


Measured memory_bytes: 5248
#include<iostream>
using namespace std;
 
int main(){
 
    int n;
 
    cin >> n;
 
    int p[n],t[n],count=0,tcount;
 
    for(int i=0;i<n;i++){
      cin >> p[i];
      t[i] = p[i];
      //count += p[i];
    }
 
    if(p[0] > p[1]){
      count += p[0] + p[1];
      p[1] = 0;
    }
    else{
      count += p[0]*2;
      p[1] -= p[0];
    }
 
    for(int i=1;i<n-1;i++){
      count += p[i] * 2;
      if(p[i] > p[i+1] ){
        p[i+1] = 0;
      }
      else{
        p[i+1] -= p[i];
      }
    }
 
    if(p[n-1] != 0){
      count += p[n-1];
    }
 
 
 
 
    tcount = t[0];
 
    for(int i=1;i<n-1;i++){
      tcount += t[i] * 2;
      if(t[i] > t[i+1] ){
        t[i+1] = 0;
      }
      else{
        t[i+1] -= t[i];
      }
    }
 
    if(t[n-1] != 0){
      tcount += t[n-1];
    }
 
 
 
    /*int maxp = max(p[0],p[1]);
 
    if(maxp == p[0]){
      count += p[0] + p[1];
      p[0] = p[1] = 0;
    }
    else{
      count += p[0] * 2;
      p[1] -= p[0];
    }
 
 
 
    maxp = max(p[n-2],p[n-1]);
 
    if(maxp == p[n-2]){
      count += p[n-2] * 2;
    }
    else{
      count += p[n-2] + p[n-1];
    }*/
 
    cout << min(count,tcount) << endl;
 
    return 0;
}

Measured memory_bytes: 3160
import itertools
from math import gcd

K = int(input())

ans = 0
G = [[None] * (K + 1) for _ in range(K + 1)]
for a in range(1, K + 1):
    for b in range(1, K + 1):
        G[a][b] = gcd(a, b)


for a, b, c in itertools.product(range(1, K + 1), repeat=3):
    ans += G[G[a][b]][c]
print(ans)


Measured memory_bytes: 69044
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
using namespace std;
inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
inline ll power(ll base, ll exp)
{
	ll ans = 1;
	while (exp > 0)
	{


		if (exp % 2 != 0)
			ans = (ans * base) % N;

		base = (base * base) % N;
		exp /= 2;
	}
	return ans % N;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	double r;
	cin >> r;
	double ans;
	ans = 2.00000000 * 3.1415926 * r;
	cout << setprecision(6);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
const int n = 1e5 + 5;

int N;

int main(){
	string s;
	cin >> s;
	N = s.size();
	int K = 1;
	int ll = 1, i = 1;
	for(i = 1; i < N; ++i){
		if(ll == 1 && s[i] == s[i-1]){
			ll = 2;
			i++;
		}else{
			ll = 1;
		}
		K++;
	}
	if(i == N+1)
		K--;
	cout << K << endl;
	return 0;
	
}


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

int main(){
	int n;
  	cin >> n;
  	vector<pair<int,int>> a(n),b(n);
  	for(int i=0;i<n;i++){
    	int k,l;
      	cin >> k >> l ;
      	a[i]={l,k};
    }
 	 for(int i=0;i<n;i++){
    	int k,l;
       	cin >> k >> l ;
       	b[i]={k,l};   	
    }
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  	sort(b.begin(),b.end());
  	int count=0;
  	for(int i=0;i<n;i++){
    	for(int j=0;j<n;j++){
        	if(a[i].second<b[j].first && a[i].first<b[j].second)
            {count++;
             b[j]={INT_MIN,INT_MIN};
             break;
            }
        }
    }
  	cout << count << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n;
    cin>>n;
    vll dp(n+1,1e10);
    dp[0]=-1;
    rep(i,n){
        ll a;
        cin>>a;
        auto index=lower_bound(all(dp),a)-dp.begin();
        dp[index]=a;
    }
    int ans=0;
    for (int i=1;i<n+1;i++){
        if (dp[i]==1e10){
            ans=i-1;
            break;
        }
    }
    if (ans==0)cout<<n<<endl;
    else cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 3584
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 05/30/20 16:02:55
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string t; cin>>t;
  for (auto& c:t) {
    if (c == '?')
      c = 'D';
  }
  cout << t << endl;

  return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> a(N,0);
    for(ll i=0;i<N;++i)cin>>a[i];
    ll ans=0;
    for(ll i=0;i<N;++i)ans+=a[i]-1;
    prt(ans)
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
//#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int main(){
  string s,t;
  cin>>s>>t;
  string u;
  REP(i,s.size()){
      u+=s[s.size()-1-i];
  }
  cout<<(u==t?"YES":"NO")<<endl;
  return 0;
}


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

int main() {
    int r;
    cin >> r;
    if (r<1200) {
        cout << "ABC" << endl;
    }
    else if (r<2800) {
        cout << "ARC" << endl;
    }
    else {
        cout << "AGC" << endl;
    }
}

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

int main()
{
    int n, res = 0;
    string a;
    cin >> n >> a;

    if(n == 1)
    {
        cout << 1 << "\n";
        return 0;
    }
    for(int i = 0; i < n - 1; ++i)
    {
        if(i == n - 2)
        {
            if(a[i] == a[i + 1]) 
                res++;
            else 
                res += 2;
        } else if(a[i] != a[i + 1])
        {
            res++;
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3752
#include<stdio.h>

int main()
{
	int a,b,c;
	scanf("%d %d %d\n",&a,&b,&c);

	if(a<b){
		if(b<c){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}else {
		printf("No\n");
	}
	return 0;

}


Measured memory_bytes: 2036
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

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

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

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


int main(void) {
	int N, k;
	cin >> N >> k;
	int ans = INF;
	rep(i, N + 1) {
		ans = min(ans, (1 << i) + (N - i)*k);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#define INF 2e9
#define rep(i,m) for(int i=0;i<m;i++)


using namespace std;

int main()
{
	long long int N;
	cin >> N;
	
	long long int x = 100;
	int ans = 0;
	while (x - N < 0)
	{
		x = x * 1.01;
		ans++;
	}
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 3592
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;

const lli N = 100001;
lli n,k;
lli a,b;
vll v(N);

int main(){
    cin >> n >> k;
    for(lli i = 0;i < n;i++){
        cin >> a >> b;
        v[a] += b;
    }
    lli i = 0;
    while(k > 0){
        k -= v[i];
        i++;
    }
    cout << i-1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h> 
int main(){
  int D, N;
  int x;
  scanf("%d%d", &D, &N);
  if(D==0){
  if(N!=100){printf("%d",N);}else{
x = 101;
printf("%d",x);
}
  }else if(D==1){
    if(N!=100){x = N*100;
  printf("%d",x); }else{
x = 10100;
 printf("%d",x); 
}
  }else if(D==2){
    if(N!=100){x = N*100;
    x = x*100;
  printf("%d",x);}else{
x = 1010000;
printf("%d",x);
}
  
  }

}

Measured memory_bytes: 128
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
typedef struct{
    ll to;
    ll cap;
    ll rev;
} edge;
vector<edge> G[10010];
bool used[10010];

ll dfs(ll v, ll t, ll f){
    if(v == t) return f;
    used[v] = true;
    rep(i,0,G[v].size()){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            ll d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    string S[110];
    rep(i,0,H) cin >> S[i];
    ll start = -1, goal = -1;
    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j] == 'S') start = i * W + j;
            if(S[i][j] == 'T') goal = i * W + j;
        }
    }
    ll h[110] = {};
    rep(i,0,H) h[i] = i + 2;
    ll w[110] = {};
    rep(i,0,W) w[i] = 2 + H + i;
    G[0].push_back((edge){h[start/W], INF, (ll)G[h[start/W]].size()});
    G[h[start/W]].push_back((edge){0, 0, (ll)G[0].size() - 1});
    G[0].push_back((edge){w[start%W], INF, (ll)G[w[start%W]].size()});
    G[w[start%W]].push_back((edge){0, 0, (ll)G[0].size() - 1});

    G[h[goal/W]].push_back((edge){1, INF, (ll)G[1].size()});
    G[1].push_back((edge){h[goal/W], 0, (ll)G[h[goal/W]].size()-1});

    G[w[goal%W]].push_back((edge){1, INF, (ll)G[1].size()});
    G[1].push_back((edge){w[goal%W], 0, (ll)G[w[goal%W]].size()-1});


    rep(i,0,H){
        rep(j,0,W){
            if(S[i][j] == 'o'){
                G[h[i]].push_back((edge){w[j], 1, (ll)G[w[j]].size()});
                G[w[j]].push_back((edge){h[i], 0, (ll)G[h[i]].size() - 1});        
                G[w[j]].push_back((edge){h[i], 1, (ll)G[h[i]].size()}); 
                G[h[i]].push_back((edge){w[j], 0, (ll)G[w[j]].size()-1});

            }
        }
    }
    ll ans = 0;
    while(1){
        memset(used, 0, sizeof(used));
        ll f = dfs(0, 1, INF);
        if(f == 0) break;
        ans += f;
    }
    // print(ans);
    if((start / W == goal / W) || (start % W == goal % W)){
        print(-1);
    }else{
        print(ans);
    }
}

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

int main(){
    int n;
    cin>>n;
    map<int,int> data;
    rep(i,n){
        int val;
        cin>>val;
        data[val]++;
    }
    cout<<data.size()<<endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<=(n);i++)

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int main(){
    int n,sn=1,tn=0;
    string s,t,ans="";
    cin >> n >> s >> t;
    ans = ans + s[0];
    reps(i,1,s.size()+t.size()-1){
        if(i%2) {
            ans = ans + t[tn];
            tn++;
        }
        else {
            ans = ans + s[sn];
            sn++;
        }
    }
    cout << ans << endl;
    return 0;  
}


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

int main(){
  unsigned int l,r;
  unsigned int mins;
  unsigned int tmp;
  cin >> l >> r;
  mins = (l%2019) * (r%2019) % 2019;
  if((r-l) >= 2018){
    mins = 0;
    cout << mins << endl;
  }else{
    for (int i = l ; i < r; i++){
      for(int j = i+1 ;j <= r ; j++){
        tmp = (i%2019) * (j%2019) % 2019;
        mins = min(mins,tmp);
      }
    }
    cout << mins << endl;
  }
  return 0;
}

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

typedef long long lint;

int n, a[200004];
lint s[200004];

lint f(int x, int y, int z) {
	if (x>=y or y>=z) return 1e18;
	lint arr[4] = {s[x], s[y]-s[x], s[z]-s[y], s[n]-s[z]};
	return *max_element(arr, arr+4) - *min_element(arr, arr+4);
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];
	for (int i=1; i<=n; i++) s[i] = s[i-1] + a[i-1];

	lint ans = 1e18;
	for (int j=2; j<n-1; j++) {
		int i = lower_bound(s, s+n, (s[j]+1)/2) - s;
		int k = lower_bound(s, s+n, (s[j]+s[n]+1)/2) - s;
		ans = min({ans, f(i, j, k), f(i, j, k-1), f(i-1, j, k), f(i-1, j, k-1)});
	}

	cout << ans;
}


Measured memory_bytes: 2560
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    even = [A[i] for i in range(n) if A[i] % 2 == 0]

    res = 0
    for number in even:
        while number % 2 == 0:
            res += 1
            number //= 2

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4148
A,B,C,D = (int(i) for i in input().split())
Alice_time = set(range(A,B+1))
Bob_time = set(range(C,D+1))
common_time = Alice_time & Bob_time
common_time_list = list(common_time)
common_time_list_sorted = sorted(common_time_list)
if len(common_time_list_sorted) > 1:
    print(common_time_list_sorted[-1]-common_time_list_sorted[0])
else:
    print(0)


Measured memory_bytes: 3060
(* O(1) *)
let solve a b t = t / a * b

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  match read_ints () with
  | [a; b; c] -> solve a b c |> string_of_int |> print_endline
  | _ -> ()

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static void gcd(int a, int b){
            int x = Math.max(a,b);
            int y = Math.min(a,b);
            int t = 0;
            while (y>0){
                t = x;
                x = y;
                y = t%y;
            }
            System.out.println(x);
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int ans = 0;
        gcd(a,b);
    }
}

Measured memory_bytes: 17060
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
    return 0;
}


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

int main() {
  string S1,S2,S3;
  cin >> S1>>S2>>S3;

  string S = "abc";
  S[0] = S1[0];
  S[1] = S2[1];
  S[2] = S3[2];
  cout << S << endl;
}

Measured memory_bytes: 256
import sys
inf = float('inf')

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def SSSP(n, Adj):
    d = [inf] * n
    p = [-1] * n
    checked = [False] * n
    d[0] = 0
    checked[0] = True
    u = 0

    for i in range(n - 1):
        for v, cost in Adj[u]:
            if d[u] + cost < d[v]:
                p[v] = u
                d[v] = d[u] + cost

        min_n = 0
        min_w = inf
        for v in range(n):
            if not checked[v] and d[v] < min_w:
                min_n = v
                min_w = d[v]

        u = min_n
        checked[u] = True

    return d

def solve():
    n = int(input())
    Adj = [[] for i in range(n)]

    for i in range(n):
        u, k, *line = [int(i) for i in input().split()]
        for j in range(k):
            Adj[u].append((line[2*j], line[2*j + 1]))

    # debug(Adj, locals())

    d = SSSP(n, Adj)

    for i in range(n):
        print(i, d[i])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 8020
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Integer k = sc.nextInt();
		String s = sc.next();
		Integer n = s.length();
		
		if (n <= k) {
			System.out.println(s);
		} else {
			System.out.println(s.substring(0, k) + "...");
		}
	}
}

Measured memory_bytes: 38504
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){
    
    string s;
    cin >> s;
    deque<char>Q;
    rep(i, s.size())Q.push_back(s[i]);
    ll f = 0;
    ll N;
    cin >> N;
    rep(i, N){
        ll q;
        cin >> q;
        if(q == 1)f ^= 1;
        else{
            ll x;
            char c;
            cin >> x >> c;
            if(f ^ (x-1) == 0)Q.push_front(c);
            else Q.push_back(c);
        }
    }
    string ans = "";
    for(auto c : Q)ans += c;
    if(f)reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1412
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    N, K = in_nn()
    A = in_nl()

    def judge(x):

        cnt = 0
        for i in range(N):
            q, r = divmod(A[i], x)
            if r == 0:
                q -= 1
            cnt += q

        return cnt <= K

    def binary_search(min_n, max_n):

        while max_n - min_n != 1:
            mid = (min_n + max_n) // 2
            if judge(mid):
                max_n = mid
            else:
                min_n = mid

        return max_n

    ans = binary_search(min_n=0, max_n=10**9)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92704
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

void fin(){
	freopen("test.txt", "r", stdin);
}

struct state{
	int total;
	int pos;
	int cake;
	state(int t = 0, int p = 0, int c = 0){
		total = t; pos = p; cake = c;
	}
	bool operator<(const state &r) const{
		return total > r.total;
	}
};

int m, n, k, d;

const int INF = 2<<29;

int getnum(string s){
	int ret = 0;
	switch(s[0]){
	case 'H':
		ret = m+n;
		break;
	case 'D':
		ret = m+n+1;
		break;
	case 'C':
		ret = 0;
		ret += atoi(s.substr(1).c_str())-1;
		break;
	case 'L':
		ret = m;
		ret += atoi(s.substr(1).c_str())-1;
		break;
	}
	return ret;
}

int main(){
//	fin();
	while(1){
		cin >> m >> n >> k >> d;
		if(!m) break;

		vector<int> cake(m);
		rep(i, m){
			cin >> cake[i];
		}

		typedef vector<int> vi;
		vector<vi> edge(m+n+2, vi(m+n+2, INF)); 
		rep(i, d){
			string s, t;
			int dist;
			cin >> s >> t >> dist;
			int from = getnum(s);
			int to = getnum(t);
			edge[from][to] = edge[to][from] = dist*k;
		}

		vector<vi> cost(1<<m, vi(m+n+2, INF));

		priority_queue<state> q;
		q.push(state(0, m+n, 0));

		while(!q.empty()){
			state s = q.top(); q.pop();

			if(cost[s.cake][s.pos] <= s.total) continue;
			cost[s.cake][s.pos] = s.total;

			rep(i, m+n+2){
				if( edge[s.pos][i] == INF ) continue;
				if(i < m){
					if((1<<i) & s.cake) continue;
					state next = s;
					next.total += edge[s.pos][i] - cake[i];
					next.pos = i;
					next.cake |= (1<<i);

					q.push(next);
				}else{
					state next = s;
					next.total += edge[s.pos][i];
					next.pos = i;

					q.push(next);
				}
			}
		}

		int best = INF;
		rep(i, 1<<m){
			best = min(best, cost[i][m+n+1]);
		}

		cout << best << endl;
	}

	return 0;
}

Measured memory_bytes: 1512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
#define endl '\n'

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    // ll t;
    ll t=1;
    // cin >> t;
    while(t--){
        int a,b; cin >> a >> b;
        cout << max(0,(a-2*b)) << endl;
    }

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通

int A, B, C;
vector<int>D;
bool F = false;
int main() {
	cin >> A >> B >> C;
	D.push_back(A);
	D.push_back(B);
	D.push_back(C);
	sort(D.begin(), D.end());
	if (D[0] == D[1] && D[1] != D[2]) F = true;
	if (D[0] != D[1] && D[1] == D[2]) F = true;
	if (F) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    input_rawA = read_func().strip().split()
    input_rawB = read_func().strip().split()
    A = []
    B = []
    sub_AB = []
    sumA = 0
    sumB = 0
    count = 0
    sum_fusoku = 0
    for i in range(N):
        A.append(long(input_rawA[i]))
        B.append(long(input_rawB[i]))
        sub_AB.append((max(A[i] - B[i],0), i))
        sumA += A[i]
        sumB += B[i]
        if A[i] < B[i]:
            count += 1
            sum_fusoku += B[i] - A[i]


    if sumA < sumB:
        print -1
        return

    sub_AB.sort(reverse = True)

    for i in range(len(sub_AB)):
        if sum_fusoku > 0:
            sum_fusoku -= sub_AB[i][0]
            count += 1
        else:
            break
    print count



if __name__ == '__main__':
    main()

Measured memory_bytes: 37004
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    ll n,x=0;
    cin>>n;

    ll a[n];

    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        x=x^a[i];
    }

    for(int i=0; i<n; i++)
    {
        cout<<(a[i]^x)<<" ";
    }
    cout<<endl;




    return 0;
}



Measured memory_bytes: 5140
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){

int a,p,P,pie;

cin >> a >> p;

P=p+3*a;

pie=P/2;

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

}


Measured memory_bytes: 3716
fn get_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let source = get_line();
    let target = get_line();
    let processed_source = format!("{}{}", source, &source[..target.len()]);

    match processed_source.find(&target) {
        Some(_) => println!("Yes"),
        None => println!("No")
    }
}



Measured memory_bytes: 5044
import std.stdio;
import std.string;
import std.conv;
import std.functional;

ulong _pow(ulong x, ulong e) {
    ulong ans = 1;
    foreach (i; 0 .. e) {
        ans *= x;
    }
    return ans;
}
alias memoize!_pow pow;

ulong solve(ulong L) {
    ulong[ulong] factor;
    ulong[] primes;
    for (ulong i = 2; i * i <= L; i++) {
        if (L % i == 0) {
            primes ~= i;
            factor[i] = 1;
            L /= i;
        }
        while (L % i == 0) {
            factor[i]++;
            L /= i;
        }
    }
    if (L != 1) {
        primes ~= L;
        factor[L] = 1;
    }
    ulong count(ulong index, ulong a, ulong b) {
        if (index >= primes.length) {
            if (a > b) return 0;
            else return 1;
        }
        ulong p = primes[index];
        ulong c = factor[p];
        ulong ans = 0;
        foreach (i; 0 .. c) {
            ans += count(index + 1, a * p.pow(i), b * p.pow(c));
            ans += count(index + 1, a * p.pow(c), b * p.pow(i));
        }
        ans += count(index + 1, a * p.pow(c), b * p.pow(c));
        return ans;
    }
    return count(0, 1, 1);
}

void main() {
    ulong L;
    while (L = readln.chomp.to!ulong, L) {
        solve(L).writeln;
    }
}

Measured memory_bytes: 3340
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;


//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

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

	for(int i = 1; i <= k; i++){
		if(b <= a) {
			b *= 2;
			continue;
		}
		if(c <= b){
			c *= 2;
			continue;
		}
	}

	if(a < b && b< c)cout << "Yes" << endl;
	else cout << "No" << endl;
}	

Measured memory_bytes: 11024
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

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

int64_t dceil(int64_t, int64_t);
int64_t dfloor(int64_t, int64_t);

int64_t dceil(int64_t x, int64_t y) {
  if (y < 0) {
    return dceil(-x, -y);
  }
  if (x < 0) {
    return -dfloor(-x, y);
  }
  return (x + y - 1) / y;
}

int64_t dfloor(int64_t x, int64_t y) {
  if (y < 0) {
    return dfloor(-x, -y);
  }
  if (x < 0) {
    return -dceil(-x, y);
  }
  return x / y;
}

int main() {
  int64_t L;
  cin >> L;
  cout << fixed << setprecision(7) << (double)(L * L * L) / 27 << endl;
  return 0;
}

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

int main() {
	int n;
	scanf("%d", &n);
	
	bool chk = false;
	for(int i=1;i<=9;i++)
		if(n%i==0 && n/i<=9) chk = true;
	
	puts(chk ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <cmath> 
using namespace std;
int main(){
  long long N;
  cin >> N;
  long long qmax = sqrt(N);
  long long sum = 0LL;
  for (long long q = 1; q <= qmax+1; q++){
    if(N%q==0){
      auto m= N / q - 1;
      if(m>q){
        sum += m;
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		StringBuffer sb = new StringBuffer(scan.next());
		StringBuffer sb1 = new StringBuffer("");
		int n = scan.nextInt();
		boolean reverse = false;

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

			if(scan.nextInt() == 1)reverse = !reverse; 

			else if(reverse){
				if(scan.nextInt() == 1)sb.append(scan.next());
				else sb1.append(scan.next());
			}
			
			else{
				if(scan.nextInt() == 2)sb.append(scan.next());
				else sb1.append(scan.next());
			}

		}

		if(!reverse){
			System.out.println(sb.insert(0, sb1.reverse().toString()).toString());
		}
		else{
			System.out.println(sb.reverse().append(sb1.toString()).toString());			
		}

	}
}

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

int main() {
	int a, b;
	cin >> a >> b;
	vector<int> an(a), br(b);
	for (auto& i : an) cin >> i;
	for (auto& i : br) cin >> i;
	int res = 0;
	for (auto i = 0; i < b; i++) {
		int use = 0;
		for (auto& j : an) {
			if (j == br[use+i]) use++;
			if (use == b) break;
		}
		res = max(res, use);
	}
	cout << res << endl;
}

Measured memory_bytes: 1232
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
using namespace std;
int n,m;
int a[100010];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	vector<int> v;
	v.push_back(abs(m-a[0]));
	for(int i=0;i<n-1;i++)v.push_back(abs(a[i]-a[i+1]));
	int ans=v[0];
	for(int i=1;i<v.size();i++)ans=__gcd(ans,v[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1276
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
#include<stack>
#include<queue>
using namespace std;

bool cmp(char x,char y)
{
	if(x>y)
		return true;
	return false;
}
int main()
{
	char s[105],t[105];
	int i,j;
	while(~scanf("%s %s",&s,&t))
	{
		sort(s,s+strlen(s));
		sort(t,t+strlen(t),cmp);
		if(strcmp(s,t)<0)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  string s, t;
  cin >> s >> t;
  {
    vector<bool> sf(26), tf(26);
    rep(i, s.size()) sf[s[i] - 'a'] = true;
    rep(i, t.size()) tf[t[i] - 'a'] = true;
    rep(i, 26) if (!sf[i] && tf[i]) {
      cout << -1 << endl;
      return;
    }
  }
  int n = s.size();
  s += s;
  vector<vi32> next(26, vi32(s.size()));
  {
    vi32 position(26, -1);
    rrep(i, s.size()) {
      position[s[i] - 'a'] = i + 1;
      rep(j, 26) next[j][i] = position[j] % n;
    }
  }
  i64 acc = 0;
  int now = 0;
  rep(i, t.size()) {
    int nxt = next[t[i] - 'a'][now];
    acc += nxt > now ? nxt - now : nxt - now + n;
    now = nxt;
  }
  cout << acc << endl;
}


Measured memory_bytes: 21868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
int main() {
ll h,n;
cin>>h>>n;
ll a[n]={}, b[n]={};
rep(i,n){ cin>>a[i]>>b[i];}
ll ca=0;
vector<vector<ll>> dp(n+1, vector<ll>(100000, 1000000000000));
dp[0][0]=0;
rep(i,n){
rep(j,100000){
dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
if(j-a[i]>=0){
dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-a[i]]+b[i]);}
}}
//rep(i,n+1)rep(j,h+1) cout << i << " " << j << " " << dp[i][j] << endl;
ll ans = 10000000000;
repl(i,h,50000) ans = min(ans,dp[n][i]);
cout << ans << endl;}


Measured memory_bytes: 788900
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli n;
	cin>>n;
	lli k;
	cin>>k;
	vector<lli> a(n);
	for(lli &x:a)cin>>x;
	vector<lli> dp(k+1);
	for(lli i=0;i<=a[0];i++)dp[i]=1;
	for(lli i=1;i<=k;i++)dp[i]=add(dp[i],dp[i-1]);
	for(lli i=1;i<n;i++){
		vector<lli> newdp(k+1);
		for(lli j=0;j<=k;j++){
			newdp[j]=add(dp[j],mod-(j-a[i]-1>=0?dp[j-a[i]-1]:0));
		}
		dp[0]=newdp[0];
		for(lli j=1;j<=k;j++){
			dp[j]=add(newdp[j],dp[j-1]);
		}
	}
	cout<<add(dp[k],mod-(k-1>=0?dp[k-1]:0))<<endl;
}


Measured memory_bytes: 1792