akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define X first
#define Y second
#define PB push_back

using namespace std;

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

const int N = 3e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 20;
const int OFF = 9;

vector < pii > ans, pitaj[N];
int imam[N], loog[N], w[N], v[N], n, q, sol[N];
pii msk[1000];

pii add(pii A, pii B){
	return {A.X + B.X, A.Y + B.Y};
}

void dfs(int x){
	if(x > n) return;
	ans.PB({v[x], w[x]});
	if((int)ans.size() == OFF){
		memset(imam, 0, sizeof(imam));
		memset(msk, 0, sizeof(msk));
		msk[0] = {0, 0};
		for(int i = 1;i < (1 << OFF);i++){
			msk[i] = add(ans[loog[i & (-i)]], msk[i - (i & (-i))]);
			if(msk[i].Y < N)
				imam[msk[i].Y] = max(imam[msk[i].Y], msk[i].X);
		}
		for(int i = 1;i < N;i++){
			imam[i] = max(imam[i], imam[i - 1]);
		}
	}
	if((int)pitaj[x].size() && (int)ans.size() >= OFF){
		int kol = (int)ans.size() - OFF;
		for(int i = 1;i < (1 << kol);i++){
			msk[i] = add(ans[OFF + loog[i & (-i)]] , msk[i - (i & (-i))]);
		}
		for(pii kv : pitaj[x]){
			int L = kv.X;
			int ans = 0;
			for(int i = 0;i < (1 << kol);i++){
				if(msk[i].Y <= L)
					ans = max(ans, msk[i].X + imam[L - msk[i].Y]);
			}
			sol[kv.Y] = ans;
		}
	}
	if((int)pitaj[x].size() && (int)ans.size() < OFF){
		int kol = (int)ans.size();
		for(int i = 1;i < (1 << kol);i++){
			msk[i] = add(ans[loog[i & (-i)]] , msk[i - (i & (-i))]);
		}
		for(pii kv : pitaj[x]){
			int L = kv.X;
			int ans = 0;
			for(int i = 0;i < (1 << kol);i++){
				if(msk[i].Y <= L)
					ans = max(ans, msk[i].X);
			}
			sol[kv.Y] = ans;
		}
	}
	dfs(2 * x); dfs(2 * x + 1);
	ans.pop_back();
}	

int main(){
	for(int i = 0;i <= 18;i++)
		loog[(1 << i)] = i;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++)
		scanf("%d%d", v + i, w + i);
	scanf("%d", &q);
	for(int i = 0;i < q;i++){
		int x, y; scanf("%d%d", &x, &y);
		pitaj[x].PB({y, i});
	}
	dfs(1);
	for(int i = 0;i < q;i++)
		printf("%d\n", sol[i]);
	return 0;
}






Measured memory_bytes: 17032
import math
A, B, H, M = map(int, input().split())

hun_kaku = 6*M
zi_kaku = 30*H+0.5*M
kakudo = min(abs(hun_kaku-zi_kaku),360-abs(hun_kaku-zi_kaku))

ans = A**2+B**2-(2*A*B*math.cos(math.radians(kakudo)))
print(math.sqrt(ans))

Measured memory_bytes: 62488
# -*- coding: utf-8 -*-
"""
Permutation - Sorting Tuples
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_5_B&lang=jp

"""
n = int(input())
ans = []
for _ in range(n):
    v, w, t, d, s = input().split()
    ans.append((int(v), int(w), t, int(d), s))

for a in sorted(ans):
    print(*a)



Measured memory_bytes: 32104
#include<iostream>
#include<string>
#include<stack>
using namespace std;
int main(){
    string str;
    while(cin>>str){
        stack<char> s;
        int ans = 0;
        for(auto c:str){
            const char v = c - '0';
            if(!s.empty()){
                if(s.top()+v == 1){
                    ans ++ ;
                    s.pop();
                    continue;
                }
            }
            s.push(v);
        }
        cout<<ans*2<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int a = N % 10;


	if (a == 3){
		cout << "bon" << "\n";
	} else if ((a == 0) || (a == 1) || (a == 6) || (a == 8)) {
		cout << "pon" << "\n";
	} else {
		cout << "hon" << "\n";		
	}

	return 0;
}


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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int a[3005][3005];
int dp[3005][3005][4];

int n, m;

int go(int i, int j, int cnt)
{
	if (i == n and j == m)
	{
		if (cnt < 3) return a[n][m];
		else return 0;
	}

	if (i > n or j > m) return INT_MIN;

	int &ans = dp[i][j][cnt];
	if (ans != -1) return ans;

	int res = INT_MIN, x = 0, op3 = 0, op4 = 0;

	int op1 = go(i + 1, j, 0);
	int op2 = go(i, j + 1, cnt);
	if (cnt < 3) op3 = a[i][j] + go(i + 1, j, 0);
	if (cnt < 3) op4 = a[i][j] + go(i, j + 1, cnt + 1);

	res = max({op1, op2, op3, op4});


	return ans = res;
}


void solve()
{
	cin >> n >> m;
	loop(i, 1, n + 1)loop(j, 1, m + 1) a[i][j] = 0;

	int k; cin >> k;
	loop(i, 0, k)
	{
		int x, y, val;
		cin >> x >> y >> val;
		a[x][y] = val;
	}
	mset(dp, -1);
	cout << go(1, 1, 0) << endl;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 357004
#include "bits/stdc++.h"
using namespace std;

#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int W = 1e5+1;
long long dp[W][101];
int in[101][2];
int main()
{
	 #ifdef LOCAL
        input_from_file;
        output_to_file;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n , w ; cin >> n >> w ;
	for(int i = 1 ; i <= n ; ++i)
		cin >> in[i][0] >> in[i][1];
	for(int i = 1 ;  i <= w ; ++i)
	{
		for(int j = 1 ; j <= n ; ++j)
		{
			dp[i][j] = max(dp[i][j-1] , (i-in[j][0]>=0?(in[j][1] + dp[i-in[j][0]][j-1]) : 0));
		}
	}
	cout << dp[w][n];

	return 0;
}

Measured memory_bytes: 79232
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main() {
	int K,A,B;
	scanf("%d",&K);
	scanf("%d %d",&A,&B);
	
	for(int i=A;i<=B;i++){
		if( i%K == 0 ){
			printf("OK");
			return 0;
		}
	}
	printf("NG");
	
}

Measured memory_bytes: 1728
import java.io.*;
public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader mBufferedReader=new BufferedReader(new InputStreamReader(System.in));
    String str;
    String[] arr;
    int n=0;
    while((str=mBufferedReader.readLine())!=null){
      if(n==0){
        n=Integer.parseInt(str);
        continue;
      }
      arr=str.split(" ");
      int[] array=new int[n];
      for(int i=1;i<=n;i++){
        array[n-i]=Integer.parseInt(arr[n-i]);
        System.out.print(array[n-i]);
        if(i!=n){
          System.out.print(" ");
        }
      }
      break;
    }
    System.out.println("");
    mBufferedReader.close();
   }
}      


Measured memory_bytes: 24512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    string s="ABC";
    s[2]+=(n-1)/999;
    cout << s << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(input())
B = list(input())

p = 10**9 + 7

domino = []
d_=''
for d in range(len(A)):
    d_0 = A[d]
    d_1 = B[d]
    if d_ == d_0:
        continue
        
    if d_0 == d_1:
        domino.append(0) # 0:縦
    if d_0 != d_1:
        domino.append(1) # 1:横
    d_ = d_0

ans = 3
if domino[0] == 1:
    ans = 6
    
for d_0,d_1 in zip(domino[:-1],domino[1:]):
    if d_0 == 0:
        ans = ans*2
    elif d_0 == 1:
        if d_1 == 0:
            pass
        else:
            ans = ans*3
    ans = ans % p
ans = ans % p 
print(ans)

Measured memory_bytes: 61756
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<p> v(m);
  vector<vector<int>> graph(n);
  vector<map<int, bool>> mp(n);
  rep(i, m) {
    cin >> v[i].first >> v[i].second;
    v[i].first--;v[i].second--;
    graph[v[i].first].push_back(v[i].second);
    graph[v[i].second].push_back(v[i].first);
    mp[v[i].first][v[i].second] = true;
    mp[v[i].second][v[i].first] = true;
  }

  vector<int> order(n-1);
  rep(i, n-1) order[i] = i+1;

  int res = 0;
  do {
    int now = 0;
    bool flag = false;
    for (int i = 0; i < n-1; ++i) {
      if(!mp[now][order[i]]){
        flag = true;
        break;
      }
      now = order[i];
    }
    if(!flag) res++;
  }while (next_permutation(ALL(order)));

  cout << res << endl;
}


Measured memory_bytes: 3640
import java.util.Scanner;

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

    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = Math.max(A - 2 * B, 0);
    System.out.println(ans);
  }
}


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

int main() {
	int N, i=10000000, n=0, Nn;
	cin >> N;
	Nn = N;
	
	for (;i > 0;i = i / 10) {
		n = n + N / i;
		N = N % i;
	}
	if (Nn % n == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#　N：展望台の数、M:道の数
N,M=list(map(int,input().split()))
H = list(map(int,input().split()))

ad_list = [[] for n in range(N)]
for m in range(M):
    load=list(map(int,input().split()))
    ad_list[load[0]-1].append(load[1])
    ad_list[load[1]-1].append(load[0])
    
cnt=0
for n in range(N):
    heith = H[n]
    for ad_p_idx in range(len(ad_list[n])+1):
#         print(ad_p_idx)
        if ad_p_idx == len(ad_list[n]):
            cnt+=1
#             print(cnt)
            break
            
        ad_p = ad_list[n][ad_p_idx]
        heith_ad = H[ad_p-1]
#         print(heith,heith_ad)
        if heith <= heith_ad:
            break
        if ad_p_idx == ad_list[n]:
            cnt+=1
print(cnt)

Measured memory_bytes: 92712
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

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

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)
 
for a,b in ab:
    uf.union(a-1,b-1)

print( uf.group_count() - 1 )

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)

using namespace std;

using ll = long long;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}

int main() {

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

    constexpr int L_MAX = 100000;

    int N;
    cin >> N;
    vector<int> V(N), W(N);
    FOR(i, 1, N + 1) cin >> V[i] >> W[i];

    int N_upper = min((1 << 9) - 1, N);
    vector<vector<ll>> dp(N_upper + 1, vector<ll>(L_MAX + 1));
    FOR(i, 1, N_upper + 1) {
        FOR(j, 1, L_MAX + 1) {
            dp[i][j] = dp[i / 2][j];
            if (j >= W[i]) {
                amax(dp[i][j], dp[i / 2][j - W[i]] + V[i]);
            }
        }
    }

    int Q;
    cin >> Q;
    REP(_, Q) {
        int v, L;
        cin >> v >> L;

        vector<int> lowers;
        while (v > N_upper) {
            lowers.push_back(v);
            v /= 2;
        }
        int H = lowers.size();
        vector<ll> sum_V(1 << H);
        vector<ll> sum_W(1 << H);
        ll result = dp[v][L];
        FOR(bit, 1, 1 << H) {
            int i = __builtin_ctz(bit);
            int bit_pred = bit ^ (1 << i);
            sum_V[bit] = sum_V[bit_pred] + V[lowers[i]];
            sum_W[bit] = sum_W[bit_pred] + W[lowers[i]];
            if (sum_W[bit] <= L) {
                amax(result, dp[v][L - sum_W[bit]] + sum_V[bit]);
            }
        }
        cout << result << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 407328
S=input()
K=int(input())

i=1
count1=0
while i<len(S):
    if S[i]==S[i-1]:
        count1+=1
        i+=1
    i+=1

ss=S*2
i=1
count2=0
while i<len(ss):
    if ss[i]==ss[i-1]:
        count2+=1
        i+=1
    i+=1

if 2*count1+1==count2 and len(set(S))!=1:
    print(K*count1+(K-1))
else:
    print(K*count2//2)

Measured memory_bytes: 9212
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
const ll inf = 1e15;
int main()
{
  int N;cin>>N;
  ll x;cin>>x;
  ll a[N]; FOR(i,0,N) cin>>a[i];
  ll mn[N]; FOR(i,0,N) mn[i] = a[i];
  ll ans = 1e15;
  FOR(k,0,N) {
    ll t = k * x;
    // 最小値を計算し直してたす
    FOR(i,0,N) {
      int j = (i - k + N) % N;
      mn[i] = min(mn[i], a[j]);
      t += mn[i];
    }
    ans = min(ans, t);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
require 'prime'
N = gets.to_i
min_n = N
1.upto(N**0.5) do |n|
    min_n = [min_n, [Math.log10(n).to_i + 1, Math.log10(N.div(n)).to_i + 1].max].min if N % n == 0
end
puts min_n

Measured memory_bytes: 2172
#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;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

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

    int n,k;
    int d;
    cin >> n >> k;
    set<int> memo;
    rep(i,k){
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            memo.insert(a);
        }
    }
    int ans;
    ans = n;
    ans -= memo.size();
    cout << ans <<endl;


    cout << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll N,K;
vector<vector<ll>> tree;
const ll MOD = ll(1e9)+7;

ll dfs(int t,int p){
    ll retVal  = 1;
    ll initK = K-2;
    if(p==-1){
        initK = K-1;
    }
    for(ll child:tree[t]){
        if(child ==p){
            continue;
        }
        retVal *= ((initK*dfs(child,t))%MOD);
        retVal %=MOD;
        --initK;
    }
    return retVal;
}

int main() {
   
    cin >> N >> K;
    tree.resize(N);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    ll ans  = dfs(0,-1) * K;
    cout << ans%MOD << endl;

    return 0;
}

Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
#define INF 100000000
#define uint unsigned int
#define MOD 1e9+7
using namespace std;

int main() {
	char c;

	cin >> c;

	switch (c)
	{
	case 'A': cout << 'T'; break;
	case 'T': cout << 'A'; break;
	case 'G': cout << 'C'; break;
	case 'C': cout << 'G'; break;

	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    mint ans = 0;
    ans += mint(2).pow(n);
    ans -= 1;
    auto comb = [&](ll n,ll a) {
        mint up=1,down=1;
        rep(i,a) {
            up *= n-i;
            down *= a-i;
        }
        mint ret = up/down;
        return ret;
    };
    ans -= comb(n,a);
    ans -= comb(n,b);
    cout << ans.x << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
ans = 0
for i in (x, y):
    if i == 1:
        ans += 300000
    elif i == 2:
        ans += 200000
    elif i == 3:
        ans += 100000
if x == y == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_N 100005
#define int long long

using namespace std;

int n,m;
int par[MAX_N];
int dis[MAX_N];

int find(int x)
{
	if(par[x]==x) return x;
	int p=par[x];
	par[x]=find(par[x]),dis[x]+=dis[p];
	return par[x];
}

bool unite(int x,int y,int z)
{
	int px=find(x),py=find(y);
	if(px==py) return dis[x]-dis[y]==z;
	dis[px]=-dis[x]+z+dis[y],par[px]=py;
	return true;
}

signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++) par[i]=i;
	int l,r,d;
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld%lld",&l,&r,&d);
		if(!unite(l,r,d))
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vvi c(3, vi(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    bool ans = true;
    for (int i = 1; i < 3; ++i) {
        rep(j, 2) {
            if (c[i][j] - c[0][j] != c[i][j+1] - c[0][j+1]) ans = false;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

#include<vector>

struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin >> n >> m;

    vector<ll> a(m),b(m);

    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
    }

    UnionFind uf = UnionFind(n+1);

    vector<ll> ans(1,(n*(n-1))/2);

    for(int i = m-1; i > 0; i--){
        ll t = ans.back();
        ll f = (uf.size(a[i])*(uf.size(a[i]) - 1))/2;
        ll bc = (uf.size(b[i])*(uf.size(b[i]) - 1))/2;
        if(uf.findSet(a[i],b[i])){
            ans.push_back(t);
        }else{
            t += f + bc;
            uf.unionSet(a[i],b[i]);
            t -= (uf.size(b[i])*(uf.size(b[i]) - 1))/2;
            ans.push_back(t);
        }
    }

    for(int i = ans.size() - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - 1e8;
const ll INFLL = numeric_limits<ll>::max() - 1e17;

int main() {
    string S;
    cin >> S;
    map<char, int> count;
    for (auto temp : S) count[temp]++;
    bool check = true;
    cout << (max(count['a'], max(count['b'], count['c'])) - min(count['a'], min(count['b'], count['c'])) <= 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 512
n = int(raw_input())
s = ''
for i in range(1,n+1):
    if (i % 3) == 0:
        s = s + ' ' + str(i)
    else:
        x = i
        while True:
            if (x % 10) == 3:
                s = s + ' ' + str(i)
                break
            x = x / 10
            if x == 0:
                break
print s

Measured memory_bytes: 4584
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int a;
	bool k = false;
	while (cin >> a&&a != 0) {
		if (k)
			cout << endl;
		string s[10];
		int b[10];
		int g[10];
		bool l[10]; 
		for(int i = 0; i < a; i++) {
			string m;
			int c, d, e;
			cin >> m >> c >> d >> e;
			s[i] = m;
			int f = c * 3 + e;
			b[i] = f;
			g[i] = f;
			l[i] = true;
		}
		sort(g, g + a);
		for (int i = a-1; i >=0; i--) {
			int h = g[i];
			for (int j = 0; j < a; j++) {
				if (b[j] == h&&l[j]) {
					cout << s[j] << "," << h << endl;
					l[j] = false;
					break;
				}
			}
		}
		k = true;
	}
}

Measured memory_bytes: 3056
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long na[] = new long[5];
		long ans = 0;
		long n = sc.nextLong();
		na[0] = sc.nextLong();
		long min = na[0];
		for (int i = 1; i < 5; i++)
		{
			na[i] = sc.nextLong();
			if(min > na[i])
			{
				min = na[i];
			}
		}
		ans = (long)(Math.ceil(((double)n)/(double)min));
		ans += 4;

		System.out.println(ans);

	}
}

Measured memory_bytes: 23764
n, x = map(int, input().split())
def solve(n, i):
    if n==0:
        return 1
    if i==0:
        return 0
    if i<(2**(n+2)-3)//2:
        return solve(n-1, i-1)
    if i==(2**(n+2)-3)//2:
        return 2**n
    if i<2**(n+2)-4:
        return 2**n + solve(n-1, i-(2**(n+2)-3)//2-1)
    return 2**(n+1) - 1
print(solve(n, x-1))

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int INF = 1001001001;
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] c = new int[n];
        int[][] a = new int[n][m];
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        int ans = INF;
        for (int s = 0; s < (1<<n); s++) {
            int cost = 0;
            int[] d = new int[m];
            for (int i = 0; i < n; i++) {
                if ((s>>i&1) == 1) {
                    cost += c[i];
                    for (int j = 0; j < m; j++) {
                        d[j] += a[i][j];
                    }
                }
            }
            boolean ok = true;
            for (int j = 0; j < m; j++) {
                if (d[j] < x) ok = false;
            }
            if (ok) ans = Math.min(ans, cost);
        }
        if (ans == INF) System.out.println(-1);
        else System.out.println(ans);
        
    }

}

Measured memory_bytes: 37296
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int sum = 0;
    for (int i=0;i<m;i++){
      sum += scan.nextInt();
    }
    if (sum > n){
      System.out.println(-1);
    }
    else{
      System.out.println(n-sum);
    }
  }
}


Measured memory_bytes: 46356
#include <stdio.h>

int main()
{
  int N,M,C,i,j,ans=0;
  int B[20];
  scanf("%d %d %d",&N,&M,&C);
  for(i=0;i<M;i++)
    scanf("%d",&B[i]);
  
  for(i=0;i<N;i++){
    int ac=0;
    for(j=0;j<M;j++){
      int a;
      scanf("%d",&a);
      ac += a*B[j];
    }
    ac += C;
    if(ac>0)
      ans++;
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -INF
for i in range(1, 1 << 10):
    profit = 0
    for k in range(N):
        cnt = 0
        for j in range(10):
            if i & 1 << j > 0 and F[k][j] == 1:
                cnt += 1
        profit += P[k][cnt]
    ans = max(ans, profit)
print(ans)
    

Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

ll n,a[100010],ans=0;
map<ll,ll> m;
multiset<ll> s;

void init(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)m[a[i]]=i;
}

int main(void){
	init();
	s.insert(-1);  // 番兵たち
	s.insert(-1);
	s.insert(n);
	s.insert(n);
	ireg(i,1,n){
		ll tmp=0,l2=-1,l=-1,r=n,r2=n;
		ll index = m[i];
		s.insert(index);
		auto itindex = s.find(index);
		auto itl = prev(itindex);
		l=*itl;
		itl--;
		l2=*itl;
		auto itr = next(itindex);
		r=*itr;
		itr++;
		r2=*itr;
		ans+=i*((l-l2)*(r-index)+(r2-r)*(index-l));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  ll s;cin>>s;
  ll x=s%1000000000,y=s/1000000000;
  if(y==1000000000){
    cout<<"0 0 1000000000 0 0 1000000000"<<endl;return 0;
  }
  cout<<"0 0 1000000000 1 "<<1000000000-x<<" "<<y+1<<endl;
}

Measured memory_bytes: 3636
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()

 



Measured memory_bytes: 7004
n, m = map(int, input().split())
a = sorted([list(map(int, input().split())) for i in range(n)])
t = len(a[0]) - 1

for j in a[0][1:]:
    for k in range(1, n):
        if not j in a[k][1:]:
            t -= 1
            break

print(t)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;

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


int main(){
    int dp[210000][2];
    int N;
    string s;
    cin >> N;
    cin >> s;

    dp[0][0] = dp[0][1] = 0;
    for(int i = 0; i < N; i++){
        if(s[i] == '.'){
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = min(dp[i][0]+1, dp[i][1]+1);
        }
        else{
            dp[i+1][0] = dp[i][0]+1;
            dp[i+1][1] = min(dp[i][0], dp[i][1]);
        }
    }

    cout << min(dp[N][0], dp[N][1]) << endl;



    return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
}
inline void putll(ll x){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
int digit(int x){
  int cnt = 0;
  while(x){
    x /= 10;
    cnt ^= 1;
  }
  return cnt;
}
int main(){
  int n = getint();
  int ans = 0;
  for(int i = 1;i <= n;i++) ans += digit(i);
  putint(ans);
  bufo.put('\n');
  bufo.flush();
  return 0;
}


Measured memory_bytes: 256
N, M, Q = map(int, input().split())

a = [[0 for i in range(509)] for j in range(509)]
sum = [[0 for i in range(509)] for j in range(509)]
ans = [[0 for i in range(509)] for j in range(509)]

for i in range(M):
  p, q = map(int, input().split())
  a[p][q] += 1

for i in range(1,N+1):
  for j in range(i,N+1):
    sum[i][j] = sum[i][j-1] + a[i][j]

for i in range(1,N+1):
  for j in range(i,N+1):
    for k in range(i,j+1):
      ans[i][j] += sum[k][j] - sum[k][i-1]

for i in range(Q):
  p, q = map(int, input().split())
  #ans = 0
  #for j in range(p,q+1):
  #  ans += sum[j][q] - sum[j][p-1]
  print(ans[p][q])


Measured memory_bytes: 67672
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    h, w = MII()
    s = ['.'*(w+2)]
    for i in range(h):
        s.append('.'+IS()+'.')
    s.append('.'*(w+2))
    ans = []
    for hi in range(1,h+1):
        tmp = ''
        for wi in range(1,w+1):
            if s[hi][wi] == '#':
                tmp += '#'
                continue
            cnt = 0
            cnt += sum([1 for c in s[hi-1][wi-1:wi+2] if c == '#'])
            cnt += sum([1 for c in s[hi][wi-1:wi+2] if c == '#'])
            cnt += sum([1 for c in s[hi+1][wi-1:wi+2] if c == '#'])
            tmp += str(cnt)
        ans.append(tmp)
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

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

int N;

int main(){
	while(cin >> N){
		vector<int> v(100010,0);
		for(int i=0;i<N;i++){
			int a;
			cin >> a;
			v[a]++;
		}
		int ans = 0;
		for(int i=1;i<99999;i++){
			int now = v[i-1]+v[i]+v[i+1];
			ans = max(ans,now);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	int x, y, z;
	cin >> x >> y >> z;
	int ans = (x - z) / (y + z);
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}

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

using namespace std;

int main()
{
	while(1){
		pair<int,int> n[5];
		int am,pm;
		for(int i=0;i<5;i++)	cin>>am>>pm,n[i]=make_pair(am+pm,i);
		if(cin.eof())	break;
		sort(n,n+5);
		cout<<(char)('A'+n[4].second)<<' '<<n[4].first<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#素因数分解、計算量はO(√N)
from collections import defaultdict
def factorize(n):
  b = 2
  dic = defaultdict(lambda: 0)
  while b * b <= n:
    while n % b == 0:
      n //= b
      dic[b] += 1
    b = b + 1
  if n > 1:
    dic[n] += 1
  return dic
N = int(input())
fct = factorize(2*N)
lis = []
for k,v in fct.items():
  lis.append(pow(k,v))
ans = 10**18
from itertools import groupby, accumulate, product, permutations, combinations
for pro in product([0,1],repeat=len(lis)):
  prod1 = 1
  for i,p in enumerate(pro):
    if p==1:
      prod1 *= lis[i]
  if prod1==1:
    continue
  prod2 = (N*2)//prod1
  if prod1<prod2:
    continue
  
  for i in range(1,prod2+1):
    if prod1*i>ans:
      break
    if (prod1*i-1)%prod2==0:
      ans = min(ans, prod1*i-1)
      break
    if (prod1*i+1)%prod2==0:
      ans = min(ans, prod1*i)
      break

print(ans)



Measured memory_bytes: 68680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;
int main() {
    ll n;cin >> n;
    vector<ll>v;
    v.push_back(1);
    for(ll i=6;i<=n;i*=6){
        v.push_back(i);
    }
    for(ll i = 9; i <= n; i *= 9) {
        v.push_back(i);
    }
    vector<ll> cost(n+1,INF);
    cost[0]=0;
    for(ll j=0;j<v.size();j++){
    	for(ll i=0;i<n;i++){
            if(i+v[j]<=n)(cost[i+v[j]]=min(cost[i]+1,cost[i+v[j]]));
        }
    }
    cout << cost[n] << endl;
    return 0;
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    string s;
    cin>>s;

    int q;
    cin>>q;
    string aux;
    int cnt = 0;
    while(q--){
        int x;
        cin>>x;
        if(x==1){
            cnt++;
        }
        else{
            int f;
            string c;
            cin>>f>>c;
            if(f==1){
                if(cnt%2==1)
                    s += c;
                else{
                    s.insert(0,c);
                }
            }
            else{
                if(cnt%2==1)
                    s.insert(0,c);
                else s += c;
            }
        }
    }
    if(cnt%2==1) reverse(all(s));
    cout<<s;
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3948
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll dp[3010] = {};
struct Combination{
private:
    ll N;
    vector<ll> fac, facinv;

public:
    Combination(ll n){
        N = n;
        fac.push_back(1); fac.push_back(1);
        rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD);
        rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2));
    }
    ll power(ll x, ll n){
        if(n == 0) return 1LL;
        ll res = power(x * x % MOD, n/2);
        if(n % 2 == 1) res = res * x % MOD;
        return res;
    }
    ll nck(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
    }
    ll npk(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[n-k] % MOD;
    }
    ll get(ll x){return fac[x];};
    ll getinv(ll x){return facinv[x];};
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    ll N;
    cin >> N;
    ll r[3010], c[3010];
    Combination cb(200010);

    rep(i,0,N){
        cin >> r[i] >> c[i];
        r[i]--; c[i]--;
    }
    vector<lpair> lp;
    rep(i,0,N) lp.push_back({r[i], c[i]});
    sort(lp.begin(), lp.end());
    rep(i,0,N){
        r[i] = lp[i].first;
        c[i] = lp[i].second;
    }

    rep(i,0,N){
        ll v = cb.nck(r[i]+c[i], r[i]);
        rep(j,0,N){
            if(i == j) continue;
            if(r[j] <= r[i] && c[j] <= c[i]){
                ll v2 = cb.nck((r[i] - r[j]) + (c[i] - c[j]), r[i] - r[j]);
                v = (v - dp[j] * v2 % MOD + MOD) % MOD;

            }
        }
        dp[i] = v;
    }

    ll ans = 0;
    rep(i,0,N){
        ans += dp[i] * cb.nck(H-1-r[i]+W-1-c[i], H-1-r[i]) % MOD;
        ans %= MOD;
    }
    ans = (cb.nck(H-1+W-1, H-1) - ans + MOD) % MOD;

    print(ans);

}

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

int main() {
  double N ; 
  cin >> N ; 
  vector<double> x(N) , y(N) ;
  vector<int> P(N) ; 
  double T=0;
  double C= 0  ; 
  
  
  
  for(int i = 0 ; i < N ; i++){
    P.at(i) = i ; 
    cin >> x.at(i) ; 
    cin >> y.at(i) ; 
  }
  
  do{ 
    for(int i = 0 ;  i < N-1 ; i++){
      T += sqrt( pow(x.at(P.at(i+1))-x.at(P.at(i)),2) + pow(y.at(P.at(i+1))-y.at(P.at(i)),2) ) ;
    }
    C++ ; 
    
  } while (next_permutation(P.begin() , P.end()) ); 
  

  cout << fixed << setprecision(10) << T/C << endl ;
 
  
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	string S;
	cin >> S;
	if(S.size() == 2)cout << S << endl;
	else cout << S[2] << S[1] << S[0] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
// #define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint (ll x = 0) : x ((x % mod + mod) % mod) {}
    mint operator-() const { return mint (-x); }
    mint &operator+= (const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-= (const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*= (const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+ (const mint a) const { return mint (*this) += a; }
    mint operator- (const mint a) const { return mint (*this) -= a; }
    mint operator* (const mint a) const { return mint (*this) *= a; }
    mint pow (ll t) const {
        if (!t) return 1;
        mint a = pow (t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow (mod - 2); }
    mint &operator/= (const mint a) { return *this *= a.inv(); }
    mint operator/ (const mint a) const { return mint (*this) /= a; }
};
istream &operator>> (istream &is, const mint &a) { return is >> a.x; }
ostream &operator<< (ostream &os, const mint &a) { return os << a.x; }

// combination mod prime
struct combination {
    vector<mint> fact, ifact;
    combination (int n) : fact (n + 1), ifact (n + 1) {
        assert (n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator() (int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint p (int n, int k) { return fact[n] * ifact[n - k]; }
} c (500500);

int main() {
    int n, m;
    cin >> n >> m;
    mint ans = 0;
    rep (i, 0, n + 1) {
        mint now = c (n, i);
        now *= c.p (m - i, n - i);
        now *= c.p (m, n);
        if (i & 1) now = -now;
        ans += now;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 10996
// https://atcoder.jp/contests/abc098/tasks/arc098_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto &x : a)
        cin >> x;
    int ans = 0, sum = 0, r = 0;
    REP(l, N) {
        while (r < N && (sum & a[r]) == 0) {
            sum += a[r++];
        }
        ans += r - l;
        sum -= a[l];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4764