akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <algorithm>
#include <cstring>
#include<queue>
#include <stack>
#include<map>
#include<vector>
#include <math.h>
using namespace std;
#define ll long long

int a[10005],b[10005];      //10005
int main(){
    int h,n;
    cin>>h>>n;
    int maxn=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        maxn=max(maxn,a[i]);
    }
    int dp[20005];     //
    memset(dp, 1e9+7, sizeof(dp));
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=a[i];j<h+maxn;j++){
            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    int minn=1e9+7;
    for(int i=h;i<h+maxn;i++){
        minn=min(minn,dp[i]);
    }
    cout<<minn<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl "\n"
#define int long long 
#define test int qt;cin>>qt;while (qt--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
int mod = 1e9 + 7;
vector<int>adj[100005];
vector<bool>vis(100000,false);
void dfs(int node) {
	vis[node] = true;
	for(auto i : adj[node]) {
		if(!vis[i])
			dfs(i);
	}
}
int32_t main()
{
    IOS;
	int n,m;cin>>n>>m;
	FOR(m){
		int x,y;cin>>x>>y;
		x--;y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int count = 0;
	FOR(n){
		if(!vis[i]){
			dfs(i);
			count++;
		}
	}
	cout<<count-1;
    return 0;
}

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

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

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

		int N = sc.nextInt();
		int[] a = nextIntArray(sc, N);

		sc.close();

		long[] left = new long[N];

		left[0] = a[0];
		for (int i = 1; i < N; i++) {
			left[i] = left[i - 1] + a[i];
		}

		long[] right = new long[N];
		right[N - 1] = a[N - 1];
		for (int i = N - 2; i >= 0; i--) {
			right[i] = a[i] + right[i + 1];
		}

		long ans = Long.MAX_VALUE;

		for (int i = 0; i < N - 1; i++) {
			ans = Math.min(ans, Math.abs(left[i] - right[i + 1]));
		}

		out.println(ans);

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 81324
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i & 1) {
			int a = i;
			vi v;
			for (int j = 2; j <= i; ++j) {
				if (a%j == 0) {
					int tmp = 0;
					while (a%j == 0) {
						a /= j;
						tmp++;
					}
					v.push_back(tmp);
				}
			}
			int t = 1;
			REP(i, v.size())t *= v[i] + 1;
			if (t == 8)ans++;
		}
	}
	cout << ans << endl;
}

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

int main() {
	int n, l;
	cin >> n >> l;
	int a = l * n + n * (n - 1) / 2;
	if (l > 0) a -= l;
	if (l + n < 1) a -= l + n - 1;
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
import sys;sys.setrecursionlimit(10**9)
class Union_Find():
  def __init__(self,n):self.n,self.r=[-1]*n,[0]*n
  def Find_Root(self,x):
    if self.n[x]<0:return x
    else:self.n[x]=self.Find_Root(self.n[x]);return self.n[x]
  def Unite(self,x,y):
    x,y=self.Find_Root(x),self.Find_Root(y)
    if x==y:return
    elif self.r[x]>self.r[y]:self.n[x]+=self.n[y];self.n[y]=x
    else:self.n[y]+=self.n[x];self.n[x]=y;self.r[y]+=self.r[x]==self.r[y]
  def isRootSame(self,x,y):return self.Find_Root(x)==self.Find_Root(y)
  def Count(self,x):return -self.n[self.Find_Root(x)]
u=Union_Find(m)
l=[list(map(int,input().split()))for _ in range(n)]
for i in range(n):
  for j in range(1,len(l[i])-1):u.Unite(l[i][j]-1,l[i][j+1]-1)
for i in range(n-1):
  if not(u.isRootSame(l[i][1]-1,l[i+1][1]-1)):print("NO");exit()
print("YES")

Measured memory_bytes: 25740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


int k, x;

int main(){
  cin >> k>> x;
  for(int i = x - k + 1; i <= x + k - 1; i++) printf("%d ", i);
  cout << endl;
}

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

string name[9];
int am[9];
int pm[9];
int sumapm[9];
int money[9];

int main(){
	for(int i=0;i<9;i++){
		cin>>name[i]>>am[i]>>pm[i];
		}
		
		for(int i=0;i<9;i++){
			sumapm[i]=am[i]+pm[i];
			}
		for(int i=0;i<9;i++){
			money[i]=am[i]*200+(pm[i]*300);
			}	
			
		for(int i=0;i<9;i++){
			cout<<name[i]<<" "<<sumapm[i]<<" "<<money[i]<<endl;
			}	
			return 0;
	}

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

using namespace std;

typedef long long ll;

int main()
{
	int A, B;
	cin >> A >> B;

	if(A > 8 || B > 8) cout << ":(" << endl;
	else cout << "Yay!" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
    int i,j,k,x,res=0;
    cin>>n;
   int dp[n][3];
   int day[n][3];
    for(i=0;i<n;i++)
    {
        for(j=0;j<3;j++)
        {
           cin>>day[i][j];
        }
    }
    dp[n-1][0]=day[n-1][0];
    dp[n-1][1]=day[n-1][1];
    dp[n-1][2]=day[n-1][2];
    for(i=n-2;i>=0;i--)
    {
        for(j=0;j<3;j++)
        {
            if(j==0)
            {
                dp[i][j]=day[i][j]+ max(dp[i+1][1],dp[i+1][2]);
            }
            else if(j==1)
            {
               dp[i][j]=day[i][j]+ max(dp[i+1][0],dp[i+1][2]);
            }
            else
            {
                dp[i][j]=day[i][j]+ max(dp[i+1][1],dp[i+1][0]);
            }
        }
    }
    res=max(dp[0][0],dp[0][1]);
    res=max(res,dp[0][2]);
    cout<<res<<endl;

}


Measured memory_bytes: 2560
T = bytearray(input().encode())

if T[0] == b'?'[0]:
  T[0] = b'P'[0] if len(T) > 1 and T[1] != b'P'[0] else b'D'[0]

for i, (old, c, new) in enumerate(zip(T, T[1:], T[2:]), start=1):
  if c == b'?'[0]:
    T[i] = b'D'[0] if new == b'P'[0] or old == b'P'[0] else b'P'[0]

if T[-1] == b'?'[0]:
  T[-1] = b'D'[0]
  
print(T.decode())

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

// flagを用いたバブルソート
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for ( int i = 0; flag; i++ ) {
    flag = 0;
    for ( int j = N - 1; j >= i + 1; j--) {
      if ( A[j] < A[j-1] ) {
        //隣接要素を交換する
        swap(A[j],A[j-1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for ( int i = 0; i < N; i++ ) cin >> A[i];

  sw = bubbleSort(A, N);

  for ( int i = 0; i < N; i++ ) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



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

int main() {
  int N;
  cin>>N;
  vector<double> d(N);
  for(int i=0; i<N; i++){
    cin>>d.at(i);
  }
  cout << fixed << setprecision(6);
  double ans = 0;
  for(int i=0; i<N; i++){
    ans += 1/d.at(i);
  }
  cout<<1/ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,ptr,res;
    int A[100000];
    
    cin >> n;
    for(int i = 0;i < n;i++)
    cin >> A[i];
    sort(A,A+n);
    while(ptr < n){
        int cc = A[ptr],f = 0;
        while(ptr < n && A[ptr] == cc){
            f++;
            ptr++;
        }
        res += f % 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
#define ND 2000000
void push(int);
int cxn,cyn,u[MN+5];
ll ans,R,x[MN+5],y[MN+5],cx[MN+5],cy[MN+5];
struct segtree
{
	struct node{int l,r,s,u;}t[ND+5];
	int rt[MN+5],tn;
	void ins(int&k,int l,int r,int x,int z)
	{
		if(!k)k=++tn;
		++t[k].s;t[k].u|=z;
		if(l==r)return;
		int mid=l+r>>1;
		if(x<=mid)ins(t[k].l,l,mid,x,z);
		else ins(t[k].r,mid+1,r,x,z);
	}
	void solve(int k,int l,int r)
	{
		if(!t[k].u)return;
		if(l==r&&!u[t[k].u])push(t[k].u);
		t[k].u=0;
		int mid=l+r>>1;
		if(l<r)solve(t[k].l,l,mid),solve(t[k].r,mid+1,r);
	}
	int query(int k,int l,int r,int ql,int qr)
	{
		if(l==ql&&r==qr){solve(k,l,r);return t[k].s;}
		int mid=l+r>>1,res;
		if(qr<=mid)res=query(t[k].l,l,mid,ql,qr);
		else if(ql>mid)res=query(t[k].r,mid+1,r,ql,qr);
		else res=query(t[k].l,l,mid,ql,mid)+query(t[k].r,mid+1,r,mid+1,qr);
		t[k].u=t[t[k].l].u|t[t[k].r].u;
		return res;
	}
}A,B;
inline int getx(ll x){return lower_bound(cx+1,cx+cxn+1,x)-cx;}
inline int gety(ll y){return lower_bound(cy+1,cy+cyn+1,y)-cy;}
void push(int v)
{
	int xl,xr,yl,yr;u[v]=1;
	xl=getx(x[v]-R);xr=getx(x[v]+R);
	yl=gety(y[v]-R);yr=gety(y[v]+R+1)-1;
	if(xl<=cxn&&cx[xl]==x[v]-R&&yl<=yr)ans+=A.query(A.rt[xl],1,cyn,yl,yr);
	if(xr<=cxn&&cx[xr]==x[v]+R&&yl<=yr)ans+=A.query(A.rt[xr],1,cyn,yl,yr);
	if(xl<=cxn&&cx[xl]==x[v]-R)++xl;--xr;
	if(yl<=cyn&&cy[yl]==y[v]-R&&xl<=xr)ans+=B.query(B.rt[yl],1,cxn,xl,xr);
	if(yr<=cyn&&cy[yr]==y[v]+R&&xl<=xr)ans+=B.query(B.rt[yr],1,cxn,xl,xr);
}
int main()
{
	int n,a,b,i,X,Y;
	n=read();a=read();b=read();
	for(i=1;i<=n;++i)
	{
		x[i]=read();y[i]=read();
		cx[i]=x[i]+=y[i];cy[i]=y[i]=x[i]-y[i]-y[i];
	}
	R=max(abs(x[a]-x[b]),abs(y[a]-y[b]));
	sort(cx+1,cx+n+1);cxn=unique(cx+1,cx+n+1)-cx-1;
	sort(cy+1,cy+n+1);cyn=unique(cy+1,cy+n+1)-cy-1;
	for(i=1;i<=n;++i)
	{
		X=getx(x[i]);Y=gety(y[i]);
		A.ins(A.rt[X],1,cyn,Y,i);
		B.ins(B.rt[Y],1,cxn,X,i);
	}
	push(a);
	cout<<ans/2;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
	ll cost;
};
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll x, y;
/******* define variable end *******/
int solve() {
	cin >> x >> y;
	bool flag = false;
	for(ll i = 0; i <= x; i++){
		if(i * 2 + (x-i) * 4 == y){
			flag = true;
		}
	}
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long ll;
using std::cout ;
using std::endl ;
using std::cin ;
using std::string ;
using std::vector ;
using std::pair ;
#define rep(i,n) for(int i=0, i##_end=(n); i<i##_end; i++)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
template<class T>bool updatemMax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool updateMin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif


int main()
{
    int N, M;
    cin >> N >> M;
    
    rep(i, M) {
        int A;
        cin >> A;
        N -= A;
        if(N < 0) {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << N << endl;
    return 0;
}


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


#define fs first
#define sc second

using namespace std;

int ab(int x){
    if(x > 0){
        return x;
    }
    else{
        return -x;
    }
}


int main(){
    int n;
    int w[110];
    cin >> n;
    int s = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i];
        s += w[i];
    }

    int t = 0;
    int res = s;
    for(int i = 0; i < n; i++){
        s -= w[i];
        t += w[i];
        res = min(res, ab(s-t));
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 
 
 
 
int main() {
    int r;
    cin >> r;
    cout << r*r << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	void run() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int t = sc.nextInt();
			long sum = t;
			int pre = sc.nextInt();
			for(int i=1;i<n;i++) {
				int now = sc.nextInt();
				sum += Math.min(t, now-pre);
				pre = now;
			}
			System.out.println(sum);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
}


Measured memory_bytes: 61792
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split(' ');
    var a = Number(inputs[0]);
    var b = Number(inputs[1]);
    var c = Number(inputs[2]);
    if (a < b && b < c) {
        console.log('Yes');
    } else {
        console.log('No');
    }
 
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 15444
#include<bits/stdc++.h>
using namespace std;
int main(){
	int k,x;
	cin>>k>>x;
	vector<int> ans;
	for(int i=x-k+1;i<=x+k-1;i++){
		ans.push_back(i);
	} 
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		if(i==0)
			cout << ans[i];
		else
			cout<<" "<<ans[i];
	} 
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
  
int A[2000000];
int B[2000000];
  
void Counting_Sort(int k){
  int i,j;
  int C[10001];
  for(i=0;i<10001;i++)C[i]=0;
  for(j=0;j<k;j++)C[A[j]]++;
  for(i=1;i<10001;i++)C[i]+=C[i-1];  
  for(j=k-1;j>=0;j--){
    C[A[j]]--;
    B[C[A[j]]]=A[j];
  }
}
  
int main(){
  int n,i;
   
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  Counting_Sort(n);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 18352
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
	int to;
	T cost;
	Edge() {};
	Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
	int n;
	bool directed;
	vector<vector<Edge<T>>> edges;
public:

	Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)) {};
	Graph() {};

	void add(int to, T cost) {
		emplace_back(to, cost);
	}

	int size() {
		return n;
	}
};


int main() {

	int N, X, Y;

	cin >> N >> X >> Y;

	int d;
	vi k(N - 1);

	REP(i, N - 1)k[i] = 0;

	X--;
	Y--;

	REP(i, N-1) {
		FOR(j, i + 1, N) {
			d = min(abs(j - i),abs(X - i) + 1 + abs(Y - j));
			k[--d]++;
		}
	}

	REP(i, N - 1) {
		cout << k[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
r = S.count('R')
g = S.count('G')
b = S.count('B')
c = 0
for i in range(N-2):
  for j in range(i+1,(i+N+1)//2):
    k = j*2-i
    if len(set([S[i], S[j], S[k]]))==3:
      c += 1
print(r*g*b-c)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define F first
#define S second
using ll = long long;
const ll mod = 1000000007;
const ll infi = 1000000000000000;
const ll md = 998244353;
using namespace std;
using vl = vector<ll>;
using pll =  pair<ll,ll>;

void  solve(){
    int n,sum;
    cin>>n;
    vector<pair<string ,int>> a(n);
    string s;
    for(int i=0;i<n;i++){
        cin>>a[i].F>>a[i].S;
    }
    cin>>s;
    int f=1,i;
    sum =0;
    for(i=0;i<n;i++) if(a[i].F==s) break;
  i++;
    for(;i<n;i++){
        sum += a[i].S;
    }
    cout<<sum;
}
        
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // int n; cin>>n; for(int i=0;i<n;i++)
        solve();
    return 0;
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    unordered_map<long long, int> mp;
    for (int i = 0; i < n; i++) {
        long long k; cin >> k;
        if (mp[k] == 1) {
            mp[k]--;
        } else {
            mp[k]++;
        }
    }
    int cnt = 0;
    for (auto x : mp) {
        if (x.second == 1) cnt++;
    }
    cout << cnt << '\n';
    return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

int solve(int N, int C, int K, vi& T) {
    sort(ALL(T));

    int ans = 0;
    int onb = 0, tw = -1;
    rep(i,N){
        if (T[i] <= tw) {
            ++onb;
        } else {
            // tw < T[i]
            if (onb > 0) {
                ++ans;
                // printf("[onboard=%d, at %d?]\n", onb, tw);
                onb = 0; tw = -1;
            }
            onb = 1; tw = T[i]+K;
        }
        if (onb == C) {
            ++ans;
            // printf("[onboard=%d, at %d]\n", onb, tw);
            onb = 0; tw = -1;
        }
    }
    if (onb > 0) {
        ++ans;
        // printf("[onboard=%d, at %d]\n", onb, tw);
    }

    return ans;
}

int main() {
    int N,C,K; cin >> N>>C>>K; // 2-1e5, 1-1e9, 1-1e9
    vi T(N); // 1-1e9
    rep(i,N) cin>>T[i];
    cout << solve(N,C,K,T) << endl;
    return 0;
}


Measured memory_bytes: 640
def cda(N, x, s, count):
    if N > 0 and x < s[0]:
        return count
    if N == 0:
        if x > 0:
            return count - 1
        else:
            return count
    else:
        return cda(N - 1, x - s[0], s[1:], count + 1)

def agc027a():
    N, x = (int(s) for s in input().split(" "))
    a = [int(s) for s in input().split(" ")]
    answer = cda(N, x, sorted(a), 0)
    print(answer)

def main():
    agc027a()

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int   N=1e2+10,M=1e5+10;
long long f[N][M],w[N],v[N];
int main()
{
	long long n,m;
	cin>>n>>m;
	for(int  i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
	}
	for(int i=0;i<=n;i++)
		for(int j=0;j<=M;j++)f[i][j]=1e9+1;
	f[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=M;j++)
		{
			f[i][j]=min(w[i],f[i-1][j]);
			if(j>v[i])f[i][j]=min(f[i-1][j],f[i-1][j-v[i]]+w[i]);

		}
	}
	long long ans=0;
	for(long long  j=1;j<=M;j++)
		if(f[n][j]<=m)ans=max(ans,j);
	cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 82484
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int[] values = new int[n];
			for (int i = 0; i < n; i++)
			{
				values[i] = sc.nextInt();
			}
			int[] costs = new int[n];
			for (int i = 0; i < n; i++)
			{
				costs[i] = sc.nextInt();
			}
			int sum = 0;
			for (int i = 0; i < n; i++)
			{
				if(values[i] >= costs[i])
				{
					int value = values[i] - costs[i];
					sum += value;
				}else
				{
				}
			}
			System.out.println(sum);
		}
	}


Measured memory_bytes: 23764
#include <stdio.h>                                                                                                                                                                                                                
#include <string.h>                                                                                                                                                                                                               
#include <stdlib.h>                                                                                                                                                                                                               
                                                                                                                                                                                                                                  
int main(void)                                                                                                                                                                                                                    
{                                                                                                                                                                                                                                 
        char str[101] = { 0 };                                                                                                                                                                                                    
        int len;                                                                                                                                                                                                                  
                                                                                                                                                                                                                                  
        scanf("%s", str);                                                                                                                                                                                                                                                                                                
        len = strlen(str);                                                                                                                                                                                                        
        printf("%c%d%c\n", str[0], len - 2, str[len - 1]);                                                                                                                                                                        
        return 0;                                                                                                                                                                                                                 
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni(), W = in.ni();
            int[] w = new int[n];
            int[] v = new int[n];
            for (int i = 0; i < n; i++) {
                w[i] = in.ni();
                v[i] = in.ni();
            }
            long[][] dp = new long[n + 1][W + 1];
            for (int i = 0; i < n; i++) {
                for (int ww = 0; ww < W; ww++) {
                    dp[i + 1][ww] = Math.max(dp[i + 1][ww], dp[i][ww]);
                    if (ww + w[i] <= W)
                        dp[i + 1][ww + w[i]] = Math.max(dp[i + 1][ww + w[i]], dp[i][ww] + v[i]);
                }
            }
            long max = 0;
            for (int ww = 0; ww <= W; ww++) {
                max = Math.max(max, dp[n][ww]);
            }
            out.println(max);

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



Measured memory_bytes: 126548
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
#pragma endregion

int main()
{
  init_main();

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, n - 1) a[i + 1] += a[i];
  vector<ll> b = a;
  // +-+-
  ll lazy = 0;
  ll sum = 0;
  rep(i, n)
  {
    a[i] += lazy;
    if (i % 2 == 0 && a[i] <= 0)
    {
      // +
      lazy += 1 - a[i];
      sum += 1 - a[i];
    }
    else if (i % 2 == 1 && a[i] >= 0)
    {
      // -
      lazy -= a[i] - (-1);
      sum += a[i] - (-1);
    }
  }

  ll Min = sum;

  // -+-+
  a = b;
  lazy = 0;
  sum = 0;
  rep(i, n)
  {
    a[i] += lazy;
    if (i % 2 == 1 && a[i] <= 0)
    {
      // +
      lazy += 1 - a[i];
      sum += 1 - a[i];
    }
    else if (i % 2 == 0 && a[i] >= 0)
    {
      // -
      lazy -= a[i] - (-1);
      sum += a[i] - (-1);
    }
  }

  chmin(Min, sum);
  cout << Min << "\n";
  return 0;
}


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


int main() {
  int id, num;
  map<int,int> m;
  vector<int> v;
  while(1) {
    scanf("%d,%d", &id, &num);
    if(id|num) ; else break;
    m[id] = num;
    v.push_back(-num);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  while(scanf("%d", &id) != EOF) {
    cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
#define ll long long int
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 (b<a) { a = b; return 1; } return 0; }
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    string s;
    ll cnt;
    while (cin >> s, s[0] != '#')
    {
        cnt = 0;
        rep(i, s.size()-1)
        {
            if (s[i] == 'q' || s[i] == 'w' || s[i] == 'e' || s[i] == 'r' || s[i] == 't' || s[i] == 'a' || s[i] == 's' || s[i] == 'd' || s[i] == 'f' || s[i] == 'g' || s[i] == 'z' || s[i] == 'x' || s[i] == 'x' || s[i] == 'c' || s[i] == 'v' || s[i] =='b'){
                if (!(s[i+1] == 'q' || s[i+1] == 'w' || s[i+1] == 'e' || s[i+1] == 'r' || s[i+1] == 't' || s[i+1] == 'a' || s[i+1] == 's' || s[i+1] == 'd' || s[i+1] == 'f' || s[i+1] == 'g' || s[i+1] == 'z' || s[i+1] == 'x' || s[i+1] == 'x' || s[i+1] == 'c' || s[i+1] == 'v' || s[i+1] == 'b'))
                    cnt++;
                    }

            else{
                if (s[i + 1] == 'q' || s[i + 1] == 'w' || s[i + 1] == 'e' || s[i + 1] == 'r' || s[i + 1] == 't' || s[i + 1] == 'a' || s[i + 1] == 's' || s[i + 1] == 'd' || s[i + 1] == 'f' || s[i + 1] == 'g' || s[i + 1] == 'z' || s[i + 1] == 'x' || s[i + 1] == 'x' || s[i + 1] == 'c' || s[i + 1] == 'v' || s[i + 1] == 'b')
                    cnt++;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;

int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	string s;
 	cin >> s;
 	if(s=="SUN") cout << 7 << '\n';
 	else if(s=="MON") cout << 6 << '\n';
 	else if(s=="TUE") cout << 5 << '\n';
 	else if(s=="WED") cout << 4 << '\n';
 	else if(s=="THU") cout << 3 << '\n';
 	else if(s=="FRI") cout << 2 << '\n';
 	else cout << 1 << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int div;
		int cnt = 0;

		for(div = a; div <= b; div++) {

			if(c%div == 0){

				cnt++;

			} else {}
		}
		sc.close();
		System.out.println(cnt);
	}

}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,ss,sss;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s>>ss>>sss;
      cout<<"A"<<ss[0]<<"C"<<"\n";
     

       
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b){
            int c = sc.nextInt();
            if(b<c){
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 26192
using System;
class c
{
    static void Main()
    {
        var ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int a = ab[0], b = ab[1];
        for (int i = 0; i < 2000; i++)
        {
            if ((int)(i * 0.08) == a && (int)(i * 0.1) == b)
            {
                Console.WriteLine(i);
                break;
            }
            if (i == 1999) Console.WriteLine(-1);
        }
    }
}

Measured memory_bytes: 27388
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  long N,M;
  cin>>N>>M;

  long A,B;
  A=min(N,M);
  B=max(N,M);

  if(A==1&&B==1){
    cout<<1<<endl;
    return 0;
  }

  if(A==1){
    cout<<B-2<<endl;
    return 0;
  }

  if(A==2){
    cout<<0<<endl;
    return 0;
  }

  cout<<(A-2)*(B-2)<<endl;

}

Measured memory_bytes: 256
import math
 
n, a, b = map(int, input().split())
 
sum_all = 0
for i in range(1, n + 1):
    sum_n = 0
    m = i
    while(m > 0):
        sum_n += math.floor(m % 10)
        m /= 10
    if a <= sum_n <= b:
        sum_all += i
 
print(sum_all)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stack>

using namespace std;

#define MAX_N (100000+1)
#define MOD (1000000007)

int cannot_step[MAX_N] = {0};
long long num_path[MAX_N] = {0};


long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

int main(void){
    int n, m;
    int impossible = 0;
    stack<int> index_stack;

    for(int i=0; i<MAX_N; ++i){
        num_path[i] = -1;
    }

    scanf("%d %d", &n, &m);
    for(int i=0; i<m; ++i){
        int a;
        scanf("%d", &a);
        cannot_step[a] = 1;
        if(cannot_step[a] == cannot_step[a-1] == 1){
            impossible = 1;
        }
    }
    if(impossible){
        printf("0\n");
        return 0;
    }

    num_path[0] = 1;
    num_path[1] = 1;

    index_stack.push(n);
    while(index_stack.empty() == 0){
        int index = index_stack.top();
        if(index<0){
            // 範囲外のため解決不要
            index_stack.pop();
            continue;
        }
        if(num_path[index] != -1){
            // 解決済み
            index_stack.pop();
            continue;
        }
        if(num_path[index-1] == -1 && cannot_step[index-1] == 0){
            // 解決必要
            index_stack.push(index-1);
        }
        if(num_path[index-2] == -1 && cannot_step[index-2] == 0){
            // 解決必要
            index_stack.push(index-2);
        }
        long long ans = 0;
        if((num_path[index-1] != -1 || cannot_step[index-1]) && (num_path[index-2] != -1 || cannot_step[index-2])){
            // 解決
            if(cannot_step[index-1] == 0){
                ans += num_path[index-1];
                ans = mod(ans, MOD);
            }
            if(cannot_step[index-2] == 0){
                ans += num_path[index-2];
                ans = mod(ans, MOD);
            }
            num_path[index] = ans;
            index_stack.pop();
        }
    }
    printf("%lld\n", num_path[n]);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for (int i = 1; i <= d; i++) {
        for (int j = 1; j <= m; j++) {
            if (i % 10 >= 2 && i / 10 >= 2 && (i % 10) * (i / 10) == j) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int ah,bh;
		int as=0,bs=0;
		int[] as_a=new int[10000];
		int[] bs_a=new int[10000];
		int i=0;
		try{
			while(true){
				int n=sc.nextInt();
				if(n==0) break;
				for(int j=0;j<n;j++){
					ah=sc.nextInt();
					bh=sc.nextInt();
					if(ah>bh) as+=ah+bh;
					else if(ah<bh) bs+=ah+bh;
					else {as+=ah;bs+=bh;}
				}
				as_a[i]=as;bs_a[i++]=bs;
				as=0;bs=0;
			}
			sc.close();
			for(int j=0;j<i;j++){
				System.out.println(as_a[j]+" "+bs_a[j]);
			}
		}catch(Exception e){
			System.out.println("Error");
		}
	}
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

int main() {
  string s;

  int n;

  cin >> s;
  cin >> n;

  deque<string> v(1000000);
  v.push_back(s);
  int re = 0;
  rep(i, n) {
    int a;
    cin >> a;
    if (a == 1) {
      re++;
      continue;
    } else {
      int b;
      string c;

      cin >> b >> c;

      if (re % 2 == 1) {
        if (b == 1) {
          v.push_back(c);
        } else {
          v.push_front(c);
        }
      } else {
        if (b == 1) {
          v.push_front(c);
        } else {
          v.push_back(c);
        }
      }
    }
  }
  string ans;
  for (string kk : v) {
    ans += kk;
  }
  if (re % 2 == 1) {
    reverse(all(ans));
  }

  cout << ans << endl;
}

Measured memory_bytes: 20320
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long int ll;

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(){

    }

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

int N,Q;
string S;

BIT bit[27];

int main(){
    cin>>N;
    cin>>S;
    cin>>Q;
    for(int i=0;i<27;++i)bit[i]=BIT(N+1);
    for(int i=0;i<N;++i){
        int c=S[i]-'a';
        bit[c].add(i+1,1);
    }
    for(int i=0;i<Q;++i){
        int q;
        cin>>q;
        if(q==1){
            int iq;
            char cq;
            cin>>iq>>cq;
            iq--;
            if(S[iq]==cq)continue;
            bit[S[iq]-'a'].add(iq+1,-1);
            bit[cq-'a'].add(iq+1,1);
            S[iq]=cq;
        }
        else {
            int l,r;
            cin>>l>>r;
            int v=0;
            for(int j=0;j<27;++j){
                int x=bit[j].sum(r)-bit[j].sum(l-1);
                if(x>0)v++;
            }
            cout<<v<<endl;
        }
    }
}

Measured memory_bytes: 53764
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	char a, b;
	cin >> a >> b;
	if (a == b)cout << 'H';
	else cout << 'D';
}

Measured memory_bytes: 256
import sys

def main():
    n,x,d=map(int,input().split())
    events_map={}
    if d==0:
        if x== 0:
            print(1)
        else:
            print(n+1)
        return
    for k in range(n+1):
        l=(k*x if d > 0 else -k*x)+(k-1)*k//2*abs(d)
        r=(k*x if d > 0 else -k*x)+(n-k+n-1)*k//2*abs(d)
        row=l%abs(d)
        if row not in events_map:
            events_map[row]=[]
        events_map[row].append((l,-1))
        events_map[row].append((r,1))
    ans=0
    for q in events_map.items():
        events=q[1]
        events.sort()
        bal=0
        total=0
        curL=-1
        for event in events:
            if bal==0 and event[1]==-1:
                curL=event[0]
            if bal==1 and event[1] ==1:
                curr=event[0]
                total+=(curr-curL)//abs(d)+1
            bal -= event[1]
        ans+=total
    print(ans)

main()


Measured memory_bytes: 87892
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int h, w;
	int a,b;
	cin >> h >> w >> a >> b;
	cout << (h -a) * (w - b) << endl;
}


Measured memory_bytes: 256