akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

vector<pair<string, int>> r;

int ind[101];

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

    for (int i = 1; i <= n; i++)
    {
        string s;
        int p;
        cin >> s >> p;
        ind[p] = i;
        r.push_back(make_pair(s, p * -1));
    }

    sort(r.begin(), r.end());

    for (auto e : r)
    {
        cout << ind[-1 * e.second] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
(N, Y) = map(int, input().split(" "))

ans = '-1 -1 -1'
for x in range(0, N+1):
    y = (Y / 1000 - 9 * x - N) / 4
    if 0 <= y <= N:
        if y.is_integer():
            y = int(y)
            z = N - x - y
            if 0 <= z <= N:
                ans = " ".join([str(x), str(y), str(z)])
                break
print(ans)


Measured memory_bytes: 38768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (int i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": ";
    printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N;
  cin >> N;
  vector<ll> P(N);
  rep(i, N) {
    cin >> P[i];
  }
  //printvec(P);

  vector<ll> Q(N);
  rep(i, N) {
    Q[P[i]-1] = i+1;
  }
  //printvec(Q);

  // We search the longuest continueous increasing seqneunces
  ll c = 0;
  for (int i = 0, j = 0; i < N; i = j) {
    j = i + 1;
    while (Q[j] > Q[j-1]) { ++j; }
    if (c < j-i) { c = j - i; }
  }

  cout << N - c << endl;
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {

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

		int N = sc.nextInt(), D = sc.nextInt(), c = 0;

		for(int i = 0; i < N; i++) {
			long X = sc.nextInt(), Y = sc.nextInt();
			if(D >= Math.sqrt(X * X + Y * Y)) c++;
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 59496
N,C = map(int,input().split())
tvs = [list(map(int,input().split())) for _ in range(N)]
chans = [[] for _ in range(C+1)]
tvs.sort(key=lambda x:x[0])
targets = []
times = [0]*(pow(10,5)+2)

for tv in tvs:
  chans[tv[2]].append([tv[0],tv[1]])

for chan in chans:
  tmp = []
  if len(chan) == 1:
    targets.append(chan[0])
    continue
  for x in range(len(chan)):
    if len(tmp) == 0:
      tmp = chan[x]
      continue
    if chan[x][0] <= tmp[1] + 1:
      tmp[1] = chan[x][1]
      if x == len(chan)-1:
        targets.append(tmp)
    else:
      targets.append(tmp)
      tmp = chan[x]

for target in targets:
  times[target[0]] += 1
  times[target[1]+1] += -1

for j in range(1,pow(10,5)+2):
  times[j] += times[j-1]

print(max(times))

Measured memory_bytes: 37128
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
int dp[1000][2][4];
signed main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    dp[0][1][1]=(s[0]>0);
    dp[0][1][0]=0;
    dp[0][0][1]=max(0,s[0]-'1');
    dp[0][0][0]=1;
    FOR(i,1,n) {
        if(s[i]=='0') {
            dp[i][1][0]=dp[i-1][1][0];
            dp[i][1][1]=dp[i-1][1][1];
            dp[i][1][2]=dp[i-1][1][2];
            dp[i][1][3]=dp[i-1][1][3];

            dp[i][0][0]=dp[i-1][0][0];
            dp[i][0][1]=dp[i-1][0][1]+dp[i-1][0][0]*9;
            dp[i][0][2]=dp[i-1][0][2]+dp[i-1][0][1]*9;
            dp[i][0][3]=dp[i-1][0][3]+dp[i-1][0][2]*9;
        } else {
            dp[i][1][0]=0;
            dp[i][1][1]=dp[i-1][1][0];
            dp[i][1][2]=dp[i-1][1][1];
            dp[i][1][3]=dp[i-1][1][2];

            dp[i][0][0]=dp[i-1][0][0]+dp[i-1][1][0];
            dp[i][0][1]=dp[i-1][0][1]+dp[i-1][0][0]*9+dp[i-1][1][1]+dp[i-1][1][0]*(s[i]-'1');
            dp[i][0][2]=dp[i-1][0][2]+dp[i-1][0][1]*9+dp[i-1][1][2]+dp[i-1][1][1]*(s[i]-'1');
            dp[i][0][3]=dp[i-1][0][3]+dp[i-1][0][2]*9+dp[i-1][1][3]+dp[i-1][1][2]*(s[i]-'1');
        }
    }
    cout << dp[n-1][0][k]+dp[n-1][1][k] << endl;
    return 0;
}



Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll d;
ll dp[10001][2][100];
ll rohan(ll p,ll c,ll s,string &g)
{
    if(p==g.size())return (s%d==0);
    if(dp[p][c][s]!=-1)return dp[p][c][s];
    ll k=9;
    if(c==0)k=g[p]-'0';
    ll ans=0;
    for(ll i=0;i<=k;i++)
    {
        ll m=1;
        if(i==k)m=c;
        ans=(ans+rohan(p+1,m,(s+i)%d,g))%mod;
    }
    return dp[p][c][s]=ans;
}
int main()
{
    fast;
    ll t,n,m,i,j,k;
    string s;
    cin>>s;
    cin>>d;
    mms(dp,-1);
    ll ans=rohan(0,0,0,s);
    ans=(ans-1+mod)%mod;
    cout<<ans;
}


Measured memory_bytes: 16768
#include<stdio.h>
#include<string.h>
 
#define N 1000
 
char A[N+1],B[N+1];
  

  
int Max(int a,int b){
  if(a>=b) return a;
  else return b;
}
int main(){
  int k,a,i,j,m,n,max,c[N+1][N+1];
  scanf("%d",&a);
  for(k=0;k<a;k++){
    scanf("%s",A);
    scanf("%s",B);
    max=0;
     m=strlen(A);
  n=strlen(B);
  for(i=1;i<=m;i++) c[i][0]=0;
  for(j=1;j<=n;j++) c[0][j]=0;
  
  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      if(A[i-1]==B[j-1]) c[i][j]=c[i-1][j-1] + 1;
      else if(c[i-1][j]>=c[i][j-1]) c[i][j]=c[i-1][j];
      else c[i][j]=c[i][j-1];
      max=Max(max,c[i][j]);
    }
  }
    printf("%d\n",max);
  }
  
  return 0;
}



Measured memory_bytes: 6480
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c>
問題文============================================================
 りんごさんは N 頂点 の連結な無向グラフを持っています。
 このグラフにはすでに M 本の辺があり、i 本目の辺は頂点 Ai と頂点 Bi を繋いでいます。
 
 りんごさんは以下の操作を行うことで、辺を追加しようと思っています。
 
 操作：頂点 u から辺をちょうど 3 本辿ることによって頂点 v に辿り着けるような u,v(u≠v) をとり、
 頂点 u と頂点 v の間に辺を追加する。
 ただし、すでに頂点 u と頂点 v の間に辺が存在する場合は辺を追加することはできない。
 りんごさんが追加できる辺の本数の最大値を求めて下さい。

=================================================================

解説=============================================================

================================================================
*/
ll N,M;
vector<vector<ll>> G;
vector<int> checked; // 1 : l / 2 : r
set<ll> l,r;

bool check(ll n,bool f){
    if(f){
        if(checked[n] == 1) return false;
        if(checked[n] == 2) return true;
        checked[n] = 1;
        for(auto &v:G[n]){
            if(check(v,false)) return true;
            l.insert(v);
        }
    }else{
        if(checked[n] == 2) return false;
        if(checked[n] == 1) return true;
        checked[n] = 2;
        for(auto &v:G[n]){
            if(check(v,true)) return true;
            r.insert(v);
        }
    }
    return false;
}

ll solve(){
    ll ret = 0;
    cin >> N >> M;
    G.resize(N); checked.resize(N);
    for(int i = 0; i < M;i++){
        ll A,B; cin >> A >> B; A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    bool f = check(0,true);
    if(f) ret =  (N*(N-1)/2) - M;
    else ret = l.size()*r.size() - M;
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


//initialization here
//
int n, ma, mb;
int a[50], b[50], c[50];
int dp[50];
//
//initialization finish


// your function is here
//

//
// your function finished



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

	// your code is here
	//

	int n; cin >> n;

	int count = 0;
	int idx[maxn];
	memset(idx, 0, sizeof idx);
	rep(i, n)
	{
		int a;
		cin >> a;
		if (idx[a] > 0) count++;
		idx[a]++;
	}
	if (count % 2 == 1)count++;

	Print(n - count);

	//
	// your code finished
	return 0;
}

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

int n;
int cnt[300000];
int arr[300000];

int cont(int x)
{
	return cnt[x] * (cnt[x] - 1) / 2;
}

int32_t main()
{
	scanf(" %lld", &n);
	for(int i = 0; i < n; i++)
		scanf(" %lld", &arr[i]), cnt[arr[i]]++;
	
	int ans = 0;
	
	for(int i = 0; i <= n; i++)
		if(cnt[i] > 1)
			ans += cont( i );

	for(int i = 0; i < n; i++)
	{
		ans -= cont( arr[i] );
		cnt[arr[i]]--;
		ans += cont(arr[i]);
		printf("%lld\n", ans);
		ans -= cont(arr[i]);
		cnt[arr[i]]++;
		ans += cont( arr[i] );
	}
	
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int MAX_N = 100010;
vector<int> adj[MAX_N*2];
bool visited[MAX_N*2] = {};

VL cnt;

void dfs(int v){
    if(visited[v] == 1) return;
    visited[v] = 1;
    cnt[v/MAX_N]++;

    for(int p : adj[v]){
        dfs(p);
    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    REP(i,N){
        int x,y; cin >> x >> y;
        y += MAX_N;
        adj[x].eb(y);
        adj[y].eb(x);
    }
    LL ans = 0;
    for(int i = 0; i < MAX_N*2; i++){
        if(visited[i] == 1) continue;
        cnt = VL(2,0);
        dfs(i);
        ans += cnt[0] * cnt[1];
    }
    cout << ans - N << endl;


}

Measured memory_bytes: 10240
#include <stdio.h>

void print(int A[], int n) {
    for (int i = 0; i < n; i++) {
        printf("%d", A[i]);
        if (i == n - 1) {
            printf("\n");
        } else {
            printf(" ");
        }
    }
}

// why it works?
void rec(int A[], int n, int i) {
    if (i == n) {
        print(A, n);
        return;
    }
    A[i] = 0;
    rec(A, n, i + 1);
    A[i] = 1;
    rec(A, n, i + 1);
}

bool solve(int A[], int n, int i, int x) {
    if (x == 0) {
        return true;
    }
    if (i == n) {
        return false;
    }
    return solve(A, n, i + 1, x) || solve(A, n, i + 1, x - A[i]);
}

int main() {
    int A[2010], n, q, x;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &x);
        if (solve(A, n, 0, x)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2604
D = [[],[0,0,1,-1],[0,-1,0,1],[0,1,-1,0]]
E = map(str, [3,1,2])
while True:
    d = []
    try:
        d = [int(raw_input()) for _ in xrange(5)]
    except:
        break
    h = set(d)
    print "\n".join(E[sum(D[dd][hh] for hh in h)] for dd in d)

Measured memory_bytes: 4224
import java.util.*;

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

    if( A == 1  ){
      A = A + 13;
    }
    if( B == 1  ){
      B = B + 13;
    }

    if(A > B ){
      System.out.println("Alice");
    }else if(A == B){
      System.out.println("Draw");
    }else {
      System.out.println("Bob");
    }
  }
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << (a - b)*(k % 2 ? -1 : 1);
	return 0;
}

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

struct T
{
  vector<int> to;
  int used;
};

#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))

vector<int> vs;
void dfs(vector<T>& p, int v)
{
  if (p[v].used)
    return;
  p[v].used = 1;
  for (int u : p[v].to) {
    dfs(p, u);
  }
  vs.push_back(v);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, M;
  cin >> N >> M;
  vector<T> p(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    p[x].to.push_back(y);
  }
  // for (int i = 0; i < N; i++) {
  //   dump(i);
  //   dumpv(p[i].to);
  // }
  for (int i = 0; i < N; i++) {
    dfs(p, i);
  }
  // dumpv(vs);
  vector<int> dp(N);
  int ans = 0;
  for (int v : vs) {
    for (int u : p[v].to) {
      maxs(dp[v], dp[u] + 1);
    }
    maxs(ans, dp[v]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9464
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
double p[3000];

double dp[3000][3000];

double solve() {
    dp[0][0] = 1.0;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = dp[i-1][0] * (1-p[i-1]);
        for (int j = 1; j <= i; j++) {
            dp[i][j] = dp[i-1][j] * (1-p[i-1]) + dp[i-1][j-1] * p[i-1];
        }
    }
    double res = 0;
    for (int i = n/2+1; i <= n; i++) res += dp[n][i];
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> p[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 68992
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    double m[1000];
    double high, low;
    int i = 0;

    while(cin >> m[i++]){
        ;
    }
    sort(m, m+i-1);
    high = m[i-2];
    low = m[0];
    cout << high - low << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num[] = new int[3];
		int b = 1;
		num[0] = sc.nextInt();
		num[1] = sc.nextInt();
		num[2] = sc.nextInt();
		Arrays.sort(num);
		for(int a:num) {
			if(b != 3) {
				System.out.print(a + " ");
			}else {
				System.out.println(a);
			}
			b++;
		}
	}
}


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

      
const long long  mod=1000000007;
long long int powmod(long long int x,long long int y){
    long long int ans=1;
    for(int i=0;i<y;i++){
        ans=ans*x%mod;
    }
    return ans;
}
int main(){
 long long int n;
 cin>>n;
 long long int res=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
  res%=mod;
  res=(res+mod)%mod;
  cout<<res<<endl;
  return 0;
    
}

Measured memory_bytes: 3628
#include <iostream>

 using namespace std;
 typedef long long ll;

 int main(void){
 ll H,W;
 cin >> H >> W;
 if(H==1 || W==1)
 {
 cout<<1;
 return 0;}
 cout << (H * W + 1) / 2 << endl;

 return 0;
 }


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

void reverse(string &s){
	for(int i=0; i < (int)s.size()/2; i++){
		swap(s[i], s[s.size()-i-1]);
	}
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
		string s;
		cin>>s;
		
		string p;
		string en = "", de = ""; 
//		queue<char> Q;
//		for(char c : s) Q.push(c);
		int q;
		cin>>q;
		int f,t;
		int rev = 0;
		while(q--){
			cin>>f;
			if(f==1) rev++;
			else{
				cin>>t;
				cin>>p;
				if((t==1 && rev%2==0) || (t==2 && rev%2)){
					de+=p;
				}
				else if((t==1 && rev%2) || (t==2 && rev%2==0)){
//					s = s+p;
					en+=p;
				}
			}
		}
		reverse(de);
		string res = de+s+en;
		if(rev%2) reverse(res);
		cout<<res;
	return 0;
}

Measured memory_bytes: 1300
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

// まだ使用していない、使用中、使用しおわった
int dp[100010][3];
signed main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
    }

    dp[1][0] = dp[1][1] = 1;
    for(int i=1; i<N; i++) {
        {
            // ### 使用していない状態 ###

            // 今回も使用しない
            dp[i+1][0] = max(dp[i+1][0], (A[i-1] != A[i] ? dp[i][0] + 1 : 1));

            // 今回から使用する
            dp[i+1][1] = max(dp[i+1][1], (A[i-1] == A[i] ? dp[i][0] + 1 : 1));
        }
        {
            // ### 使用中の状態 ###

            // 今回も使用する
            dp[i+1][1] = max(dp[i+1][1], (A[i-1] != A[i] ? dp[i][1] + 1 : 1));

            // ここから使用をやめる
            dp[i+1][2] = max(dp[i+1][2], (A[i-1] == A[i] ? dp[i][1] + 1 : 1));
        }
        {
            // ### 使用しおわった状態 ###

            // 使用しないことしかできない
            dp[i+1][2] = max(dp[i+1][2], (A[i-1] != A[i] ? dp[i][2] + 1 : 1));
        }
    }

    int ans = 0;
    for(int i=0; i<=N; i++) {
        for(int j=0; j<3; j++) {
            // fprintf(stderr, "dp[%lld][%lld] = %lld\n", i, j, dp[i][j]);
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6004
import java.util.*;
 
public class Main{
	public static void main(String[]args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int x = scan.nextInt();
      	int[] l = new int[n];
      	int[] d = new int[n+1];
      	d[0] = 0;
      	for(int i = 0; i<n; i++){
        	l[i] = scan.nextInt();
        }
      	int counter = 1;
      	for(int i = 0; i < n;i++){
        	if(d[i] + l[i] <= x){
            	counter++;
            }
          	
          	d[i+1] = d[i] + l[i];
          	
        }
      	System.out.print(counter);
    
    }
 
}

Measured memory_bytes: 21460
module Main where
import Data.List
import qualified Data.Vector.Unboxed as V

main :: IO()
main = do    
  n <- (read <$> getLine) :: IO Int
  a <- (fmap read <$> words <$> getLine) :: IO [Int]
  let l = V.fromList $ scanl' gcd 0 a
  let r = V.fromList $ reverse $ scanl' gcd 0 (reverse a)
 
  --print $ foldl max 0 $
  --  fmap (\i-> gcd (l V.! i) (r V.! (i+1))) [0..(n-1)]
        
  --print $ maximum $
  --  zipWith gcd l r

  print $ foldr max 0 $
     [ gcd (l V.! i) (r V.! (i + 1)) | i <- [0 .. ((fromIntegral n) - 1)] ]


Measured memory_bytes: 84348
#include<stdio.h>
int main(void)
{
	int H,R,a;
	scanf("%d %d",&H,&R);
	a=-1*R;
	if(H>=0){
		printf("%d\n",1);
	}
	else if(a==H){
		printf("%d\n",0);
	}
	else{
		printf("%d\n",-1);
	}
	return 0;
}


Measured memory_bytes: 2712
#include<stdio.h>

//アルファベットは +_３２でアスキーコード内で大文字小文字の変換ができる

int main() {
    //変数の宣言
    char hako[1200];
    int i=0, j; //処理用
    
    //入力（エンターで終わり
    while (1) {
        scanf("%c", &hako[i]);
        if (hako[i] == '\n') {
            break;
        }
        i++; //カウンター回す
    }
    
    //大→小変換
    for (j=0; j<i; j++) {
        if (hako[j] >= 'A' && hako[j] <= 'Z') {
            hako[j] += 32;
        }else if (hako[j] >= 'a' && hako[j] <= 'z') {
            hako[j] -= 32;
        }
        printf("%c", hako[j]);
    }
    printf("\n");
    
    
    
    
    
    return 0;
}



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

int main()
{
    string s;
    cin >> s;
    
    string result = "";
    for (int i = 0; i < s.length(); i++) {
        if (i == 0 || i % 2 == 0) {
            result += s[i];
        }
    }
    
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
#define ull unsigned long long
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
using namespace std;
int par[MAXN];
int find(int u)
 {
 	return (par[u] == u) ? u : par[u] = find(par[u]);
 }
int main()
{

int n,m;
cin >> n >> m;
for(int i = 1 ; i <= n ; i++)
 par[i] = i;
 
for(int i = 0 ;i < m ; i++)
	  {
	     int a,b,c;
	  	cin >> a >> b >> c;
	  	int u = find(a);
	  	int v = find(b);
	  	if(u!=v)
	  		 par[v] = u;
	  }



int ans = 0;
for(int i = 1 ; i <= n ; i++)
     ans+=(find(i) == i);


cout << ans ;







} 

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
string a,b,c;
cin>>a>>b>>c;
cout<<char(a[0]-' ')<<char(b[0]-' ')<<char(c[0]-' ')<<endl;
}










Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<n; i++)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	string s, t;
	cin >> s >> t;
	sort(ALL(s));
	sort(ALL(t));
	reverse(ALL(t));
	if (s < t)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BOOST {ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef long long ll;

vector<int> dp(100000,-1);
int cost(vector<int> &h,int n)
{
    if(dp[n]!=-1)
        return dp[n];
    if(n<=0)
        return dp[0] = 0;
    dp[n] = min(
        cost(h,n-1)+abs(h[n]-h[n-1]),
        cost(h,n-2)+abs(h[n]-h[n-2])
    );
    return dp[n];
}
int main()
{
    BOOST
    int n;
    cin>>n;
    vector<int> h(n,0);
    for(int i=0;i<n;i++)cin>>h[i];
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]); 
    cout<<cost(h,n-1)<<'\n';
    return 0;
}

Measured memory_bytes: 6364
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
using namespace std;

int main() {
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		double xa,ya,ra,xb,yb,rb;
		scanf("%lf%lf%lf%lf%lf%lf", &xa,&ya,&ra,&xb,&yb,&rb);
		ra = fabs(ra);
		rb = fabs(rb);
		double xd = xa-xb;
		double yd = ya-yb;
		double rd = ra+rb;
		double rd2 = fabs(ra-rb);
		double sq_cdist = xd*xd+yd*yd;
		double sq_rdist = rd*rd;
		double sq_rdist2 = rd2*rd2;
		if(sq_cdist<sq_rdist2) {
			if(ra>rb) {
				printf("2\n");
			} else {
				printf("-2\n");
			}
		} else if(sq_cdist<=sq_rdist) {
			printf("1\n");
		} else {
			printf("0\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int mod=998244353;
const int N=700;
int n,m,a[N][N];
int od[N],ev[N],bit[N],xxj[N];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j],a[i][j]&=1;
	if(n<m)
	{
		for(int i=1;i<=n;i++)
			for(int j=i+1;j<=m;j++)
				swap(a[i][j],a[j][i]);
		swap(n,m);
	}

	int u=max(n,m);
	od[1]=1;ev[1]=3;
	for(int i=2;i<=u;i++)
	{
		od[i]=(ev[i-1]+3ll*od[i-1]%mod)%mod;
		ev[i]=(od[i-1]+3ll*ev[i-1]%mod)%mod;
	}
	int cnt=0;
	for(int i=1;i<=u;i++)
	{
		int p=i;
		for(int j=i+1;j<=u;j++)
			if(a[i][i]<a[j][i]) p=j;
		if(p!=i) swap(a[p],a[i]);
		if(!a[i][i])
		{
			int fl=0;
			for(int j=i+1;j<=m;j++) fl|=a[i][j];
			if(fl) swap(a[i],a[++u]);
			continue;
		}
		cnt++;
		for(int j=i+1;j<=u;j++)
			if(a[j][i])
				for(int k=i;k<=u;k++)
					a[j][k]^=a[i][k];
	}
/*
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
			if(a[i][j])
			{
				if(xxj[j])
					for(int k=j;k<=m;k++)
						a[i][k]^=a[xxj[j]][k];
				else {xxj[j]=i;cnt++;break;}
			}
	}
*/	bit[0]=1;
	for(int i=1;i<=u;i++) bit[i]=2ll*bit[i-1]%mod;
	int bs=1ll*bit[n-cnt]*bit[m-cnt]%mod;
	printf("%lld\n",1ll*od[cnt]*bs%mod);
}


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

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

  if (a == "A") {
    cout << "T" << endl;
  }
  else if (a == "T"){
    cout << "A" << endl;
  }
  else if (a == "C"){
    cout << "G" << endl;
  }
  else if (a == "G"){
    cout << "C" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,t;
cin >>s >>t;
int nagasa,tigai;
nagasa = t.size();
tigai = nagasa;


for (int j=0;j<(s.size()-nagasa +1);j++){
int count=0;
for(int i=0;i<nagasa;i++){
if(s[i+j]!=t[i])
count++;
} 
//cout << count <<endl;
if (count<tigai)
tigai=count;
}

cout << tigai <<endl;

}

Measured memory_bytes: 3616
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n; cin >> n;
    string s,t; cin>>s>>t;
    string ans;
    
    rep(i,n){
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    } 

    cout << ans << ln;
    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x; cin >> x;
	if (x < 3){
		cout << 0 << endl;
	}else{
		cout << x / 3 << endl;
	} // end if

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
typedef long long ll;
const ll mod=1e9+7;
ll fac[maxn+5],inv[maxn+5];
vector<int> g[maxn+5];
ll dp[maxn+5],ans[maxn+5];
int sz[maxn+5];
int n;
ll C(int n,int m)
{
    if(n<m) return 0;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
void cal(ll &f,int n,ll g,int m)
{
    f=C(n+m,n)*f%mod*g%mod;
}
void mul(ll &a,ll b)
{
    a=a*b%mod;
}
void dfs(int k,int fa)
{
    sz[k]=1;
    dp[k]=1;
    for(auto u:g[k])
        if(u!=fa)
        {
            dfs(u,k);
            mul(dp[k],dp[u]*inv[sz[u]]%mod);
            sz[k]+=sz[u];
        }
    // mul(dp[k],inv[sz[k]]);
}
ll Pow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
ll Inv(ll x)
{
    return Pow(x,mod-2,mod);
}
void dfs1(int k,int fa,ll num)
{
    // if(k==4) cout<<"ce "<<num<<" "<<sz[k]<<endl;
    // if(k==2) cout<<"ce "<<num<<endl;
    ans[k]=dp[k]*num%mod*fac[n-1]%mod;
    if(ans[k]<0) ans[k]+=mod;
    for(auto u:g[k])
        if(u!=fa)
            dfs1(u,k,dp[k]*Inv(dp[u])%mod*num%mod*inv[n-sz[u]]%mod*sz[u]%mod);
}
int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<n;++i)
    {
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    fac[0]=1;
    for(int i=1;i<=n;++i) fac[i]=fac[i-1]*i%mod;
    inv[0]=inv[1]=1;
    for(int i=2;i<=n;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    // for(int i=1;i<=n;++i) inv[i]=inv[i-1]*inv[i]%mod;
    dfs(1,0);

    dfs1(1,0,1);
    for(int i=1;i<=n;++i) printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 20980
#include<stdio.h>
#include<string.h>

int main(void){
	int N;
	char S[50];
	int i;
	int num=0;
	
	scanf("%d %s",&N,S);
	
	for(i=0;i<N-2;i++){
		if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') num++;
	}
	printf("%d\n",num);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int ans, sum;
int count(int n, int s, int a) {

	int result;
	int i;
	if (n == 1) {
		if (s >= a&&s <= 9)
			return 1;
		else
			return 0;
	}
	result = 0;
	for (i = a; i <= 9 && i<s; i++)
		result += count(n - 1, s - i, i + 1);
	return result;
}

int main(void) {
	int n,s;
	while (1) {
		scanf("%d %d",&n,&s);
		if (n == 0 && s == 0)break;

		printf("%d\n",count(n,s,0));
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define lli long long int
#define fw(i, s, e) for (ll i = s; i < e; ++i)
#define fe(i, s, e) for (ll i = s; i <= e; ++i)
#define fb(i, e, s) for (ll i = e; i >= s; --i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define mem(a, i) memset(a, i, sizeof(a))
#define ld long double
#define endl "\n"
#define in(P) \
    ll P;     \
    cin >> P;
int main()
{
    FASTIO
    // L(T)
    {
    }
    in(n);
    ll a[n + 90];
    fw(i, 1, n + 1) cin >> a[i];
    ll mx = 0;
    ll mn = 0;
    ll cst = 1000;
    ll stk = 0;
    if (a[1] <= a[2])
    {
        mn = a[1];
    }
    fw(i, 2, n)
    {
        if (a[i] >= a[i - 1] && a[i] >= a[i + 1] && mn > 0)
        {
            stk = cst / mn;
            cst = cst % mn;
            mx = a[i];

            cst += (mx * stk);
            stk = 0;
            mn = 0;
        }
        if (a[i] <= a[i - 1] && a[i] <= a[i + 1])
        {
            mn = a[i];
            // stk += cst / mn;
            // cst %= mn;
        }
    }
    if (a[n] >= a[n - 1] && mn > 0)
    {
        stk = cst / mn;
        cst = cst % mn;
        mx = a[n];

        cst += (mx * stk);
        stk = 0;
        mn = 0;
    }
    cout << cst << endl;

    return 0;
}

Measured memory_bytes: 3644
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()

	if a == b {
		fmt.Println("a == b")
	} else if a > b {
		fmt.Println("a > b")
	} else {
		fmt.Println("a < b")
	}
}


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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n,m;
string a[50],b[50];

int main(){
  scanf("%d %d",&n,&m);
  REP(i,n) cin >> a[i];
  REP(i,m) cin >> b[i];
  REP(i,n-m+1)REP(j,n-m+1){
    bool flag = true;
    REP(k,m)REP(l,m){
      //printf("%c %c",a[i+k][j+m],b[k][l]);
      flag &= a[i+k][j+l] == b[k][l];
    }
    if(flag){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
}


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

int n,v[55],c,ans,dp[2500];
int main(){
	scanf("%d",&n);
	for(int i =0;i<n;i++){
		scanf("%d",&v[i]);
	}
	memset(dp,-1,sizeof dp);
	dp[0] =0;
	for(int i =0;i<n;i++){
		scanf("%d",&c);
		for(int j =2000;j>=0;j--){
			if(dp[j]!=-1){
				dp[j+c] = max(dp[j+c],dp[j]+v[i]);
			}
		}
	}
	ans =0;
	for(int i =0;i<=2000;i++){
		ans = max(ans,dp[i]-i);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll


int t, n, m, k, a[300010], q, l, r;



int32_t main(){
INIT
int A=0;
cin>>n;


for(int i=1; i<=n; i++){
    cin>>a[i]; A^=a[i];
}

for(int i=1; i<=n; i++){
    a[i]=A^a[i];
}

for(int i=1; i<=n; i++){
    cout<<a[i]<<" ";
}

return 0;
}



Measured memory_bytes: 5216
#include<bits/stdc++.h>
#define rep(i, n, k) for(int i=k; i<n; ++i)
#define drep(i, n, k) for(int i=k; i>=n; --i)
using namespace std;

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int ans;
  ans = min(a*n, b);
  cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    ll N;
    cin >> N;
    vector<vector<P>> v(N, vector<P>());
    rep(i, N) {
        ll A;
        cin >> A;
        rep(j, A) {
            ll x, y;
            cin >> x >> y;
            v[i].push_back(P(x-1, y));
        }
    }
    ll ma = 0;
    rep(i, 1 << N) {
        vector<ll> tmp(N, 0);
        ll m = 0;
        rep(j, N) {
            tmp[j] = (i & (1 << j)) > 0;
            m += tmp[j];
        }
        bool flag = false;
        rep(j, N) {
            if (tmp[j] == 0) continue;
            for(P p : v[j]) {
                if(tmp[p.first] != p.second) flag = true;
            }
        }
        if (!flag) {
            ma = max(ma, m);
        }
    }
    print(ma);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long

int main() {
    
    ll n;
    cin >> n;
    ll a[n];
    ll x[16][16],y[16][16];
    for(ll i=0;i<n;i++){
        cin >> a[i];
        for(ll j=0;j<a[i];j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    
    ll ans=0;
    // bit全探索
    
    ll x1[n];//状態管理
    
    for (int bit=0;bit < (1<<n) ; ++bit){
        ll ans1=0;
        for(int i=0;i<n;i++) {
            if(bit & (1<<i)){
                       x1[i]=1;
                ans1++;
                   }
                   else x1[i]=0;
        }
        
        bool OK=true;
       
        //証言採用パート
        for(int i=0;i<n;i++){
            
            if(bit & (1<<i)){//採用
                
                for(ll j=0;j<a[i];j++){
                    
                    if(x1[x[i][j]]!=y[i][j]){
                        OK=false;
                        break;
                    }
                    
                }
                    
            }
        }
        if(OK){//ans1 cout part
            ans=max(ans,ans1);
        }
        
    }
    cout << ans << endl;
}



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

#define ll long long
#define ff(i,c,n) for(ll i=c;i<n;i++)


int main(){
    ll n;
    cin>>n;
    ll h[n];
    ff(i,0,n) cin>>h[i];
    if(n==2) cout<<abs(h[1]-h[0]);
    else{
        ll dp[n];
        dp[0]=0;
        dp[1]=abs(h[1]-h[0]);
        ff(i,2,n){
            dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
        }
        cout<<dp[n-1];
    }

}

Measured memory_bytes: 1792
INF = float('inf')

def judge(src):
    x_max = INF
    x_min = -INF
    for i,(s1,s2) in enumerate(zip(src,src[1:])):
        if s1 == s2:
            return 'none'
        if i%2:
            s1,s2 = s2,s1
        if s1 != 'x' and s2 != 'x':
            if s1 < s2:
                return 'none'
            else:
                continue
        if s1 == 'x':
            if x_max <= s2:
                return 'none'
            x_min = max(x_min, s2 + 1)
        elif s2 == 'x':
            if s1 <= x_min:
                return 'none'
            x_max = min(x_max, s1 - 1)
        if x_max < x_min:
            return 'none'
    return x_max if x_max == x_min else 'ambiguous'

while True:
    N = int(input())
    if N == 0: break
    src = [INF] + list(map(lambda x:x if x=='x' else int(x), input().split())) + [INF if N%2 else -INF]
    print(judge(src))

Measured memory_bytes: 5724
#include <stdio.h>

int main(){
    int x = 0, max = 0, N;
    char s[101];
    scanf("%d %s", &N, s);

    for(int i = 0; s[i] != '\0'; i++){
        switch(s[i]){
            case 'I':
                x++;
                if(max < x){
                    max = x;
                }
                break;
            case 'D':
                x--;
                break;
        }
    }
    printf("%d\n", max);
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = n - 1; i >= 0; i--){
        if(i != n - 1) cout << " ";
        cout << a[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <string.h>
using namespace std;



int main(){

    int K, X, start, end;
    cin >> K >> X;
    start = X-K+1;
    end = X+K-1;
    //cout << start << end << "\n";
    while(start!=end+1){
        cout << start << " ";
        start++;
    }

    return 0;
}

//g++ ファイル名 --input-charset=utf-8 --exec-charset=cp932
//日本語出力するときのやつ

Measured memory_bytes: 256
using System;
class Practice
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] num = new int[3];
        for (int i = 0; i < 3; ++i)
        {
            num[i] = int.Parse(str[i]);
        }
        Array.Sort(num);
        Console.WriteLine(num[0] + " " + num[1] + " " + num[2]);
    }
}


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

int main() {

// ax = by + c;
// ax - by = c;

int a, b, c;

cin >> a >> b >> c;

vector<int> list(b);
string answer = "NO";
for (int i = 1; i <= b; i++) {
    int mod = (i * a) % b;
    if (c == mod) {
        answer = "YES";
    }
    if (list.at(mod) == 0) {
        list.at(mod) = 1;
    } else {
        break;
    }
}

cout << answer << endl;

return 0;
}

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

int main(){
  string str, revStr;
  
  cin >> str;
  for(int i = 0; i < str.length(); i++) {
    revStr.push_back(str[str.length() - 1 - i]);
  }
  cout << revStr << endl;
  return 0;
}

Measured memory_bytes: 3152
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();

		if ((a + b) % 2 == 0) {
			System.out.println((a + b) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}

}


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

int main() {
  string s; cin >> s;
  string ans;
  for (auto e: s) {
    if (e != 'B') ans.push_back(e);
    else if (ans.size() > 0) ans.pop_back();
  }
  cout << ans << endl;
}

Measured memory_bytes: 256