akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

    ll n, m;
    cin >> n >> m;

    vector<ll> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];

    ll MOD = 1e9 + 7;
    vector<vector<ll>> dp(n+1, vector<ll>(m+1, 0)), sm(n+1, vector<ll>(m+1, 0));
    rep(i, n) rep(j, m){
        if(s[i] == t[j]){
            dp[i+1][j+1] = sm[i][j] + 1;
            dp[i+1][j+1] %= MOD;
        }
        sm[i+1][j+1] = sm[i][j+1] + sm[i+1][j] + MOD - sm[i][j] + dp[i+1][j+1];
        sm[i+1][j+1] %= MOD;
    }

    cout << (sm[n][m] + 1) % MOD << endl;
}


Measured memory_bytes: 66020
n = int(input())
a = list(map(int, input().split()))

s_1 = 0
s_2 = 0
m = 10 ** 9 + 7
for i in range(n):
    s_1 += a[i] % m
    s_2 += (a[i] ** 2) % m
s = (s_1 * s_1 - s_2) * pow(2, m - 2) % m
print(s)

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

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

using vs = vector<string>;

using pll = pair<ll,ll>;
using vpl = vector<pll>;
using vvpl = vector<vpl>;

using tll = tuple<ll,ll,ll>;
using vtl = vector<tll>;

using vb = vector<bool>;
using vvb = vector<vb>;

using ld = long double;
using vd = vector<ld>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;

#define R(a,i) for(ll a=0; a < (i); (a)++)
#define FOR(a,i,j) for(ll a=(i); a < (j); (a)++)
#define RD(a,i) for(ll a=(i)-1; (a) >= 0; (a)--)
#define FORD(a,i,j) for(ll a=(j)-1; (a) >= (i); (a)--)

#define xx first
#define yy second
#define pb push_back
#define eb emplace_back

#define all(X) begin(X),end(X)
#define sz(X) (X).size()

const ll oo = 0x3f3f3f3f3f3f3f3f;
const ld eps = 1e-9;

#define DBG 0
#define TR(X) {if(DBG) cerr << (#X) << " = " << (X) << "\n";}
#define TRV(X,i) {if(DBG) cerr << (#X) << "[" << i << "] = " << (X[i]) << "\n";}
#define TRM(X,i,j) {if(DBG) cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j]) << "\n";}
#define TRP(X,i,j) {if(DBG) cerr << (#X) << "[" << i << "][" << j << "] = (" << (X[i][j]).xx << ", " << (X[i][j]).yy << ")\n";}
#define hline {if(DBG) cerr << "----------------------------------------------------------------------" << "\n";}
#define PK(X) {if(DBG) cerr << (X) << "\n";}

const ll mod = 1e9+7;

template <class T>
void myMin(T& a, T b){
	a = min(a,b);
}

template <class T>
void myMax(T& a, T b){
	a = max(a,b);
}

#define TRM(X,i,j,k) {if(DBG) cerr << (#X) << "[" << i << "][" << j << "] = " << (X[i][j][k]) << "\n";}
int main(void){
	cin.sync_with_stdio(false);
	cin.tie(0);

	string K;
	ll D;
	cin >> K >> D;

	vvvl dp(10005, vvl(100, vl(2)));

	dp[0][0][0] = 1;

	FOR(len,0,sz(K)) {
		ll cur = K[len] - '0';
		FOR(i,0,D){
			FOR(j,0,cur) {
				dp[len+1][(i+j)%D][1] += dp[len][i][0];
				dp[len+1][(i+j)%D][1] %= mod;
			}
			dp[len+1][(i+cur)%D][0] += dp[len][i][0];
			dp[len+1][(i+cur)%D][0] %= mod;
			FOR(j,0,10){
				dp[len+1][(i+j)%D][1] += dp[len][i][1];
				dp[len+1][(i+j)%D][1] %= mod;
			}
		}
	}

	FOR(len,0,sz(K) + 1){
		FOR(i,0,D){
			FOR(k,0,2){
				TRM(dp,len,i,k);
			}
		}
	}

	cout << ((((dp[sz(K)][0][1] + dp[sz(K)][0][0]) % mod) + mod - 1) % mod) << endl;
}


Measured memory_bytes: 57588
// helloworld.cpp : アプリケーションのエントリ ポイントを定義します。
//
/*#include "stdafx.h"*/
//
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <iterator>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
//
int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int S = A + B + C + D + E + F;
    cout << S - min(E, F) - min(A, min(B, min(C, D))) << endl;
    return 0;
}



Measured memory_bytes: 3088
#include<iostream>
using namespace std;
const int N=101;
long long t[N],val[N],dp[100001][N];
int main()
{
	int T,m;cin>>m>>T;
	for(int i=1;i<=m;i++)
		cin>>t[i]>>val[i];
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=T;i++)
		{
			dp[i][j]=dp[i][j-1];
			if(i>=t[j])dp[i][j]=max(dp[i][j],dp[i-t[j]][j-1]+val[j]);
		}
	}
	cout<<dp[T][m];
}

Measured memory_bytes: 82440
#include <iostream>

int main() {

    long a,b,c,d,cd,c_count,d_count,cd_count,ans,x,r,tmp;

    std::cin >> a >> b >> c >> d;

    if(a%c == 0)
        c_count = b/c-a/c + 1;
    else
        c_count = b/c-a/c;

    if(a%d == 0)
        d_count = b/d-a/d + 1;
    else
        d_count = b/d-a/d;

    x = c * d;

    /* 自然数 c > d を確認・入替 */
    if(c<d){
        tmp = c;
        c = d;
        d = tmp;
    }

    /* ユークリッドの互除法 */
    r = c % d;
    while(r!=0){
        c = d;
        d = r;
        r = c % d;
    }


    cd = x/d;

    if(a%cd == 0)
        cd_count = b/cd-a/cd + 1;
    else
        cd_count = b/cd-a/cd;

    ans = (b-a+1) - (c_count + d_count - cd_count);

    std::cout << ans;

    return 0;
}

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

int main() {
  int e;
  while(cin >> e && e) {
    int ans=1<<29;
    for(int z=0; z*z*z<=e; z++) {
      for(int y=0; z*z*z+y*y<=e; y++) ans=min(ans,e-z*z*z-y*y+z+y);
    }
    cout << ans << endl;
  }
  return 0;
}


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

/*............................*/

#define uint uint64_t
#define mx 100001
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define mp make_pair
#define pb push_back
#define inf INT_MAX
#define pi acos(-1)
#define eps 1e-8
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define input(ara, n)          \
   for (int i = 0; i < n; i++) \
   scanf("%d", &ara[i])
#define inputl(ara, n)                   \
   for (long long int i = 0; i < n; i++) \
   scanf("%lld", &ara[i])
#define pf(a) printf("%d\n", a);
#define pfl(a) printf("%lld\n", a);
#define pfi(a) printf("%d ", a);
#define pfll(a) printf("%lld ", a);
#define sc(a) scanf("%d", &a)
#define scc(a, b) scanf("%d %d", &a, &b)
#define sccdbl(a, b) scanf("%lf %lf", &a, &b)
#define sccc(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scccdbl(a, b, c) scanf("%lf %lf %lf", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define sccl(a, b) scanf("%lld %lld", &a, &b)
#define scccl(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
using namespace std;
int main()
{
   // int t;
   // sc(t);
   // while (t--)
   // {

   // }
   char b;
   cin >> b;
   if (b == 'A')
   {
      cout << "T" << '\n';
   }
   else if (b == 'T')
   {
      cout << "A" << '\n';
   }
   else if (b == 'G')
   {
      cout << "C" << '\n';
   }
   else
   {
      cout << "G" << '\n';
   }
   return 0;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
// template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int N;
// DPテーブル
long long h[100010];

long long dp[100010];
int main(){
    cin >> N;
    
    for (int i=0; i< N; ++i) cin >> h[i];
    
    for(int i=0; i<N; ++i) dp[i] = INF;
    
    dp[0] = 0;
    for(int i=1; i< N; ++i){
        chmin(dp[i], dp[i-1] + abs(h[i] -h[i-1]));
        if (i > 1)  chmin(dp[i], dp[i-2] + abs(h[i] -h[i-2]));
    }
    
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define inf INT_MAX
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
dy[8] = { 1,1,0,-1,-1,-1,0,1 };

template<class T>inline bool maxi(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	lint n, in; cin >> n;
	int pos[200000];
	rep(i, n) {
		cin >> in;
		pos[in-1] = i;
	}
	lint ans = -inf, ctr = 1;
	rep(i, n-1) {
		if (pos[i] < pos[i + 1])ctr++;
		else {
			maxi(ans, ctr);
			ctr = 1;
		}
	}
	maxi(ans, ctr);
	co(n - ans);
	gc();
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);

//-------------------------------------------


int main(){

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

    int N,M;
    cin >> N;

    string s[N];
    REP(i,N){
        cin >> s[i];
    }

    cin >> M;
    string t[M];

    REP(i,M){
        cin >> t[i];
    }

    int cnt = 0;
    int cnt2 = 0;
    int maxi = 0;


    REP(i , N){

        cnt = 0;
        cnt2 = 0;
        REP(j , N){
            if ( s[j] == s[i] ){
                cnt++; //dump(cnt);
            }
        }
        REP(k, M){
            if(  t[k] == s[i]  ){
                cnt2++; //dump(cnt2);
            }
        }

        int cntst = cnt - cnt2;
        //dump(cntst);
        maxi = max( cntst, maxi);
    }

    if (maxi > 0) cout << maxi;
    else cout << 0;

    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    
    sort(d.begin(), d.end());

    cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
string keyence="keyence";
ll k,n;
ll t[100000],d[100000];
int main(){
    ll n;cin>>n;
    char a[n],b[n],c[n];
    rep(i,0,n)cin>>a[i];
    rep(i,0,n)cin>>b[i];
    rep(i,0,n)cin>>c[i];
    ll ans=0;
    rep(i,0,n){
        if(a[i]==b[i]&&b[i]==c[i]){
            ans=ans;
        }else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]){
            ans++;
        }else{
            ans+=2;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	
	int n, k;
	scanf("%d %d", &n, &k);
	int a[n];
	
	for(int i = 0 ; i < n ; i++){
		scanf("%d", &a[i]);
	}
	
	for(int i = k ; i < n ; i++){
		if(a[i-k] < a[i]){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 2424
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

ll dp[55][55][2555] ; 
int x[55] ; 

int main()
{
    int N, A ; 
    scanf("%d%d", &N, &A) ; 
    for(int i = 1 ; i <= N ; i++) {
        scanf("%d", x+i) ; 
    }
    dp[0][0][0] = 1LL ; 
    for(int i = 1 ; i <= N ; i++) {
        for(int j = 0 ; j <= i ; j++) {
            for(int sum = 0 ; sum <= 2500 ; sum++) {
                dp[i][j][sum] = dp[i-1][j][sum] ; 
                if(j && sum >= x[i])
                    dp[i][j][sum] += dp[i-1][j-1][sum-x[i]] ; 
            }
        }
    }
    ll ans = 0 ; 
    for(int sel = 1 ; sel <= N ; sel++)
        ans += dp[N][sel][sel*A] ; 
    printf("%lld\n", ans) ; 
    return 0 ; 
}



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

int main() {

	int  p = 5;
	vector<int> c(p);
	for (int i = 0; i < p; i++) {
		cin >> c[i];
	}
	int k; cin >> k;
	bool can = true;
	for (int i = 0; i < p; i++) {
		for (int j = 0; j < p; j++) {
			if (i == j) continue;
			if (k < abs(c[i] - c[j])) {
				can = false;
			}
		}
	}
	if (can) cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 3636
A = []
for _ in range(3):
    A.append([int(i) for i in input().split()])

N = int(input())

grid = [[0] * 3] + [[0] * 3] + [[0] * 3]

for i in range(N):
    b = int(input())

    for j in range(3):
        for k in range(3):
            if b == A[j][k]:
                grid[j][k] = 1

ans = "No"

for j in range(3):
    if sum(grid[j]) == 3:
        ans = "Yes"


for k in range(3):
    tmp = 0
    for j in range(3):
        tmp += grid[j][k]
    if tmp == 3:
        ans = "Yes"

tmp = 0
for i in range(3):
    tmp += grid[i][i]
if tmp == 3:
    ans = "Yes"

tmp = 0
for i in range(3):
    tmp += grid[i][2-i]
if tmp == 3:
    ans = "Yes"


print(ans)


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

int main()
{
    int a, b;
    cin >> a >> b;
    string ans = "";
    if (a <= b)
    {
        for (int i = 0; i < b; i++)
            ans += to_string(a);
        cout << ans << endl;
        return 0;
    }
    else if (a > b)
    {
        for (int i = 0; i < a; i++)
            ans += to_string(b);
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int b[100000];
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d){
    cout<<"Left\n";
  }
  if(a+b==c+d){
    cout<<"Balanced\n";
  }
  if(a+b<c+d){
    cout<<"Right\n";
  }
  return(0);
}


Measured memory_bytes: 256
l = input()
a = l[0]
b = l[1]
c = l[2]
d = l[3]


while(True):
    if(a==b and b==c and c==d):
        print("No")
        break
    if(a==b and c==d):
        print("Yes")
        break
    if(a==c and b==d):
        print("Yes")
        break
    if(a==d and c==b):
        print("Yes")
        break
    else:
      print("No")
      break

Measured memory_bytes: 3064
fun main(array: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val d = readLine()?.split(" ")?.map(String::toInt) ?: return
    val count = hashMapOf<Int, Int>()
    d.sorted().forEachIndexed { i, v ->
        if (!count.containsKey(v)) {
            count[v] = i + 1
        } else {
            count[v] = count[v]!! + 1
        }
    }
    val m = n / 2
    var l = -1
    count.keys.sorted().forEachIndexed { i, v ->
        if (l != -1) {
            println((v - l).toString())
            return
        } else if (count[v] == m) {
            l = v
        }
    }
    println("0")
}


Measured memory_bytes: 58588
X = input()
a = int(X[0])
b = int(X[1])
c = int(X[2])
d = int(X[3])
end = 0
res = a
L = ['+', '-']

for i in L:
    if end == 1:
        break
    for j in L:
        if end == 1:
            break
      
        for k in L:
            res = a
            if i == '+':
                res += b
            else:
                res -= b
            
            if j == '+':
                res += c 
            else:
                res -= c
                
            if k == '+':
                res += d
            else:
                res -= d
            
            if res == 7:
                end = 1
                print(str(a) + i + str(b) + j + str(c) +  str(k) + str(d) + '=7')
                break
                
            

Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    ll V[100] = {2,1};
    int N;
    cin >> N;
    for(int i = 2;i <= N;i++){
        V[i] = V[i-1] + V[i-2];
    }
    cout << V[N] << endl;
}

Measured memory_bytes: 256
n = int(input())
b = 1
while b & n == 0:
    b *= 2
if b == n:
    print("No")
else:
    print("Yes")
    print(1, 2)
    for i in range(2, n, 2):
        print(i, i + 1)
        print(i + 1, n + 1)
        print(n + 1, n + i)
        print(n + i, n + i + 1)
    if n % 2 == 0:
        print(n, n + b)
        print(n - b + 1, n * 2)


Measured memory_bytes: 54488
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, k;
string s;

signed main() {
    cin >> n >> k >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << endl;
}


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

int main() {
  int N,a,b,c;
  unsigned long s=0;
  cin >> N;

  for(a=1;a<=N;a++){
    for(b=1;b<=N;b++){
      for(c=1;c<=N;c++){
        s=s+gcd(gcd(a,b),c);
      }
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3540
N,A=gets.split.map(&:to_i)
r=N
(1..32).each{|i|
	v=(0..1<<60).bsearch{|e|s=1;i.times{|j|s*=(e+j)/i};s>=N}
	r=[r,A*(i-1)+v].min
}
p r

Measured memory_bytes: 2044
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;


void solve(){
    int n, m;
    cin >> n >> m;
    char a[140][149];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i <= n; i++){
        if(i == 0 || i == n){
            for(int k = -1; k <= m; k++) cout << "#";
            if(i == n) break;
            cout << endl;
        }
        for(int j = -1; j <= m; j++){
            if(j == -1 || j == m) cout << "#";
            else{
                cout << a[i][j];
            }
        }
        cout << endl;
    }
}
int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

ans = 0
N = Int()

for i in range(1,N+1):
    if i%3!=0 and i%5!=0:
        ans += i
print(ans)

Measured memory_bytes: 64548
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;

vector<ll> vec[90010];
int main(){

    rep(i,90010) vec[i].push_back(0);
    
    int h,w,d;
    cin >> h >> w >> d;
    map<int,pii> mp;
    int tmp;
    int q;
    int left,right;
    int cnt = 0;
    ll ans = 0;

    rep(i,h){
        rep(j,w){
            cin >> tmp;
            tmp--;
            mp[tmp] = make_pair(j,i);
        }
    }
    
    rep(i,d){
        for(int j = 0; i+j+d < h*w; j += d){
            pii p1 = mp[i+j];
            pii p2 = mp[i+j+d];
            int dis = abs(p1.first - p2.first);
            dis += abs(p1.second - p2.second);
            if(vec[i].size() > 1){
                dis += vec[i][vec[i].size()-1];
            }
            
            vec[i].push_back(dis);
        }
    }

    

    cin >> q;

    rep(i,q){
        ans = 0;
        cin >> left >> right;
        left--; right--;
        if(left == right){
            cout << 0 << endl;
            continue;
        }
        cnt = (right - left) / d;
        tmp = left % d;
        
        ans += vec[tmp][(right-tmp)/d];
        if((left-tmp)/d > 0){
            ans -= vec[tmp][((left-tmp)/d)];
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 15112
#define errOut(s) \
  { std::cerr << __LINE__ << ":" << #s << ":" << (s) << std::endl; }

#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
//#include <boost/multi_array.hpp>
//#include <boost/optional.hpp>
//#include <boost/range/adaptors.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n, std::vector<int64_t> as) {
  int64_t ret = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 2 == 0) {
      continue;
    }
    if (as[i - 1] % 2 == 0) {
      continue;
    }
    ret ++;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> as(n);
  for (int i = 0; i < n; i++) {
    std::cin >> as[i];
  }
  auto const res = solve(n, std::move(as));
  std::cout << res << std::endl;
  return 0;
}


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

#define ll long long
#define pll pair<ll,ll> 

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;

	
}


Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;

template <typename T> inline constexpr bool chmin(T &a, T b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T> inline constexpr bool chmax(T &a, T b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
template <typename ite>
void print_ite(ite start, ite end, char sp = ' ', char en = '\n') {
  for (auto i = start; i != end; i++)
    cout << *i << sp;
  cout << en;
}
template <typename ite> void scan_ite(ite start, ite end) {
  for (auto i = start; i != end; i++)
    cin >> (*i);
}
inline void Yes(bool condition) { cout << (condition ? "Yes\n" : "No\n"); }

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  ll ans = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int l = 1; l <= k; l++) {
        ans += gcd(i, gcd(j, l));
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3188
N = gets.to_i
A = gets.split.map(&:to_i)

counter = Hash.new(0)

A.each do |a|
  counter[a] += 1
end

case counter.size 
when 3
  if counter.keys.inject(:^) == 0 && counter.values.all? { |n| n == N / 3 }
    puts 'Yes'
  else
    puts 'No'
  end
when 2
  if counter[0] == N / 3
    puts 'Yes'
  else
    puts 'No'
  end
when 1
  if counter[0] == N
    puts 'Yes'
  else
    puts 'No'
  end
else
  puts 'No'
end


Measured memory_bytes: 11916
input = STDIN.gets.split(" ")

w = input[0].to_f
h = input[1].to_f
x = input[2].to_f
y = input[3].to_f

rx = w - x
ry = h - y

ans = 0

if rx == x
  ans = x * h
  puts "#{ans} #{ry == y ? 1 : 0}"
  exit
end

if ry == y
  puts "#{y * w} #{rx == x ? 1 : 0}"
  exit
end

a = (ry - y) / (rx - x).to_f
b = y - a * x
ans = (((-b/a)+((h-b)/a))*h)/2.0

puts "#{ans} 0"

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

int main()
{

    int K, S;
    cin >> K >> S;

    int ans = 0;

    for (int a = 0; a <= K; ++a)
    {
        for (int b = 0; b <= K; ++b)
        {
            
            int c = S - a - b;
            if (0 <= c and c <= K) ans++;
            
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
import heapq

n = int(input())
edges = [set((w, j) for j, w in enumerate(map(int, input().split())) if w > -1) for _ in range(n)]

visited = [False] * n
visited[0] = True
queue = list(edges[0])
heapq.heapify(queue)
total_cost, remains = 0, n - 1
while True:
    cost, vertex = heapq.heappop(queue)
    if visited[vertex]:
        continue
    visited[vertex] = True
    total_cost += cost
    remains -= 1
    if not remains:
        break
    queue.extend(edges[vertex])
    heapq.heapify(queue)

print(total_cost)

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

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

    string s;
    int K;
    cin >> s >> K;

    vector<char> alphabet;
    for (int i = 0; i < s.size(); ++i) {
        alphabet.push_back(s[i]);
    }
    sort(alphabet.begin(), alphabet.end());

    auto target_itr = alphabet.begin();
    char target_char;
    set<string> C;
    int count = 0;
    while (1) {
        target_char = *target_itr;
        for (int i = 0; i < s.size(); ++i) {
            if (s[i] == target_char) {
                for (int j = 0; j < K && (i + j) < s.size(); ++j) {
                    C.insert(s.substr(i, j + 1));
                    ++count;
                }
            }
        }
        if (C.size() >= K) {
            break;
        } else {
            while (*(++target_itr) == target_char);
        }
    }

    auto ans = C.begin();
    rep(i, K - 1) {
        ++ans;
    }

    cout << *ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>
#include<set>
#include<queue>

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

using namespace std;


int main(){
	string s; cin >> s;
	string temp = "CODEFESTIVAL2016";
	int res = 0;
	rep(i, s.size()){
		if(s[i] != temp[i])
			res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=10010, MAXM=1500000, MAXE=20000000;

int n, m, k, u, v, x, y, t, a, b, ans;
int X[MAXN], Y[MAXN];
pii A[MAXN<<1];
bool mark[MAXM];
int comp[MAXM], cid;
int seg[MAXN<<3], N;
int E[MAXE], M;
int prv[MAXE];
int hd[MAXM], hdr[MAXM];
vector<int> /*G[MAXM], GR[MAXM], */topol;

inline void add_edge(int u, int v){
	/*
	G[u].pb(v);
	GR[v].pb(u);*/
	E[++M]=v;
	prv[M]=hd[u];
	hd[u]=M;
	
	E[++M]=u;
	prv[M]=hdr[v];
	hdr[v]=M;
}

inline void add_clause(int u, int v){
	add_edge(u^1, v);
	add_edge(v^1, u);
}

void Set(int id, int tl, int tr, int pos, int val){
	if (pos<tl || tr<=pos) return ;
	if (tr-tl==1){
		seg[id]=val;
		return ;
	}
	int mid=(tl+tr)>>1;
	Set(id<<1, tl, mid, pos, val);
	Set(id<<1 | 1, mid, tr, pos, val);
	if (seg[id<<1]!=-1 && seg[id<<1 | 1]!=-1){
		seg[id]=(N++)<<1;
		add_clause(seg[id<<1]^1, seg[id]);
		add_clause(seg[id<<1 | 1]^1, seg[id]);
		add_clause(seg[id<<1]^1, seg[id<<1 | 1]^1);
	}
	else seg[id]=seg[id<<1]+seg[id<<1 | 1]+1;
}

inline void Add(int pos){
	Set(1, 0, n<<1, pos, pos);
}
inline void Rem(int pos){
	Set(1, 0, n<<1, pos, -1);
}

void dfs1(int node){
	mark[node]=1;
	for (int i=hd[node]; i; i=prv[i]){
		int v=E[i];
		if (!mark[v]) dfs1(v);
	}
	topol.pb(node);
}

void dfs2(int node, int cid){
	comp[node]=cid;
	for (int i=hdr[node]; i; i=prv[i]){
		int v=E[i];
		if (!comp[v]) dfs2(v, cid);
	}
}

bool check(int val){
	for (int i=0; i<2*N; i++){
		mark[i]=0;
		comp[i]=0;
		hd[i]=hdr[i]=0;
		//G[i].clear();
		//GR[i].clear();
	}
	N=n;
	M=0;
	cid=0;
	topol.clear();
	memset(seg, -1, sizeof(seg));
	int j=0;
	for (int i=0; i<2*n; i++){
		while (A[i].first-A[j].first>=val) Rem(A[j++].second);
		Add(A[i].second);
	}
	for (int i=0; i<2*N; i++) if (!mark[i]) dfs1(i);
	reverse(all(topol));
	for (int v:topol) if (!comp[v]) dfs2(v, ++cid);
	for (int i=0; i<N; i++) if (comp[i<<1]==comp[i<<1 | 1]) return 0;
	return 1;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>X[i]>>Y[i];
		A[i<<1]={X[i], i<<1};
		A[i<<1 | 1]={Y[i], i<<1 | 1};
	}
	sort(A, A+2*n);
	int dwn=0, up=1000000000/(n-1)+2;
	while (up-dwn>1){
		int mid=(dwn+up)>>1;
		if (check(mid)) dwn=mid;
		else up=mid;
	}
	cout<<dwn<<'\n';
	
	return 0;
}


Measured memory_bytes: 77036
#include <stdio.h>

int main()
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a == 1)
		a = 14;
	if (b == 1)
		b = 14;
	if (a > b)
		puts("Alice");
	else if (b > a)
		puts("Bob");
	else
		puts("Draw");
}

Measured memory_bytes: 128
n,x,y=map(int,input().split())
x-=1
y-=1
D=[[0]*n for _ in range(n)]
for i in range(n-1):
    for j in range(i+1,n):
        D[i][j]=min(abs(j-i),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))

K=[0]*(n-1)

for i in range(n-1):
    for j in range(i+1,n):
        K[D[i][j]-1]+=1

for k in K:
    print(k)

Measured memory_bytes: 80476
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())
void solve(){
	string s;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2];
	

		
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    //test{solve();cout<<'\n';}
	solve();
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 

 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("./input.txt","r",stdin);
  //  freopen("./output.txt","w",stdout);
    int n;
    cin>>n;

    string a;
    cin>>a;
    int prev = -1;
    string out="";
    for(int i=0;i<a.size();i++)
    {
        if(prev==-1||prev!=a[i]-'a')
        {
            out+=a[i];
            prev = a[i]-'a';
        }
        else
        {
            // if(prev == a[i]-'a')
        }
    }
    cout<<out.size();

}

Measured memory_bytes: 592
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
ll A[100005];
ll ans;
ll x = 2;
int main() {
    cin >> N;
    rep(i, N) cin >> A[i];
    // rep(i, N) cout << A[i] << " ";
    // cout << endl;
    ans = A[0] - 1;
    A[0] = 1;
    rep(i, N) if (i) {
        if (A[i] == 1) continue;
        if (A[i] == x) {
            x++;
        }
        ll add = (A[i] - 1) / x;
        ans += add;
        A[i] -= add * x;
        // printf("%d %d %d(%d)\n", i, A[i], add, x);
    }
    // rep(i, N) cout << A[i] << " ";
    // cout << endl;
    cout << ans << endl;

    return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    int Sunuke[N] = {};
    for (int i = 0; i < K; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int A; cin >> A;
            Sunuke[A - 1] = 1;
        }
    }
    int answer = 0;
    for (int i = 0; i < N; i++) {
        if (Sunuke[i] == 0) {
            answer++;
        }
    }
    cout << answer << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,x,y,p,min=INT_MAX;
  cin >>a >>b >>c >>x >>y;
  for(int i=0; i<100001; ++i) {
    p = 2*c*i + a*max(0,x-i) + b*max(0,y-i);
    if(min>p) min=p;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
people, point, num = gets.split(" ").map(&:to_i)
ans = readlines.map(&:to_i)

points = Array.new(people,point)
n = points.size

ans.each do |a|
    points[a-1] += 1
end

points.each do |point|
    if point > num
        puts 'Yes'
    else
        puts 'No'
    end
end

Measured memory_bytes: 12028
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int ans = 0;
	for(int i = 0; i < 1000; i++){
		int num = i;
		int cnt = 0;
		for(char c : S){
			if(c - '0' == num % 10){
				cnt += 1;
				num /= 10;
			}
		}
		if(cnt >= 3){
			ans += 1;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  string s;
  int Q;
  while(cin >> s >> Q){

    deque<char> d;
    for(auto c : s) d.push_back(c);

    bool rev = false;

    REP(i,Q){
      int T; cin >> T;

      if(T == 1){
        rev = !rev;
      }else{
        int F; cin >> F;
        char c; cin >> c;

        if((F == 1) ^ rev){
          d.push_front(c);
        }else{
          d.push_back(c);
        }
      }
    }

    if(rev) reverse(ALL(d));

    string ans;
    for(auto c : d) ans.push_back(c);

    puts_all(ans);
    
  }


  return 0;
}


Measured memory_bytes: 1368
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            // n,m,l入力
            int[] intInputInfoArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int n = intInputInfoArray[0];
            int m = intInputInfoArray[1];
            int l = intInputInfoArray[2];

            // n,m,lから行列A,B,Cの配列を作成
            int[,] intAMatrixArray = new int[n, m];
            int[,] intBMatrixArray = new int[m, l];
            long[,] longCMatrixArray = new long[n, l];

            int[] intInputTempDataArray;

            // 行列Aのデータ入力
            for (int row = 0; row < n; row++)
            {
                intInputTempDataArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int col = 0; col < m; col++)
                {
                    intAMatrixArray[row, col] = intInputTempDataArray[col];
                }
            }

            // 行列Bのデータ入力
            for (int row = 0; row < m; row++)
            {
                intInputTempDataArray = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                for (int col = 0; col < l; col++)
                {
                    intBMatrixArray[row, col] = intInputTempDataArray[col];
                }
            }

            // 行列Cの計算
            for (int row = 0; row < n; row++)
            {
                for (int col = 0; col < l; col++)
                {
                    for (int index = 0; index < m; index++)
                    {
                        longCMatrixArray[row, col] += intAMatrixArray[row, index] * intBMatrixArray[index, col];
                    }
                }
            }

            // 出力
            for (int row = 0; row < n; row++)
            {
                for (int col = 0; col < l; col++)
                {
                    if (col != l - 1)
                    {
                        Console.Write(longCMatrixArray[row, col] + " ");
                    }
                    else
                    {
                        Console.Write(longCMatrixArray[row, col]);
                        break;
                    }
                }
                Console.Write("\r\n");
            }
        }
    }
}


Measured memory_bytes: 20440
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c&&c==a){
        cout<<"No"<<endl;
        return 0;
    }else if(a!=b&&b!=c&&c!=a){
        cout<<"No"<<endl;
        return 0;
    }else{
        cout<<"Yes"<<endl;
        return 0;
    }
}
        


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

int n;
ll fact[1000001];

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

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0){
		return res*(p-fact[n%p])%p;
	}
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}


void solve(){
	ll ans=0;
	ll sum=0;
	for(int i=2;i<=n-1;i++){
		ll val=fact[i];
		val=val*mod_comb(i-1,n-1-i,MOD)%MOD;
		val=val*fact[n-1-i]%MOD;
		val+=MOD-sum;
		val%=MOD;
		ans=(ans+(ll)val*i%MOD)%MOD;
		sum+=val;
		sum%=MOD;
	}
	printf("%lld\n",ans);
}

int main(void){
	scanf("%d",&n);
	fact[0]=1;
	for(ll i=1;i<=1000000;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	if(n==2){
		printf("1\n");
	}
	if(n==3){
		printf("4\n");
	}
	if(n>=4){
		solve();
	}
	return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#include<algorithm>
using namespace std;
bool cmp(int x,int y){return x>y;}
int main(){
  int n,k;
  int list[101]; 
 while(scanf("%d%d",&n,&k)!=EOF){
     for(int i=0;i<n;i++){
        scanf("%d",&list[i]);
     }
 sort(list,list+n,cmp);
int ans=0;
for(int i=0;i<k;i++){
    ans+=list[i];
    }
printf("%d\n",ans);
  }
return 0;
}

Measured memory_bytes: 128
n = int(input())
#k, x = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))
import bisect
al.sort();bl.sort();cl.sort()
ans=0
for bi in bl:
    c1 = bisect.bisect_right(al, bi-1)
    c2 = n-bisect.bisect_left(cl, bi+1)
    ans += c1*c2
print(ans)

Measured memory_bytes: 29616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

const ll N=2e5+10;
vec fst(N),nxt(N),lst(N),ans(N),rep(N);
ll flag[N];

int main() {
  ll n,k;
  cin >> n >> k;
  vec a(n+1);
  for(ll i=1;i<=n;i++) {
    cin >> a[i];
    if(!fst[a[i]])fst[a[i]]=i;
  }
  nxt[n+1]=1;
  for(ll i=n;i;i--) {
    if(!lst[a[i]]) nxt[i]=fst[a[i]]+1;
    else nxt[i]=nxt[lst[a[i]]+1];
    lst[a[i]]=i;
  }
  ll cnt=0;
  for(ll i=1;!flag[i];i=nxt[i]) {
    flag[i]=1;
    rep[++cnt]=i;
  }
  memset(flag,0,sizeof(flag));
  ll top=0;
  for(ll i=rep[(k-1)%cnt+1];i<=n;i++) {
    if(!flag[a[i]]) ans[++top]=a[i],flag[a[i]]=1;
    else {
      while(ans[top+1]!=a[i]){
        flag[ans[top--]]=0;
      }
    }
  }
  for(ll i=1;i<=top;i++) {
    if(i!=1) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 12416
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <climits> 
#include <numeric> 
#include <iomanip> 
//#include <iterator>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9+7;

double moreHeads(vector<double>& probs) {
    int n = probs.size();
    vector<double> dp(n+1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; ++ i) {
        for (int j = i+1; j >=0; -- j) {
            if (j>0) dp[j] = dp[j-1]*probs[i] + dp[j]*(1-probs[i]);
            else dp[j] = dp[j] * (1-probs[i]);
        }
    }
    double prob = 0;
    return accumulate(dp.begin() + n/2+1, dp.end(), prob);
}

int main() {
    int N; 
    cin>>N;
    vector<double> probs(N);
    for (auto& p : probs) cin>>p;
    cout<< setprecision(10)<<moreHeads(probs)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,d,l,ans,ko=0,sa=0;
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	while(a>0){
		a=a-c;
		ko++;
	}
	while(b>0){
		b=b-d;
		sa++;
	}
	if(ko>sa){
		ans=l-ko;
	}else{
		ans=l-sa;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 596