akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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

int main()
{   
    //ノード数n,エッジ数m
    ll n,m; cin >> n >> m;
    vector<vector<ll> > c(n,vector<ll>(n,0));
    for(int i=0;i<m;i++){
        int a,b;cin >> a >> b;
        a--;b--;
        c[a][b] = 1;
    }
    vector<ll> d(n);
    for(int i=0;i<n;i++)d[i]=i;
    int count = 0;
    do{
        bool isres = true;
        if(c[0][d[1]] == 0 && c[d[1]][0] == 0)
            isres = false;
        for(int i=1;i<n-1;i++){
            if(c[d[i]][d[i+1]] == 0 && c[d[i+1]][d[i]] == 0){
                isres = false;
                break;
            }
        }
        if(isres)count++;
    }while(next_permutation(d.begin()+1,d.end()));
    cout << count << endl;
}
    

Measured memory_bytes: 256
S = input()
if S[0] != 'A':
    print('WA')
elif S[2:-1].count('C') != 1:
    print('WA')
else:
    upper = 0
    for c in S:
        if c.isupper():
            upper += 1
    print('AC' if upper == 2 else 'WA')


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

ans = 1145141919810364364334
for i in range(1,2**n):
    ls = [0] * n
    qq = []
    
    for j in range(n):
        if (i >> j) & 1:
            ls[j] = 1
            qq.append(j)
            
    if sum(ls) < k:
        continue
        
    else:
        mt = a[0]
        cost = 0
        for j in range(1,n) :
            if mt < a[j]:
                mt = a[j]
            else:
                if ls[j] == 1:
                    cost += mt + 1 - a[j]
                    mt += 1
    ans = min(ans,cost)
    
print(ans)

Measured memory_bytes: 43484
#include<bits/stdc++.h>
#define ll long long
ll n;
const int N=2e5+5;

using namespace std;
int main(){
				 cin>>n;
				 ll a[n];
                ll dp[n+2];
				 for(int i=0;i<n;i++)cin>>a[i];
                 for(int i=0;i<=n;i++)dp[i]=LLONG_MAX;
                 dp[0]=0;
                  for(int i=0;i<n-1;i++)
                  {
					 if(i+1<n)
					 dp[i+1]  =min(dp[i+1],dp[i]+abs(a[i+1]-a[i]));
					 
					 
					 if(i+2<n)dp[i+2]=min(dp[i+2],dp[i]+abs(a[i+2]-a[i]));
					 
				  }
				 // for(int i=0;i<n;i++)cout<<dp[i]<<" ";
				  cout<<dp[n-1]<<"\n";
	
	
	
	
	}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

template <class T> void max_swap(T& a, const T b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int sec_time()
{
	int h, m, s;
	scanf("%d%d%d", &h, &m, &s);
	return 3600*h + 60*m + s;
}
void print_time(int s)
{
	printf("%d %d %d\n", s / 3600, (s / 60) % 60, s % 60);
}
int main()
{
	for (int i = 0; i < 3; ++i)
	{
		int enter = sec_time();
		int leave = sec_time();
		print_time(leave - enter);
	}
}

Measured memory_bytes: 0
from itertools import combinations
N = int(input())
K = 0
for i in range(2,N+2):
    if N==(i*(i-1))//2:
        K = i
        break
if K==0:
    print("No")
else:
    S = {i:[] for i in range(1,K+1)}
    cnt = 1
    for x in combinations(range(1,K+1),2):
        i,j = x
        S[i].append(cnt)
        S[j].append(cnt)
        cnt += 1
    print("Yes")
    print(K)
    for i in range(1,K+1):
        print(len(S[i]),*S[i])

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

int main() {
  int N;
  cin >> N;
  int a = N;
  int b = N;
  int log = 1;
  int sum = 0;
  
  //log の操作 log　= Nの桁数
  for (int i = 0;true;i++){
    a /= 10;
    if ( a > 0 ){
      log++;
    }
    else {
      break;
    }
  }
  
  for( int i = 0 ;i < log;i++){
    sum += (b % 10);
    b /= 10;
  }
  if ( N % sum == 0 ){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
    
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace abc080_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[,] arF = new int[N,10];           
            for(int i = 0;i < N; i++)
            {
                string stF = Console.ReadLine();
                string[] stArF = stF.Split(' ');
                for(int j = 0;j < stArF.Length; j++)
                {
                    arF[i, j] = Convert.ToInt32(stArF[j]);
                }
            }
            int[,] arP = new int[N, 11];
            for(int i = 0; i < N; i++)
            {
                string stP = Console.ReadLine();
                string[] stArP = stP.Split(' ');
                for(int j = 0;j < stArP.Length; j++)
                {
                    arP[i, j] = Convert.ToInt32(stArP[j]);
                }
            }
            Queue<string> queue = Recursion();
            int result = int.MinValue;
            while(queue.Count > 0)
            {
                string pattern = queue.Dequeue();
                if(int.Parse(pattern) == 0)//最低でも一回は営業しないと駄目なため
                {
                    continue;
                }
                int[] shopCount = new int[N];
                for (int i = 0; i < pattern.Length; i++)
                {
                    if(pattern[i] == '0')
                    {
                        continue;
                    }
                    for(int j = 0; j < N; j++)
                    {
                        if(arF[j, i] == 0)
                        {
                            continue;
                        }
                        shopCount[j]++;

                    }
                }
                int sum = 0;
                for(int i = 0; i < N; i++)
                {
                    sum += arP[i, shopCount[i]];
                }
                result = Math.Max(sum, result);
            }
            Console.WriteLine(result);    
        }

        static Queue<string> Recursion(int len = 10, Queue<string> queue = null)
        {
            string[] stAr = new string[] { "0", "1" };//構成文字
            if (queue != null)
            {
                if (queue.Peek().Length >= len)
                {
                    return queue;
                }
                var newQueue = new Queue<string>();
                while (queue.Count > 0)
                {
                    var oldStr = queue.Dequeue();
                    foreach (string str in stAr)
                    {
                        newQueue.Enqueue(oldStr + str);
                    }
                }
                return Recursion(len, newQueue);
            }
            else
            {
                queue = new Queue<string>();
                foreach (string str in stAr)
                {
                    queue.Enqueue(str);
                }
                return Recursion(len, queue);
            }
        }
    }
}


Measured memory_bytes: 13376
#include <iostream>
#include <utility>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
using namespace std;

typedef pair<int,int> pii;
#define x first
#define y second

int main() {
	int m, n;
	while(cin >> m >> n, m || n) {
		int s, t;
		vector<pii> v0, v1;
		cin >> s;
		for(int i = 0; i < s; i++) {
			pii a;
			cin >> a.x >> a.y;
			a.x--; a.y--;
			v0.push_back(a);
		}
		cin >> t;
		for(int i = 0; i < t; i++) {
			pii a;
			cin >> a.x >> a.y;
			a.x--; a.y--;
			v1.push_back(a);
		}

		int ans = 0;
		for(int i = 0; i < v1.size(); i++) {
			v0.push_back(v1[i]);
			int tmp = 0;
			for(int j = 0; j < n; j++) {
				for(int k = 0; k < m; k++) {
					bool valid = true;
					int val = -1;
					int mn = 10000;
					for(int l = 0; l < v0.size(); l++) {
						int h;
						int w;
						h = abs(v0[l].y - j);
						w = fabs((v0[l].x + (v0[l].y % 2) / 2.0) - (k + (j % 2) / 2.0)) - h / 2.0 + 1e-6;
						if(w < 0)
							w = 0;
						if(mn == h + w)
							valid = false;
						else if(mn > h + w) {
							val = l;
							mn = h + w;
							valid = true;
						}
					}
					if(valid && val == v0.size() - 1)
						tmp++;
				}
			}

			ans = max(ans, tmp);
			v0.pop_back();
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long int x;
    cin>>x;

    bool prime[1000001]={false};

       for(int i=2;i<=1000000;i++)
        {
            if(prime[i]==false)
            {
               for(int j=2;i*j<=1000000;j++)
                prime[i*j]=true;
            }
        }
          long int value;
        for(int i=2;i<=1000000;i++)
        {
            if(prime[i]==false && i>=x)
              {
                 value=i;
                  break;
              }
        }
      cout<<value;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

void check()
{
	int a,b,c,d;
	scanf("%1d%1d%1d%1d",&a,&b,&c,&d);
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			for(int k=0;k<2;k++)
			{
				int t1=i==0?a+b:a-b;
				int t2=j==0?t1+c:t1-c;
				int t3=k==0?t2+d:t2-d;
				if(t3==7)
				{
					printf("%d%c%d%c%d%c%d=7\n",a,i==0?'+':'-',b,j==0?'+':'-',c,k==0?'+':'-',d);
					return;
				}
			}
}

int main()
{
	check();
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    double min_dif = 100000000;
    for(int i = 0; i < N; i++){
        min_dif = min(min_dif, abs(A - (T - H[i] * 0.006)));
    }
    for(int i = 0; i < N; i++){
        if(abs(A - (T - H[i] * 0.006)) == min_dif){
            cout << i + 1 << endl;
            return 0;
        }
    }
}


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

int main()
{
    char s[200010];
    char t[200010];

    // 標準入力から1行bufに格納
    fgets(s, sizeof(s), stdin);
    fgets(t, sizeof(t), stdin);

    int len_s = strlen(s);

    int count = 0;
    for(int i=0; i<len_s; i++){
        if(s[i] != t[i]){
            count++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 2036
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline


H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]
b, w = 0, 0

def dfs(i, j):
    if visited[i][j]:
        return (0, 0)

    visited[i][j] = True

    if S[i][j] == '#':
        b, w = 1, 0
    else:
        b, w = 0, 1

    for di, dj in move:
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W):
            continue
        if S[i][j] != S[ni][nj]:
                db, dw = dfs(ni, nj)
                b, w = b + db, w + dw

    return (b, w)


result = 0
for i in range(H):
    for j in range(W):
        b, w = dfs(i, j)
        result += b * w
print(result)



Measured memory_bytes: 151924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc127_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int A, B;
  cin >> A >> B;

  ll ans = 0;
  if (A <= 5)
    ans = 0;
  else if (A >= 13)
    ans = B;
  else
    ans = B / 2;

  cout << ans << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
string str;
string target = "keyence";
int main()
{
  cin >> str;
  if (str == target)
  {
    puts("YES");
    return 0;
  }
  int n = str.size();
  for (int i = 0; i < n; i++)
  {
    for (int j = i; j < n; j++)
    {
      //delete [i,j]
      string S = "";
      for (int k = 0; k < n; k++)
      {
        if (i <= k && k <= j)
        {
          continue;
        }
        else
          S.push_back(str[k]);
      }
      if (S == target)
      {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 200005

int N;
int A[SIZE];
int ans[SIZE];
int dp[SIZE];
vector<int> G[SIZE];

void dfs(int node_id,int pre_node){

	int loc = lower_bound(dp,dp+(N+1),A[node_id])-dp;

	int pre = dp[loc];
	dp[loc] = A[node_id];

	ans[node_id] = lower_bound(dp,dp+(N+1),BIG_NUM)-dp;

	for(int i = 0; i < G[node_id].size(); i++){

		int child = G[node_id][i];
		if(child == pre_node)continue;

		dfs(child,node_id);
	}

	dp[loc] = pre;
}


int main(){

	scanf("%d",&N);

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

		scanf("%d",&A[i]);
	}

	int from,to;

	for(int i = 0; i < N-1; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
		G[to].push_back(from);
	}

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

		dp[i] = BIG_NUM;
	}

	dfs(0,-1);

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

		printf("%d\n",ans[i]);
	}

	return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int h,w,n;
    cin >> h >> w >> n;
    map<int,set<pair<int,int>>> erased1,erased2;
    rep(i,0,n){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        erased1[b-a].insert(make_pair(a,b));
        erased2[a+b+1].insert(make_pair(a,b+1));
    }

    rep(i,0,w){
        int x=i,y=0;
        while(y<=h-1){
            if(x%2==y%2){
                if(x==w-1) ++y;
                else{
                    int d=min(w-x-1,h-y);
                    int nx=x+d,ny=y+d;
                    auto it=erased1[x-y].lower_bound(make_pair(y,-inf));
                    if(it!=erased1[x-y].end()){
                        int bx=it->second,by=it->first;
                        nx=bx;
                        ny=by+1;
                    }
                    x=nx;
                    y=ny;
                }
            }else{
                if(x==0) ++y;
                else{
                    int d=min(x,h-y);
                    int nx=x-d,ny=y+d;
                    auto it=erased2[x+y].lower_bound(make_pair(y,-inf));
                    if(it!=erased2[x+y].end()){
                        int bx=it->second,by=it->first;
                        nx=bx;
                        ny=by+1;
                    }
                    x=nx;
                    y=ny;
                }
            }
        }
        cout << x+1 << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Measured memory_bytes: 59384
#include <iostream>
#include <map>
using namespace std;
int main(){
    int n; cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        int a; cin >> a;
        if(mp[a] == 0) mp[a]++;
        else mp.erase(a);
    }
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 8104
#include <iostream>
using namespace std;
int main(void){
  	string input;
  	cin>>input;
  	
  	int buffer = 0;
  	for(int i=0;i<(int)input.size();i++){
      	int num=stoi(input.substr(i,1));
      	buffer+=num;
      	buffer%=9;
    }
  	
  	if(buffer==0){
      	cout<<"Yes"<<endl;
    }else{
      	cout<<"No"<<endl;
    }
  	
  	return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	int b[100];
	int max=0;
	int min=101;
	long int sum=0;
	long int minn=10000000;
	for(int i=0;i<a;i++)
	{
		cin>>b[i];
		if(b[i]>max) max=b[i];
		if(b[i]<min) min=b[i];
	}
	for(int i=min;i<=max;i++)
	{
		for(int j=0;j<a;j++)
		{
			sum+=abs(b[j]-i)*abs(b[j]-i);
		}
		if(sum<minn)
		{
			minn=sum;
			sum=0;
		}
	}
	if(a==1) cout<<0;
	else cout<<minn;
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
#define int long long
const int PMAX=50000;
vector<int> PF(PMAX, 1);
void MKPF(){for (int i=2;i<sqrt(PMAX);i++) if(PF[i]==1) for(int j=i*2;j<PMAX;j+=i) PF[j] = 0;}
signed main(){
	MKPF();
	int a;
	while( scanf("%lld", &a) != EOF ){
		if(a==0) break;
		int c=0;
		for(int i=2; i<=a/2; i++){
			if(PF[i]==1 && PF[a-i]==1) c++;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define All(x) (x).begin(),(x).end()
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=1e9+7;
const int inf=0x7fffffff;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// fast read
template<class T> void 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<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}

long double a,b;

int main(){
	//freopen("test.in","r",stdin);
	scanf("%Lf%Lf",&a,&b);
	long double ans=a*b;
	printf("%.Lf\n",floor(ans));
	return 0;
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
#define L long long
using namespace std;
int n,m,x[100010],a[100010];
L p;
struct orz
{
	int a[100010];
	inline orz operator*(orz x)
	{
		orz p;
		int i;
		for(i=1;i<n;i++)
		  p.a[i]=a[x.a[i]];
		return p;
	}
}u[70],w;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	L k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  {
	   scanf("%d",&x[i]);
	   w.a[i]=u[0].a[i]=i;
	  }
	scanf("%d%lld",&m,&p);
	for(i=1;i<=m;i++)
	  {
	   scanf("%d",&j);
	   swap(u[0].a[j],u[0].a[j-1]);
	  }
	for(i=1;i<60;i++)
	  u[i]=u[i-1]*u[i-1];
	for(i--;i>=0;i--)
	  if(p&(1ll<<i))
	    w=w*u[i];
	for(i=1;i<n;i++)
	  a[i]=x[w.a[i]+1]-x[w.a[i]];
	for(i=0,k=x[1];i<n;i++,k+=a[i])
	  printf("%lld\n",k);
	return 0;
}


Measured memory_bytes: 28160
#include<bits/stdc++.h>
using namespace std;
#define int 		long long
#define ull 		unsigned long long
#define vi 			vector<int>
#define vvi			vector<vi>
#define pb			push_back
#define mii  		map<int, int>
#define pii 		pair<int, int>
#define pq 			priority_queue<int>
#define pqs 		priority_queue<int, vi, greater<int>>
#define mod 		1000000007
#define inf 		1e18
#define ps(x, y) 	fixed<<setprecision(y)<<x
#define w(t)		int t; cin>>t; while(t--)
#define rep(i,a,b)	for(int i = a; i < b; i++)
#define repd(i,a,b)	for(int i = a; i>= b; i--)
int32_t main()
{
	string str;
	cin>>str;
	if(str[str.size() -1] == 's')
		str += "es";
	else
		str += 's';
	cout<<str;
	return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll K; cin >> K;
  ll mk10 = 10 % K;
  ll mk7 = 7  % K;
  ll a = 7;
  ll ans = 0;

  ll amodk;
  amodk = a % K;
  set<ll> m;
  while(1){
    ans ++;
    if(amodk == 0) break;
    if(m.find(amodk) != m.end()) {
      ans = -1;
      break;
    }
    m.insert(amodk);
    a = amodk;
    amodk = (((mk10 *( a % K)) % K) + mk7) % K;
  }
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 50476
#include<algorithm>
#include<cmath>
#include<cstdint>
#include<cstdio>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); ++i)
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(v) begin(v), end(v)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

const double PI = acos(-1.0);

int main() {
  std::ios::sync_with_stdio(false);

  int r, g, b;
  cin >> r >> g >> b;
  int t = r * 100 + g * 10 + b;
  if (t % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


# UnionFind
class UnionFind:
    # 負: ルートで値は木の深さを表す
    # 正: 子で値は次のノードを表す
    def __init__(self, size: int) -> None:
        self.nodes = [-1] * size  # 初期状態では全てのノードがルート

    def root(self, x: int) -> int:
        if self.nodes[x] < 0:
            return x
        else:
            self.nodes[x] = self.root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x: int, y: int) -> None:
        root_x, root_y = self.root(x), self.root(y)
        if root_x != root_y:
            if self.nodes[root_x] != self.nodes[root_y]:  # グラフの高さが異なる場合
                # 木のランクが高い方のルートに併合させる
                # 併合後にランクの変動はない
                if self.nodes[root_x] < self.nodes[root_y]:
                    self.nodes[root_y] = root_x
                else:
                    self.nodes[root_x] = root_y
            else:
                # ランクが等しい木同士を併合させるので
                # 併合後は木のランクが1つ上がる
                self.nodes[root_x] += -1
                self.nodes[root_y] = root_x


n, q = LI()
query = [LI() for _ in range(q)]

uf = UnionFind(n)
for com, x, y in query:
    if com == 0:  # 連結クエリ
        uf.unite(x, y)
    else:  # 判定クエリ
        if uf.root(x) == uf.root(y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 22796
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
  ll n;
  cin >> n;
  ll a,ans=0;
  for(ll i=0;i<n;i++) {
    cin >>a;
    while(1){
      if(a%2==1) break;
      a/=2;
      ans++;
    }
  }
  cout <<ans<<endl;
}


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

struct ModValue
{
    static constexpr int
        value = 1'000'000'007;
};

template<int mod = ModValue::value>
struct mint
{   
    long long x;
    
    mint(long long xx = 0) : x(xx % mod){}
    
    mint(const mint&) = default;
    mint& operator=(const mint& rhs) = default;
    
    mint operator-() const
    {
        return mint(-x);
    }
    
    mint& operator+=(const mint rhs)
    {
        x += rhs.x;
        if(x >= mod)
        {
            x -= mod;
        }
        
        return *this;
    }
    
    mint& operator-=(const mint rhs)
    {
        x += mod - rhs.x;
        if(x >= mod)
        {
            x -= mod;
        }
        
        return *this;
    }
    
    mint& operator*=(const mint rhs)
    {
        x *= rhs.x;
        x %= mod;
        return *this;
    }
    
    mint operator+(const mint rhs) const
    {
        return mint(*this) += rhs;
    }
    
    mint operator-(const mint rhs) const
    {
        return mint(*this) -= rhs;
    }
    
    mint operator*(const mint rhs) const
    {
        return mint(*this) *= rhs;
    }
    
    mint pow(long long t) const
    {
        mint rtn = 1;
        mint tmp = *this;
        while(t > 0)
        {
            if(t & 1)
            {
                rtn *= tmp;
            }
            tmp *= tmp;
            t >>= 1;
        }
        return rtn;
    }
    
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint& operator/= (const mint rhs)
    {
        return *this *= rhs.inv();
    }
    mint operator/ (const mint rhs) const
    {
        return mint(*this) /= rhs;
    }
};
template<int mod = ModValue::value>
std::istream& operator>>(std::istream& is, mint<mod>& m)
{ return is >> m.x; }

template<int mod = ModValue::value>
std::ostream& operator<<(std::ostream& os, mint<mod>& m)
{ return os << m.x; }

template<int mod = ModValue::value>
struct combination
{
    // factorial, invFactorial
    std::vector<mint<mod>> fact, ifact;
    
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        fact[0] = 1;
        for(int i = 1; i <= n; ++i)
        {
            fact[i] = fact[i - 1] * i;
        }
        
        // inv
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i)
        {
            ifact[i - 1] = ifact[i] * i;
        }
    }
    
    mint<mod> operator()(int n, int k)
    {
        if(k < 0 || k > n)
        {
            return 0;
        }
        // nCk = n! / k!(n-k)!
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main()
{
    long long k;
    std::string s;
    
    std::cin >> k >> s;
    long long n = s.size();
    
    combination c(n+k);
    mint rtn = 0;
    for(long long i = 0; i <= k; ++i)
    {
        rtn += mint(26).pow(k - i) * mint(25).pow(i) * c(n-1+i,n-1);
    }
    
    std::cout << rtn << std::endl;
}

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

using namespace std;

int main()
{
    int n, ans, _min, r[200010];
    cin>>n>>r[0]>>r[1];
    _min=r[0];
    ans=r[1]-_min;
    for (int i=2; i<n; i++)
    {
        cin>>r[i];
        _min=min(_min, r[i-1]);
        ans=max(ans, r[i]-_min);
    }
    cout<<ans<<'\n';
    return 0;
}



Measured memory_bytes: 3900
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
 
#define ll long long
 
#define pq(name,type) priority_queue<type> name
#define vec(name,type,length,value) vector<type> name(length,value)
#define vec2(name,type,length,width,value) vector<vector<type>> name(length,vector<type>(width,value));
 
int main(){
	ll N,hp;
  cin >> N >> hp;
  vec(normal,ll,N,0);
  vec(throwing,ll,N,0);
  vector<ll> c;
  ll nmax = 0,tm = 0,n = 0;
  froop1(0,N){
    cin >> normal.at(i) >> throwing.at(i);
  }
  froop1(0,N){
    if(nmax < normal.at(i)){
      nmax = normal.at(i);
      tm = throwing.at(i);
      n = i;
    }else if(nmax == normal.at(i) && throwing.at(n) > throwing.at(i)){
      nmax = normal.at(i);
      tm = throwing.at(i);
      n = i;
    }
}
ll count = 0;
  froop1(0,N){
    if(throwing.at(i) > nmax && i != n){
      c.push_back(throwing.at(i));
  }
}
  sort(c.begin(),c.end(),greater<long long>());
  froop1(0,c.size()){
   if(hp <= 0) break;
    hp -= c.at(i);
    count++;
  }
 while(hp > 0){
  if(hp <= throwing.at(n)){
    hp -= throwing.at(n);
  }else{
    hp -= normal.at(n);
  }
   count++;
 }
  cout << count << endl;
}

Measured memory_bytes: 5840
def warshall_floyd(d):
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
 
 
h, w = list(map(int, input().split())) 
 
power = [list(map(int, input().split())) for i in range(10)] 

power = warshall_floyd(power)

ans = 0
for i in range(h):
    wall = list(map(int, input().split()))  
    for key in wall:
        if key == -1:
            continue
        ans += power[key][1]
print(ans)


Measured memory_bytes: 73640
// CONTEST

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

// Utility
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, X, Y) for (int I = (X); I < (Y); I++)
using ll = int64_t;
using ull = uint64_t;
template<typename T> struct is_container {
template<typename C> static char test(typename C::const_iterator*); template<typename> static int test(...);
static bool const value = sizeof(test<T>(nullptr)) == sizeof(char) && !std::is_same<std::string, T>::value;
};
namespace std {
template<class ...Ts>        istream& operator>>(istream& i, tuple<Ts...>& x) { apply([&](auto&&... ys){ ((i >> ys), ...); }, x); return i; }
template<class T1, class T2> istream& operator>>(istream& i, pair<T1, T2>& x) { i >> x.first >> x.second; return i; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
istream& operator>>(istream& i, T& x) { for (auto& y : x) { i >> y; } return i; }
}

// Debugging
#define DD(X) std::cout << #X ": " << (X) << std::endl << std::flush
#define DD2(X) std::cout << #X ":" << std::endl; for (auto x : (X)) { std::cout << x << std::endl << std::flush; }
namespace std {
template<class ...Ts>        ostream& operator<<(ostream& o, const tuple<Ts...>& x) { o << "("; apply([&](auto&& y, auto&&... ys){ o << y; ((o << ", " << ys), ...); }, x); o << ")"; return o; }
template<class T1, class T2> ostream& operator<<(ostream& o, const pair<T1, T2>& x) { o << tie(x.first, x.second); return o; }
template<class T, enable_if_t<is_container<T>::value, int> = 0>
ostream& operator<<(ostream& o, const T& x) { o << "{"; for (auto it = x.begin(); it != x.end(); it++) { if (it != x.begin()) { o << ", "; } o << *it; } o << "}"; return o; }
}

// Main
void mainCase() {
  int n;
  cin >> n;
  vector<ll> ls(n, 0);
  cin >> ls;

  ll res = 0;
  ll maxi = ls[0];
  FOR(i, 1, n) {
    res += max((ll)0, maxi - ls[i]);
    maxi = max(maxi, ls[i]);
  }
  cout << res << endl;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  // [ Single case ]
  mainCase();
  return 0;
  // [ Multiple cases ]
  // int t;
  // cin >> t;
  // FOR(i, 0, t) { mainCase(); }
  // return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 1; i <= b-a; ++i) {
        sum += i;
    }
    cout << sum - b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back
#define vs vector<string>

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N,P;
    cin>>N>>P;
    map<ll,ll> m;
    m=prime_factor(P);
    ll Ans=1;
    for(auto p:m){
        ll key=p.first;
        ll v=p.second;
        rep(i,v/N){
            Ans*=key;
        }
    }
    cout<<Ans<<endl;
}

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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long a,b,c,d,e,f,g,h;
    cin>>a>>b>>c>>d;

    long long count1=a*c;
    long long count2=a*d;
    long long count3=b*c;
    long long count4=b*d;
    std::vector<long long> v;
    v.push_back(count1);
    v.push_back(count2);

    v.push_back(count3);

    v.push_back(count4);

    sort(v.begin(), v.end());
    cout<<v[3]<<endl;



    
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k, a, b, flag = 0;
    cin>>k>>a>>b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            flag = 1;
            break;
        }
    }
    if (flag) {
        cout<<"OK"<<endl;
    }
    else {
        cout<<"NG"<<endl;
    }
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include<unordered_map>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;


int main() {
	int n;
	cin >> n;
	unordered_map<int, int>note;
	deque<int>side;
	ll S = 0;
	rep(i, n) {
		int m;
		cin >> m;
		if (note[m] == 0) {
			note[m] = 1;
		}
		else {
			note[m] = 0;
			side.push_back(m);
		}
	}
	if (side.size() <= 1) {
		cout << 0 << endl;
	}
	else {
		sort(all(side));
		reverse(all(side));
		S =(ll) side[0] * side[1];
		cout << S << endl;
	}
}


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

using namespace std;

int N, Q;
int a[220000], b[220000];
vector<int> G[220000];
int val[220000];
int counter[220000];
int p[220000], x[220000];

void dfs(int idx,int cnt, int par) {
    for (int i = 0; i < G[idx].size(); i++) {
        if (G[idx][i] == par)continue;
        counter[G[idx][i]] += cnt;
        dfs(G[idx][i],cnt+val[G[idx][i]], idx);
    }
}

signed main() {
    cin >> N >> Q;
    for (int i = 0; i < N - 1; i++) {
        cin >> a[i] >> b[i];
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    for (int i = 0; i < Q; i++) {
        cin >> p[i] >> x[i];
        val[p[i]] += x[i];
        counter[p[i]] += x[i];
    }
    dfs(1,val[1] ,0);
    for (int i = 1; i <= N; i++)cout << counter[i] << " ";
    cout << endl;
}


Measured memory_bytes: 28160
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();

		sc.close();

		int[][] s = new int[2][100100];

		int[] idx = new int[2];
		int f = 0;

		if (S.charAt(0) == '1') {
			f = 0;
			s[f][idx[f]]++;
		} else {
			idx[0] = 1;
			f = 1;
			s[f][idx[f]]++;
		}

		for (int i = 1; i < N; i++) {
			if (S.charAt(i - 1) != S.charAt(i)) {
				idx[f]++;
				f ^= 1;
			}
			s[f][idx[f]]++;
		}

		int[][] w = new int[2][100101];
		for (int i = 0; i < 100100; i++) {
			w[0][i + 1] = w[0][i] + s[0][i];
			w[1][i + 1] = w[1][i] + s[1][i];
		}

		int ans = Integer.MIN_VALUE;
		for (int i = 0; i + K <= 100000; i++) {
			// [i, i+K)
			// 逆立ちの数
			int sum = w[1][i + K] - w[1][i];
			sum += w[0][i + K + 1] - w[0][i];

			ans = Math.max(ans, sum);

		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 26604
#include <bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define int long long
string s;
int n, pref[500005], suff[500005], power[500005], used[30], reach1[500005], reach[500005], mx[500005], mx1[500005];
const int mod = 1e9 + 7;
vector<int> d[500005];
int hs(int x, int y, int type){
    return ((pref[y] - (pref[x] * power[y - x] * 1ll) % mod) % mod + mod) % mod;
}
signed main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> s;
    n = s.length();
    s = "+" + s;
    power[0] = 1;
    for(int i = 1; i <= 500000; i++){
        for(int j = 2; j <= 500000 / i; j++)
            d[i * j].pb(i);
    }
    for(int i = 1; i <= n; i++)
        power[i] = (1ll * power[i - 1] * 30) % mod;
    for(int i = 1; i <= n; i++)
        pref[i] = ((1ll * pref[i - 1] * 30) % mod + s[i] - 'a' + 1) % mod;
    int ck = 0;
    for(int i = 1; i <= n / 2; i++){
        long long val = hs(0, i, 1);
        for(int l = i; l + i <= n; l += i){
            if(hs(l, l + i, 1) == val)
                reach[i] = l + i;
            else
                break;
        }
        mx[i] = max(mx[i - 1], reach[i]);
    }
    for(int i = 1; i <= n / 2; i++){
        long long val = hs(n - i, n, 1);
        reach1[i] = n + 1;
        for(int l = n - i; l - i >= 0; l -= i){
            if(hs(l - i, l, 1) == val)
                reach1[i] = l - i + 1;
            else
                break;
        }
    }
    if(mx[n / 2] < n)
        cout << "1\n1\n";
    else{
        int ans = 0, sum = 0;
        for(int i = 1; i <= n; i++)
            used[s[i] - 'a']++;
        for(int i = 0; i <= 25; i++){
            if(used[i] > 0)
                sum++;
        }
        if(sum == 1){
            cout << n << "\n" << 1 << "\n";
            return 0;
        }
        for(int i = 1; i <= n; i++){
            int len = n - i, ck = 0;
            if(i >= 2){
                for(int j = 0; j < d[i].size(); j++){
                    if(reach[d[i][j]] >= i)
                        ck = 1;
                }
            }
            if(len >= 2){
                for(int j = 0; j < d[len].size(); j++){
                    if(reach1[d[len][j]] <= i + 1)
                        ck = 1;
                }
            }
            if(ck == 0)
            ans++;
        }
    cout << "2\n";
    cout << ans << "\n";
    }
}

Measured memory_bytes: 110772
#include<iostream>
#include<string>

using namespace std;

int main(){
    int k;
    cin>>k;
    string s;
    cin>>s;
   
    if(s.size()<=k){
        cout<<s<<"\n";
    }else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"...\n";
    }
    
    return 0;
}

Measured memory_bytes: 3624
H,W=map(int, input().split())
src=[input() for _ in range(H)]
ans=[]
for row in src:
    ans.append(list(row))
dxy = [(-1,-1),(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1)]
for y in range(H):
    for x in range(W):
        if src[y][x] == '#': continue
        c=0
        for dx, dy in dxy:
            if x+dx<0 or x+dx>W-1 or y+dy<0 or y+dy >H-1: pass
            elif src[y+dy][x+dx] == "#": c += 1
        ans[y][x] = c
for row in ans:
    print("".join(list(map(str,row))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

void write();
template <typename T, typename... Args>
void write(T x, Args... args);
template <typename T>
void print_all(vector<T>& a);

void solve() {
    const int N = 5e5;
    string s(N, '0');
    int l = 2e5, r = 2e5;
    string t;
    cin >> t;
    for (auto& c : t) s[r++] = c;
    int q, rev = 0;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int tp;
        cin >> tp;
        if (tp == 1)
            rev ^= 1;
        else {
            int f;
            char c;
            cin >> f >> c;
            if ((f ^ rev) & 1)
                s[--l] = c;
            else
                s[r++] = c;
        }
    }
    t = string(s.begin() + l, s.begin() + r);
    if (rev) reverse(all(t));
    cout << t << '\n';
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

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

    return 0;
}

void write() { cout << "\n"; }
template <typename T, typename... Args>
void write(T x, Args... args) {
    cout << x << ' ';
    write(args...);
}
template <typename T>
void print_all(vector<T>& a) {
    for (int i = 0; i < a.size(); ++i) cout << a[i] << " \n"[i == a.size() - 1];
}

Measured memory_bytes: 1516
#include<stdio.h>
int flg[100000],n,p1,q1;
int i,j,flg1[100000];
int main(void){
	scanf("%d",&n);
	for(i=1;i<100000;i++){
			flg[i]=1;
			flg1[i]=1;
	}
	for(i=2;i*i<=10000;i++){
		if(flg[i]==1){
			for(j=2;j*i<=10000;j++){
				flg[j*i]=0;
				flg1[j*i]=0;
			}
		}
	}
	while(n!=0){
		for(i=n;i>=5;i--){
			if(flg[i]==1 && flg[i-2]==1){
				printf("%d %d\n",i-2,i);
				break;
			}
		}
		scanf("%d",&n);
		for(i=1;i<=n;i++){
			flg[i]=flg1[i];
		}
	}
	return 0;
}

Measured memory_bytes: 1380
from itertools import accumulate
N, W_limit = map(int, input().split())
W, V = [], []
for i in range(N):
    w, v = map(int, input().split())
    W.append(w)
    V.append(v)

# 基準となるW
base_W = W[0]
# 0 ~ 3の範囲に調節
W = [w - base_W for w in W]

# 重みごとに商品を分ける
Items = [[] for i in range(4)]
for w, v in zip(W, V):
    Items[w].append(v)

# 降順ソートして累積和を取っておく
Items = [[0] + sorted(x, reverse=True) for x in Items]
Items = [list(accumulate(x)) for x in Items]

# それぞれの重さから何個選ぶかで全探索
ans = 0
for w0 in range(len(Items[0])):
    for w1 in range(len(Items[1])):
        for w2 in range(len(Items[2])):
            for w3 in range(len(Items[3])):
                tmp_W = (w0 * base_W) + (w1 * (base_W + 1)) + (w2 * (base_W + 2)) + (w3 * (base_W + 3))
                if tmp_W > W_limit:
                    continue
                tmp_V = Items[0][w0] + Items[1][w1] + Items[2][w2] + Items[3][w3]
                ans = max(ans, tmp_V)

print(ans)


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

int main(){
    set<string> s;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string t;
        cin >> t;
        s.insert(t);
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        int n = s.length();
        string s1 = s.substr(0, (n - 1) / 2);
        string s2 = s.substr((n + 1) / 2, n);
        //    cout << s1 << " " << s2 << "\n";
        if (s1 == s2)
            cout << "Yes"
                 << "\n";
        else
        {
            cout << "No"
                 << "\n";
        }
    }
}

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

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

  ll minA = 0;
  ll sumA = 0;
  for(ll i=0; i < n; i ++) {
    sumA += a[i];
    // 偶数項を正とする
    if (i%2==0) {
      if (sumA <= 0) {
        minA += abs(sumA) + 1;
        sumA += abs(sumA) + 1;
      }
    } else {
      if (sumA >= 0) {
        minA += abs(sumA) +1;
        sumA -= abs(sumA) +1;
      }
    }
  }

  ll minB = 0;
  ll sumB = 0;
  for(ll i=0; i < n; i ++) {
    sumB += a[i];
    // 奇数項を正とする
    if (i%2!=0) {
      if (sumB <= 0) {
        minB += abs(sumB) + 1;
        sumB += abs(sumB) + 1;
      }
    } else {
      if (sumB >= 0) {
        minB += abs(sumB) +1;
        sumB -= abs(sumB) +1;
      }
    }
  }

  cout << min(minA, minB) << endl;
  return 0;
}

Measured memory_bytes: 4360