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

int main(){
	while(1){
		int m, f, r;
		cin >> m >> f >>r;
		if(m == -1 && f == -1 && r == -1){
			break;
		}

		if(m == -1 || f == -1 || m+f < 30){
			cout << 'F' << endl;
		}else if(m+f >= 80){
			cout << 'A' << endl;
		}else if(m+f >= 65){
			cout << 'B' << endl;
		}else if(m+f >= 50 || r >= 50){
			cout << 'C' << endl;
		}else{
			cout << 'D' << endl;
		}
	}

	return(0);
}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int abc[26] = {};
  while(getline(cin,s)){
    for(int i = 0;i < s.size();i++){
      if(s[i]>='a'&&s[i]<='z') abc[s[i]-'a']++;
      else if(s[i]>='A'&&s[i]<='Z') abc[s[i]-'A']++;
    }
  }
  for(int i = 0;i < 26;i++){
    cout << (char)('a'+i) << " : " << abc[i] << endl;
  }
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll x,a,b,c;
  cin >> a >> b >> c >> x;
  ll ans = 0;
  rep(i,a+1){
    rep(j,b+1){
      rep(k,c+1){
        if(500*i+100*j+50*k == x){
          ans++;
        }
      }
    }
  }
  cout << ans;
 return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

int N, C[SIZE];
vector<pair<int, int>> G[SIZE];

pair<ll, ll> dfs(int now, int back = -1) {
  pair<ll, ll> res = {0, 0};

  for (auto e : G[now]) {
    int to = e.first;
    if (back == to) continue;
    auto r = dfs(to, now);

    res.first += min(r.first, r.second + e.second);
    res.second += min(r.first, r.second);
  }

  if (C[now]) {
    res.second = min(res.first, res.second);
    res.first = INF;
  }

  return res;
}

int main() {
  scanf("%d", &N);

  for (int i = 1; i < N; i++) {
    scanf("%d", C + i);
  }

  for (int i = 0; i < N - 1; i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    G[x].push_back({y, c});
    G[y].push_back({x, c});
  }

  auto res = dfs(0);

  printf("%lld\n", res.first);

  return 0;
}


Measured memory_bytes: 7924
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut vs = vec![];
    let mut ws = vec![];
    for _ in 0 .. n {
        let x = get!();
        vs.push(x);
        ws.push(x);
    }
    vs.sort();
    vs.reverse();
    for i in 0 .. n {
        if ws[i] == vs[0] {
            println!("{}", vs[1]);
        } else {
            println!("{}", vs[0]);
        }
    }
    
}

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


int main(){
  int N;
  cin>>N;
 int sum =0;
  
  for(int i=0;i<N;i++){
    int X,Y;
    cin>>X>>Y;
    sum+=Y-X+1;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int sum[] = new int[n];

		for (int i = 1; i < n; i++) {
			if ("AC".equals(s.substring(i - 1, i + 1))) {
				sum[i] = sum[i - 1] + 1;
			} else {
				sum[i] = sum[i - 1];
			}
		}

		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();

			System.out.println(sum[r - 1] - sum[l - 1]);
		}

		sc.close();

	}

}


Measured memory_bytes: 64032
#include<iostream>
using namespace std;
int main(){
  int tmp;
  int N;
  int i;
  cin>>N;
  int a[N];
  for(i=0;i<N;i++){
  cin>>a[i];
  }
  for(int j=0;j<N-1;j++){
  for(i=0;i<N-1;i++) {
  if(a[i]>=a[i+1]){
    tmp=a[i];
    a[i]=a[i+1];
    a[i+1]=tmp;
  }
  }
  }
  cout<<a[N-1]-a[0]<<endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

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

	long double eps = 1.0e-14;

	if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

using namespace std;

typedef long long ll;

int main(){
	int L,R;
	cin >> L >> R;
	int l = L % 2019;
	if (R-L >= 2019 - l){
		cout << 0 << endl;
	}
	else{
		int ans = 2020;
		for (int i = l; i <= l+(R-L)-1; i++){
			for (int j = l+1 ; j <= l+(R-L); j++){
				ans = min(ans,(i*j)%2019);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <fstream>
#define N 500000+1
#define M 250000+1
using namespace std;

int L[M], R[M];

int Merge(int A[], int left, int mid, int right)
{

    int times = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    int i, j, k;
    for (i = 0; i < n1; i++)
    {
       L[i] = A[left+i];
    }
    for (i = 0; i < n2; i++)
    {
        R[i] = A[mid+i];
    }
    L[n1] = R[n2] = INT_MAX;
    i = j = 0;
    for (k = left; k < right; k++)
    {
        if (L[i] <= R[j])
            A[k] = L[i++];
        else
            A[k] = R[j++];
        times++;
    }
    return times;
}
int Merge_Sort(int A[], int left, int right)
{
    int mid;
    int cb_time = 0;
    if (left + 1 < right)
    {
        mid = (left+right)/2;
        cb_time += Merge_Sort(A, left, mid);
        cb_time += Merge_Sort(A, mid, right);
        cb_time += Merge(A, left, mid, right);
    }
    return cb_time;
}
int main()
{
    int i, n;
    int cb_times;
    int A[N];
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> A[i];
    cb_times = Merge_Sort(A, 0, n);

    for (i = 0; i < n; i++)
    {
        if (i)
            cout << " ";
        cout << A[i];
    }
    cout << endl << cb_times << endl;
    return 0;
}



Measured memory_bytes: 6884
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	map <int,int> mp;
	int n;
	cin>>n;
	bool f=1;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		mp[x]++;
		if(mp[x]>1)
			f=false;
	}
	printf("%s\n",f?"YES":"NO"); 
	return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,h,da=0;
string st;
int main()
{
	cin>>n;
	cin>>st;
	for(int i=0;i<st.size();i++)
	{
		if(st[i]=='I')h++;
		else h--;
		if(h>da)da=h;
	}
	cout<<da<<endl;
	return 0;
}

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

int waitTime[ 100 ];
const int NUM_SEATS = 17;

int isVacancy( int* seats, int n )
{
	int empties = 0;
	for( int i = 0; i < NUM_SEATS; ++i ){
		if( seats[ i ] <= 0 ){
			++empties;
			if( empties == n ){
				return i - n + 1;
			}
		}else{
			empties = 0;
		}
	}
	return -1;
}

void pass( int* seats, int* time )
{
	++*time;
	for( int i = 0; i < NUM_SEATS; ++i ){
		--seats[ i ];
	}
}

int main()
{
	int seats[ NUM_SEATS ];
	memset( seats, 0, sizeof(seats) );
	int time = 0;
	for( int i = 0; i < 100; ++i ){
		while( time < i * 5 ){
			pass( seats, &time );
		}
		int numPeople = i % 5 == 1 ? 5 : 2;
		int eatingTime = 17 * ( i % 2 ) + 3 * ( i % 3 ) + 19;
		int emptySeat = 0;
		while( ( emptySeat = isVacancy( seats, numPeople ) ) == -1 ){
			pass( seats, &time );
		}
		for( int j = emptySeat; j < numPeople + emptySeat; ++j ){
			seats[ j ] = eatingTime;
		}
		waitTime[ i ] = time - i * 5;
	}

	int input;
	while( cin >> input ){
		cout << waitTime[ input ] << endl;
	}


	return 0;
}

Measured memory_bytes: 1156
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

#N, K = [ int(x) for x in input().split() ]
#V = [ int(x) for x in input().split() ]

N = int(input())

print((N-2)*180)



Measured memory_bytes: 25064
class Dice(object):
    def __init__(self):
        self.number = [0 for _ in range(6)]
        self.before = [0 for _ in range(6)]

    def set_number(self, l):
        for i in range(6):
            self.number[i] = l[i]

    def roll(self, loc):
        d = {
            'N': (1, 5, 2, 3, 0, 4),
            'S': (4, 0, 2, 3, 5, 1),
            'E': (3, 1, 0, 5, 4, 2),
            'W': (2, 1, 5, 0, 4, 3)
        }
        for i in range(6):
            self.before[i] = self.number[i]

        for i, j in enumerate(d[loc]):
            self.number[i] = self.before[j]

    def roll_clockwise(self):
        for i in range(6):
            self.before[i] = self.number[i]
        self.number = [self.before[i] for i in (0, 2, 4, 1, 3, 5)]

    def set_Top_and_Front(self, top, front):
        top_index = self.number.index(top)
        if top_index == 5:
            self.roll('E')
            self.roll('E')
        elif top_index == 4:
            self.roll('S')
        elif top_index == 3:
            self.roll('E')
        elif top_index == 2:
            self.roll('W')
        elif top_index == 1:
            self.roll('N')
        front_index = self.number.index(front)
        if front_index == 1:
            pass
        elif front_index == 2:
            self.roll_clockwise()
        elif front_index == 3:
            self.roll_clockwise()
            self.roll_clockwise()
            self.roll_clockwise()
        elif front_index == 4:
            self.roll_clockwise()
            self.roll_clockwise()

    def get_Top(self):
        return self.number[0]

    def get_right(self):
        return self.number[2]


if __name__ == '__main__':
    l = list(map(int, input().split()))
    dice = Dice()
    dice.set_number(l)
    m = int(input())
    for _ in range(m):
        i, j = list(map(int, input().split()))
        dice.set_Top_and_Front(i, j)
        print(dice.get_right())



Measured memory_bytes: 5612
#define z 1000000
a[z],b[z],n,i=1,x,c;main(){for(;i++<z;)a[i]=i;for(i=-1;i++<z;)if(a[i])for(b[x++]=i,c=0;c<z;c+=i)a[c]=0;for(;~scanf("%d",&n);){c=0;while(b[c]<=n&&b[c])c++;printf("%d\n",c);}exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <random>
#include <math.h>
#include <algorithm>
#include <queue>
#define LL long long

using namespace std;

const int mod = 1e9+7;
const int maxn = 11234567;

int dp[1<<13];
int key[1123];
int a[1123];

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

    int t;
    int n, m, x, c;

    scanf("%d%d", &n, &m);

    for (int i = 0; i < m; ++i)
    {
        scanf("%d%d", &a[i], &x);
        key[i] = 0;
        while(x--)
        {
            scanf("%d", &c);
            key[i] |= (1<<(c-1));
        }
    }

    memset(dp, 0, sizeof(dp));

    int en = (1<<n)-1;
    for (int i = 0; i < en; ++i)
    {
        if (i != 0 && dp[i] == 0) continue;
        for (int j = 0; j < m; ++j)
        {
            int k = (i|key[j]);
            if (dp[k] == 0) dp[k] = dp[i] + a[j];
            else dp[k] = min(dp[i]+a[j], dp[k]);
        }
    }

    if (dp[en] == 0)puts("-1");
    else printf("%d\n", dp[en]);

    return 0;
}


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


int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m = -1;
    cin >> n;
    map <string,int> mp;
    string s;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        mp[s]++;
        if(m < mp[s])
            m = mp[s];
    }
    map<string, int> :: iterator it;
    for(it = mp.begin(); it != mp.end(); it++)
    {
        if(it->second == m)
        {
            cout << it->first << "\n";
        }
    }
}


Measured memory_bytes: 19240
h,w=map(int,input().split())
from collections import defaultdict
data=defaultdict(int)
for y in range(h):
    line=input()
    for x in range(w):
        if line[x]=='#':
            data[(y,x)]=-1
            for i in range(-1,2):
                for j in range(-1,2):
                    if data[(y+i,x+j)]!=-1:
                        data[(y+i,x+j)]+=1
for y in range(h):
    s=''
    for x in range(w):
        if data[(y,x)]==-1:s+='#'
        else:s+=str(data[(y,x)])
    print(s)

Measured memory_bytes: 3700
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>

#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Mabs(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define Abs(a) (a)>0?(a):(-(a))
template <typename QvQ> inline QvQ Min2(QvQ a,QvQ b){if(a<b) return a;return b;}
template <typename QvQ> inline QvQ Max2(QvQ a,QvQ b){if(a>b) return a;return b;}
template <typename QvQ> inline QvQ Abs2(QvQ a){if(a>0) return a;return -a;}

#define n1kw 10000000
#define inf 0x7f7f7f7f
#define dinf 0x3f3f3f3f
#define llinf 0x7f7f7f7f7f7f7f7f
#define lldinf 0x3f3f3f3f3f3f3f3f

#define ll long long
#define rei register int
#define inv inline void
#define inb inline bool
#define ini inline int

#define bl putchar(' ')
#define ed putchar('\n')
#define test std::cout<<"this:"
#define card system("pause")

#define read2(a,b) read(a),read(b)
#define write2(a,b) write(a),bl,write(b)
#define read3(a,b,c) read(a),read(b),read(c)
#define write3(a,b,c) write(a),bl,write(b),bl,write(c)

//char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

template <typename QvQ>inv read(QvQ &x)
{
    x=0;int f=1;
    char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
    x=x*f;
}
template <typename QvQ>inv write(QvQ x)
{
    if(x<0) x=-x,putchar('-');
    if(x>9) write(x/10);
    putchar(x%10+48);
}
using namespace std;
int n,a[100005],dqd;
priority_queue <int> q[100005];
int main()
{
    read(n);
    for(rei i=1;i<=n;++i) read(a[i]);
    q[++dqd].push(a[1]);
    for(rei i=2;i<=n;++i)
    {
    	if(a[i]<=q[dqd].top()) q[++dqd].push(a[i]);
    	else
    	{
    		int l=1,r=dqd,pos;
			while(l<=r)
			{
				int mid=(l+r)>>1;
				if(a[i]>q[mid].top()) pos=mid,r=mid-1;
				else l=mid+1;
			}
			q[pos].push(a[i]);
    	}
    }
    write(dqd);
    return 0;
}

Measured memory_bytes: 6912
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    using SPI = tuple<string, int, int>;
    vector<SPI> spi(n);
    rep(i, n){
        string S; int p; cin >> S >> p;
        spi[i] = SPI(S, -p, i);
    }
    sort(_all(spi));

    for(auto& e : spi){
        int i;
        tie(ignore, ignore, i) = e;
        cout << i + 1 << endl;
    }

    return 0;
}


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

int main(void) {
    int64_t X;
    int64_t a,b;

    cin >> X;

    a = X/500;
    b = (X-(a*500))/5;
    
    cout << a*1000 + b*5 << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){ 
	string a,b;
	int A,B;
	cin>>a>>b;
	A=a.size();
	B=b.size();
    if(A>B){
		cout<<"GREATER"<<endl;
		return 0;
	}
	else if(A<B){
		cout<<"LESS"<<endl;
		return 0;
	}
	for(int i=0;i<min(A,B);i++){
		if(a[i]>b[i]){
			cout<<"GREATER"<<endl;
			return 0;
		}
		else if(a[i]<b[i]){
			cout<<"LESS"<<endl;
			return 0;
		}
	}
	cout<<"EQUAL"<<endl;
	return 0;
}

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

int main() {
    int X, Y, a, b, c;
    cin >> X >> Y >> a >> b >> c;
    vector<int> P(a), Q(b);
    for(auto &e : P) cin >> e;
    for(auto &e : Q) cin >> e;
    priority_queue<int> que;
    for(int i = 0; i < c; ++i) {
        int r; cin >> r;
        que.push(r);
    }

    sort(P.begin(), P.end(), greater<int>());
    sort(Q.begin(), Q.end(), greater<int>());

    for(int i = 0; i < X; ++i) que.push(P[i]);
    for(int i = 0; i < Y; ++i) que.push(Q[i]);

    int64_t ans = 0;
    for(int i = 0; i < X + Y; ++i) {
        ans += que.top();
        que.pop();
    }

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


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int n,w;
ll w1;
vector< vector< ll > > item;
vector< vector< ll > > sum;

ll dfs(int m, ll now){
  if(m == 4)return 0;
  ll calc = 0;
  for(int i = 0;i < sum[m].size();++i){
    if((w1+m)*i > now)break;
    calc = max(calc,
               sum[m][i] + dfs(m+1, now - (w1+m)*i));
  }
  return calc;
}

int main(void){
  cin >> n >> w;
  item.resize(4);
  sum.resize(4);
  item.resize(4);
  ll ww,vv;
  cin >> ww >> vv;
  w1 = ww;
  item[0].push_back(vv);
  for(int i = 0;i < n-1;++i){
    cin >> ww >> vv;
    item[ww - w1].push_back(vv);
  }
  for(int i = 0;i < 4;++i){
    sort(item[i].begin(), item[i].end(),
         greater<ll>() );
  }
  for(int i = 0;i < 4;++i){
    ll calc = 0;
    sum[i].push_back(calc);
    for(int j = 0;j < (int)item[i].size();++j){
      calc += item[i][j];
      sum[i].push_back(calc);
    }
  }
  /*
  for(int i = 0;i < 4;++i){
    for(int j = 0;j < (int)sum[i].size();++j){
      cout << sum[i][j] << " "; 
    }
    cout << endl;
  }
  */
  cout << dfs(0,w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    
    if (a < b) cout << "a < b" << endl;
    else if (a > b) cout << "a > b" << endl;
    else cout << "a == b" << endl;
    
    return 0;
}


Measured memory_bytes: 3088
S = input()

from datetime import datetime as dt

ans = 0

#x = dt.strptime(S, "%Y%m")

try:
  x = dt.strptime("20"+S, "%Y%m")
  ans_s = "YYMM"
except:
  ans += 1
try:
  dt.strptime(S[:2] + "20" + S[2:], "%m%Y")
  ans_s = "MMYY"
except:
  ans += 1
  
if ans == 2:
  print("NA")
elif ans == 0:
  print("AMBIGUOUS")
else:
  print(ans_s)

Measured memory_bytes: 51820
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	map<char,int> mp;
	string f; cin>>f;
	rep(i,0,f.size()){
		mp[f[i]]++;
	}
	rep(i,0,n-1){
		string s; cin>>s;
		int m=s.size();
		map<char,int> cnt;
		rep(j,0,m){
			cnt[s[j]]++;
			//cout<<cnt[s[i]]<<" ";
		}
		//cout<<endl;
		for(auto &c:mp){
			c.second=min(c.second,cnt[c.first]);
		}
	}
	string ans;
	for(auto c:mp){
		//cout<<c.first<<" "<<c.second<<endl;
		rep(i,0,c.second){
			ans.push_back(c.first);
		}
	}
	sort(all(ans));
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
def get_prime_nums(max_p)
  primes = (0..max_p).map{true}
  primes[0] = primes[1] = false

  smp = Math::sqrt(0.5 + max_p).to_i

  for p in (2..smp)
    if (primes[p])
      (p * p).step(max_p, p){|q| primes[q] = false}
    end
  end

  #puts "#{primes.select{|p| p }.length} primes"

  return primes
end

### main

max_p = 110000
primes = get_prime_nums(max_p)

p_nums = (2..max_p).select{|p| primes[p]}

while true
  n = gets.chomp.to_i
  break if n == 0

  sum = 0
  for i in (0...n)
    sum += p_nums[i]
  end

  puts sum
end

Measured memory_bytes: 7120
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int x,y,z,t,d;
	cin>>x>>y>>z;
	d = x/y;
	while(1){
		t = d*y+(d+1)*z;
		if(t<=x) break;
		d--;
		}
	cout<<d<<nw;
	
	return 0;
}

Measured memory_bytes: 256
import fractions


def main():
    n = int(input())
    a = list(map(int, input().split()))

    lcm_temp = 1

    for i in range(n):
        lcm_temp = lcm(lcm_temp, a[i])

    lcm_temp -= 1

    sum = 0
    for i in a:
        sum += lcm_temp % i
    print(sum)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a*b // gcd(a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5688
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let bs = Array.init m @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let _ = for i = 0 to n - m do
  for j = 0 to n - m do
    let is_ok = ref true in
    for y = 0 to m - 1 do
      for x = 0 to m - 1 do if a_s.(i + y).[j + x] <> bs.(y).[x] then is_ok := false done done;
    if !is_ok then (print_endline "Yes"; exit 0) done done; print_endline "No"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){ return (int)s.size(); }

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> w(n+1),e(n+1);
    w[0] = 0; e[n] = 0;
    rep(i,n){
        w[i+1] = w[i];
        if(s[i] == 'W') w[i+1]++;
    }
    for(int i = n-1; i >= 0; i--){
        e[i] = e[i+1];
        if(s[i] == 'E') e[i]++;
    }
    int ans = 1e9;
    rep(i,n) ans = min(ans, w[i]+e[i+1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
	double a, h;

	while (cin >> a >> h)
	{
		if (a == 0 && h == 0) break;
		double b = a / 2;
		double x = sqrt(b * b + h * h);
		printf("%.6f\n", a * a + (a * x * 0.5) * 4);
	}
	return 0;
}


Measured memory_bytes: 3160
/*  ex3_3
    L40S38  */
#include<stdio.h>
int main(void){
    int n, k, r, digit;
    scanf("%d %d",&n, &k);
    //整数nをk進法で表す
    r=n;
    digit=0;
    while(r>0){
        //rはnをkでdigit回割ったときの商
        digit ++;
        r=r/k;
    }
    printf("%d",digit);
    return 0;
}    

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[200];
  cin>>n;
  for(int i=0;i<2*n;i++)cin>>a[i];
  sort(a,a+2*n);
  int ans=0;
  for(int i=0;i<n;i++)ans+=a[i*2];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from math import ceil
inputs = sys.stdin.readlines()

d, g = map(int, inputs[0].split())
P = list(map(int, map(lambda x: x.split()[0], inputs[1:])))
C = list(map(int, map(lambda x: x.split()[1], inputs[1:])))

ans = float('inf')
for bit in range(1 << d):
    count, total, rest = 0, 0, set(range(1, d+1))
    for i in range(d):
        if bit & (1 << i):
            total += P[i] * (i + 1) * 100 + C[i]
            count += P[i]
            rest.discard(i + 1)

    if total < g:
        use = max(rest)
        n = min(P[use-1], ceil((g - total) / (use * 100)))
        count += n
        total += n * use * 100
    if total >= g:
        ans = min(ans, count)
print(ans) 


Measured memory_bytes: 3188
#include <stdio.h>

int main () {
	char alp;
	scanf("%c", &alp);
	
	if(alp >='A' && alp <='Z') {
	printf("A\n");
	} 
	else if(alp >='a' && alp <='z') {
	printf("a\n");
	}
	return 0;
}

Measured memory_bytes: 1580
n=int(input())
a=list(map(int,input().split()))
ans=1000
kabu=0
direct=0

for i in range(n-1):
  #print(i,ans,kabu)
  if a[i+1] > a[i] and direct <= 0:
    kabu = ans // a[i]
    ans %= a[i]
    direct = 1
    # 次が下→上の切り替え時に買う
  elif a[i+1] < a[i] and direct >= 0:
    # 上→下の切り替え時に売る
    ans += kabu*a[i]
    kabu = 0
    direct = -1
ans += kabu*a[-1]
print(ans)

Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int n, a[50],p=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i;j++) {
            p += a[i] * a[j];
        }
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
int main()
{
int N;
std::string S;
int K;
 
std::cin >> N;
std::cin >> S;
std::cin >> K;
 
for (int i = 0; i < N; ++i){
    if (S[i] == S[K - 1]) {
       std::cout << S[K - 1] ;
       } else {
       std::cout << "*";
       }
}
 
return 0;
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

#define int int64_t
//int a[N+2];
int v[100];
int pref[100]={0};
int suff[100]={0};
int32_t  main(){
  IOS;
  int n,KK;cin>>n>>KK;
  fori(i,n)cin>>v[i];
  memset(pref,0,sizeof(pref));
  memset(suff,0,sizeof(suff));
  for(int i=1;i<=n;++i)pref[i]=v[i]+pref[i-1];
  for(int i=n;i>=1;--i)suff[i]=v[i]+suff[i+1];
  //total operations is i+j+k 
  int ans=0;
  int K=KK;
  for(int i=0;i<=K;++i){
    for(int j=0;j<=K;++j){
      for(int k=0;k<=K;++k){
        if(i+j+k<=K && i<n-j+1 ){
                    //cout<<i<<" "<<j<<" "<<k<<" i,j,k\n";
          //prefix sum of i 
          //suffix sum of j 
          //remove k neg elements 
          int pf=pref[i];
          int sf=suff[n-j+1];
          //pick negative least elements 
          priority_queue<int>pq;
          for(int x=1;x<=i;++x){
            if(v[x]<0)pq.push(-v[x]);
          }
          for(int x=n-j+1;x<=n;++x){
            if(v[x]<0)pq.push(-v[x]);
          }
          //pick top k ;
          int kol=k;
          int sum=0;
          while(kol-- && pq.size()>0){
            sum+=pq.top();
            pq.pop();
          }
          sum*=-1;
          int val=pf+sf-sum;
                      //cout<<val<<" val\n";
          ans=max(ans,pf+sf-sum);
        }
      }

    }
  }
  cout<<ans<<endl;

  return 0;
}



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

using namespace std;

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v; stringstream ss(s); string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}
#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n, k; cin >> n >> k;
	vector<int> a(n);
	REPU(i, 0, n) cin >> a[i];

	int ans = n;
	REPU(i, 0, n) {
		if (a[i] == 1) {
			for (int j = max(0, i - k + 1); j < min(i + k, n); ++j) {
				int res = (n - j + k - 3) / (k - 1) + (j + k - 2) / (k - 1);
				amin(ans, res);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		if(K > 1) {
			System.out.println(N - (K - 1) - 1);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 22612
#include <stdio.h>

int main() {
  int A,B;
  int sum = 0;
  
  scanf ("%d %d",&A,&B);
  
  for (int i = 0; i < 2; ++i) {
    if (A >= B) {
      sum += A;
      A--;
    }
    else {
      sum += B;
      B--;
    }
  }
  
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int odp = 0;
    if (n <= k)
        odp = n * x;
    else
        odp = k * x + (n - k) * y;
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  long long h, w;
  
  cin >> h >> w;
  
  long long movable_count = 0;
  
  movable_count += (h / 2 * 2) * (w / 2 * 2) / 2;
  
  if(h == 1 || w == 1){
    cout << 1 << endl;
    return 0;
  }
  
  if(h % 2 == 1){
    movable_count += (w + 1) / 2;
  }
  if(w % 2 == 1){
    movable_count += (h + 1) / 2;
    if(h % 2 == 1){
      movable_count -= 1;
    }
  }
  
  cout << movable_count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
  ll N;
  ll x;
  cin >> N;
  ll minNum = 1e16;
  for(int i=0; i<5; i++){
    cin >> x;
    minNum = min(minNum, x);
  }
  ll ans = 4 + (N+minNum-1)/minNum;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        // O(n) time and space
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        char[] numbers = in.next().toCharArray();

        long result = 0;
        long moder = 1;
        long prev = 0;
        HashMap<Integer, Integer> seen = new HashMap<>();
        seen.put(0, 1);
        for (int i = numbers.length - 1; i >= 0; i--) {
            long num = (moder * (numbers[i] - '0') + prev) % 2019;
            if (seen.containsKey((int) num)) result += seen.get((int) num);
            seen.merge((int) num, 1, Integer::sum);
            prev = num;
            moder = (moder * 10) % 2019;
        }
        out.println(result);

        out.close();
    }



    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

using namespace std;
int top, S[1000];

void push(int x) {
	S[++top] = x;
	return;
}

int pop() {
	top--;
	return S[top + 1];
}

int main(void) {
	int a, b;
	top = 0;
	char s[100];
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return 0;
}

Measured memory_bytes: 2712
from collections import defaultdict

n, m = map(int, input().split())

ans = 0
i = 1
while i * i <= m:
    if m % i == 0:
        a, b = i, m // i
        if b >= n:
            ans = max(ans, a)
        if a >= n:
            ans = max(ans, b)
    i += 1
print(ans)


Measured memory_bytes: 9460
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1005;
const int mod=1e9+7;

int h,w,a,b;
signed main(){
    FastIO;
    cin>>h>>w>>a>>b;
    rep(i,1,h){
        rep(j,1,w){
            cout<<((i<=b)^(j<=a));
        }
        cout<<'\n';
    }
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<long long> a(n+1);
  
  if(n == 0){
  	cout << 2 << endl;
  }
  else if(n== 1){
  	cout << 1 << endl;
  }
  else{
  	a.at(0) = 2;
  	a.at(1) = 1;
  	for(int i = 2; i < n+1; i++){
    	a.at(i) = a.at(i-1)+a.at(i-2);
    }
    cout << a.at(n) << endl;
  }
}

Measured memory_bytes: 256
# coding: utf-8
for i in range(int(input())):
    data = input()
    d_set = set()
    for i in range(len(data)-1):
        str1 = data[ 0 : i+1 ]
        str2 = data[ i+1 : len(data) ]
        d_set.add(str1+str2)
        d_set.add(str1+str2[::-1])
        d_set.add(str1[::-1]+str2)
        d_set.add(str1[::-1]+str2[::-1])
        
        d_set.add(str2+str1)
        d_set.add(str2+str1[::-1])
        d_set.add(str2[::-1]+str1)
        d_set.add(str2[::-1]+str1[::-1])
    print(len(d_set))

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

int cmpnum(const int *n1, const int *n2)
{
  if(*n1 > *n2){
    return 1;
  }else if(*n1 < *n2){
    return -1;
  }else{
    return 0;
  }
}

int main()
{
  
  int n,temp;
  int count = 1;
  scanf("%d",&n);

  int d[n];
  for(int i=0; i<n; i++){
    scanf("%d",&d[i]);
  }

  qsort(d,n,sizeof(int),cmpnum);

  for(int i=1; i<n; i++){
    if(d[i-1]<d[i]){
      count ++;
    }
  }

  printf("%d",count);

}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <map>
#include <cstring>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

void solve_D_re(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    int a = 0;

    int len = s.size();
    string s_1 = s.substr(0, len/2);
    string s_2 = s.substr(len/2, len);

    reverse(s_1.begin(), s_1.end());

    REP(i,q){
        int num;
        cin >> num;
        if(num == 1){
            a++;
        } else{
            int f;
            char c;
            cin >> f >> c;
            if((f + a) % 2 == 1){
                s_1 += c;
            } else{
                s_2 += c;
            }
        }
    }

    reverse(s_1.begin(), s_1.end());
    string ans = s_1 + s_2;
    if(a % 2 == 1) reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main(void){
    solve_D_re();
    
    return 0;
}

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

#define MAX_N 105

int N, A, B, C, D, S[MAX_N + 1];

int main()
{
	scanf("%d", &N);

	for (int i = 0; i < (N * N - N) / 2; i++)
	{
		scanf("%d", &A);
		scanf("%d", &B);
		scanf("%d", &C);
		scanf("%d", &D);

		if (C > D) { S[A] += 3; }
		if (C < D) { S[B] += 3; }
		if (C == D) { S[A] += 1; S[B] += 1; }
	}

	int rank;

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

		for (int j = 1; j <= N; j++)
		{
			if (S[i] < S[j]) { rank += 1; }
		}

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

	return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
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(){
    ll x;cin>>x;
    if(x>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define INF 1000000000000000000
int n,k,a[114514],b[114514],c[114514],ans;
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,n){
		b[i]=a[i];
		if(i)b[i]+=b[i-1];
		c[i]=max(0ll,a[i]);
		if(i)c[i]+=c[i-1];
	}
	ans=max(ans,max(0ll,b[k-1])+c[n-1]-c[k-1]);
	rep(i,n){
		if(i+k>=n)break;
		int x=max(0ll,b[i+k]-b[i]);
		int y=c[n-1]-(c[i+k]-c[i]);
		ans=max(ans,x+y);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 346589
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x,y;
	int now=0;
	for(fint i=1;i<=n;i++)
	{
		cin>>x>>y;
		if(x==y)
		now++;
		else
		now=0;
		if(now>=3)
		return cout<<"Yes",0;
	}
	return cout<<"No",0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<math.h>
#include<limits.h>
#define MAX 100000


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


int main(){
 int n,q,i,com,j,sum;
 int x,y;
 int A[MAX];
 int B[MAX];
 int b,L,R;

 scanf("%d %d",&n,&q);
 b=floor(sqrt(n));

 for(i=0;i<n;i++){
   A[i]=0;
   B[i]=0;
 }


 for(i=0;i<q;i++){

   scanf("%d %d %d",&com,&x,&y);

   if(com==0){/*add*/
     A[x]+=y;
     B[x/b]+=y;
   }

   else if(com==1){/*getsum*/
     if(x==y)printf("%d\n",A[x]);

     else{
       L=x/b; R=y/b; sum=0;
       if(L==R){
         for(j=x;j<=y;j++)sum+=A[j];
         printf("%d\n",sum);
       }else{
         for(j=x;j<(L+1)*b;j++)sum+=A[j];
         for(j=L+1;j<R;j++)sum+=B[j];
         for(j=R*b;j<=y;j++)sum+=A[j];
         printf("%d\n",sum);
       }
     }

   }

 }


return 0;
}


Measured memory_bytes: 2620
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, c;
  cin >> a >> b >> c;
  int t1 = min(a, c);
  c -= t1;
  int t2 = min(b, c);
  c -= t2;
  b -= t2;
  cout << t1 + t2 * 2 + b + (c > 0) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define scl(n) scanf("%lld", &n)
#define pcl(n) printf("%lld\n", n)
#define pcl1(n) printf("%lld ", n)
#define nln printf("\n")
#define dev(x) cout << #x << " " << x << " ";
#define PTT pair<ll, ll>

map<ll, ll> mp, mp1;
map<ll, ll>::iterator itr;

int main()
{
    ll n, x;
    string s, t;
    cin >> s;
    cin >> t;
    ll cnt = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] != t[i])
        {
            cnt++;
        }
    }
    pcl(cnt);
    return 0;
}

Measured memory_bytes: 3836
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 800005
#define ll long long
int tar[N], nex[N], fir[N], cnt = 1;
int n, rt1, rt2, deg[N], ans[N], vis[N];
void Read(int &p)
{
	p = 0;
	int f = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar())f |= (c == '-');
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
	if (f)p = -p;
}
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void Dfs(int r)
{
	for (int &t = fir[r]; t; t = nex[t])
	{
		if (vis[t])continue;
		int v = tar[t];
		vis[t] = vis[t ^ 1] = 1;
		Dfs(v);
		if (r > 2 * n || v > 2 * n)
			continue;
		if (r + n == v)
			ans[r] = 1;
		if (v + n == r)
			ans[v] = -1;
	}
}
int main()
{
	Read(n);
	for (int i = 1; i <= n; i++)
	{
		int x;
		Read(x);
		deg[i] ^= 1;
		if (x != -1)
		{
			Add(x, i), Add(i, x);
			deg[x] ^= 1;
		}
		else
			Add(2 * n + 1, i), Add(i, 2 * n + 1);
	}
	for (int i = 1; i <= n; i++)
	{
		int x;
		Read(x);
		deg[n + i] ^= 1;
		if (x != -1)
		{
			Add(n + x, n + i), Add(n + i, n + x);
			deg[n + x] ^= 1;
		}
		else
			Add(2 * n + 1, n + i), Add(n + i, 2 * n + 1);
	}
	for (int i = 1; i <= n; i++)
	{
		if (deg[i] != deg[n + i])
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	puts("POSSIBLE");
	for (int i = 1; i <= n; i++)
		if (deg[i])
			Add(i, n + i), Add(n + i, i);
	Dfs(2 * n + 1);
	for (int i = 1; i <= n; i++)
		printf("%d%c", ans[i], i == n ? 10 : 32);
}
//

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

ll MODNum = 1000000007;
using namespace std;

int main (void) {
    string s;
    cin >> s;
    vector<vector<ll>> dp(s.size(), vector<ll>(13, 0));
    if ( s[0] != '?' ){
        dp[0][s[0] - '0'] = 1;
    }
    else{
        for ( int i = 0; i < 10; i++ ) dp[0][i] = 1;
    }

    for ( int k = 0; k < s.size() - 1; k++ ){
        if ( s[k+1] ==  '?' ){
            for ( int i = 0; i < 13; i++ ){
                for ( int j = 0; j < 10; j++){
                    dp[k+1][(i*10%13+j)%13] += dp[k][i];
                    dp[k+1][(i*10%13+j)%13] %= MODNum;
                    //cout << dp[k+1][(i*10%13+j)%13] << endl;
                }
            }
        }
        else{
            for ( int i = 0; i < 13; i++ ){
                dp[k+1][(i*10%13+(s[k+1] - '0'))%13] += dp[k][i];
                dp[k+1][(i*10%13+(s[k+1] - '0'))%13] %= MODNum;
            }
        }
    }
    cout << dp[s.size()-1][5] << endl;
    return 0;
}


Measured memory_bytes: 13696