akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int n;
    int count=0;

    cin>>n;

    FOR(i,1,n){
        if(n-i<=i){
            break;
        }
        count++;
    }
    cout<<count<<endl;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vi a(n);
    ll sum = 0, cnt = 0, minv = LLONG_MAX;

    rep(i, 0, n) {
        cin >> a[i];

        if (a[i] < 0) {
            ++cnt;
            a[i] *= -1;
        }

        sum += (ll)a[i];
        minv = min(minv, (ll)a[i]);
    }

    if (cnt % 2 == 0) {
        cout << sum << endl;
    } else {
        cout << sum - 2 * minv << endl;
    }

    return 0;
}

Measured memory_bytes: 640
MOD = 10 ** 9 + 7
n, k = gets.split.map(&:to_i)

min_memo = [0]
1.upto(n - 1) do |i|
  min_memo[i] = min_memo[i - 1] + i
end

max_memo = [n]
1.upto(n - 1) do |i|
  max_memo[i] = max_memo[i - 1] + (n - i)
end

ans = 1
k.upto(n) do |i|
  min = min_memo[i - 1]
  max = max_memo[i - 1]
  ans += (max - min) + 1
end
puts ans % MOD


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n);
    cinv(v,0,n);
    vector<ll> v_zo(k);
    cinv(v_zo,0,k);

    ll one=0;
    ll zero=0;
    FOR(i,0,n){
      if(v[i] == 1) one++;
      else zero++;
    }
    ll flag=0;
    FOR(i,0,k){
      if(i%2==0) flag += v_zo[i];
    }

    ll flag_start=0;
    if(one == zero) flag_start=2;
    else if(flag == one) flag_start=1;

    ll one_sum = 1e9;
    ll zero_sum = 1e9;
    vector<ll> tmp_v = v;

    if(flag_start != 0){
      ll turn = 1;
      ll sum_x = 0;
      ll tmp_res = 0;
      FOR(i,0,k){
        ll x = v_zo[i];
        FOR(j,0,x){
          ll pos = sum_x + j;
          // 入れ替え
          if(v[pos] != turn){
            FOR(p,pos,n){
              if(v[p] == turn){
                ll val = v[p];
                v.erase(v.begin() + p);
                v.insert(v.begin() + pos, val);
                tmp_res += p-pos;
                break;
              }
            }
          }
        }
        turn = (turn + 1) % 2;
        sum_x += x;
      }
      one_sum = tmp_res;
    }
    v = tmp_v;
    if(flag_start != 1){
      ll turn = 0;
      ll sum_x = 0;
      ll tmp_res = 0;
      FOR(i,0,k){
        ll x = v_zo[i];
        FOR(j,0,x){
          ll pos = sum_x + j;
          // 入れ替え
          if(v[pos] != turn){
            FOR(p,pos,n){
              if(v[p] == turn){
                ll val = v[p];
                v.erase(v.begin() + p);
                v.insert(v.begin() + pos, val);
                tmp_res += p-pos;
                break;
              }
            }
          }
        }
        turn = (turn + 1) % 2;
        sum_x += x;
      }
      zero_sum = tmp_res;
    }
    cout<<min(one_sum, zero_sum)<<endl;

}



Measured memory_bytes: 3216
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  
  ll n;
  string s;
  cin >> s;

  n = sz(s);

  vll a(n,0),b(n,1),c(n);

  rep(i,n)
  {
    a[i] = i % 2;
    b[i] = (i+1) % 2;
    c[i] = s[i] - '0';
  }

  ll a_cnt = 0;
  ll b_cnt = 0;

  rep(i,n)
  {
    if(c[i] != a[i])
    {
      a_cnt++;
    }
    if(c[i] != b[i])
    {
      b_cnt++;
    }
  }

  ll ans = min(a_cnt,b_cnt);

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 2816
N, K = map(int,input().split())

p = 0
for i in range(1, N + 1):
    if i >= K:
        p += (N - K + 1) / N
        break
    j = i
    p_ = 1
    while j < K:
        j *= 2
        p_ /= 2
    p += p_ / N

print(p)


Measured memory_bytes: 2940
//arc068_d.cpp
//Mon Jul  8 23:07:14 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

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

	sort(a,a+n);

	int total = 0;
	int uniq = 0;
	int prevnum = -1;
	for (int i=0;i<n;i++){
		if (prevnum != a[i]){
			uniq++;
		}
		total++;
		prevnum = a[i];
	}

	cout << uniq - (total-uniq)%2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
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*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(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(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
int main(){
    ll A,V,B,W,T;
    cin>>A>>V>>B>>W>>T;
    
    if(A>B){
        
        if(A-V*T<=B-W*T)cout<<"YES";else cout<<"NO";
    }else if(A==B){
        cout<<"YES";
    }else{
        ull a=A+V*T,b=B+W*T;
        if(a>=b)cout<<"YES";else cout<<"NO";
    }
    
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string s;
  cin >> s;
  int count = 0;
  rep(i,s.size()-1){
    if(s[i] != s[i+1]) count ++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val S = sc.next

    S.map { c =>
      (((c -'A' + N) % 26) + 'A').toChar
    }.mkString("")
  }
}


Measured memory_bytes: 30652
#include <iostream>
using namespace std;
 
int main() {
	string a, b, c;
	cin>>a>>b>>c;
	int an=0, bn=0, cn=0;
	char x = a[an];
	while (an<=a.length() and bn<=b.length() and cn<=c.length()){
		if (x=='a'){
			if (an==a.length()){
				cout << "A\n";
			}
			x=a[an];
			an++;
		}
		if (x=='b'){
			if (bn==b.length()){
				cout << "B\n";
			}
			x=b[bn];
			bn++;
		}
		if (x=='c'){
			if (cn==c.length()){
				cout << "C\n";
			}
			x=c[cn];
			cn++;
		}
	}
}

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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n,m; cin >> n >> m;
    ll x[n],y[n],z[n];
    rep(i,n) cin >> x[i] >> y[i] >> z[i];
    ll ans = 0;
    for(int bit = 0; bit < (1<<3); bit++){
        vector<ll> v;
        rep(i,n){
            ll tmp = 0;
            if(bit & (1<<2)) tmp += x[i];
            else tmp -= x[i];
            if(bit & (1<<1)) tmp += y[i];
            else tmp -= y[i];
            if(bit & (1<<0)) tmp += z[i];
            else tmp -= z[i];
            v.push_back(tmp);
        }
        sort(all(v));
        reverse(all(v));
        ll tmp = 0;
        for(int i = 0; i < m; i++){
            tmp += v[i];
        }
        ans = max(ans,tmp);
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main()
{
  int N, X; cin >> N >> X;
  vector<int> L(N+1, 0);
  for (int i = 1; i <= N; ++i) {
    cin >> L[i];
    L[i] += L[i-1];
  }

  for (int i = 1; i <= N; ++i) {
    if (L[i] > X) {
      cout << i << endl;
      return 0;
    }
  }

  cout << N+1 << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

lastT, lastX, lastY = 0, 0, 0
flag = "Yes"

N = int(input())
for i in range(N):
    t, x, y = map(int, input().split())

    # print( math.fabs(t - lastT) + math.fabs(t - lastT) )

    if ( t - lastT < math.fabs(x - lastX) + math.fabs(y - lastY)
        or ( (t - lastT) - math.fabs(x - lastX) - math.fabs(y - lastY) ) % 2 == 1 ):
        flag = "No"

    lastT = t
    lastX = x
    lastY = y

print(flag)


Measured memory_bytes: 9104
import itertools

def _get_distance(p1, p2):
    return ((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) ** 0.5

def _get_min_distance(points):
    min_d = 400
    for p1, p2 in itertools.combinations(points, 2):
        min_d = min(min_d, _get_distance(p1, p2))
    return min_d

def closest_pair_distance(points, axis):
    # axis: x; 0, y; 1
    n = len(points)
    if n <= 3:
        return _get_min_distance(points)
    else:
        mid = n // 2
        px, py = zip(*points)
        if len(set(px)) > len(set(py)):
            if axis:
                points.sort(key = lambda p: p[0])
            axis1 = 0
            axis2 = 1
        else:
            if not axis:
                points.sort(key = lambda p: p[1])
            axis1 = 1
            axis2 = 0
        A_points = points[:mid]
        B_points = points[mid:]
        d_Amin = closest_pair_distance(A_points.copy(), axis1)
        d_Bmin = closest_pair_distance(B_points.copy(), axis1)
        dist = min(d_Amin, d_Bmin)
        min_d = dist
        for ap in A_points[::-1]:
            if B_points[0][axis1] - ap[axis1] >= dist:
                break
            for bp in B_points:
                if bp[axis1] - ap[axis1] >= dist:
                    break
                if ap[axis2] - dist < bp[axis2] < ap[axis2] + dist:
                    min_d = min(min_d, _get_distance(ap, bp))
        return min_d

# Acceptance of input
import sys

file_input = sys.stdin

n = int(file_input.readline())

P = [tuple(map(float, line.split())) for line in file_input]

# Solve
P.sort(key = lambda p: p[0])
ans = closest_pair_distance(P, 0)

print('{:f}'.format(ans))

Measured memory_bytes: 31652
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
    
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X), B(Y), C(Z);
    rep(i,X) cin >> A[i];
    rep(i,Y) cin >> B[i];
    rep(i,Z) cin >> C[i];

    sort(A.begin(), A.end(), greater<long long>());
    sort(B.begin(), B.end(), greater<long long>());
    sort(C.begin(), C.end(), greater<long long>());

    vector<long long> sums;

    for (int l = 0; l < X && l + 1 <= K; l++) {
        for (int m = 0; m < Y && (l + 1) * (m + 1) <= K; m++) {
            for (int n = 0; n < Z && (l + 1) * (m + 1) * (n + 1) <= K; n++) {
                sums.push_back(A[l] + B[m] + C[n]);
            }
        }
    }

    sort(sums.begin(), sums.end(), greater<long long>());
    
    rep(i,K) cout << sums[i] << endl;

    return 0;
}

Measured memory_bytes: 1404
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

int N, Q;
int V[1 << 18], W[1 << 18];
int botv[1 << 9], botw[1 << 9];
int top[1 << 9][100001];

void chmax(int &lhs, int rhs) {
  if (lhs < rhs) lhs = rhs;
}
void chmax(long long &lhs, long long rhs) {
  if (lhs < rhs) lhs = rhs;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d %d", &V[i], &W[i]);
  }
  for (int i = W[1]; i <= 100000; ++i) {
    top[1][i] = V[1];
  }
  for (int i = 2; i <= N; ++i) {
    if (i >= 512) break;
    int p = i >> 1;
    for (int j = 0; j <= 100000; ++j) {
      top[i][j] = top[p][j];
      if (j - W[i] >= 0) {
        chmax(top[i][j], top[p][j - W[i]] + V[i]);
      }
      if (j >= 1) {
        chmax(top[i][j], top[i][j - 1]);
      }
    }
  }
  scanf("%d", &Q);
  while (Q--) {
    int v, l;
    scanf("%d %d", &v, &l);
    int botsize = 1;
    while (v >= 512) {
      for (int i = 0; i < botsize; ++i) {
        botv[i + botsize] = botv[i] + V[v];
        botw[i + botsize] = botw[i] + W[v];
      }
      botsize <<= 1;
      v >>= 1;
    }
    long long ans = 0;
    for (int i = 0; i < botsize; ++i) {
      if (botw[i] <= l) {
        chmax(ans, (long long) botv[i] + top[v][l - botw[i]]);
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}


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

int n, k;
int a[100000];

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans;
	if ((n - 1) % (k - 1) == 0)ans = (n - 1) / (k - 1);
	else ans = (n - 1) / (k - 1) + 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned ll
#define ioi exit(0);
 
#define f first
#define s second
 
#define inf (int)1e9 + 7
 
#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
 
#define mp(x,y) make_pair(x,y)
 
#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)
 
#define pb push_back
#define ppb pop_back
 
#define bitcoin __builtin_popcount
 
#define endl "\n"
 
#define in(x) insert(x)
 
#define sz(x) (int)x.size()
 
#define all(x) x.begin(),x.end()
 
#define pw2(x) (1ll<<x) //2^x
 
#define forit(it,v) for (typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
 
#define sqr(x) ((x) * 1ll * (x))
 
#define UpdateRandom srand (time(NULL));
 
using namespace std;
 
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;

int n,k;
int a[N];
ll dp[200][N];

int main(){
		
	NFS
	
	cin >> n >> k;
	
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	
	for(int i=0;i<=a[1];i++){
		dp[1][i]=dp[1][i-1]+1;
	}

	for(int i=a[1]+1;i<=k;i++){
		dp[1][i]=dp[1][i-1];
	}

	for(int i=2;i<=n;i++){
		for(int j=0;j<=k;j++){
			if(j-a[i]-1>=0)dp[i][j]=dp[i-1][j]-dp[i-1][j-a[i]-1];
			else dp[i][j]=dp[i-1][j];
			dp[i][j]%=MOD;
			dp[i][j]+=dp[i][j-1];
			dp[i][j]%=MOD;
		}
	}
	
	if(dp[n][k]-dp[n][k-1]<0) cout << dp[n][k]-dp[n][k-1]+MOD << endl;

	else cout << dp[n][k]-dp[n][k-1] << endl;
	
	ioi
}

Measured memory_bytes: 286976
#include <bits/stdc++.h>
#define x real()
#define y imag()
#define EPS 0.0000001
using namespace std;
typedef complex<double> point;

double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
int ccw(point a,point b,point c){
  point d = b-a,e = c-a;
  if(cross(d,e)>-EPS) return 1;//"COUNTER_CLOCKWISE"
  if(cross(d,e)<EPS) return -1;//"CLOCKWISE"
  if(dot(d,e)<0) return 2;//"ONLINE_BACK"
  if(abs(d) < abs(e)) return -2;//"ONLINE_FRONT"
  return 0;//"ON_SEGMENT"
}

point crosspoint(point a,point b,point c,point d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

vector<point> ConvexCut(vector<point> &polygon,point a,point b){
  vector <point> res;
  for(int i=0;i<polygon.size();i++){
    point A=polygon[i],B=polygon[(i+1)%polygon.size()];
    if(ccw(a,b,A)!=-1)res.push_back(A);
    if(ccw(a,b,A)*ccw(a,b,B)==-1)res.push_back(crosspoint(a,b,A,B));
  }
  return res;
}

double get_area(vector <point> &polygon){
  if(polygon.size()<3)return 0;
  double res=0;
  for(int i=0;i<polygon.size();i++)
    res+=cross(polygon[i],polygon[(i+1)%polygon.size()])/2;
  return res;
}

int main(){
  /*
  while(1){
    int v,n,d;
    vector <point> pl;
    cin>>n>>d>>v;
    if(!n&&!d&&!v) break;
    for(int i=0,a,b;i<n;i++) cin>>a>>b,pl.push_back(point(a,b));
    
    double V=min(get_area(pl),(double)v);
    double ans=0;
    for(int i=0;i<n;i++){
      double L=0,M,R=2010;
      int I=1000;
      while(I--){
	M=(L+R)/2;
	point h=pl[(i+1)%n]-pl[i],b=h;
	h=(point(0,M)*h/abs(h))+pl[i];

	vector<point> a=ConvexCut(pl,h+b,h);
	double res=get_area(a);
	assert(res>0);

	if(res*d>=V)R=M;
	else L=M+0.000000001;
      }
      
      ans=max(ans,L);

    }
    assert(ans<2001&&ans>0.000000001);
    printf("%.8f\n",ans);
  }
  */
  int n;
  cin>>n;
  vector <point> pl;
  for(int i=0,a,b;i<n;i++)cin>>a>>b,pl.push_back(point(a,b));
  int m;
  cin>>m;
  while(m--){
    double a,b,c,d;
    point A,B;
    cin>>a>>b>>c>>d;
    A=point(a,b),B=point(c,d);
    vector <point> res=ConvexCut(pl,A,B);
    printf("%.8f\n",get_area(res)); 
  }
  
  return 0;
}

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

int main() {
    int n, w, h;
    cin >> n >> w >> h;
    vector<int> imsw(w + 1, 0);
    vector<int> imsh(h + 1, 0);
    for (int i = 0; i < n; ++i) {
        int x, y, wid;
        cin >> x >> y >> wid;
        ++imsw[max(0, x - wid)];
        --imsw[min(w, x + wid)];
        ++imsh[max(0, y - wid)];
        --imsh[min(h, y + wid)];
    }
    int sum = 0;
    int f1 = 0, f2 = 0;
    for (int i = 0; i < w; ++i) {
        sum += imsw[i];
        if (!sum) {
            f1 = 1;
            break;
        }
    }
    sum = 0;
    for (int i = 0; i < h; ++i) {
        sum += imsh[i];
        if (!sum) {
            f2 = 1;
            break;
        }
    }
    puts(f1 && f2 ? "No" : "Yes");
    return 0;
}

Measured memory_bytes: 3624
n = int(raw_input())
a = map(int, raw_input().split())

temp = 0
cnt = 0
for i in range(n):
	for j in range(n-i-1):
		if a[j] > a[j+1]:
			temp = a[j]
			a[j] = a[j+1]
			a[j+1] = temp
			cnt += 1

for i in range(n):
	if i != n-1:
		print(a[i]),
	else:
		print(a[i])

print cnt

Measured memory_bytes: 6464
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (0 != n) {

            int a[] = new int[n];
            int an = 0;

            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt();
            }
            int best = -99999999;
            for (int l = 0; l < n; l++) {
                int sum = 0;
                for (int r = l; r < n; r++) {
                    sum = sum + a[r];
                    if (best < sum) {
                        best = sum;
                    }
                }
            }
            System.out.println(best);
            n = scanner.nextInt();
        }

    }
}



Measured memory_bytes: 35784
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <algorithm>

using namespace std;

int main(void) {
  int r, c;
  int j = 0;
  string item, line;
  cin >> r >> c;
  cin.ignore();
  int sheet[r + 1][c + 1];
  int row = 0;
  int column = 0;
  fill(sheet[0], sheet[r], 0);
  for(int i = 0; i < r; i++) {
    getline(cin, line);
    stringstream ss(line);
    while(getline(ss, item, ' '))
      sheet[i][j++] = atoi(item.c_str());
    j = 0;
  }
  for(int i = 0; i < r; i++) {
    for(int j = 0; j < c; j++) {
      row += sheet[i][j];
    }
    sheet[i][c] = row;
    row = 0;
  }
  for(int i = 0; i < c + 1; i++) {
    for(int j = 0; j < r; j++) {
      column += sheet[j][i];
    }
    sheet[r][i] = column;
    column = 0;
  }
  for(int i = 0; i < r + 1; i++) {
    for(int j = 0; j < c + 1; j++) {
      cout << sheet[i][j];
      if(j != c)
        cout << ' ';
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<string> c(a);
  vector<char> d(b + 2, '#');
  for(int i = 0; i < a; i++) {
    cin >> c.at(i);
  }
  for(int i = 0; i < b + 2; i++) {
    cout << d.at(i);
  }
  cout << endl;
  for(int i = 0; i < a; i++) {
    cout << '#' << c.at(i) << '#' << endl;
  }
  for(int i = 0; i < b + 2; i++) {
    cout << d.at(i);
  }
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
ll gcd(ll ga,ll gb){
  while(gb > 0){
    ll tmp;
    tmp=ga;
    ga=gb;
    gb=tmp%gb;
  }
  return ga;
}
ll lcm(ll hm,ll hn){
  if((0==hm)||(0==hn)){
     return 0;
  }else{
     return ((hm/gcd(hm,hn))*hn);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll a,b,c,d;cin>>a>>b>>c>>d;a--;
  //caricurate
  ll u,dk;u=(b/c)+(b/d)-(b/lcm(c,d));dk=(a/c)+(a/d)-(a/lcm(c,d));
  cout<<(b-a)-(u-dk)<<endl;
  //output
}


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

int pare[lim+1],rank[lim+1];

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

int find(int x){
	if(pare[x]==x)return x;
	return pare[x] = find(pare[x]);
}

void unit(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		pare[x] = y;
	}else{
		pare[y] = x;
		if(rank[x]==rank[y])rank[x]++;
	}
}

int same(int x,int y){
	return find(x)==find(y);
}


int main(void){
	int N,M,i,ans=0;
	scanf("%d%d",&N,&M);
	int p[N+1];
	for(i=1;i<=N;i++){
		scanf("%d",&p[i]);
	}
	int x,y;
	init(N);
	for(i=0;i<M;i++){
		scanf("%d%d",&x,&y);
		unit(x,y);
	}
	for(i=1;i<=N;i++){
		if(same(p[i],i))ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1280
// C - Anti-Division
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long x = c * d / __gcd(c, d);
	long long c1 = b / c - (a - 1) / c;
	long long c2 = b / d - (a - 1) / d;
	long long c3 = b / x - (a - 1) / x;
	cout << (b - a + 1 - (c1 + c2 - c3)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p, l, r;};
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if(u == NIL) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if(u == NIL) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}

/* 後方順巡回 */
void postParse(int u) {
  if(u == NIL) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

int main(void) {
  int i, v, l, r, root;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    T[i].p = NIL;
  }
  
  for(i=0; i<n; i++) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL) T[l].p = v;
    if(r != NIL) T[r].p = v;
  }
  
  for(i=0;i<n;i++) if(T[i].p == NIL) root = i;
  
  printf("Preorder\n");
  preParse(root);
  printf("\n");

  printf("Inorder\n");
  inParse(root);
  printf("\n");

  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}

/*
9
0 1 4
1 2 3
2 -1 -1
3 -1 -1
4 5 8
5 6 7
6 -1 -1
7 -1 -1
8 -1 -1
*/



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

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

  map<int, int> ids_in;
  map<int, int> ids_out;
  for(int i=0; i<N; i++){
    int left,right;
    cin >> left >> right;

    if(ids_in.count(left)){ ids_in.at(left)++; }
    else                  { ids_in[left]= 1; }

    if(ids_out.count(right)){ ids_out.at(right)++; }
    else                    { ids_out[right]= 1; }
  }

  vector<pair<int, int>> ranges(N);
  int cnt_in= 0;
  for(auto [left, freq]:ids_in){
    for(int f=0; f<freq; f++){
      ranges.at(cnt_in).first= left;
      cnt_in++;
    }
  }
  int cnt_out= 0;
  for(auto [right, freq]:ids_out){
    for(int f=0; f<freq; f++){
      ranges.at(cnt_out).second= right;
      cnt_out++;
    }
  }

  int lower= (N%2==1) ? ranges.at((N-1)/2).first
                      : ranges.at(N/2-1).first+ ranges.at(N/2).first;
  int upper= (N%2==1) ? ranges.at((N-1)/2).second
                      : ranges.at(N/2-1).second+ ranges.at(N/2).second;
  int ans= upper- lower+ 1;

  cout << ans << endl;
}

Measured memory_bytes: 23524
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        '''
        xとyは-=1して使う
        '''
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,Q = map(int,input().split())
u = UnionFind(n)
ans_ls = []
for i in range(Q):
    q,x,y = map(int,input().split())
    if q == 1:
        if u.same(x,y):
            ans_ls.append(1)
        else:
            ans_ls.append(0)
    else:
        u.union(x,y)
for i in range(len(ans_ls)):
    print(ans_ls[i])



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

int n, ans;
string a, b, c;

int main() {
    cin >> n >> a >> b >> c;
    rep(i, n) {
        if (a[i] == b[i] && b[i] == c[i]) {
            continue;
        } else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
            ans++;
        } else {
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string s; cin >> s;
    ll cnt = 0;
    int judge = 0; //judgeが1の間、判定が続きます
    ll ans = 0;

    //右から文字列を見ていきます
    //C,Bの順に発見したらjudgeに1を入れて、cnt++して判定開始
    //BCを発見したらcntを1増やして、iを1減らす
    //Aを発見したらそれまでのcntをansに足す
    //BC,A以外が来たら判定終了、cntとjudgeをリセットして次の判定を待つ
    for(int i = s.size()-1; i >= 1; i--){
        if(s[i-1] == 'B' && s[i] == 'C'){
            judge = 1;
            cnt++;
            i--;
        }else if(judge == 1 && s[i] == 'A'){
            ans += cnt;
        }else{
            judge = 0;
            cnt = 0;
        }
    }
    if(judge == 1 && s[0] == 'A') ans += cnt;
    cout << ans << endl;
}

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

int main()
{
int a;
int b;
scanf("%d",&a);
b=a/pow(10,3);
a-=(b*pow(10,3));
for(int i=0; i<3; ++i){
	if(b==int(a/pow(10,2-i))){
		printf("Bad\n");
		return 0;
	}else{
		b=a/pow(10,2-i);
		a-=(b*pow(10,2-i));
	}
}
printf("Good\n");
return 0;
}


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

int main() {
  int N , M ;
  cin >> N >> M ;
  
  
  if (N == M ){
    cout << "Yes" << endl ; 
  }
  else {
    cout << "No" << endl ; 
  }
  
  
  
  
  
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n,mini=200,maxi=-200,ans=200000000;
int a[200];
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mini=min(a[i],mini);
        maxi=max(a[i],maxi);
    }
    for(int i=mini;i<=maxi;i++){
        int sum=0;
        rep(j,n){
            sum+=(i-a[j])*(i-a[j]);
        }
        ans=min(sum,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 0) {
        cout << (B[N / 2] + B[N / 2 - 1]) - (A[N / 2] + A[N / 2 - 1]) + 1 << "\n";
    } else {
        cout << B[N / 2] - A[N / 2] + 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 6376
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    	int d, n;
    	cin >> d >> n;
    	
    	if( d == 0 ) {
    		if( n == 100 ) {
    			cout << 101 << endl;
    		} else {
    			cout << n << endl;
    		}
    	}
    	else if( d == 1 ) {
    		if( n == 100 ) {
    			cout << 100*101 << endl;
    		} else {
    		 	cout << n*100 << endl;
    		}
    	}
    	else {
    		if( n == 100 ) {
    			cout << 10000*101 << endl;
    		} else {
    			cout << n*10000 << endl;
    		}
    	}
     return 0;
    }

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

int main() {

    std::string str;
    std::cin >> str;
    if (str.size() < 3) {std::cout << 0 << std::endl; }
    else {
        int global_max = 0, sumJ, sumO, sumI, bIdx, fIdx;
        for (int i = 1; i < str.size()-1; i++) {
            if (str[i] == 'O' && str[i-1] == 'J') {
                bIdx = i-1; sumO = 1; i++;
                for (; i < str.size()-1; i++) {
                    if (str[i] != 'O') break;
                    sumO++;
                }
                if (str[i] != 'I') continue;
                sumJ = 0;
                while (bIdx >= 0) {
                    if (str[bIdx] != 'J' || sumJ == sumO) break;
                    bIdx--; sumJ++;
                }
                if (sumJ < sumO) continue;
                sumI = 0;
                while (i < str.size()) {
                    if (str[i] != 'I' || sumI == sumO) break;
                    i++; sumI++;
                }
                if (sumI < sumO) continue;
                global_max = std::max(global_max, sumO);
            }

        }
        std::cout << global_max << std::endl;
    }

    return  0;
}



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

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;

        vector<int> h(n), w(m);
        for(int i=0; i<n; i++){
            cin >> h[i];
        }
        for(int i=0; i<m; i++){
            cin >> w[i];
        }

        unordered_map<int,int> width, height;
        for(int i=0; i<n; i++){
            int subtotal=0;
            for(int j=i; j<n; j++){
                subtotal+=h[j];
                if(height.count(subtotal) == 0){
                    height[subtotal] = 1;
                }else{
                    height[subtotal]++;
                }
            }
        }
        for(int i=0; i<m; i++){
            int subtotal=0;
            for(int j=i; j<m; j++){
                subtotal+=w[j];
                if(width.count(subtotal) == 0){
                    width[subtotal] = 1;
                }else{
                    width[subtotal]++;
                }
            }
        }
        
        int ans=0;
        for(auto pair:width){
            auto itr = height.find(pair.first);
            if(itr != height.end()){
                ans += itr->second*pair.second;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 29916
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll ok[12345678], iro[12345678], visit[12345678];
signed main() {
	ll n, c = 0, a, b, cnt = INF, ans1 = 0; string s; cin >> s;
	if (s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
main(){
    int n;
    cin>>n;
    vector<int>a;
    for(int i=0;i<n;++i){
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
    int ans=a[n-1];
    int cnt=2;
    int tmp=n-2;
    while(tmp){
        if(tmp>=2){
            ans+=2*a[n-cnt++];
            tmp-=2;
        }else{
            ans+=a[n-cnt++];
            break;
        }
    }
    cout<<ans<<endl;
}


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

int comp(const void *a,const void *b);

int main(){
	int i[10];
	int j;
	for(j=0;j<10;j++)scanf("%d",&i[j]);

//	for(j=0;j<10;j++) printf("dbg i[%d]=%d\n",j,i[j]);


	qsort(i,10,sizeof(int),comp);
//	for(j=0;j<10;j++) printf("dbg s i[%d]=%d\n",j,i[j]);
	for(j=0;j<3;j++) printf("%d\n",i[9-j]);

	return 0;
}

int comp(const void *a,const void *b){
	int x= *(int *)a;
	int y= *(int *)b;
	return x-y;
}

Measured memory_bytes: 604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
    int N, M;
    cin >> N >> M;
    
    for(long int i = M / N; 1 <= i; i--){
        if(M % i == 0){
            cout << i << endl;
            return 0;
        }

    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b, c, x=0, y=0;
	
	while( scanf("%d,%d,%d", &a, &b, &c) != EOF ){
		if(a*a+b*b == c*c) x++;
		else if(a==b && c<a+b) y++; 
	}
	
	printf("%d\n%d\n", x, y);

	return 0;
}

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

int main() {
	int n, sum[5] = {0};
	string str;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		cin >> str;
		if (str == "AC") {
			sum[0]++;
		}
		else if (str == "WA") {
			sum[1]++;
		}
		else if (str == "TLE") {
			sum[2]++;
		}
		else if (str == "RE")
			sum[3]++;
	}
	printf("AC x %d\n", sum[0]);
	printf("WA x %d\n", sum[1]);
	printf("TLE x %d\n", sum[2]);
	printf("RE x %d", sum[3]);
	return 0;
}

Measured memory_bytes: 3768
function main(input){
    let args = input.split(" ").map(x=>parseInt(x));
    let answer = 0;
    for(let i=args[0];i<=args[1];i++){
        if(args[2]%i===0) answer++;
        
    }
    console.log(answer);
    
    
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 15412
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return "".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

s = input().split()
q = onem()

de = cl.deque(s)

co = 0

for i in range(q):
    po = input().split()
    if len(po) == 1:
        co = co ^ 1
    else:
        f = int(po[1])
        if co == 0:
            if f == 1:
                de.appendleft(po[2])
            else:
                de.append(po[2])

        else:
            if f == 1:
                de.append(po[2])
            else:
                de.appendleft(po[2])

if co == 0:
    print(jo(de))
else:
    print(jo(de)[::-1])






Measured memory_bytes: 7140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, M);
  if (abs(N - M) > 1) {
    print(0);
    return;
  }
  ll mx = max(N, M) + 1;
  vector<ll> dp(mx);
  dp[0] = 1;
  rep(i, 1, mx) {
    dp[i] = (dp[i - 1] * i) % MOD;
  }
  ll ans = (dp[N] * dp[M]) % MOD;
  if (N == M) ans = (ans * 2) % MOD;
  print(ans);
}


Measured memory_bytes: 1024
N = int(input())

class Matrix:
    def __init__(self, N):
        self.M = [[0 for _ in range(N)] for _ in range(N)]
    
    def set(self, i, j, val):
        self.M[i-1][j-1] = val
    
    def __repr__(self):
        str_lines = []
        for line in self.M:
            str_lines.append(' '.join(map(str, line)))
        return '\n'.join(str_lines)

matrix = Matrix(N)

for _ in range(N):
    tmp = input().split()
    node_id = int(tmp[0])
    neighbor_num = int(tmp[1])
    neighbors = list(map(int, tmp[2:]))
    
    for n in neighbors:
        matrix.set(node_id, n, 1)

print(matrix)


Measured memory_bytes: 5748
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	string t;
	cin >> t;
	int n = t.size();
	int i = n - 1;
	while(i >= 0) {
		if(t[i] != '?') {
			i--;
			continue;
		}

		t[i] = 'D';
		i--;
	}
	cout << t << endl;
	return 0;
}


Measured memory_bytes: 3756
n=int(input())
s=input()
sm=0
for x in [(x,y,z) for x in range(10) for y in range(10) for z in range(10)]:
    token=0
    for i in range(n):
        if x[token]==int(s[i]):
            token+=1
            if token==3 : break
    if token==3 : sm+=1
print(sm)

Measured memory_bytes: 73832
while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n - 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

Measured memory_bytes: 7664
#include <bits/stdc++.h>
 
using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

const int N = 1000;

int n, ans;
int a[2][N + 5];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif 

    read(n);
    for(int d = 0; d < 2; ++ d) {
        for(int i = 1; i <= n; ++i) {
            read(a[d][i]);
        }
    }

    for(int i = n; i >= 1; --i) a[1][i] += a[1][i+1];
    for(int i = 1; i <= n; ++i) a[0][i] += a[0][i-1], chkmax(ans, a[0][i] + a[1][i]);

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,f[12];
int main(){
           cin>>a>>b>>c;
           f[a]++;
           f[b]++;
           f[c]++;
           if(f[a]==2 && (f[b]==1 || f[c]==1)) cout<<"Yes";
           else{
                      if(f[b]==2 &&(f[c]==1 || f[a]==1)) cout<<"Yes";
                      else cout<<"No";
           }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	int n, i = 1;
	cin >> n;
	while (1) {
		if (i * i > n) {
			cout << (i - 1) * (i - 1) << endl;
			break;
		}
		i++;
	}
	return 0;
}

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int beforeA = 0;
    long ans = 0;
    for (int cnt = 0; cnt < n; cnt++) {
      int a = sc.nextInt();
      int step = 0;
      if (beforeA > a) {
        step = beforeA - a;
      }
      ans += step;
      beforeA = a + step;
    }
    System.out.println(ans);
    sc.close();
  }
}


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

namespace ABC154A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ST = Console.ReadLine().Split(' ');
            string[] AB = Console.ReadLine().Split(' ');
            string U = Console.ReadLine();
            if (ST[0] == U)
            {
                Console.WriteLine("{0} {1}",int.Parse(AB[0]) - 1,AB[1]);
            }
            else if (ST[1] == U)
            {
                Console.WriteLine("{0} {1}",AB[0], int.Parse(AB[1]) - 1);
            }
        }
    }
}


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

int main(){
	char ch0, ch1;
	int cup[3] = {0};
	cup[0] = 1;
	while (~scanf("%c,%c\n", &ch0, &ch1)) {
		swap(cup[ch0-'A'], cup[ch1-'A']);
	}
	for (int i = 0; i < 3; i++) {
		if (cup[i] == 1) {
			cout << (char)('A' + i) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0