akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
//#define int ll
//#define endl '\n'

// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// print number in binary -> cout << bitset<20>(n);

// simple segment tree without lazy propagation (good if updating just single indexes)
// tl,tr = current range, idx=idx of the current item, pos = what pos I want to update
const int N=200010;
int n,q;

#define NEUTRAL 9223372036854775807
#define NEUTRAL_LAZY 9223372036854775807
#define COMBINE(a, b) (min(a,b))
#define L(a) (2*a)
#define R(a) (2*a+1)
#define OUT (l>=rb || r<=lb)
#define LEAF (idx>=POW)
#define FULL (l<=lb && r>=rb)
struct segmentTree{
    ll POW, N;
    vector<ll> tree, lazy;
    segmentTree(vector<ll> &v){
        N = v.size();
        POW = pow(2, ceil(log2(N)));
        tree.assign(2*POW, NEUTRAL);
        lazy.assign(2*POW, NEUTRAL_LAZY);
        for (ll i = 0; i < N; i++) tree[i + POW] = v[i];
        for (ll i = POW - 1; i > 0; i--) tree[i] = COMBINE(tree[L(i)], tree[R(i)]);
    }
    ll realVal(ll idx) { return min(tree[idx],lazy[idx]); }
    void applyLazy(ll idx){
        if (lazy[idx] != NEUTRAL_LAZY){
            tree[idx] = realVal(idx);
            lazy[L(idx)] = lazy[idx];
            lazy[R(idx)] = lazy[idx];
            lazy[idx] = NEUTRAL_LAZY;
        }
    }
    ll query(ll l, ll r) { return query(l, r, 0, POW, 1); }
    ll query(ll l, ll r, ll lb, ll rb, ll idx){
        if (OUT) return NEUTRAL;
        if (LEAF) return realVal(idx);
        if (FULL) return realVal(idx);
        applyLazy(idx);
        ll mid = (lb + rb) / 2;
        return COMBINE(query(l, r, lb, mid, L(idx)), query(l, r, mid, rb, R(idx)));
    }
    void update(ll l, ll r, ll val) { update(l, r, 0, POW, 1, val); }
    void update(ll l, ll r, ll lb, ll rb, ll idx, ll val){
        if (OUT) return;
        if (LEAF) { lazy[idx] = val; return; }
        if (FULL) { lazy[idx] = val; return; }
        applyLazy(idx);
        ll mid = (lb + rb) / 2;
        update(l, r, lb, mid, L(idx), val);
        update(l, r, mid, rb, R(idx), val);
        tree[idx] = COMBINE(realVal(L(idx)), realVal(R(idx)));
    }
};

main(){
	cin.tie(0);cin.sync_with_stdio(0);
	cin>>n>>q;
	vector<ll>aa(n-2,n-2),bb(n-2,n-2);
	segmentTree a(aa),b(bb);
	ll res=ll(n-2)*(n-2);
	for(int i=0;i<q;++i){
		int t,x;cin>>t>>x;
		if(t==1){
			int dist=a.query(x-2,x-1);
			cerr<<"a "<<x-2<<" "<<x-1<<" "<<dist<<endl;
			res-=dist;
			if(b.query(0,1)>x-2)b.update(0,dist,x-2);
		}else{
			int dist=b.query(x-2,x-1);
			cerr<<"b "<<x-2<<" "<<x-1<<" "<<dist<<endl;
			res-=dist;
			if(a.query(0,1)>x-2)a.update(0,dist,x-2);
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 24264
#include <iostream>
#include <algorithm>
#include <deque>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
#include <cmath>
#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(s, i, n) for (i = s; i < n; i++)
using namespace std;

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

    int i, r = 7%K;
    rep0(i, K)
    {
        if (r == 0)
        {
            cout << i + 1 << endl;
            return 0;
        }
        r = (r * 10 + 7) % K;
    }

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

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#define LEN 100005

typedef struct pp
{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0,tail=0,n;

void enqueue(P);
P dequeue(void);

int main()
{
  int elaps = 0,c,j=0;
  int i,q;
  P u;
  scanf("%d %d",&n,&q);
  for (i=0;i<n;i++)
    {
      scanf("%s",Q[i].name);
      scanf("%d",&Q[i].t);
    }
  while(j!=n)
    {
      u=dequeue();
      if(u.t<=q)
	{
	  elaps+=u.t;
	  printf("%s %d\n",u.name,elaps);
	  j++;
	}
      else
	{
	  elaps=q+elaps;
	  u.t=u.t-q;
	  enqueue(u);
	}
    }
  return 0;
}

void enqueue(P line)
{
  /*if(head==(tail+1)%n)
    printf("era\n");*/
  Q[tail]=line;
  if(tail+1==n)
    tail=0;
  else
    tail++;
}

P dequeue()
{
  P line;
  /*if(head==tail)
    printf("era\n");*/
  line=Q[head];
  if(head+1==n)
    head=0;
  else
    head++;
  return line;
}



Measured memory_bytes: 6844
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int a,b,c,d; cin>>a>>b>>c>>d;
    cout<<(a!=c)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
VI findAll(string S,string pattern){VI P;ll pos=(ll)S.find(pattern);
while(pos!=string::npos){P.push_back(pos);pos=(ll)S.find(pattern,pos+1);}return P;}
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
bool is_prime(ll n){if(n<2)return 0;for(int i=2;i*i<n;i++)if(n%i==0)return 0;return 1;}
inline void eratosthenes(VB& p){rep(i,SZ(p))p[i]=1;p[0]=p[1]=0;
rep(i,SZ(p)/2+1){if(p[i])for(ll j=i+i;j<SZ(p);j+=i)p[j]=0;}}
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}// x^n%mod
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
using Graph=vector<vector<int> >;//int と P

int main(){
    int n,m;cin>>n>>m;
    priority_queue<ll>q;
    rep(i,n){
        ll a;cin>>a;
        q.push(a);
    }
    rep(i,m){
        ll max_v=q.top();q.pop();
        q.push(max_v/2);
    }
    ll ans=0;
    while(q.size()){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	map<char,int>a;
	a['<']=1;
	a['>']=2;
	a['^']=3;
	a['v']=4;
	int dx[5]={0,0,0,-1,1};
	int dy[5]={0,-1,1,0,0};
	int w;
	cin>>w;
	rep(z,w){
		if(z)cout<<endl;
		int n,m;
		cin>>n>>m;
		vector<vector<char> >in(n+2,vector<char>(m+2));
		rep(i,n+2)rep(j,m+2)
			if(!i||!j||i==n+1||j==m+1)in[i][j]='#';
			else cin>>in[i][j];
		int q;cin>>q;
		string s;cin>>s;
		int x,y;
		rep(i,n+2)rep(j,m+2)if(a[in[i][j]]){x=i;y=j;}
		rep(i,q){
			if(s[i]=='D'){
				in[x][y]='v';
				if(in[x+1][y]=='.'){in[x][y]='.';x++;in[x][y]='v';}
			}
			if(s[i]=='U'){
				in[x][y]='^';
				if(in[x-1][y]=='.'){in[x][y]='.';x--;in[x][y]='^';}
			}
			if(s[i]=='R'){
				in[x][y]='>';
				if(in[x][y+1]=='.'){in[x][y]='.';y++;in[x][y]='>';}
			}
			if(s[i]=='L'){
				in[x][y]='<';
				if(in[x][y-1]=='.'){in[x][y]='.';y--;in[x][y]='<';}
			}
			if(s[i]=='S'){
				int d=a[in[x][y]];
				int sx=x;
				int sy=y;
				while(1){
					sx+=dx[d];
					sy+=dy[d];
					if(in[sx][sy]=='#')break;
					if(in[sx][sy]=='*'){
						in[sx][sy]='.';
						break;
					}
				}
			}
		}
		rep(k,n){
			rep(j,m)cout<<in[k+1][j+1];
			cout<<endl;
		}

	}
}

Measured memory_bytes: 1228
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	ll ans=0;
	int Bnum=0;
	rep(i,N){
		if(S[i]=='B') Bnum++;
		else ans+=Bnum;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define LIM 100005
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define vi vector <int>
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
int32_t main()
{
  IOS;
  int t,x,y,k,n,i,j;
  map <string,int> m;
  cin>>n; string s;
  while(n--)
  {
      cin>>s;
      m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
  cout<<"WA x "<<m["WA"]<<endl;
  cout<<"TLE x "<<m["TLE"]<<endl;
  cout<<"RE x "<<m["RE"]<<endl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >>n ;
    set <string> s;
    for (int z=0;z<n;z++){
        string ss;
        cin >> ss;
        s.insert(ss);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 19204
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;
int main(){
    int d, g; cin >> d >> g;
    int ans = 100000000;
    vector<int> p(d), c(d);
    REP(i, d) cin >> p[i] >> c[i];
    
    REP(i, (1<<d)){
        int hampa=-1, score=0, cnt=0;
        REP(j, d){
            if(i & (1<<j)){
                score += p[j] * 100 * (j+1) + c[j];
                cnt += p[j];
            }
            else hampa = j;
        }
        if(hampa >= 0){
            if(score + (p[hampa]-1) * 100 * (hampa+1) < g) continue;
            else cnt += max((g - score + 100 * (hampa+1) -1) / (100 * (hampa+1)), 0);
        }else if(score < g) continue;
        
        ans = min(ans, cnt);
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
    ll N; cin >> N;
    map<ll,ll> mp;
    rep(i,N){
        ll a; cin >> a;
        mp[a-1]++; mp[a]++; mp[a+1]++;
    }
    ll ma = -1;
    for(auto it : mp){
        ma = max(ma, it.second);
    }
    cout << ma << endl;
}

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

namespace ABC173D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] Ainput = Console.ReadLine().Split(' ');
            long[] A = new long[N];
            for(int i = 0; i < N; i++)
            {
                A[i] = long.Parse(Ainput[i]);
            }
            Array.Sort(A);
            Array.Reverse(A);
            //Console.WriteLine(string.Join("",A));
            int count = 2;
            long ans = A[0];
            long max = 0;
            if ((N-1) % 2 == 0)
            {
                max = N - 2;
                ans += A[(N - 1)/2];
            }
            else
            {
                max = N-1;
            }
            while (count <= max)
            {
                if (count % 2 == 0)
                {
                    ans += A[count / 2];
                }
                else
                {
                    ans += A[(count - 1) / 2];
                }
                count += 1;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 46620
using System;
namespace 令和{
    class ABC{
        static void Main(){
            string[] n_k = Console.ReadLine().Split();
            int n = int.Parse(n_k[0]);
            int k = int.Parse(n_k[1]);
            double p = 0;
            for(int i=1;i<n+1;i++){
                if(i>=k){p += (double)1/n;
                }else{
                    int count = 0;
                    int ti = i;
                    while(true){
                        ti *= 2;
                        count ++;
                        if(ti>=k){
                            p += 1/(n * Math.Pow(2,count));
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(p);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <complex>


using namespace std;
typedef long long ll;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while (n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);

        for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
    }

    void eval(int k, int l, int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k];
            if (r - l > 1) {
                lazy[2 * k + 1] += lazy[k] / 2;
                lazy[2 * k + 2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            node[k] = node[2 * k + 1] + node[2 * k + 2];
        }
    }

    ll getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        eval(k, l, r);
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl + vr;
    }
};

int main() {
	ll N, D, A; cin >> N >> D >> A;
	
	vector<pair<ll, ll>> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i].first;
		cin >> p[i].second;
	}
	sort(p.begin(), p.end());

	vector<ll> v(N);
	for (int i = 0; i < N; i++) {
		v[i] = (p[i].second + A - 1) / A;
	}

    LazySegmentTree seg(vector<ll>(N, 0));
    for (int i = 0; i < N; i++) {
        seg.add(i, i + 1, v[i]);
    }

    ll ans = 0;
	int c = 0;
	for (int i = 0; i < N; i++) {
		while (1) {
			if (c == N - 1 || p[c + 1].first > p[i].first + D * 2) {
				break;
			}
			c++;
		}
        ll x = seg.getsum(i, i + 1);
        if (x > 0) {
            seg.add(i, c + 1, -x);
            ans += x;
        }
	}

    cout << ans << endl;

	return 0;
}

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

using std::string;
using namespace std;

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

	if (S == "SUN") {
		cout << 7 << endl;
	}
	else if (S == "MON") {
		cout << 6 << endl;
	}
	else if (S == "TUE") {
	cout << 5 << endl;
	}
	else if(S == "WED") {
	cout << 4 << endl;
	}
	else if(S == "THU") {
	cout << 3 << endl;
	}
	else if(S == "FRI") {
	cout << 2 << endl;
	}
	else if(S == "SAT") {
	cout << 1 << endl;
	}
	
	return 0;

}

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

ll gcd(ll a,ll b){
   if(b<a) swap(a,b);
   ll r = a%b;
   while(r){
       a = b;
       b = r;
       r = a%b;
   }
   return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k,g,M=0;
    cin >> n >> k;
    for(int i = 0;i < n;i ++){
        ll a;
        cin >> a;
        if(i==0) g=a;
        else g=gcd(g,a);
        if(M<a) M=a;
    }
    if(k%g==0 && k<=M) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
#include <utility>
#include <vector>

using namespace std;

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


int main(){

	int a,b;
	ios_base::sync_with_stdio(false);
	cin>>a>>b;	
	if(a==1) a=14;
	if(b==1) b=14;
	if(a<b) cout<<"Bob"<<endl;
	else if(a>b) cout<<"Alice"<<endl;
	else cout<<"Draw"<<endl;

	return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	for(int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}
	int ans = INT_MAX;
	for(int i = 0; i < (1 << d); i++) {
		int num = 0;
		int s = 0;
		for(int j = 0; j < d; j++) {
			if((i >> j) & 1) { 
				s += c[j] + (j + 1) * 100 * p[j];
				num += p[j];
			}
		}
		for(int j = d - 1; j >= 0; j--) {
			if(!((i >> j) & 1)) {
				if(s >= g) break;
				for(int k = 0; k < p[j]; k++) {
					if(s >= g) break;
					s += (j + 1) * 100;
					num++;
				}
			}
		}
		ans = min(num, ans);
	}
	cout << ans << endl;

	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

const long long INF = 1LL<<60;
int N;
long long K;
vector<int> P;
vector<long long> C;

long long solve() {
    long long res = -INF;

    // 順列を各サイクルに分解する
    vector<bool> used(N, false);
    vector<vector<long long>> ss;
    for (int i = 0; i < N; ++i) {
        if (used[i]) continue;
        int cur = i;
        vector<long long> s;
        while (!used[cur]) {
            used[cur] = true;
            s.push_back(C[cur]);
            cur = P[cur];
        }
        ss.push_back(s);
    }

    // 各サイクルごとに考える
    for (auto vec : ss) {
        long long M = vec.size();

        // サイクルを二週したものの累積和
        vector<long long> sum(M*2+1, 0);
        for (int i = 0; i < M*2; ++i) sum[i+1] = sum[i] + vec[i%M];

        // amari[r] := 連続する r 個の総和の最大値
        vector<long long> amari(M, -INF);
        for (int i = 0; i < M; ++i) {
            for (int j = 0; j < M; ++j) {
                chmax(amari[j], sum[i+j] - sum[i]);
            }
        }

        // 余りの長さで場合分け
        for (int r = 0; r < M; ++r) {
            if (r > K) continue;
            long long q = (K - r) / M;
            if (r == 0 && q == 0) continue;

            if (sum[M] > 0) chmax(res, amari[r] + sum[M] * q);
            else if (r > 0) chmax(res, amari[r]);
        }
    }
    return res;
}

int main() {
    cin >> N >> K;
    P.resize(N); C.resize(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];
    for (int i = 0; i < N; ++i) cin >> C[i];
    cout << solve() << endl;
}

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

int main(void) {

        int i, n, a_i[10000], min, max;
        long sum = 0;
        char *tp, words[10000*8];

        scanf("%d\n", &n);
        fgets(words, sizeof(words),stdin);
        tp = strtok(words, " ");
        i = 0;
        while(tp) {
                a_i[i] = min = max = atoi(tp);
                tp = strtok(NULL, " ");
                i++;
        }

        for(i = 0; i < n; i++) {
                if(min > a_i[i]) min = a_i[i];
                if(max < a_i[i]) max = a_i[i];
                sum += a_i[i];
        }

        printf("%d %d %ld\n", min, max, sum);
}



Measured memory_bytes: 2120
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll n,h,res=0,sum=0;cin>>n>>h;
	vll a,b;
	loop(n,i,0){
		ll aa,bb;cin>>aa>>bb;
		a.pb(aa),b.pb(bb);
	}
	sort(allv(a),greater<int>());
	sort(allv(b),greater<int>());
	for(auto x:b){
		if(x<a[0])
			break;
		sum+=x;
		res++;
		if(sum>=h)
			return cout<<res,0;
	}
	h-=sum;
	cout<<(ll)res+(ll)ceil(1.0*h/a[0])<<endl;
	return 0;
}


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


int main(){
    int A, B, Q; cin >> A >> B >> Q;
    vector<ll> S(A+2);
    vector<ll> T(B+2);
    S[0] = T[0] = -110000000000000;
    S[A+1] = T[B+1] = 110000000000000;
    rep(i, A) cin >> S[i+1];
    rep(i, B) cin >> T[i+1];
    int direction[2] = {0, -1};
    rep(i, Q){
        ll x; cin >> x;
        auto sx = lower_bound(S.begin(), S.end(), x);
        auto tx = lower_bound(T.begin(), T.end(), x);
        ll ans = 20000000000000000;
        for(int i : direction){
            // cout << *(sx-1) << endl;
            for(int j : direction){
                ans = min(ans, min(abs(*(sx+i)-x) + abs(*(sx+i)-*(tx+j)), abs(*(tx+j)-x) + abs(*(sx+i)-*(tx+j))));
            }
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4704
#include <iostream>

using namespace std;
using llong = long long;
constexpr llong p = 1000000007;

llong power_mod(llong m,llong n){
  llong pm = 1;
  llong mult=m;
  while(n!=0){
    if(n&1)
      pm = (pm*mult)%p;
    n >>= 1;
    mult = (mult*mult)%p;
  }
  return pm;
}

int main(){
  llong m,n;
  cin >> m >> n;
  cout << power_mod(m,n) << endl;
  return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#include <time.h> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
ll dp[3003][3003]; 
ll sum[3003];
int arr[3003];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n,a,b;
  sd(n);
  for(int i = 1; i <= n; i++)
  {
    sd(arr[i]);
    dp[i][i] = arr[i];
    sum[i] = sum[i] + sum[i - 1]  + arr[i];
  }
  for(int i = 2; i <= n; i++) // size
  {
      for(int j = 1; j + i - 1 <= n; j++)
          dp[j][i + j - 1] = max(sum[i + j - 1] - sum[j] - dp[j + 1][i + j - 1] + arr[j], sum[i + j - 2] - sum[j - 1] - dp[j][i + j - 2] + arr[i + j - 1]);
  }
  cout << 2 * dp[1][n] - sum[n]<< '\n';
  return 0;
} 

Measured memory_bytes: 70016
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n,k,s,m,a[25];
int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		  if (ch=='-') w=-1;
		  ch=getchar();
	}
	while (ch<='9' && ch>='0'){
		  x=(x<<1)+(x<<3)+ch-'0';
		  ch=getchar();
	}
	return x*w;
}
int main(){
	n=read();
	for (int i=0;i<=20;i++)
		if (n&(1<<i)) k++,a[k]=i;
	for (int i=1;i<a[k]+1;i++) m+=2;
	for (int i=k-1;i>=1;i--) ++m;
	printf("%d %d\n",a[k]+1,m);
	for (int i=1;i<a[k]+1;i++){
		printf("%d %d %d\n",i,i+1,0);
		printf("%d %d %d\n",i,i+1,(1<<(i-1)));
	}
	s=(1<<a[k]);
	for (int i=k-1;i>=1;i--){
		printf("%d %d %d\n",a[i]+1,a[k]+1,s);
		s|=(1<<a[i]);
	}	
	return 0;
}

Measured memory_bytes: 256
from collections import deque
n, q = map(int, input().split())
d = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    d[a].append(b)
    d[b].append(a)
ans = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x
# print(d)
d2 = [True] * n

def bfs():
    que = deque([0])
    d2[0] = False
    while len(que) != 0:
        val = que.popleft()

        for i in range(len(d[val])):
            if d2[d[val][i]] == True:
                que.append(d[val][i])
                ans[d[val][i]] += ans[val]
                d2[d[val][i]] = False
    return ans
print(' '.join(map(str,bfs())))

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

using namespace std;
typedef long long ll;
typedef long double ld;

ld dist(int x1, int y1, int x2, int y2) {
	ll tmp = (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2);
	return sqrt(tmp);
}
int n, x[10], y[10], p[10];

int main() {
	cin >> n; 
	ld gt = 1.0;
	for (int i = 1; i <= n; ++i) { cin >> x[i] >> y[i]; p[i] = i; gt *= i; }
	ld ans = 0.0;
	do {
		ld tmp = 0.0;
		for (int i = 1; i < n; ++i)
			tmp += dist(x[p[i]], y[p[i]], x[p[i + 1]], y[p[i + 1]]);
		ans += tmp;
	} while (next_permutation(p + 1, p + n + 1));
	ans = ans / gt;
	cout.precision(20);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int h[100010];
int dp[100010];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
        if (i == 1) {
            continue;
        }
        if (i == 2) {
            dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
            continue;
        }
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    cout << dp[n];
}

Measured memory_bytes: 4340
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		ll A,B,x,ans=0;

		cin >> A >> B >>x;

		if(A==0 && B!=0){
			ans=B/x+1;
		}else if(B==0){
			ans = 1;
		}else{
			ans=B/x-(A-1)/x;
		}

		cout << ans <<endl;

		return 0;
    }

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $n);
$line = trim(fgets(STDIN));
//Aの要素を昇順にする
$A = array_map(function ($val) {
    return (int)$val;
}, explode(' ', $line));
sort($A);
//Aの合計値
$sum = array_sum($A);

fscanf(STDIN, '%d', $q);
$line = trim(fgets(STDIN));
//探索済み配列
$arr = array();
foreach (explode(' ', $line) as $m) {
    $m = (int)$m;
    //Aの合計値より大きいので不可能
    if ($m > $sum) {
        echo "no\n";
        $arr[$m] = false;

    //既に探索済み
    } elseif (isset($arr[$m])) {
        echo $arr[$m] ? "yes\n" : "no\n";

    } else {
        $bool = solve(0, $m);
        $arr[$m] = $bool;
        echo $bool ? "yes\n" : "no\n";
    }
}

function solve($i, $m)
{
    global $n, $A;

    if ($m === 0) {
        return true;
    } elseif ($i === $n) {
        return false;
    } elseif (solve($i + 1, $m)) {
        return true;
    } elseif (solve($i + 1, $m - $A[$i])) {
        return true;
    }

    return false;
}

Measured memory_bytes: 6724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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


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

	vector<int> L(n + 1);
	vector<int> R(n + 1);

	for (int i = 0; i < n; i++){
		L[i + 1] = gcd(L[i], a[i]);
	}
	for (int i = n - 1; i >= 0; i--){
		R[i] = gcd(R[i + 1], a[i]);
	}

	int ans = 0;
	for (int i = 0; i < n; i++){
		ans = max(ans, gcd(L[i], R[i + 1]));
	}

	cout << ans << endl;
	
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
typedef long long ll;

int main() 
{
    int n, tmp;
    ll min=(1e13), max=-(1e13);
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &tmp);
        if (tmp-min>max) max = tmp-min;
        if (min>tmp) min = tmp;
    }
    printf("%d\n", max);
    return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>
#include<stdlib.h>
long cmp(const void *a,const void *b){
  return *(long*)a - *(long*)b;
}

int main(){
  long n;
  long a;
  long b;
  long x[100010] = {};
  long diff[100010] = {};
  long i;
  long sum=0;
  long cnt = 0;
 
  scanf("%ld %ld %ld",&n,&a,&b);
  for(i=0;i<n;i++){
    scanf("%ld",&x[i]);
  }
  for(i=0;i<n-1;i++){
    diff[i] = (x[i+1] - x[i])*a;
  }
  
  qsort(diff,n-1,sizeof(long),cmp);
  
  /*for(i=0;i<n;i++){
    printf("%ld/",diff[i]);
  }*/
  for(i=0;i<n-1;i++){
    if(diff[i] <= b){
      sum += diff[i];
    }else{
      sum += b;
    }
  }
  printf("%ld",sum);
  return 0;
}

Measured memory_bytes: 2556
#include <cstdio>

using namespace std;

char fig [9][9];

int main()
{
	
	while (scanf("%s", fig[0]) != EOF){
		for (int i = 1; i < 8; i++){
			scanf("%s", fig[i]);
		}
		
		for (int y = 0; y < 8; y++){
			for (int x = 0; x < 8; x++){
				if (fig[y][x] != '0'){
					if (fig[y][x + 1] == '1' && fig[y + 1][x] == '1' && fig[y + 1][x + 1] == '1'){
						printf("A\n");
						y = 10;
						break;
					}
					else if(fig[y + 1][x] == '1' && fig[y + 2][x] == '1' && fig[y + 3][x] == '1'){
						printf("B\n");
						y = 10;
						break;
					}
					else if(fig[y][x + 1] == '1' && fig[y][x + 2] == '1' && fig[y][x + 3] == '1'){
						printf("C\n");
						y = 10;
						break;
					}
					else if(fig[y + 1][x] == '1' && fig[y + 1][x - 1] == '1' && fig[y + 2][x - 1] == '1'){
						printf("D\n");
						y = 10;
						break;
					}
					else if(fig[y][x + 1] == '1' && fig[y + 1][x + 1] == '1' && fig[y + 1][x + 2] == '1'){
						printf("E\n");
						y = 10;
						break;
					}
					else if(fig[y + 1][x] == '1' && fig[y + 1][x + 1] == '1' && fig[y + 2][x + 1] == '1'){
						printf("F\n");
						y = 10;
						break;
					}
					else if(fig[y][x + 1] == '1' && fig[y + 1][x] == '1' && fig[y + 1][x - 1] == '1'){
						printf("G\n");
						y = 10;
						break;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 948
import java.util.*;
public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //int a = sc.nextLong();
        //int b = sc.nextLong();
        String s = sc.next();
        //Long x = sc.nextLong();


        if(n%2 != 0){
            System.out.println("No");
        } else{
            String x = s.substring(0,n/2);
            String y = s.substring(n/2);
            if(x.equals(y)){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }

    }
}


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

using i64 = long long;

constexpr int MAX = 1010000;
constexpr int MOD = 1000000007;

i64 fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
                fac[i] = fac[i - 1] * i % MOD;
                inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
                finv[i] = finv[i - 1] * inv[i] % MOD;
        }
}

i64 COM(int n, int k) {
        if (n < k || n < 0 || k < 0) return (0);
        return (fac[n] * (finv[k] * finv[n - k] % MOD) % MOD);
}

int main()
{
        COMinit(); 

        int X, Y;
 
        cin >> X >> Y;

        if ( (X + Y) % 3 != 0 || (X + Y) / 3 > X || (X + Y) / 3 > Y ) {
                cout << 0 << endl;
        } else {
                int n = (X + Y) / 3;
                int k = (X - n);
 
                cout << COM(n, k) << endl;
        }
 
        return (0);
}


Measured memory_bytes: 23936
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using lint=int64_t;
using namespace std;

int fact(int n)
{
	if(n==0)return 1;
	return n*fact(n-1);
}

int main()
{
	int N;
	int x[10]={};
	int y[10]={};

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> x[i] >> y[i];

	int pat[10]={};
	for(int i=0;i<N;i++)
		pat[i]=i;

	double lensum=0;
	do
	{
		double len=0;
		for(int i=0;i<N-1;i++)
		{
			double dx=x[pat[i]]-x[pat[i+1]];
			double dy=y[pat[i]]-y[pat[i+1]];
			len+=sqrt(dx*dx+dy*dy);
		}
		lensum+=len;
	}while(next_permutation(pat,pat+N));

	cout << fixed << setprecision(10);
	cout << lensum/(double)fact(N) << endl;
	return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;
	cout << n*m << endl;
	return 0;
}


Measured memory_bytes: 3676
h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=w-t:
    g[r]+=[i]*(w-t)
    r+=1; c-=w-t; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])

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

int north=5;
int west=4;
int south=2;
int east=3;
int center=1;
int reverse=6;
int temp=0;

int result=1;


void change(char buffer[128]){


	if (!strcmp(buffer,"South")){
		result += north;
		temp = south;
		south = center;
		center = north;
		north = reverse;
		reverse = temp;
		//printf("nnnn:%d\n",north );
	}
	else if ((!strcmp(buffer,"East"))){
		result += west;
		temp = east;
		east = center;
		center = west;
		west = reverse;
		reverse = temp;
	}
	else if ((!strcmp(buffer,"North"))){
		result += south;
		temp = north;
		north = center;
		center = south;
		south = reverse;
		reverse = temp;
		}
	else if ((!strcmp(buffer,"West"))){
		result += east;
		temp = west;
		west = center;
		center = east;
		east = reverse;
		reverse = temp;
		}
	else if ((!strcmp(buffer,"Right"))){
		result += center;
		temp = north;
		north = west;
		west = south;
		south = east;
		east = temp;
	
	}
	else if ((!strcmp(buffer,"Left"))){
		result += center;
		temp = north;
		north = east;
		east = south;
		south = west;
		west = temp;
	}
	else {
		return ;
	}
}

int main (void){

	int i=0;
	int input=0;
	char buffer[128];
	int count=0;
	int result_array[128];

	while(1){
		scanf("%d", &input);
		if(input == 0)
			break;

		while(i < input){
			//printf("input: \n");
			scanf("%s",buffer);

			change(buffer);
			i++;
		}
		i=0;
		result_array[count]= result;
		result=1;
		north=5;
		west=4;
        south=2;
		east=3;
		center=1;
		reverse=6;
		temp=0;
		count++;

	}

	for ( i=0; i<count; i++){
		printf("%d\n",result_array[i]);
	}


	return 0;
}

Measured memory_bytes: 604
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int X = sc.nextInt();
		final int N = sc.nextInt();
		if(N==0){
			sc.close();
			System.out.println(X);
			return;
		}
		ArrayList<Integer> p = new ArrayList<>();
		int max=0;
		for(int i=0;i<N;++i){
			p.add(sc.nextInt());
		}
		for(int i=0;i<N;++i){
			max = Math.max(p.get(i), max);
		}
		sc.close();
		int ans = 0;
		int i=0;
		int min = 101;
		int tmp = min;
		while(i<(X+max)){
			if(p.contains(i)) {
				++i;
				continue;
			}
			min = Math.min(Math.abs(X-i), min);
			if(Math.min(tmp, min)==tmp){break;}
			ans = i;
			++i;
			tmp = min;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35956
a=input()

count=0
if len(a)==2:
    if a[0]==a[1]:
        print(1,2)
        count=1

for i in range(len(a)-2):
    if count==1:
        break
    x=a[i]
    y=a[i+1]
    z=a[i+2]
    if x==y:
        print(str(i),str(i+2))
        count=1
        break
    elif z==y:
        print(str(i+1),str(i+3))
        count=1
        break
    elif x==z:
        print(str(i+1),str(i+3))
        count=1
        break

if count==0:
    print(-1,-1)

Measured memory_bytes: 3188
s=input()
n=int(input())
f=0
l=""
r=""
for i in range(n):
	q=input().split()
	if q[0]=="1":
		f^=1
	else:
		if (f==0 and q[1]=="1") or (f==1 and q[1]=="2"):
			l=l+q[2]
		else:
			r=r+q[2]

if f==0:
	ans=l[::-1]+s+r
else:
	ans=r[::-1]+s[::-1]+l

print(ans)







Measured memory_bytes: 4468
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
const int INF = 1<<28;
const int MAX = 10;
int main(){

  for(int n;cin>>n,n;){
    vector<vector<int>> d(MAX, vector<int> (MAX, INF));

    int max_node=0;
    for(int i=0;i<n;++i){
      int a,b,c;
      cin>>a>>b>>c;
      d[a][b]=c;
      d[b][a]=c;
      d[a][a]=0;
      d[b][b]=0;
      if(max_node<a) max_node = a;
      if(max_node<b) max_node = b;
    }

    int node,time=INF;

    // i=起点 j=終点 k=iとjの間の点　起点からk点を経由して終点に行く
    for(int k=0;k<=max_node;++k)
      for(int i=0;i<=max_node;++i)
        for(int j=0;j<=max_node;++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    for(int i=0;i<=max_node;++i){
      int sum=0;
      for(int j=0;j<=max_node;++j){
        if(d[i][j]!=INF) sum += d[i][j];
      }
      if(time>sum){
        time = sum;
        node = i;
      }
    }

    cout << node << " " << time << endl;
  }

  return 0;
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A == B && A != C) || (B == C && B != A) || (C == A && A != B)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

int main() {
  std::string N;
  std::cin >> N;
  const char last_digit = N[N.size() - 1];

  switch (last_digit - '0') {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    std::cout << "hon" << std::endl;
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    std::cout << "pon" << std::endl;
    break;
  case 3:
    std::cout << "bon" << std::endl;
    break;
  }

  return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <math.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long bit[n][30];
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < 30; j++) {
      bit[i][j] = 0;
    }
  }
  long a;
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a);
    bit[i][0] = a;
    for (long j = 1; j < 30; j++) {
      bit[i][j] += bit[i][j-1]/2;
      bit[i][j-1] %= 2;
    }
  }
  long count[30];
  for (long i = 0; i < 30; i++) {
    count[i] = 0;
  }
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < 30; j++) {
      if (bit[i][j] == 1) {
        count[j]++;
      }
    }
  }
  long ans_bit[30];
  long ans;
  for (long i = 0; i < n; i++) {
    for (long j = 0; j < 30; j++) {
      if (count[j]%2 == 0) {
        ans_bit[j] = bit[i][j];
      } else {
        if (bit[i][j] == 0) {
          ans_bit[j] = 1;
        } else {
          ans_bit[j] = 0;
        }
      }
    }
    ans = 0;
    for (long j = 0; j < 30; j++) {
      ans += pow(2,j)*ans_bit[j];
    }
    printf("%ld", ans);
    if (i != n-1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 49448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define INF 1000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, a[10010], b[10010], ta, mu;

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n) {
		if (a[i] <= b[i])ta += (b[i] - a[i]) / 2;
		else mu += a[i] - b[i];
	}
	if (ta >= mu)cout << "Yes" << endl;
	else cout << "No" << endl;
	ggr
}

Measured memory_bytes: 384
#include <stdio.h>
#include<math.h>
int main()
{
	int n,d,x[11][11];
	float dis; 
	int DIS,sum=0;
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n ; i++)
	{
		for(int j=1;j<=d ;j++ )
		{
			scanf("%d",&x[i][j]);
		}				
	}	
	for(int i=1;i<=n ;i++ )
	{
		for(int j=i+1;j<=n ;j++ )
		{
			dis=0;
			for(int k=1;k<=d ; k++)
			{
				dis=dis+pow(fabs(x[i][k]-x[j][k]),2);
			}
			DIS=sqrt(dis);
			if(sqrt(dis)==DIS) sum++;
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
        #include <sstream>
        #include <vector>
         
        using namespace std;
         
        int main(void)
        {
        	int32_t n, temp;
        	vector<int32_t> rabbits;
         
        	cin >> n;
        	rabbits.reserve(n);
         
        	for (; n > 0; --n) {
        		cin >> temp;
        		rabbits.push_back(temp);
        	}
         
        	int32_t count{ 0 };
        	for (auto i{0}; i < rabbits.size(); ++i) {
        		if (i == rabbits.at(rabbits.at(i) - 1) - 1)
        			++count;
        	}
         
        	cout << count / 2 << endl;
        }

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m; cin >> n >> m;
  vector<int> c(m, 0);
  for(auto &i : c) cin >> i;
  int INF = 1e9;
  vector<vector<int> > dp(m+1, vector<int>(n+1, INF));
  dp[0][0] = 0;
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n+1; j++){
      int ni = i + 1;
      chmin(dp[ni][j], dp[i][j]); // 金額そのままで種類増やす
      int nj = j + c[i];
      if(nj > n) continue;
      chmin(dp[ni][nj], dp[i][j] + 1);
      chmin(dp[ni][nj], dp[ni][j] + 1);
    }
  }
  cout << dp[m][n] << endl;
}


Measured memory_bytes: 7172
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
const u32 P=998244353;
u32 f[3001][3001], g[3001][3001];
int main() {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	g[a][b]=1;
	for(int i=a; i<=c; ++i) {
		for(int j=b; j<=d; ++j) {
			if(j>b) f[i][j]=(1llu*i*(f[i][j-1]+g[i][j-1]))%P;
			if(i>a) g[i][j]=(1llu*j*g[i-1][j]+f[i-1][j])%P;
		}
	}
	printf("%u\n", (f[c][d]+g[c][d])%P);
	return 0;
}

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D), c(D);
  for (int i = 0; i < D; i ++) {
    cin >> p[i] >> c[i];
  }

  int ans = 1e9;
  for (int i = 0; i < (1 << D); i ++) {
    int cnt = 0;
    int score = 0;
    for (int j = 0; j < D; j ++) {
      if (i >> j & 1) {
        cnt += p[j];
        score += p[j] * (j + 1) * 100;
        score += c[j];
      }
    }
    for (int j = D - 1; j >= 0; j --) {
      if (~i >> j & 1) {
        for (int k = 0; k < p[j] && score < G; k ++) {
          score += (j + 1) * 100;
          cnt ++;
        }
      }
    }

    if (score >= G) {
      ans = min(ans, cnt);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A,B,C = LI(),LI(),LI()
A.sort()
C.sort()

from bisect import bisect_left,bisect_right

ans = 0
for i in range(N):
    b = B[i]
    ans += bisect_left(A,b)*(N-bisect_right(C,b))

print(ans)


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


void cc_env(){
	#ifndef ONLINE_JUDGE
		freopen("input", "r", stdin);
		freopen("output", "w", stdout);
		// 
	#endif
}



void self_min(ll &a, ll b){
	a = min({a,b});
}


int main(){
	// cc_env();
	// input part;
	int N, W, w, v, V=0;
	cin>>N>>W;

	vector<vector<int> > inputArr(N, vector<int>(2, 0));
	for(int i=0;i<N;i++){
		cin>>inputArr[i][0]>>inputArr[i][1];
		V += inputArr[i][1];

	}

	// deciding size of dp array
	vector<ll> dp(V+1, INT_MAX);
	dp[0] = 0;
	for(int i=0;i<N;i++){
		w = inputArr[i][0];
		v = inputArr[i][1];
		
		// processing
		for(int value_already = V-v; value_already >=0; --value_already){
			// cout<<dp[weight_already+w]<<" "<<dp[weight_already]+v<<endl;
			self_min(dp[value_already+v], (dp[value_already]+w));
		}

		// for(int i=0;i<dp.size();i++)
		// 	cout<<dp[i]<<" ";
		// cout<<endl;

	}
	
	// find max among value array
	int maxVal = 0;
	for(int i=dp.size()-1;i>=0;i--){
		// cout<<dp[i]<<" ";
		if(dp[i] <= W)
			maxVal = max(maxVal, i);
	}
	cout<<endl;
	cout<<maxVal<<endl;
	return 0;

}


Measured memory_bytes: 1024