akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

const int N = 123456;
int p[2 * N + 1];

int main(){
	for(int i = 0;i <= 2 * N;++i){
		p[i] = i;
	}
	for(int i = 2;i <= sqrt(2 * N);++i){
		if(p[i]){
			for(int j = i + i;j <= 2 * N;j += i){
				p[j] = 0;
			}
		}
	}
	p[1] = 0;
	int n;

	while(cin >> n, n){
		int c = 0;
		for(int i = n + 1;i <= n + n;++i){
			if(p[i]) ++c;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 2124
#include <iostream>
#include <vector>
#include <string>

using namespace std;

string nodeInfo[] = { "root", "internal node", "leaf" };

struct Node {
    int depth;
    int status;
    int parent;
    int dim;
    vector<int> child;;
} tree[100000];

void treeRecur(int u, int d) {
    tree[u].depth = d;
    int k = tree[u].dim;
    if (k > 0) {
        tree[u].status = 1;
        for (int i = 0; i < k; ++i) {
            treeRecur(tree[u].child[i], d + 1);
        }
    }
    else {
        tree[u].status = 2;
    }
}

void treeBuild(int n) {
    int root;
    for (int i = 0; i < n; ++i) {
        if (tree[i].parent == -1) {
            root = i;
            break;
        }
    }
    treeRecur(root, 0);
    tree[root].status = 0;
}

int main() {
    int n, id, k, c;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        tree[i].parent = -1;
        tree[i].status = 0;
    }
    for (int i = 0; i < n; ++i) {
        cin >> id >> k;
        tree[id].dim = k;
        if (k > 0) {
            for (int j = 0; j < k; ++j) {
                cin >> c;
                tree[id].child.push_back(c);
                tree[c].parent = id;
            }
        }
    }
    treeBuild(n);
    for (int i = 0; i < n; ++i) {
        cout << "node " << i;
        cout << ": parent = " << tree[i].parent;
        cout << ", depth = " << tree[i].depth;
        cout << ", " << nodeInfo[tree[i].status] << ", [";
        for (int j = 0; j < tree[i].dim; ++j) {
            cout << tree[i].child[j];
            if (j < tree[i].dim - 1)
                cout << ", ";
        }
        cout << "]" << endl;
    }

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

#define MOD 1000000007

const int MAX = 1000005;
ll fac[MAX], finv[MAX], inv[MAX];

void Cinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll C(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    Cinit();
    int x, y;
    cin >> x >> y;
    if((4*x-2*y)%6==0){
        int xx = (4*x-2*y)/6;
        int yy = x-xx*2;
        cout << C(xx+yy, xx) << endl;
    }else{
        cout << 0 << endl;
    }


    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pb push_back
#define mp make_pair
const unsigned int mod = 1e9+7;
const int mx=100005;
int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout); 
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll n;cin >> n;
	char s[n][11];
	ll ak;
	vector <string > vec;
	rep(i,n){
		cin >> s[i];
		sort(s[i],s[i]+strlen(s[i]));
		vec.push_back(s[i]);
	}
	sort(vec.begin(),vec.end());
	ll ans=0;
	ll ok=1;
	for(ll i=1;i<vec.size();i++){
	/*	if(vec[i]==vec[i+1] and ok){
			ans+=2;
		}*/
		if(vec[i]!=vec[i-1] and ok){
			ans+=((ok-1)*ok)/2;
			ok=1;
		}
		if(vec[i]==vec[i-1]){
			++ok;
		}

	}
	ans+=((ok-1)*ok)/2;
	cout << ans << endl;
}
	

Measured memory_bytes: 6772
H, W = map(int, input().split())

ans_array = [['#'] * (W + 2) for i in range(H + 2)]

for i in range(H):
    s = list(input())
    for j in range(W):
        ans_array[i + 1][j + 1] = s[j]

ans = ''
for i in range(H + 2):
    for j in range(W + 2):
        ans += ans_array[i][j]
    print(ans)
    ans = ''

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

"""
・最小全域木、Union-Find
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from operator import itemgetter

# Union-Find木
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

N = int(input())
X = [[0] * 2 for i in range(N)]
Y = [[0] * 2 for i in range(N)]
for i in range(N):
    x, y = map(int, input().split())
    X[i][0] = x
    X[i][1] = i
    Y[i][0] = y
    Y[i][1] = i
# 元indexを保持して座標位置順にソート
X.sort(key=itemgetter(0))
Y.sort(key=itemgetter(0))

edges = []
for i in range(1, N):
    # 座標上で隣り合う頂点同士で辺集合を作る
    edges.append((X[i-1][1], X[i][1], X[i][0] - X[i-1][0]))
    edges.append((Y[i-1][1], Y[i][1], Y[i][0] - Y[i-1][0]))
# コスト順にソート
edges.sort(key=itemgetter(2))

uf = UnionFind(N)
ans = 0
grp = N
# Union-Findで閉路を作らない確認をして最小全域木を作る
for x, y, w in edges:
    if not uf.same(x, y):
        uf.union(x, y)
        ans += w
        grp -= 1
    # グループが1つになれば、それ以上やる必要ない
    if grp == 1:
        break
print(ans)


Measured memory_bytes: 60720
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[200000] = {};
	int t;
	for (int i = 1; i < n; i++) {
		cin >> t;
		a[t - 1]++;
	}

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

	return 0;
}

Measured memory_bytes: 4416
def main():

    A, B, C, X, Y = map(int, input().split())

    num_a = 0
    num_b = 0
    num_c = 0

    if A >= C*2:
        num_c += X*2
    if B >= C*2:
        num_c += max(Y*2 - num_c, 0)

    left_X = max(X-num_c/2, 0)
    left_Y = max(Y-num_c/2, 0)

    # print(num_c, left_X, left_Y)
    if A + B >= C*2:
        num_c += min(left_X, left_Y)*2

    num_a = max(X-num_c/2, 0)
    num_b = max(Y-num_c/2, 0)

    # print(num_a, num_b, num_c)

    print(int(A*num_a + B*num_b + C*num_c))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long min = Long.MAX_VALUE;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            long temp = Long.parseLong(sc.next());
            if (min > temp) {
                ans++;
                min = temp;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 48764
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

int main() {
    string A, B;
    cin >> A >> B;
    string ans = "EQUAL";
    if(A.size() > B.size()){
        ans = "GREATER";
    }else if(A.size() < B.size()){
        ans = "LESS";
    }else{
        if(A > B){
            ans = "GREATER";
        }else if(A < B){
            ans = "LESS";
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// syakyo http://mikecat.6.ql.bz/aojcode/V11/1145/

#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif

string input;

char result;
int current;
int target;

void go_next(int repeat, int start, int end){
    for(int repeating = 0; repeating < repeat && current < target; repeating++){
        for(int i = start; i < end && current < target; i++){
            if(isdigit(input[i])){
                // repeat
                int next_repeat = input[i]-'0';
                int j;
                for(j=i+1; j < end && isdigit(input[j]); j++){
                    next_repeat = next_repeat*10 + input[j]-'0';
                }
                int k, depth;
                if(input[j] == '('){
                    for(k=j+1, depth=1; k < end && depth > 0; k++){
                        if(input[k]=='(') depth++;
                        else if(input[k]==')') depth--;
                    }
                    go_next(next_repeat,j+1,k-1);
                    i=k-1;
                } else {
                    k=j+1;
                    go_next(next_repeat,j,j+1);
                    i=j;
                }
            } else {
                current++;
                if(current >= target) result = input[i];
            }
        }
    }
}

int main(){
    while(cin >> input >> target && input!="0"){
        result = '0';
        current = -1;
        go_next(1,0,input.size());
        cout << result << endl;
    }
}

Measured memory_bytes: 1212
def bfs(field,H,W,start_x,start_y,tmp_N):
    direction = [[-1,0],[1,0],[0,-1],[0,1]]
    que = []
    que.append([start_x,start_y])
    INF = 1000000
    min_path = [[INF] * W for i in range(H)]
    min_path[start_y][start_x] = 0
    while len(que) != 0:
        current = que.pop(0)
        for d in direction:
            nx = current[0] + d[0]
            ny = current[1] + d[1]
            if 0 <= nx < W and 0 <= ny < H and field[ny][nx] != "X" and min_path[ny][nx] == INF:
                min_path[ny][nx] = min_path[current[1]][current[0]] + 1
                if field[ny][nx] == tmp_N: # at the same cheese-power number
                    return nx,ny,min_path[ny][nx]
                else:
                    que.append([nx,ny])

def getField():
    matrix = []
    first = input().strip()
    H,W,N = map(int,first.split())
    for i in range(H):
        row = list(input().strip())
        for j in range(W):
            if row[j].isdigit():
                row[j] = int(row[j])
        matrix.append(row)
    return matrix,H,W,N

def getStart(field):
    for y in range(len(field)):
        for x in range(len(field[0])):
            if field[y][x] == "S":
                return x,y

def main():
    matrix,H,W,N = getField()
    sx,sy = getStart(matrix)
    distance = 0
    for k in range(N):
        if k != 0:
            tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,tmps[0],tmps[1],k+1)
            distance += tmp_dist
            tmps = [tmp_x,tmp_y]
        else:
            tmp_x,tmp_y,tmp_dist = bfs(matrix,H,W,sx,sy,k+1)
            distance += tmp_dist
            tmps = [tmp_x,tmp_y]
    print(distance)


if __name__=='__main__':
    main()

Measured memory_bytes: 36852
// Danielxlr
// https://atcoder.jp/contests/abc174/tasks/abc174_c
// math

#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int k , kkk=7, steps=1;
    cin>>k;

while(kkk%k!=0){
    if(steps>=(pow(10,6)+5)){
        steps=-1;
        break;
    }
    steps++;
    kkk=kkk*10+7;
    kkk%=k;
    }
    cout<<steps;
    return 0;
}

Measured memory_bytes: 3644
S = gets.chomp
ans = ''
i = 0
for nums in S.split(/\A(.{2,2})/, 2)[1..-1] do
    if nums.to_i > 12 || nums.to_i == 0
        ans += "Y"
    else
        ans += "M"
    end
    i += 1
end

if ans == "YM"
    puts "YYMM"
elsif ans == "MY"
    puts "MMYY"
elsif ans == "MM"
    puts 'AMBIGUOUS'
else
    puts 'NA'
end


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

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

    long long int num = 0;

    unordered_map<string, int> sList;
    for (int i = 0; i < n; ++i)
    {
        string input;
        cin >> input;
        sort(input.begin(), input.end());

        auto iter = sList.find(input);

        if (iter != sList.end())
        {
            num += iter->second;

            ++iter->second;
        }
        else
        {
            sList.insert(make_pair(input, 1));
        }
    }

    cout << num << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vector<pii> > vvpii;

#define pb push_back
#define endl '\n'
#define INF (int)1e9
#define EPS 1e-9
#define gcd __gcd
#define rs resize
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; } //for struct sorting

void printV(vector<int> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " " ;
	}
	cout << endl;
}

void print2V(vvi v){
	FOR(i, 0, v.size()){
		FOR(j, 0, v[i].size()){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

int n, k, dp[200000], arr[200000];

int path(int cur){
//	cout << "inside with: " << cur << endl;
	if(cur > n){
//		cout << "outside " << endl;
		return INF;
	}
	if(cur == n){
//		cout << "on point" << endl;
		return 0;
	}
	if(dp[cur] != INF){
//		cout << "already computed" << endl;
		return dp[cur];
	}
	for(int i = 1; i <= k; i++){
		dp[cur] = min( dp[cur], path(cur+i)+abs(arr[cur]-arr[cur+i]) );
	}
	return dp[cur];
}

int main(){
	cin >> n >> k;
	for(int i = 1; i <= n+k+5; i++){
		dp[i] = INF;
	}
	for(int i = 1; i <= n; i++){
		cin >> arr[i];
	}
	cout << path(1);
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;} 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 
// ========================================================
signed main(){
  #ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  #endif
  fio;
    int n;
    cin>>n;
    unordered_map<string,int> cnt;
    for0(i,n){
        string s;
        cin>>s;
        cnt[s]++;
    }
    cout<<"AC x "<<cnt["AC"]<<endl;
    cout<<"WA x "<<cnt["WA"]<<endl;
    cout<<"TLE x "<<cnt["TLE"]<<endl;
    cout<<"RE x "<<cnt["RE"]<<endl;
  rr;
}



Measured memory_bytes: 3676
#include <iostream>

#include <float.h> // DBL_EPSILON

#include <cmath>

int main()
{
	int a, b;

	std::cin >> a >> b;

	double k_d = (double)(a + b) / 2;
	int k_i = ceil(k_d);

	if (fabs(k_d - (double)k_i) <= DBL_EPSILON)
		std::cout << k_i;
	else
		std::cout << "IMPOSSIBLE";

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N= sc.nextInt();
		int A[] = new int[N];
		int result =0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			result=result^A[i];
		}
		for (int i=0;i<N;i++) {
			System.out.print(result^A[i]);
			System.out.print(" ");
		}
	}
}


Measured memory_bytes: 60176
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let a = line[0];
    let b = line[1];
    let n = line[2];

    let ans = if n >= b {
        a * (b-1) / b
    } else {
        a * n / b
    };

    println!("{}", ans);
}


Measured memory_bytes: 2160
#include<stdio.h>

int main() {
	int p, q, r;
	scanf("%d%d%d", &p, &q, &r);
	if (p <= q || p <= r) {
		if (q < r)
			printf("%d\n", p + q);
		else
			printf("%d\n", p + r);
	}
	else
		printf("%d\n", q + r);


	return 0;
}

Measured memory_bytes: 128
from collections import Counter

S = input()
P = 2019

def solve(S, P):
    S = S[::-1]
    T = [0] * len(S)
    T[0] = int(S[0]) % P
    power = 1
    for i in range(1, len(S)):
        power *= 10
        power %= P
        T[i] = T[i - 1] + power * int(S[i])
        T[i] %= P
    counter = Counter(T)
    return sum(x * (x - 1) // 2 for x in counter.values()) + counter[0]


print(solve(S, P))

Measured memory_bytes: 16672
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

int main(){
	int i,n;
	string a;
	cin>>n;
	cin>>a;
	for(i=0;i<a.length();i++){
		a[i]=(char)((a[i]-65+n%26)%26+65);
	}
	cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n;
	cin >> n;
	int cake = 4;
	int donut = 7;
	bool b = false;
	for (int ci = 0; ci < 30; ++ci)
	{
		for (int di = 0; di < 20; ++di)
		{
			if(n == ci * cake + di * donut){
				b = true;
			}
		}
	}
	if(b){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using P = pair<int,int>;
using LL = long long;
int n,m,in[M];
LL dp[M],dp2[M];
P card[M];
int main()
{
    while (~scanf("%d %d", &n,&m)) {
        REP(i,1,n) scanf("%d", &in[i]);
        REP(i,1,m) scanf("%d %d",&card[i].second,&card[i].first);
        sort(in+1, in+n+1);
        sort(card+1, card+m+1, greater<P>());

        dp[0] = 0;
        REP(i,1,n) dp[i] = dp[i-1] + in[i];

        MSET(dp2, -1);
        dp2[0] = 0;
        int pos=1;
        REP(i,1,m) {
            if (pos>n) break;
            REP(j,pos,min(pos+card[i].second-1, n))
                dp2[j] = dp2[j-1] + card[i].first;
            pos += card[i].second;
        }

        LL ans = dp[n];
        REP(i,1,n) if(dp2[i]!=-1) ans = max(ans, dp2[i] + dp[n]-dp[i]);

        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll n,k; cin >> n >> k;
    vl a(n);
    rep(i,n) cin >> a[i];
    vl sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    vl v;
    rep(i,n){
        REP(j,i+1,n+1){
            v.push_back(sum[j]-sum[i]);
        }
    }
    ll ans = 0;
    ll m = v.size();
    vl vv = v;
    for(ll bit=40; bit>=0; bit--){
        ll cnt = 0;
        for(auto i : v){
            if(i & (1LL<<bit)){
                cnt++;
                vv.push_back(i);
            }
        }
        if(cnt >= k){
            ans += (1LL<<bit);
            v = vv;
        }
        vv.clear();
    }
    cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  int a=51;
  string ans;
  for(int i=0;i<N;i++){
    cin >> p.at(i);
    if(p.at(i)!=i+1){
      a=i;
    }
  }
  if(a==51){
    ans = "YES";
  }
  else{
    int b=p.at(a);
    int c=p.at(b-1);
    p.at(a)=c;
    p.at(b-1)=b;
    int count = 0;
    for(int i=0;i<N;i++){
      if(p.at(i)!=i+1){
        ans = "NO";
        count++;
        break;
      }
    }
    if(count==0){
      ans = "YES";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int a, b, i;
    int west, east;

    scanf("%d %d", &a, &b);

    west = east = 1;
    for (i = 2; i < 1000; ++i) {
        west = east;
        east += i;
        if (west < a) continue;
        if ((west - a) == (east - b)) {
            printf("%d\n", west - a);
            return 0;
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	deque<char> ans_str;
	int Q;

	string str;
	cin>>str;
	cin>>Q;


	//input str operate
	//ans_str.reserve(300001);
	for(int i = 0; i < str.length(); i++){
		ans_str.push_back(str[i]);
	}
	int zengo_flag = 1;

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

		if(query_num == 1){
			zengo_flag *=  -1;
//			auto f_c = ans_str.front();
//			auto b_c = ans_str.back();
//			ans_str.pop_front();
//			ans_str.pop_back();
//			ans_str.push_front(b_c);
//			ans_str.push_back(f_c);
		}
		else{
			int F;
			char C;
			cin>>F;
			cin>>C;

			if(zengo_flag == 1){
				if(F == 1){
					ans_str.push_front(C);
				}
				else{
					ans_str.push_back(C);
				}
			}
			else{
				if(F == 1){
					ans_str.push_back(C);
				}
				else{
					ans_str.push_front(C);
				}
			}
		}
	}

	if(zengo_flag == 1){
		for_each(ans_str.begin(),ans_str.end(),[&](char c){
			cout<<c;
			});
	}
	else{
		for_each(ans_str.rbegin(),ans_str.rend(),[&](char c){
			cout<<c;
			});
	}
	cout<<endl;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
template<typename T>
inline T read(T&x){
	x=0;int f=0;char ch=getchar();
	while (ch<'0' || ch>'9') f|=(ch=='-'),ch=getchar();
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x=f?-x:x;
}
const int N=(1<<18)+10;
int n,i,j,status,a[N];
pair<int,int> f[N];
inline void up(pair<int,int> &a,pair<int,int> b){
	if (b.second>=a.first){
		a=b;
	}
	else if (b.first>=a.first){
		a.second=a.first;
		a.first=b.first;
	}
	else if (b.first<a.first && b.first>=a.second){
		a.second=b.first;
	}
}
int main(){
	read(n);
	for (i=0;i<(1<<n);++i){
		read(a[i]);
		f[i].first=a[i];
	}
	for (i=0;i<n;++i){
		for (status=0;status<(1<<n);++status){
			if (status&(1<<i)) up(f[status],f[status^(1<<i)]);
		}
	}
	for (i=1;i<(1<<n);++i){
		int res=f[i].first+f[i].second;
		for (j=1;j<n;j++){
			if (i&(1<<j)){
				int pos=(i^(1<<j))|((1<<j)-1);
				res=max(res,f[pos].first+f[pos].second);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

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

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  for(int b=0;b<(1<<n);b++){
    if(__builtin_popcount(b)!=k) continue;
    cout<<b<<":";
    for(int i=0;i<n;i++)
      if((b>>i)&1) cout<<" "<<i;
    cout<<"\n";
  }
  cout<<flush;
  return 0;
}



Measured memory_bytes: 3176
#include <iostream>

using namespace std;

int c2(int a) {
	int x;
	x = a * (a - 1) / 2;
	return x;
}

int main()
{
	int n, m;
	cin >> n >> m;
	int x, a, b;
	a = c2(n);
	b = c2(m);
	x = a + b;
	
	cout << x;

	return 0;
}

Measured memory_bytes: 256
M = int(input())
DC = [tuple(map(int,input().split())) for i in range(M)]

total_d = 0
total_len = 0
for d,c in DC:
    total_d += d*c
    total_len += c

ans = (total_d - 1)//9 + total_len - 1
print(ans)

Measured memory_bytes: 23692
n=  int( input())
a = list( map( int , input().split()))
d ={}
for item in a:
	if item  in d:
		d[item]+=1
	else:
		d[item] =1;
ans =0
for val in d.values():
	ans += (val * (val-1)) //2
for item in a:
	temp =ans
	temp -= ( (d[item] * (d[item] -1) ) //2 )
	temp += ( (max(d[item]-2 ,0) * (d[item] -1) ) //2 )
	print(temp)

Measured memory_bytes: 26268
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n,a[maxn],x;
ll ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); n++;
	for (int i=1;i<=n;i++) read(a[i]),ans+=a[i];
	for (int i=1;i<n;i++) {
		read(x);
		if (x>=a[i]) {
			a[i+1]=max(0,a[i+1]-(x-a[i]));
			a[i]=0;
		} else a[i]-=x;
	}
	for (int i=1;i<=n;i++) ans-=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if(a==b){
      for(int i=0;i<a;++i){
        System.out.print(a);
      }
    }
    else if(a>b){
      for(int i=0;i<a;++i){
        System.out.print(b);
      }
    }
    else{
      for(int i=0;i<b;++i){
        System.out.print(a);
      }
    }
  }
}


Measured memory_bytes: 22740
from collections import Counter

n, v = map(int, input().split())
a, b, c, d = (tuple(map(int, input().split())) for _ in range(4))
ab = Counter(ai + bi for ai in a for bi in b)
cd = Counter(ci + di for ci in c for di in d)
print(sum(t * cd[v - k] for k, t in ab.items() if v - k in cd))

Measured memory_bytes: 219244
import math

a,b,x=[int(x) for x in input().split()]
h = x/(a*a)

if h == b:
    ans=0
elif b/2 <= h <b:
    ans=math.degrees(math.atan(2*(b-h)/a))
else :
    ans=math.degrees(math.atan((a*b*b)/(2*x)))

print(ans)

Measured memory_bytes: 3060
from sys import stdin
input = stdin.readline
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = [0] * N
    for i in A:
        ans[i - 1] += 1
    print(*ans, sep="\n")

if __name__ == '__main__':
    main()

Measured memory_bytes: 31912
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int x;
    cin >> x;
    int ans=x;
    int ctr=1;
    while(ans%360!=0){
        ans+=x;
        ctr++;
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3652
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using D = double;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr double HDINF = 50000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define RALL(qpqpq)           (qpqpq).rbegin(),(qpqpq).rend()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define RFOR(i,tptpt,ypypy)  for(LL i=(tptpt);i>=(ypypy);i--)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)


int a, b, c;

int main() {
	cin >> a >> b >> c;
	int ret = INF;
	ret = min(ret,abs(a - b) + abs(b - c));
	ret = min(ret,abs(a - c) + abs(c - b));
	ret = min(ret,abs(b - a) + abs(a - c));
	ret = min(ret,abs(b - c) + abs(c - a));
	ret = min(ret,abs(c - a) + abs(a - b));
	ret = min(ret,abs(c - b) + abs(b - a));
	cout << ret << endl;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	// bfs（幅優先探索）
	// https://qiita.com/drken/items/996d80bcae64649a6580
	int start = 0;
	vector<int> dist(n, -1);	//startからの距離を格納。未訪問は-1
	vector<int> ans(n);
	queue<int> que;
	dist[start] = 0;
	que.push(start);
	while(!que.empty()) {
		int v = que.front();
		que.pop();
		for(int nv: g[v]) {
			if(dist[nv] != -1) continue;
			dist[nv] = dist[v] + 1;
			ans[nv] = v;
			que.push(nv);
		}
	}
	
	
	cout << "Yes" << endl;
	rep(i, n-1) cout << ans[i+1]+1 << endl;
	return 0;
}

Measured memory_bytes: 10648
#include <stdio.h>

int a[100000],b[100000];
int cnt=0;
char c[100000];
int result[100000];
int main(void){
	while(1){
		scanf("%d %c %d",&a[cnt],&c[cnt],&b[cnt]);
		if(c[cnt]=='?') break;
		switch(c[cnt]){
			case '+':
				result[cnt]=a[cnt]+b[cnt];
				break;
			case '-':
				result[cnt]=a[cnt]-b[cnt];
				break;
			case '/':
				result[cnt]=a[cnt]/b[cnt];
				break;
			case '*':
				result[cnt]=a[cnt]*b[cnt];
				break;
		}
		cnt++;
	}//cnt1大きい
	
	int i;
	for(i=0;i<cnt;i++){
		printf("%d\n",result[i]);
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;

int main(){
  int n; string s;
  cin >> n;
  cin >> s;
  vector<vector<ll>> dp(n,vector<ll>(n+1,0));
  for(int i = 1; i <= n; i++) dp[0][i] = 1;
  rep(i,n-1) {
    vector<ll> sum(n+1,0);
    rep(j,n) sum[j+1] = (sum[j] + dp[i][j+1]) % mod; 
    for(int j = 1; j <= n-i-1; j++) {
      if(s[i] == '>') dp[i+1][j] = (sum[n] - sum[j]) % mod;  
      else dp[i+1][j] = sum[j];  
    }
  }
  ll ans = (dp[n-1][1] + mod) % mod;
  cout << ans << endl;
  return 0;
}

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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int memo[26];
string s,ans;

main() {
    cin >> s;
    rep(i,s.size()) memo[s[i]-'a']++;
    rep(i,26) if (!memo[i]) {
        otp(s)ct((char)(i+'a'))
        return 0;
    }
    repm(i,26) {
        int tmp=s[i]-'a';
        s.pop_back();
        repo(j,tmp+1,26) if (!memo[j]) {
            otp(s)ct(char(j+'a'))
            return 0;
        }
        memo[tmp]--;
    }
    ct(-1)
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>

using namespace std;

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

	bool judge = true;

	for(int i=0; i<k; i++){
		if(a >= b){
			b *= 2;
		}
		else if(b >= c)
			c *= 2;

		else
			break;
	}

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

	else
		cout << "No" << endl;


}




Measured memory_bytes: 3104
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static char[][] board = new char[3][3];
	
	static boolean read() {
		String line = sc.next();
		if(line.equals("0")) return false;
		board[0][0] = line.charAt(0); board[0][1] = line.charAt(1); board[0][2] = line.charAt(2);
		for(int i = 1; i < 3; i++) {
			line = sc.next();
			for(int j = 0; j < 3; j++) board[i][j] = line.charAt(j);
		}
		return true;
	}
	
	static String solve() {
		char stone;
		boolean win;
		
		for(int i = 0; i < 3; i++) {
			win = true;
			stone = board[i][0];
			if(stone == '+') continue;
			for(int j = 1; j < 3; j++) {
				if(stone != board[i][j]) win = false;
			}
			if(win) return "" + stone;
		}
		
		for(int j = 0; j < 3; j++) {
			win = true;
			stone = board[0][j];
			if(stone == '+') continue;
			for(int i = 1; i < 3; i++) {
				if(stone != board[i][j]) win = false;
			}
			if(win) return "" + stone;
		}
		
		if(board[0][0] != '+' && board[0][0] == board[1][1] && board[0][0] == board[2][2]) return "" + board[0][0];
		
		if(board[2][0] != '+' && board[2][0] == board[1][1]  && board[1][1] == board[0][2]) return "" + board[2][0];
		
		return "NA";
	}
	
	public static void main(String[] args) {
		while(read()) {
			System.out.println(solve());
		}

	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int a,v,b,w;
	cin>>a>>v>>b>>w;
	int t;
	cin>>t;
	if(v<=w){
		cout<<"NO"<<endl;
		return;
	}
	int dx=v-w;
	int dis=abs(a-b);
	int time=ceil((double)dis/dx);
	if(time<=t){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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


int main(){
	int a[128];
	a[0]=a[1]=1;
	for(int i=1 ; i<32 ; i++){
		a[i]=a[i-1];
		if(i>1) a[i]+=a[i-2];
		if(i>2) a[i]+=a[i-3];
	}
	int n;
	while(cin>> n){
		if(n!=0){
		int day = (a[n]-a[n]%10)/10 + 1;
		int year =(day - day %365 )/365 + 1;
		cout<<year<<endl;
		}
	}


}

Measured memory_bytes: 1160
function main(input) {
  const lines = input.split('\n');
  const N = parseInt(lines.shift());

  const tasks = [];
  for(var i=0; i<N; i++){
    var tmp = lines[i].split(' ').map( x => parseInt(x) );
    tasks.push(tmp);
  }

//  tasks.sort( (a,b) => a[1]-b[1] );
  tasks.sort(function(a, b){
    return a[1]- b[1];
  });

  var result = 'Yes';
  var sum = 0;

  for(var i=0; i < N; i++){
    sum += Number(tasks[i][0]);
    if(sum > Number(tasks[i][1])){
      result = 'No';
      break;
    }
  }
  console.log(result);
 }

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  string s; cin >> s;
  int q; cin >> q;
  string t="";
  
  rep(i,q){
    int ty; cin >> ty;
    if(ty==1) swap(s,t);
    else{
      int f; cin >> f;
      char c; cin >> c;
      if(f==1) t+=c;
      else s+=c;
    }
  }
  reverse(t.begin(),t.end());
  t+=s;
  cout << t << endl;  
  
  return 0;
}


Measured memory_bytes: 1128
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  ll H; cin >> H;
  ll cnt = 0, m = 1;

  while (H>0){
    cnt += m;
    m *= 2;
    H /= 2;
  }
  cout << cnt << endl;
  
  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char S[210000];
char T[210000];
int s[210000];
int t[210000];
int h[30];
int main(){
	scanf("%s%s",S,T);
	int sz=0;
	for(int i=0;i<30;i++)h[i]=-1;
	for(int i=0;S[i];i++){
		if(h[S[i]-'a']==-1){
			h[S[i]-'a']=sz++;
		}
		s[i]=h[S[i]-'a'];
	}
	sz=0;
	for(int i=0;i<30;i++)h[i]=-1;
	for(int i=0;T[i];i++){
		if(h[T[i]-'a']==-1){
			h[T[i]-'a']=sz++;
		}
		t[i]=h[T[i]-'a'];
	}
	for(int i=0;S[i];i++){
		if(s[i]!=t[i]){
			printf("No\n");return 0;
		}
	}
	printf("Yes\n");
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n;
	char a[10005];
	scanf("%d",&n);
	getchar();
	scanf("%s",a);
	int s=strlen(a);
	for(int i=0;i<s;i++)
	{
		a[i]+=n;
		if(a[i]>'Z')
		a[i]-=26;
	}
	printf("%s\n",a);
}

Measured memory_bytes: 256
using System;

namespace rensyuu1
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = 1;
            while (true)
            {
                string lss = Console.ReadLine();
                string[] ss = lss.Split(new char[] { ' ' });
                int x = int.Parse(ss[0]);
                int y = int.Parse(ss[1]);

                if (x == 0 && y == 0)
                {
                    break;
                }

                else if (x > y)

                {
                    int z = y;
                    y = x;
                    x = z;
                    Console.WriteLine("{0} {1}", x, y);
                }

                else
                {
                    Console.WriteLine("{0} {1}", x, y);
                }

                i++;

                }
            }
        }
    }


Measured memory_bytes: 17924
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
#define int LL
const int MAX_N=200005;
int a[MAX_N]; 
int n;
signed main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	cin>>n;
	For(i,1,n)a[i]=read()-i;
	sort(a+1,a+n+1);
	int ans=0;
	For(i,1,n)ans+=abs(a[i]-a[n/2+1]);
	cout<<ans<<endl; 
	return 0;
}



Measured memory_bytes: 1792
n,k = map(int, input().split())
array = [0] * n
for i in range(k):
    d = int(input())
    l = list(map(int, input().split()))
    for j in l:
        array[j-1] = 1
ans = 0
for i in range(len(array)):
    if array[i] == 0:
        ans += 1
print(ans)



Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define V_MAX 100005
#define INF 1e10
typedef long long ll;
typedef pair<int, ll> P; // 点と、そこへの始点からの最短距離

struct edge {
	int to;
	ll cost;
};

int main(){
	ll nv,ne,r;
	cin >> nv>>ne>>r;

	vector<edge> G[V_MAX];

	rep(i, ne) {
		int s,t;
		ll w;
		cin >> s>>t>>w;
		G[s].push_back({t,w});	// 構造体は{}で表せる
	}

	// 始点からの最短距離を格納
	ll d[V_MAX];
	rep(i, V_MAX) {
		d[i] = INF;
	}
	d[r] = 0;

 	// priority_queue<P, vector<P>, greater<P>> Q;
 	queue<P> Q;

 	Q.push(P(r, 0));

 	while(!Q.empty()) {
 		// P p = Q.top(); Q.pop();
 		P p = Q.front(); Q.pop();
 		int vertex = p.first;
 		ll cost = p.second;
 		if (d[vertex] < cost) {
 			// out of date
 			continue;
 		}
 		rep(i, (int)G[vertex].size()) {
 			edge e = G[vertex][i];
 			// 周辺点について、更新できるようならしていく
 			if (d[e.to] > d[vertex] + e.cost) {
 				d[e.to] = d[vertex] + e.cost;
 				Q.push(P(e.to, d[e.to]));
 			}
 		}
 	}

 	rep(i, nv) {
 		if (d[i]==INF) {
 			cout << "INF" << endl;
 		} else {
 			cout << d[i] << endl;
 		}
 	}
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	for(int i=0; i<3; i++){
		string s;
		cin >> s;
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>

char s[110][20];
int min(int a,int b){
	if(a < b) return a;
	else return b;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%s",s[i]);
	}
	int p = strlen(s[1]);
	//printf("%d ",k);
	for(int i = 2;i <= n;i++){
		int flag = 0;
		for(int k = 1;k <= n;k++){
			if(i == k) continue;
			int a = strlen(s[i]);
			int b = strlen(s[k]);
			if(a != b) continue;
			int t = 0;
			for(int w = 0;w < a;w++){
				if(s[i][w] != s[k][w]) t = 1;
			}
			if(!t) {
				flag = 1;
				//printf("i:%d   k:%d\n",i,k);
			}
		}
		if(s[i][0] != s[i - 1][p - 1] || flag){
			printf("No");
			return 0;
		}
		p = strlen(s[i]);
	}
	printf("Yes");
	return 0;
} 

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


int main() {
  int n, k;
  cin >> n >>k;
  int d;
  int a;
  vector<bool> have(n,false);
  rep(i,k) {
    cin >> d;
    rep(j,d){
      cin >> a;
      have[a-1] = true;
    }
  }
  int ans = 0;
  rep(i,n){
    if(!have[i]) ++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
N = int(input())
list = list(map(str, input().split()))
print(' '.join(list))

for i in range(1, N):
  v = list[i]
  j = i - 1
  while j >= 0 and int(list[j]) > int(v):
    list[j+1] = list[j]
    j += -1
  list[j+1] = v
  print(' '.join(list))


Measured memory_bytes: 5600