akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
int n;
pair<ll,ll>a[200010];
ll ksm(ll n){
	ll r=1ll*n,ret=1,k=2;
	while(r){
		if(r&1)ret=(ret*k)%mod;
		k=(k*k)%mod;
		r>>=1;
	}
	return ret;
}
map<pair<ll,ll>,ll>r;
ll sum;
ll cnt;
vector<pii>p;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n;
    rep(i,1,n+1){
    	cin>>a[i].fi>>a[i].se;
		ll gd=gcd(a[i].fi,a[i].se);
		if(gd==0) sum++;
		else{
			a[i].fi/=gd;
			a[i].se/=gd;
			if(a<0) a[i].fi=-a[i].fi,a[i].se=-a[i].se;
			r[{a[i].fi,a[i].se}]++;
		}
	}
	cnt=1;
	for(auto it:r){
		if(it.se==0) continue;
		ll u=it.fi.fi,v=it.fi.se;
		ll d=ksm(r[{u,v}]);
		v=-v;
		if(v<0) u=-u,v=-v;
		if(r.count({v,u})){
			d=(d+ksm(r[{v,u}])-1)%mod;
			r[{v,u}]=0;
		}
		cnt=(cnt*d)%mod;
	}
	cout<<(cnt-1+sum+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 19212
#include <cstdio>
using namespace std;

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == 1) a += 13;
    if (b == 1) b += 13;
    if (a == b){
        printf("Draw\n");
    } else if (a > b ){
        printf("Alice\n");
    } else{
        printf("Bob\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(a >= k) cout << k;
    else if(a + b >= k) cout << a;
    else cout << a - (k - a - b);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		for(;sc.hasNext();){
			String[] s=sc.nextLine().split(",");
			int[] lengths=new int[10];
			int length=0;
			for(int i=0;i<10;i++)
				length+=lengths[i]=Integer.parseInt(s[i]);
			int v1=Integer.parseInt(s[10]);
			int v2=Integer.parseInt(s[11]);
			double x=(double)v1*length/(v1+v2);
//			println("x="+x);
//			println("[x]="+(int)x);
			int tot=0;
			for(int i=0;i<10;i++){
				tot+=lengths[i];
				if(x<tot+EPS){
					//x<tot
					//x-tot<0
					println(""+(i+1));
					break;
				}
			}
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n1,num;
    set<int> set1;
    cin >> n1;
    
    for(int i = 0;i < n1;++i){
        cin >> num;
        set1.insert(num);
    }
    
    cin >> n1;
    for(int i = 0;i < n1;++i){
        cin >> num;
        if(!set1.insert(num).second){
            cout << num << endl;
        }
    }
}



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

using namespace std;

typedef long long ll;

ll MIN = -1000000000000000000;

ll getMax(vector<ll>& arr, vector<vector<ll>>& dp, ll here, ll left){
    if(dp[here][left] != MIN){
        return dp[here][left];
    }
    if(left == 0){
        return dp[here][left] = getMax(arr, dp, here+2, left) + arr[here];
    }
    ll inc = arr[here] + getMax(arr, dp, here+2, left);
    ll exc = getMax(arr, dp, here+1, left-1);
    return dp[here][left] = max(inc, exc);
}

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;
    vector<ll> arr(N);
    for(int i = 0 ; i < N; ++i){
        cin >> arr[i];
    }
    vector<vector<ll>> dp(N+2, vector<ll>(3, MIN));
    for(int i = 0 ; i < 2; ++i){
        dp[N][i] = 0;
        dp[N+1][i] = 0;
    }
    dp[N][2] = MIN-1;
    dp[N+1][2] = MIN-1;

    ll left = 1 + (N%2 == 1);
    ll ret = getMax(arr, dp, 0, left);

    cout << ret << endl;

}

Measured memory_bytes: 21944
<?php

fscanf(STDIN, "%d", $n);
$plan = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    $tmp = [$a, $b, $c];
    $plan[] = $tmp;
}

$dp = array_fill(0, $n, array_fill(0, 3, 0));
$dp[0][0] = $plan[0][0];
$dp[0][1] = $plan[0][1];
$dp[0][2] = $plan[0][2];

for ($i = 1; $i < $n; ++$i) {
    for ($j = 0; $j < 3; ++$j) {

        for ($k = 0; $k < 3; ++$k) {
            if ($j === $k) continue;

            chmax($dp[$i][$k], $dp[$i - 1][$j] + $plan[$i][$k]);
        }
    }
}
function chmax(&$a, $b) {
    if ($a < $b) $a = $b;
}

echo max($dp[$n - 1]);


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;



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





Measured memory_bytes: 3588
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		double[] v = new double[n];
	
		for(int i = 0; i < n; i++) {
			v[i] = sc.nextDouble();
		}
		
		Arrays.sort(v);

		for(int i = 0; i < n-1; i++) {
			v[i+1] = (v[i] + v[i+1]) / 2;
		}
		
		System.out.println(v[n-1]);

	}
}


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

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


	vector<vector<int>> dp(s.size(), vector<int>(13, 0));
	vector<int> surplusV(10, 0);
	for (int i = 0; i < 10; ++i) {
		surplusV[i] = i;
	}
	// 初期化
	{
		if (s[s.size() - 1] == '?') {
			for (int num = 0; num < 10; ++num) {
				int surplus = num % 13;
				dp[0][surplus] = 1;
			}
		}
		else {
			int num = s[s.size() - 1] - '0';
			int surplus = num % 13;
			dp[0][surplus] = 1;
		}
	}

	int count = 1;
	for (int i = static_cast<int>(s.size()) - 2; 0 <= i; --i) {
		{
			int temp = surplusV[1];
			for (int j = 1; j < 10; ++j) {
				surplusV[j] = temp * j * 10 % 13;
			}
		}
		if (s[i] == '?') {
			for (int num = 0; num < 10; ++num) {
				int surplus = surplusV[num];
				for (int k = 0; k < 13; ++k) {
					int temp = k + surplus;
					if (13 <= temp) {
						temp -= 13;
					}
					dp[count][temp] = (dp[count][temp] + dp[count - 1][k]) % 1000000007;
				}
			}
		}
		else {
			int num = s[i] - '0';
			int surplus = surplusV[num];
			for (int j = 0; j < 13; ++j) {
				int temp = j + surplus;
				if (13 <= temp) {
					temp -= 13;
				}
				dp[count][temp] = dp[count - 1][j];
			}
		}
		++count;
	}
	cout << dp[s.size() - 1][5] << endl;

	return 0;
}

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

int main(){
    ll n;
    cin>>n;
    ll temp=0;
    ll limit=sqrt(n);
    for(ll i=1;i<=limit;i++){
          if(n%i==0)temp=i;
    }
    ll temptwo=n/temp;
    ll ans=0;
    while(temptwo>0){
        temptwo/=10;
        ans+=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b)a=b;};
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b)a=b;};
#define F first
#define S second
namespace Geometry{

  
  typedef long double D;
  typedef complex<long double> P;
  const D PI = asin(1) * 2;
  const D EPS=1e-7;

  
  P reflect(P vec, P x){return vec * conj(x / vec);}
  P reflect(P p1, P p2, P x){return p1 + reflect(p2 - p1, x - p1);}
}
using namespace Geometry;

signed main(){
  int n;
  while(cin>>n){
    if(n==0){break;}
  vector<int> A(n);
  P s;
  D x,y;
  cin>>x>>y;
  s={x,y};
  for(int i=0;i<n;i++){A[i]=i;}
  vector<P> pt(n);
  for(auto &I:pt){
    cin>>x>>y;
    I={x,y};
    I-=s;
  }
  int ans=0;
  do{
    vector<pair<P,P>> L;
    for(auto &I:A){
      pair<P,P> W={pt[I],pt[(I+1)%n]};
      for(auto &T:L){
	T.F=reflect(W.F,W.S,T.F);
	T.S=reflect(W.F,W.S,T.S);
      }
      L.push_back(W);
    }
    vector<pair<D,int>> K;
    bool j=true;
    for(auto &I:L){
      P vec=I.S-I.F; vec/=abs(vec);
      vec*=EPS;
      I.F+=vec;
      I.S-=vec;
      D lf=arg(I.F),rg=arg(I.S);
      if(abs(rg-lf)<1e-9){j=false;}
      if(lf>rg){swap(lf,rg);}
      if(rg-lf>PI){
	K.emplace_back(-PI-EPS,1);
	K.emplace_back(lf,-1);
	K.emplace_back(rg,1);
	K.emplace_back(PI+EPS,-1);
      }
      else{
	K.emplace_back(lf,1);
	K.emplace_back(rg,-1);
      }
    }
    if(!j){continue;}
    j=false;
    int cnt=0;
    sort(K.begin(),K.end());
    for(auto &I:K){
      cnt+=I.S;
      if(cnt==n){j=true;}
    }
    if(j){ans++;}
  }while(next_permutation(A.begin(),A.end()));
  cout<<ans<<endl;
  }
  return 0;
}



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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    lint n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    --n;
    bool flag = false;
    for(lint i = 0 ; i <= n ; ++i){
        lint p = i, q = n - i;
        flag |= (a + max(p, q) * c - min(p, q) * d <= b && b <= a - min(p, q) * c + max(p, q) * d);
        flag |= (a + min(p, q) * c - max(p, q) * d <= b && b <= a - max(p, q) * c + min(p, q) * d);
    }
    if(flag){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int main()
{
    ll n;
    cin >> n;
    ll num = n;
    int keta = 0;
    vector<char> p;
    while (n > 0)
    {
        // cout << n % 26 << endl;
        if (n % 26 == 0)
        {
            p.push_back('z');
            n -= 1;
        }
        else
        {
            p.push_back(n % 26 - 1 + 'a');
        }
        n /= 26;
    }
    for (int i = p.size() - 1; i >= 0; i--)
    {
        cout << p[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
  public static void main (String args[]) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String input = br.readLine();
    System.out.print(input.replaceAll("[a-z]","x"));
  }
}

Measured memory_bytes: 23252
al = "abcdefghijklmnopqrstuvwxyz"
S1 = sorted(list(set(input())))
if (len(S1)==26):
    print("None")
else:
    for i in range (len(S1)):
        if al[i] != S1[i]:
            print(al[i])
            break
        elif i == len(S1)-1:
            print(al[len(S1)])
            break

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
	
long long A,B,X,W;
scanf("%lld%lld%lld",&A,&B,&X);
if(A==0)
W=(B/X)+1;
else{

W=(B/X)-(A-1)/X;
}

cout<<W;
	
	
	
	
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, a[200000];

ll calc(ll b) {
	ll res = 0;
	REP(i, n) res += abs(a[i] - b);
	return res;
}

ll solve(ll l, ll r) {
	if (l+3 >= r) return min(calc(l), min(calc(l+1), calc(l+2)));
	ll a = l+(r-l)/3, b = (a+r)/2;
	ll va = calc(a), vb = calc(b);
	if (va > vb) return solve(a, r);
	else return solve(l, b);
}

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) a[i] -= i+1;
	cout << solve(-1000000001, 1000000001) << endl;
	return 0;
}


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

int main(){
  int ai,am,ac,ae;
  int bi,bm,bc,be;
  
  scanf(" %d %d %d %d",&ai,&am,&ac,&ae);
  scanf(" %d %d %d %d",&bi,&bm,&bc,&be);
  
  printf("%d\n",max(ai+am+ac+ae,bi+bm+bc+be));
  
  return 0;
}

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

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

using namespace std;
using lint=long long;

int main(){
	lint n,x,d; cin>>n>>x>>d;

	if(d==0){
		cout<<(x==0?1:n+1)<<'\n';
		return 0;
	}

	if(d<0) d=-d, x=-x;

	map<lint,vector<pair<lint,lint>>> I;
	for(lint m=0;m<=n;m++){
		lint mn=m*(m-1)-n*(n-1)/2;
		lint mx=n*(n-1)/2-(n-m)*(n-m-1);

		lint l=(2*m-n)*x+d*mn;
		lint r=(2*m-n)*x+d*mx;

		int idx=l%(2*d);
		if(idx<0) idx+=2*d;
		I[idx].emplace_back(l,r+1);
	}

	lint ans=0;
	for(auto& p:I){
		auto& J=p.second;
		sort(J.begin(),J.end());
		lint r;
		rep(i,J.size()){
			if(i==0 || r<=J[i].first){
				ans+=(J[i].second-J[i].first+2*d-1)/(2*d);
				r=J[i].second;
			}
			else if(r<J[i].second){
				ans+=(J[i].second-r+2*d-1)/(2*d);
				r=J[i].second;
			}
		}
	}
	cout<<ans<<'\n';

	return 0;
}


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

typedef long long ll;
#define PB push_back

int counter(int mask) {
	if (mask == 0) return 0;
	return counter(mask >> 1) + (mask & 1);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	vector<vector<pair<int, int>>> testimonies;
	for (int i=0; i<n; ++i) {
		vector<pair<int, int>> t;
		int a; cin >> a; 
		for (int j=0; j<a; ++j) {
			int x, y; cin >> x >> y;
			t.PB({x, y});
		}
		testimonies.PB(t);
	}
	int result = 0;
	for (int mask = 0; mask < (1 << n); ++mask) {
		bool ok = true;
		for (int i = 0; i < n; ++i) {
			if (!(mask & (1 << i))) continue; // unkind 
			for (auto j : testimonies[i]) {
				if (((mask >> (j.first - 1)) & 1) ^ j.second) ok = false; // contradiction
			}
		}
		if (ok) result = max(result, counter(mask));
	}
	cout << result;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int ans = 0;
            for (int i = 0; i < N - 1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    ans += d[i] * d[j];
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11348
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
const int M = 2000005 ;
using namespace std ;
int n , cnt ;
char s[M] ;

int main() {
	scanf("%d",&n) ;
	scanf("%s",s + 1) ;
	for(int i = 1 ; i <= n ; i ++)
		if(s[i] == 'R')
			++ cnt ;
		else -- cnt ;
	if(cnt > 0) printf("Yes\n") ;
	else printf("No\n") ;
	return 0 ;
}

Measured memory_bytes: 256
//ABC 176 D--Wizard in Maze 
//题目地址：https://atcoder.jp/contests/abc176/tasks/abc176_d
//题解地址：https://atcoder.jp/contests/abc176/editorial/79
 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll h,w,cx,cy,dx,dy;
    cin >> h >> w >> cx >> cy >> dx >> dy;
    cx--;
    cy--;
    dx--;
    dy--;
    string s[h];
    for (ll i=0;i<h;i++)cin >> s[i];
    deque<P> que;

    que.push_back(P(cx,cy));
    bool visited[h][w];
    ll d[h][w];
    for (ll i=0;i<h;i++){
        fill(visited[i],visited[i]+w,false);
        fill(d[i],d[i]+w,INF);
    }
    d[cx][cy]=0;
    visited[cx][cy]=true;

    while(!que.empty()){
        P p=que.front();
        ll X=p.first,Y=p.second;
        if (X==dx and Y==dy){
            cout << d[X][Y] << endl;
            return 0;
        }
        visited[X][Y]=true;
        que.pop_front();
        for (ll i=-2;i<3;i++){
            for (ll j=-2;j<3;j++){
                ll x=X+i,y=Y+j;
                if (x<h and x>=0 and y<w and y>=0 and s[x][y]=='.'){
                    if (visited[x][y])continue;
                    if (abs(i)+abs(j)<2){
                        que.push_front(P(x,y));
                        d[x][y]=d[X][Y];
                        visited[i][j]=true;
                    }else{
                        if (d[X][Y]+1<d[x][y]){
                            d[x][y]=d[X][Y]+1;
                            que.push_back(P(x,y));
                        }
                    }
                }
            }
        }

    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 14476
n,k = gets.chomp.split.map(&:to_i)
d = []
a = []
k.times do 
    d << gets.to_i
    a << gets.split.map(&:to_i)
end

a.flatten!
a.uniq!
count = 0
(1..n).each do |i|
    unless a.include?(i)
        count += 1
    end
end
puts count

Measured memory_bytes: 14328
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 1001;
ll dp[MAX][MAX] = {};
char pos[MAX][MAX];

int main() {
    

    ll h,w;
    cin >> h >> w;
    for (ll i=1;i<=h;i++){
        for (ll j=1;j<=w;j++){
            cin >> pos[i][j];
        }
    }
    for (ll i=0;i<=h;i++){
        dp[i][0] = 0;
    }
    for (ll j = 0;j<=w;j++){
        dp[0][j] = 0;
    }
    dp[1][1] = 1;
    for (ll i=1;i<=h;i++){
        for (ll j=1;j<=w;j++){
            if(pos[i][j] == '#'){
                continue;
            }
            if(pos[i-1][j] != '#'){
                dp[i][j] += dp[i-1][j];
            }
            if(pos[i][j-1] != '#'){
                dp[i][j] += dp[i][j-1];
            }
            dp[i][j] %= mop;
        }
    }
    cout << dp[h][w] << endl;

}




Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

	int N; cin >> N;
	vector<ld> v(N); rep(i,N) cin >> v[i];

	sort(all(v));

	ld x = v[0];
	rep1(i, N ) {
		x = (ld) (x + v[i]) / 2.0;
	}
	cout << fixed << setprecision(10) << x << endl;
	return 0;

    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{


      int n,i;
      scanf("%d",&n);

        int ans=0;

         for(i=1;i<=n;i=i+2)
        {
             int j;
             int sq=sqrt(i);
             int cnt=0;
             for(j=1;j<=sq;j++)
             {
                if(i%j==0)
                {
                 cnt++;

                }

             }
            double s=sqrt(i);
            int fl=floor(s);
            if(((fl-s)!=0)&&(cnt==4))
            {
               ans++;

            }

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

       return 0;



}




Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t a, b;
  cin >> a >> b;
  int64_t maxbit = 1;
  while (b >= std::pow(2, maxbit)) {
    maxbit++;
  }
  // cout << maxbit << endl;
  std::bitset<64> bit;
  // i=0
  if (a % 2 == 0 & b % 2 == 0) {
    if (((b - a) / 2) % 2 == 0)
      bit[0] = false;
    else
      bit[0] = true;
  } else if (a % 2 == 1 && b % 2 == 1) {
    if (((b - a) / 2) % 2 == 0)
      bit[0] = true;
    else
      bit[0] = false;
  } else if (a % 2 == 0 && b % 2 == 1) {
    if (((b - 1 - a) / 2) % 2 == 0)
      bit[0] = true;
    else
      bit[0] = false;
  } else {
    if (((b + 1 - a) / 2) % 2 == 0)
      bit[0] = false;
    else
      bit[0] = true;
  }
  cerr << "bit0 is " << ((bit[0]) ? "true" : "false") << endl;
  for (int64_t i = 1; i < maxbit; i++) {
    cerr << "=======" << endl;
    cerr << i << endl;
    int64_t cycle = std::pow(2, i + 1);
    if (a / cycle != b / cycle) {
      int64_t remainder_begin = 0;
      int64_t remainder_end   = 0;

      remainder_begin = (a % cycle == 0) ? 0 : cycle - (a % cycle);
      remainder_end   = (b % cycle) + 1 == cycle ? 0 : (b % cycle) + 1;
      cerr << remainder_begin << " " << remainder_end << endl;
      int64_t count = 0;
      count += std::min(remainder_begin, cycle / 2);
      count += std::max(remainder_end - cycle / 2, (int64_t)0);
      cerr << count << endl;
      if (count % 2 == 0) {
        bit[i] = false;
      } else {
        bit[i] = true;
      }
    } else {
      cerr << "Same Cycle" << endl;
      int64_t ma = (a % cycle) + 1;
      int64_t mb = (b % cycle) + 1;
      if (ma > mb) std::swap(ma, mb);
      if (mb <= cycle / 2) {
        cerr << 0 << endl;
        bit[i] = false;
      } else {
        int64_t lower_limit = std::max(ma, cycle / 2 + 1);
        int64_t count       = mb - lower_limit + 1;
        cerr << count << endl;
        if (count % 2 == 0) {
          bit[i] = false;
        } else {
          bit[i] = true;
        }
      }
    }
  }
  cout << bit.to_ullong() << endl;

  return 0;
}


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

int main() {
	int N; cin >> N;
	int v[25], c[25];
	for (int i = 0; i < N; i++){
		cin >> v[i];
	}
	int d[25];
	for (int i = 0; i < N; i++) {
		cin >> c[i];
		d[i] = v[i] - c[i];
	}
	int sum = 0;
	int i = N - 1;
	sort(d,d+N);
	while (d[i] > 0 && i>=0) {
		sum += d[i];
		i--;
	}
	cout << sum;
}


Measured memory_bytes: 256
import sys
import heapq  # heapqライブラリのimport

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, C = rl()
STC = [[] for _ in range(C+1)]

for _ in range(N):
    s, t, c = rl()
    STC[c].append((s, t))

for i in range(1, C+1):
    stc = STC[i]
    stc.sort()
    p = []
    for j in range(1, len(stc)):
        if stc[j][0] == stc[j-1][1]:
            stc[j] = (stc[j-1][0], stc[j][1])
            p.append(j-1)
    for x in p[::-1]:
        stc.pop(x)
    STC[i] = stc

program = []
for stc_list in STC:
    for s, t in stc_list:
        program.append((s, t))

program.sort()

recorder = [-1]
heapq.heapify(recorder)

for s, t in program:
    if s-0.5 > recorder[0]:
        heapq.heappop(recorder)
    heapq.heappush(recorder, t)

print(len(recorder))


Measured memory_bytes: 24452
#include<bits/stdc++.h>
using namespace std;
bool is(int n){
    if(n>=1&&n<=9)return true;
    return false;
}
#define ll long long
int main(){
    ll n,m;
    cin>>n;
    ll sq =sqrt(n);

     ll res = n;

     for(ll i=1;i<=sq;i++){
        if(n%i==0){
                ll f = n/(ll)i;
            res = min(res,(ll)f+i-2);
        }
     }
     cout<<res<<endl;
    return 0;
}


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

#define Abigail inline void
typedef long long LL;

const int N=50,C=26,INF=(1<<30)-1;

int n,cnt[N+9][C+9],ca;
char s[N+9],ans[N*N+9];

Abigail into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
  	scanf("%s",s+1);
		int len=strlen(s+1);
		for (int j=1;j<=len;++j) ++cnt[i][s[j]-'a']; 
	}
}

Abigail work(){
  for (int i=0;i<C;++i){
  	int mn=INF;
  	for (int j=1;j<=n;++j) mn=min(mn,cnt[j][i]);
  	for (int j=1;j<=mn;++j) ans[++ca]=i+'a';
	}
}

Abigail outo(){
  for (int i=1;i<=ca;++i)
    putchar(ans[i]);
  puts("");
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

int main(){
    int n;cin>>n;
    string x;cin>>x;
    vector<int> pop(2e6,0);
    for(int i=1;i<2e6;++i){
        pop[i]=pop[i%__builtin_popcount(i)]+1;
    }
    reverse(x.begin(),x.end());
    int cnt=0;
    for(int i=0;i<n;++i)if(x[i]=='1') cnt++;

    int tot1=0,p1=1;
    int tot2=0,p2=1;
    for(int i=0;i<n;++i){
        if(x[i]=='1'){
            tot1=(tot1+p1)%(cnt+1);
            if(2<=cnt) tot2=(tot2+p2)%(cnt-1);
        }
        p1=(p1*2)%(cnt+1);
        if(2<=cnt) p2=(p2*2)%(cnt-1);
    }

    vector<int> ans;
    p1=p2=1;
    for(int i=0;i<n;++i){
        if(x[i]=='1'){
            if(cnt==1) ans.push_back(0);
            else{
                int y=(tot2-p2+(cnt-1))%(cnt-1);
                ans.push_back(pop[y]+1);
            }
        }else{
            int y=(tot1+p1)%(cnt+1);
            ans.push_back(pop[y]+1);
        }

        p1=(p1*2)%(cnt+1);
        if(2<=cnt) p2=(p2*2)%(cnt-1);
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<n;++i) cout<<ans[i]<<endl;
    return 0;
}



Measured memory_bytes: 12340
#include<iostream>
using namespace std;
main()
{
	long fix=0;
	for(int i=0;i<9;i++)
	{
		int L=0,R=10;
		while(R-L>1)
		{
			int M=L+R>>1;
			long now=fix*10+M;
			cout<<"? "<<now*1000000000<<endl;
			char ans;cin>>ans;
			if(ans=='Y')R=M;
			else L=M;
		}
		fix=fix*10+L;
	}
	fix++;
	while(fix%10==0)fix/=10;
	long now=fix;
	bool flag=true;
	while(now)flag&=now%10==9,now/=10;
	cout<<"? "<<fix+1<<endl;
	char ans;cin>>ans;
	if(ans==(flag?'Y':'N'))
	{
		while(true)
		{
			cout<<"? "<<fix<<1<<endl;
			cin>>ans;
			fix*=10;
			if(ans=='Y')break;
		}
	}
	cout<<"! "<<fix<<endl;
}

Measured memory_bytes: 684
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
 
using namespace std;
 
void solve(int s){
    int in;
     
    for(int i=0;i<9;i++){
        scanf("%d",&in);
        s-=in;
    }
     
    printf("%d\n",s);
     
    return;
}
 
 
int main(){
    int s;
     
    while(1){
        scanf("%d",&s);
        if(s==0) break;
        solve(s);
    }
     
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
long int GCD(long int A, long int B){
  if(A < B) return GCD(B, A);
  if(B == 0) return A;
  else return GCD(B, A%B);
}  

int main() {
  int N, ans, left = 1;
  cin >> N ;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i] == left){
      left++;
    }  
  }  
  ans = N - left + 1;
  if(ans != N){
    cout << ans << endl;
  }
  if(ans == N){
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=(1e9)+7;
int n,k,tmp;
int dp[2][3000][55];
void update(int &x,int y) {
	x+=(ll)y*tmp%mod;
	if (x>=mod) x-=mod;
}
int main() {
	read(n); read(k);
	if (k&1) { printf("0\n"); return 0; }
	k/=2;
	dp[0][k][0]=1;
	for (int i=0;i<n;i++) {
		memset(dp[i&1^1],0,sizeof(dp[i&1^1]));
		for (int j=0;j<=i*(i+1)/2+k;j++)
		for (int l=0;l<=i;l++) {
			tmp=dp[i&1][j][l];
			if (j>=i) update(dp[i&1^1][j-i][l-1],l*l);
			update(dp[i&1^1][j+i][l+1],1);
			update(dp[i&1^1][j][l],l*2+1);
		}
	}
	printf("%d\n",dp[n&1][0][0]);
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 0; i + 2 < s.size(); i++)
	{
		if(s.substr(i, 3) == "ABC")
			ans++;
	}
	cout << ans;
	return 0;
}

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

using namespace std;

#define FOR(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 PB push_back
#define F first
#define S second

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

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

	int x, n; cin >> x >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	sort(all(v));

	int dif = 1e9, best = -1;
	for(int i = 0; i < 105; i++){
		if(binary_search(all(v), i)) continue;
		if(abs(x-i) < dif){
			dif = abs(x-i);
			best = i;
		}
	}

	cout << best << '\n';
	
	return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
using namespace std;
const int N =  1e2+5;
const int INF = 0x3f3f3f3f;
typedef long long LL;
char s[N];
int main(){
   scanf("%s",s+1);
   for(int i=1;i<=19;++i){
     if(s[i]==',')putchar(' ');
     else putchar(s[i]);
   }
   printf("\n");
   return 0;
}

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

using namespace std;

int main(){
    int n;
    int ans=0;
    cin>>n;
    
    for(int i=1;i<=n;i++) ans+=i;
    
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 256
//****** @author mdazmat9 **********
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
const ll size=1e6;
ll dp[size];
void solve() {
    ll n,k,r,s,p;cin>>n>>k>>r>>s>>p;
    string t;cin>>t;
    vector<char> dp(n);
    ll ans=0;
    for(ll i=0;i<n;i++){
        if(i<k){
            if(t[i]=='r'){
                ans+=p;
                dp[i]='p';
            }
            if(t[i]=='p'){
                ans+=s;
                dp[i]='s';
            }
            if(t[i]=='s'){
                ans+=r;
                dp[i]='r';
            }
        } else{
            if(t[i]=='r'){
                if(dp[i-k]!='p') {
                    ans += p;
                    dp[i] = 'p';
                } else dp[i]='-';
            }
            if(t[i]=='p'){
                if(dp[i-k]!='s') {
                    ans += s;
                    dp[i] = 's';
                } else dp[i]='-';
            }
            if(t[i]=='s'){
                if(dp[i-k]!='r') {
                    ans += r;
                    dp[i] = 'r';
                } else dp[i]='-';
            }
        }
    }
    cout<<ans;


}
int main()
{
    IOS;
    ll test=1;
   // cin>>test;
    while(test--){
        solve();
    }
    return 0;
}


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

int main() {
  string n;

  cin >> n;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '1') {
      n[i] = '9';
    } else if (n[i] == '9') {
      n[i] = '1';
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int N,dis[100010],par[100010],ok=1;

void init(){
	for(int i=0;i<=N;i++)par[i] = i;
}

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

void unit(int x,int y,int z){
	int px=find(x), py=find(y);
	if(px==py){
		if(abs(dis[x]-dis[y])!=z)ok=0;
	}else{
		par[py]=px;
		dis[py]=dis[x]+z-dis[y];
	}
}

int main(void){
	int M,i;
	scanf("%d%d",&N,&M);
	init();
	for(i=0;i<M;i++){
		int L,R,D;
		scanf("%d%d%d",&L,&R,&D);
		unit(L,R,D);
	}
	if(ok)printf("Yes");
	else printf("No");
	
	return 0;
}

Measured memory_bytes: 896
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;
 
#define M5 100007
 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
 
 
void solve() {
    string S;
    string pS;
    int Q;
    cin >> S >> Q;

    int rev = 0;
    REP(i,Q){
        int a;
        cin >> a;
        if(a == 1){
            rev++;
        } else{
            int f;
            char c;
            cin >> f >> c;
            if(rev%2==0){
                if(f==1){
                    pS.push_back(c);
                } else{
                    S += c;
                }
            } else{
                if(f==1){
                    S += c;
                }else{
                    pS.push_back(c);
                }
            }
        }
    }
    string ansS;
    REP(i,pS.size()){
        ansS.push_back(pS[pS.length()-i-1]);
    }
    ansS += S;

    if(rev%2==0){
            cout << ansS;
    } else{
            string ansS2;
            REP(i,ansS.length()){
                ansS2.push_back(ansS[ansS.length()-i-1]);
            }
            cout << ansS2;
        }

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

Measured memory_bytes: 1616
n = int(input())
def inserter(sp, splist) :
    if  splist == [] :
        return [sp]
    elif sp[0] < splist[0][0] :
        return [sp] + splist
    elif sp[0] == splist[0][0] :
        if int(sp[1]) > int(splist[0][1]) :
            return [sp] + splist
        else :
            return [splist[0]] + inserter(sp, splist[1:])
    else :
        return [splist[0]] + inserter(sp, splist[1:])
lst = []
for i in range(n) :
    s, p = input().split()
    lst = inserter([s, p, i+1], lst)
for j in lst :
    print(j[2])

Measured memory_bytes: 3064
#template
from collections import Counter
def inputlist(): return [int(i) for i in input().split()]
#template
M,D = inputlist()
count = 0
for m in range(1,M+1):
    for d in range(10,D+1):
        if d//10 < 2 or d%10 < 2:
            continue
        d10 = d//10
        d1 = d%10
        if d1*d10 == m:
            count+=1
print(count)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
const int N=1000005,mu=1000000007;
int inv[N],p[N],n,ans,last; 
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*1ll*x%mu)
		if (y&1) ans=1ll*ans*x%mu;
	return ans;
}
int C(int x,int y){
	return 1ll*p[x]*inv[y]%mu*inv[x-y]%mu;
}
int main(){
	scanf("%d",&n);
	if (n==2){
		puts("1");
		exit(0);
	} 
	if (n==3){
		puts("4");
		exit(0);
	}
	p[0]=1;
	for (int i=1;i<=n;i++) p[i]=1ll*i*p[i-1]%mu;
	inv[n]=ksm(p[n],mu-2);
	for (int i=n-1;i>=0;i--) inv[i]=inv[i+1]*1ll*(i+1)%mu;
	for (int i=(n+1)/2;i<=n-1;i++){
		int x=C(i-1,n-i-1)*1ll*p[i]%mu*p[n-i-1]%mu;
		ans=(ans+i*1ll*(x-last+mu)%mu)%mu;
		last=x;
	}
	printf("%d\n",ans);
}

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

int main(){
    long long n,c,k;
    cin >> n >> c >> k;
    long long t[n];
    for(int i=0;i<n;i++) cin >> t[i];
    sort(t,t+n);
    long long res=0,i=0;
    while(i<n){
        long long j=i;
        while(i<n&&i-j<c&&t[i]<=t[j]+k){
            i++;
        }
        res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
int cnt[13];
int used[25];
signed main(){
	int n;
	cin>>n;
	cnt[0]++;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		cnt[x]++;
	}
	if( cnt[0] >= 2 || cnt[12]>=2){
		cout<<0<<endl;
		return 0;
	}
	if(cnt[0]==1){
		used[0]++;
		used[24]++;
	}
	if(cnt[12]==1){
		used[12]++;
	}
	for(int i=1;i<=11;i++){
		if(cnt[i]>=3){
			cout<<0<<endl;
			return 0;
		}
	}
	vector<int> s;
	for(int i=1;i<=11;i++){
		if(cnt[i] == 2){
			used[i]=1;
			used[24-i]=1;
		}
		else if(cnt[i] == 1){
			s.pb(i);
		}
	}
	int ss = s.size();
	int ans = -1;
	for(int i=0;i<(1<<ss);i++){
		int cur = i;
		for(int j=0;j<ss;j++){
			if(cur%2==1){
				used[s[j]]=0;
				used[24-s[j]]=1;
			}
			else{
				used[s[j]]=1;
				used[24-s[j]]=0;
			}
			cur /= 2;
		}
		int tmp=24;
		vector<int> v;
		for(int j=0;j<=24;j++){
			if(used[j]==1){
				v.pb(j);
			}
		}
		for(int j=0;j<v.size()-1;j++){
			tmp = min(tmp, v[j+1]-v[j]);
		}
		if(ans<tmp){
			ans=tmp;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scanf("%s", &S)

	nZero := strings.Count(S, "0")
	nOne := strings.Count(S, "1")

	var ans int
	if nZero < nOne {
		ans = nZero
	} else {
		ans = nOne
	}

	fmt.Println(ans * 2)
}

Measured memory_bytes: 1280
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

y = [0 for i in range(m)]
for i in range(1, m):
    y[i] = x[i] - x[i-1]

y = sorted(y, reverse=True)

if n >= m:
    print(0)
else:
    print(sum(y[n-1:]))


Measured memory_bytes: 13960
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  string S; cin >> S;
  
  bool app[26];
  rep(i,26) app[i] = false;
  for (int i = 0; S[i] != '\0'; i++) {
    app[S[i] - 'a'] = true;
  }
  rep(i,26) {
    if (!app[i]) {
      printf("%c\n", (char)(i+'a'));
      return 0;
    }
  }
  puts("None");
  return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	ll N;
	vector<string> w;
	set<string> wSet;
	cin >> N;

	rep(i, 0, N){
		string temp;
		cin >> temp;
		w.push_back(temp);
		wSet.insert(temp);
	}
	if (w.size() != wSet.size()){
		cout << "No" << endl;
		return 0;
	}
	rep(i, 0, N - 1){
		if (w[i][w[i].size() - 1] != w[i + 1][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int A, B,C;
    cin >>A >> B >> C;
    int ans;
    if(A*C <= B){
        ans = C;
    }else{
        ans = (int)(B/A);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;

int main(){
    int n,i,k;
    string s;
    cin>> n>>k;
    cin>>s;

    int hantensuu = 0;
    rep(i,n-1){
        if(s[i] != s[i+1]) hantensuu++;
    }
    //cout << "hantensuu:" << hantensuu << endl;

    int ans = n - 1 - fmax(0,(hantensuu - 2*k));

    cout << ans << endl;
}

Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	m := make([]int, 2019)
	m[0] = 1
	ans := 0
	for i := 0; i < len(s); i++ {
		x, _ := strconv.Atoi(string(s[i]))
		y := make([]int, 2019)
		for j := 0; j < 2019; j++ {
			y[(j*10+x)%2019] += m[j]
		}
		copy(m, y)
		m[0]++
		ans += m[0] - 1
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		scanner.close();
		int plus = 0, minus = 0;

		for (int n = 0; n < S.length(); n++) {
			String s = S.substring(n, n + 1);
			if (s.equals("+")) {
				plus++;
			} else if (s.equals("-")) {
				minus++;
			}
		}
		int A = plus - minus;
		System.out.println(A);
	}
}

Measured memory_bytes: 21332