akhauriyash/Code-Regression huggingface dataset:
# frozen_string_literal: true

class Rl
  def initialize(str, r, l)
    @str = str
    @r = r
    @l = l
    calc_rls
  end

  def nums
    ns = []
    0.upto(@str.size - 1) do |i|
      if i == @r
        ns.push @rs
      elsif i == @l
        ns.push @ls
      else
        ns.push 0
      end
    end
    ns
  end

  def calc_rls
    if @r.odd?
      @rs = @str.size / 2
      @ls = @str.size - @rs
    else
      @ls = @str.size / 2
      @rs = @str.size - @ls
    end
  end
end

s = gets.chomp.split('')

rls = []
left = 0
rflag = true
r = 0
l = 0
0.upto(s.size) do |i|
  if rflag
    if s[i] == 'L'
      r = i - 1
      l = i
      rflag = false
    end
  else
    if i == s.size || s[i] == 'R'
      rflag = true
      rls.push Rl.new(s[left..(i-1)], r - left, l - left)
      left = i
    end
  end
end
nums = []
rls.each do |e|
  nums.push e.nums
end
puts nums.flatten.join(' ')


Measured memory_bytes: 20860
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pii pair<ll,ll>
#define vec vector<ll>
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define M 1000000007

using namespace std;


int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll a, b,c,d;
	cin>>a>>b>>c>>d;
	ll i=0;
	while(a>0 && c>0)
	{
		if(i==0)
		{
			c=c-b;
			i=1;
		}
		else
		{
			a=a-d;
			i=0;
		}
	}
	if(a>0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    string S;
    cin >> S;

    int ans = 0;
    if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') ans = 3;
    else if ((S[0] == 'R' && S[1] == 'R') || (S[1] == 'R' && S[2] == 'R')) {
        ans = 2;
    }
    else if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') ans = 1;

    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    sort(a,a+n,greater<long long>());
    if(a[n-1] == 0)cout << 0;
    else {
        long long sum = 1,che = 1000000000000000000;
        for(int i = 0;i < n;i++){
            sum *= a[i];
            if(che / a[i] <= 0){
                sum = -1;
                break;
            }
            che /= a[i];
        }
        cout << sum;
    }
}

Measured memory_bytes: 4420
int def2(int a, int b){return a<b?b-a:a-b;}
int min2(int a, int b){return a>b?b:a;}
int n, k, x, ans, now, i;
int main(){
  scanf("%d%d", &n, &k);
  for(i=0; i<n; i++){
    scanf("%d", &x);
    now=min2(def2(0,x),def2(k,x))<<1;
    ans+=now;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int gcd(int m, int n)
{
	if (0 == m || 0 == n)
		return 0;
	while(m != n) {
		if (m > n) m = m - n;
    else n = n - m;
	}
	return m;
}

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

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

  int minval = a[0];
  for (int i = 1; i < n; ++i) {
    int val = a[i] % a[0];
    if (val != 0 && minval > val) {
      minval = val;
    }
  }

  bool flag = true;
  int tag = a[0];
  while (flag) {
    int tmp = tag % minval;
    if (tmp == 0) flag = false;
    else {
      tag = minval;
      minval = tmp;
    }
  }
  cout << minval << endl;
  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

const int MAX = 510000;
#define	MOD 998244353

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);

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

long	COM(int N, int K) {
	if (N<K)
		return 0;
	if ((N<0)||(K<0))
		return 0;
	return (fac.at(N) * ((finv.at(K)*finv.at(N-K)) %MOD)) %MOD;
}

ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

//vector<ll> KKK(200001, -1);

ll	F(const ll &N, const ll &M, const ll &K) {
	ll SS=0;
	for (auto i=0; i<=K; i++) {
		SS +=((M*myPow(M-1, N-i-1))%MOD*COM(N-1, i))%MOD;
		SS %=MOD;
	}
	return SS;
}

int	main() {
	// Array
	// Initialize
	ComInit();
	ll N, M, K;
	cin >>N >>M >>K;
	cout <<F(N, M, K) <<endl;
	return 0;
}



Measured memory_bytes: 14952
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

#define _SI(arr) (sizeof(arr)/sizeof(arr[0])

int main() {
	string s;
	cin >> s;
	int a[27] = { 0 };
	for (ll i = 0; i < s.size(); i++)
	{
		a[s[i] - 'a']++;
	}
	for (ll i = 0; i < 26; i++)
	{
		if (a[i] == 0)
		{
			char p = 'a' + i;
			cout << p << endl;
			exit(0);
		}
	}

	cout << "None" << endl;

}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define PB push_back
#define MP make_pair
#define F first
#define S second

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



int main(){
	int s;
	cin >> s;
	s %= 10;
	if(s==2||s==4||s==5||s==7||s==9){
		cout << "hon" << endl;
	}
	else if(s==0||s==1||s==6||s==8){
		cout <<"pon"<<endl;
	}
	else{
		cout <<"bon"<<endl;
	}
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int count = 0;
  rep(i, N - 1){
    if(N % (i + 1) == 0){
      count += N / (i + 1) - 1;
    }else{
      count += N / (i + 1);
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a, b; char c; cin >> a >> c >> b;
  while(true)
  {
    if(c=='?') return 0;
    if(c=='+') cout << a+b << "\n";
    else if (c=='-') cout << a-b << "\n";
    else if (c=='/') cout << a/b << "\n";
    else cout << a*b << "\n";
    cin >> a >> c >> b;
  }
}


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

int main() {
  int n;
  cin >> n;
  
  cout << 111 + 999 - n << endl;
   
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)

int digit_sum(int x) {
  int ans = 0;
  while (x != 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for (int x = 1; x <= n; x++) {
    int ds = digit_sum(x);
    if (a <= ds && ds <= b) cerr << x << " " << ds << endl;
    if (a <= ds && ds <= b) ans += x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

const int mod = 1e9 + 7;
typedef long long li;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Mul(int x, int y) { return (int)((li)x * y % mod); }
inline int Mul(int x, int y, int z) { return Mul(x, Mul(y, z)); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) {
  return Pow(x, mod - 2);
}

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

const int maxn = 1e5;

typedef pair<int, int> pii;
vector<pii> P;

void Read(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  static int x[maxn], y[maxn];
  for (int i = 0; i < n; ++i) scanf("%d", x + i);
  for (int i = 0; i < m; ++i) scanf("%d", y + i);
  for (int i = 0; i < n; ++i) {
    if (x[i] < y[0] || x[i] > y[m - 1]) continue;
    int j = lower_bound(y, y + m, x[i]) - y;
    P.push_back({x[i] - y[j - 1], y[j] - x[i]});
  }
}

int ys[maxn + 1], ny;
int bit[maxn + 1];

void InitBit(void) {
  FILL(bit, ny, 0);
}

inline int Low(int i) {
  return i & -i;
}

void AddBit(int i, int x) {
  for (; i < ny; i += Low(i + 1)) {
    Add(bit[i], x);
  }
}

int SumBit(int i) {
  int sum = 0;
  for (--i; i >= 0; i -= Low(i + 1)) {
    Add(sum, bit[i]);
  }
  return sum;
}

int main(void) {
  Read();
  sort(P.begin(), P.end(), [&](const pii &a, const pii &b) -> bool {
      return a.first == b.first ? a.second > b.second : a.first < b.first;
    });
  P.erase(unique(P.begin(), P.end()), P.end());

  ny = 0;
  for (pii p : P) ys[ny++] = p.second;
  ys[ny++] = 0;
  sort(ys, ys + ny);
  ny = unique(ys, ys + ny) - ys;
  for (pii &p : P) {
    p.second = lower_bound(ys, ys + ny, p.second) - ys;
  }

  InitBit();
  AddBit(0, 1);
  for (pii p : P) {
    int y = p.second;
    AddBit(y, SumBit(y));
  }
  printf("%d\n", SumBit(ny));
  return 0;
}


Measured memory_bytes: 2420
ans = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
N = int(input())
print(*ans[:N])

Measured memory_bytes: 3064
n = int(input())
ans = 8
if n >= 400:
    ans = 8
if n >= 600:
    ans = 7
if n >= 800:
    ans = 6
if n >= 1000:
    ans = 5
if n >= 1200:
    ans = 4
if n >= 1400:
    ans = 3
if n >= 1600:
    ans = 2
if n >= 1800:
    ans = 1
print(ans)

Measured memory_bytes: 9140
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

int a; string s;

void solve() {
	cin >> a >> s;
	if (a >= 3200)cout << s << endl;
	else cout << "red" << endl;
}

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

using namespace std;

//typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



int powint(double a, double b){
	return (int)(pow(a, b) + 0.1);
}

// レベルnで、下からxまでのPの枚数
int P(int n, int x){
	if (n == 0){
		if (x == 0) return 0;
		else return 1;
	}
	if (x == 1)
		return 0;
	if (x <= 4 * powint(2.0, n-1) - 3 + 1)
		return P(n - 1, x - 1);
	else if (x == 4 * powint(2.0, n - 1) - 3 + 2)
		return P(n - 1, x - 1)+1;
	else
		return P(n - 1, x - (4 * powint(2.0, n - 1) - 3 + 2)) + (2 * powint(2.0, n - 1) - 1) + 1;
}

signed main(){

	int N, X;
	cin >> N >> X;

	cout << P(N, X) << endl;

	return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N,M;
	cin >> N>>M;
	ll sum = 0;
	for(int i =0; i<M;i++)
	{
		ll temp;
		cin >> temp;
		sum += temp;
	}
	if(sum > N)
	{
		cout <<"-1"<<endl;
	}
	else
	{
		cout << N-sum <<endl;	
	}
	

}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  int i;
  int sum=0;
  vector<int> vec(n);
  for(i=0;i<n;i++){
    cin >> vec.at(i);
    sum+=vec.at(i);
  }
  int count=n;
  sort(vec.begin(),vec.end());
  for(i=0;i<100000;i++){
    if(sum<=x){
      count++;
      sum+=vec.at(0);
    }else{
      break;
    }
  }
  cout << count-1;
}

 

Measured memory_bytes: 256
#include <iostream>

using namespace std;


void solve()
{
	double a[16];
	for(int i = 0; i < 16; ++i)
	{
		a[i] = i / 16.0;
	}
	double n;
	while(cin >> n, n >= 0)
	{
		char c[13];
		bool flag =true;
		for(int i = 0; i < 16; ++i)
		{
			if(n - (int)n == a[i])
			{
				flag = false;
				for(int j = 12; j >= 9; --j)
				{
					c[j] = i % 2 + '0';
					i /= 2;
				}
				break;
			}
		}
		if(flag)
		{
			cout << "NA" << endl;
		}
		else
		{
			c[8] = '.';
			int num = n;
			for(int i = 7; i >= 0; --i)
			{
				c[i] = num % 2 + '0';
				num /= 2;
			}
			for(int i = 0; i < 13; ++i)
			{
				cout << c[i];
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
n, m = map(int, input().split())

if n >= 2:
    n2 = int(n * (n - 1) / 2)
else:
    n2 = 0

if m >= 2:
    m2 = int(m * (m - 1) / 2)
else:
    m2 = 0
print(n2 + m2)


Measured memory_bytes: 2940
//http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_4_B
#include<iostream>
using namespace std;
int main(){
  int n,q;
  cin >> n;
  int S[n];
  for(int i = 0; i<n; i++){
    cin >> S[i];
  }
  cin >> q;
  int T[q];
  for(int i = 0; i<q; i++){
    cin >> T[i];
  }
  //Source??¨???????????????????????????????????????


  int answer = 0;
  int left = 0, right = n;
  for (size_t j = 0; j < q; j++) {
    int left = 0, right = n;
    int key = T[j];
    while(left < right){
      int mid = (left+right)/2;
      if(S[mid] == key){
        answer++;
      //  cout << j << "???????????¢?´¢?????????" << endl;
    //    cout << answer << endl;
        break;
      }
      else{
        if(S[mid] < key){
        left = mid+1;
      //  cout << "left " << left << endl;
        }
        else{
          right = mid;
        //  cout << "right " << right << endl;
        }
      }
    }
  }
  cout  << answer << endl;
  return 0;
}

Measured memory_bytes: 1744
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int a,b;

int main(){
	scanf("%d%d",&a,&b);
	if(a>=1&&a<=9&&b>=1&&b<=9) printf("%d",a*b);
	else printf("-1");
	return 0;
} 

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;

class DBouquet {
public:
    long myPow(int64_t x, int64_t n, int64_t m) {
        if (n == 1) {
            return x % m;
        }
        if (n % 2 == 0) {
            int64_t tmp = myPow(x, n / 2, m);
            return int64_t(tmp * tmp) % m;
        } else {
            int64_t tmp = myPow(x, (n - 1) / 2, m);
            return int64_t(tmp * tmp) % m * x % m;
        }
    }

    int64_t calc(int64_t n, int64_t a) {
        int64_t tmp = 1;
        for (int i = 1; i < a + 1; ++i) {
            tmp = (tmp * myPow(i, MOD - 2, MOD)) % MOD;
        }
        for (int i = n; i > n - a; --i) {
            tmp = tmp * i % MOD;
        }
        return tmp;
    }

    void solve(std::istream &cin, std::ostream &cout) {
        long n, a, b;
        cin >> n >> a >> b;
        cout << (MOD+MOD + myPow(2, n, MOD) - 1 - calc(n, a) - calc(n, b)) % MOD << endl;
    }
};


int main() {
    DBouquet solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

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

func main() {
	var d, g int
	fmt.Scan(&d, &g)
	p, c := make([]int, d), make([]int, d)
	for i := range p {
		fmt.Scan(&p[i], &c[i])
	}

	ans := 1000000000
	for mask := 0; mask < (1 << uint(d)); mask++ {
		s, num, restMax := 0, 0, -1
		for i := 0; i < d; i++ {
			if mask>>uint(i)&1 == 1 {
				s += 100*(i+1)*p[i] + c[i]
				num += p[i]
			} else {
				restMax = i
			}
		}
		if s < g {
			s1 := 100 * (restMax + 1)
			need := (g - s + s1 - 1) / s1
			if need >= p[restMax] {
				continue
			}
			num += need
		}
		ans = min(ans, num)
	}
	fmt.Println(ans)
}


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

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

	string s;
	cin >> s;
	int n = s.length();
	sort(s.begin(),s.end());
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "no";
			return 0;
		}
	}
	cout << "yes";
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		int[][] num = new int[4][13];
		char[][] suit = new char[4][13];
		while (true) {
			char trump = sc.next().charAt(0);
			if (trump == '#') break;
		
			for (int i = 0; i < 4; i++) {
				for (int j = 0; j < 13; j++) {
					String s = sc.next();
					if (Character.isDigit(s.charAt(0))) {
						num[i][j] = Integer.parseInt(""+s.charAt(0));
					} else {
						switch(s.charAt(0)) {
						case 'T': num[i][j] = 10; break;
						case 'J': num[i][j] = 11; break;
						case 'Q': num[i][j] = 12; break;
						case 'K': num[i][j] = 13; break;
						case 'A': num[i][j] = 14; break;
						}
					}
					suit[i][j] = s.charAt(1);
				}
			}
			
			int winner = 0;
			int ns = 0, sw = 0;
			for (int i = 0; i < 13; i++) {
				int max = 0, tmax = 0;
				int win = -1, twin = -1;
				for (int j = 0; j < 4; j++) {
					if (suit[j][i] == suit[winner][i]) {
						if (max < num[j][i]) {
							max = num[j][i];
							win = j;
						}
					} else if (suit[j][i] == trump) {
						if (tmax < num[j][i]) {
							tmax = num[j][i];
							twin = j;
						}
					}
				}
				if (tmax > 0) {
					winner = twin;
					if (twin % 2 == 0) ns++;
					else sw++;
				} else {
					winner = win;
					if (win % 2 == 0) ns++;
					else sw++;
				}
			}
			if (ns > sw) {
				out.printf("NS %d\n", ns-6);
			} else {
				out.printf("EW %d\n", sw-6);
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

using namespace std;

int calc_shortest(int i, int j, int x, int y) {
    if(i <= x && j >= y) {
        return x - i + j - y + 1;
    }
    if(i <= x && j >= x && j <= y) {
        return x - i + min(j - x, 1 + y - j);
    }
    if(j > y && i >= x && i <= y) {
        return j - y + min(y - i, 1 + i - x);
    }
    if(i >= x && i <= y && j >= x && j <= y) {
        return min(j - i, 1 + i - x + y - j);
    }
    return j - i;
}

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> cnt(n, 0);

    for(int i = 1; i <= n; i++) {
        for(int j = i+1; j <= n; j++) {
            // i is less than j
            int dist = calc_shortest(i, j, x, y);
            cnt[dist]++;
        }
    }
    for(int i = 1; i <= n-1; i++) {
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

ll sum;
ll m = (ll)2e9 + 1000;
int n;
bool eq = true;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	while(n--) {
		ll x, y;
		scanf("%lld%lld", &x, &y);
		sum += x;
		eq &= x == y;
		if (x > y) m = min(m, y);
	}
	if (eq) {
		printf("0\n");
	} else {
		printf("%lld\n", sum - m);
	}

	return 0;
}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class Key, class T> struct radix_heap {
  static_assert(is_integral<Key>::value, "");
  array<vector<pair<Key, T>>, sizeof(Key) * 8 + 1> v;
  Key last = 0;
  size_t sz = 0, ptr = 0;
  static int lg(Key a) { return a ? __lg(a) : -1; }
  void emplace(Key key, T val) {
    assert(key >= last);
    v[lg(key ^ last) + 1].emplace_back(key, val);
    ++sz;
  }
  void pull() {
    if (ptr < v[0].size()) return;
    v[0].clear(), ptr = 0;
    int i = 1;
    while (v[i].empty()) ++i;
    last = min_element(begin(v[i]), end(v[i]), [](auto a, auto b) {
      return a.first < b.first;
    })->first;
    for (auto e : v[i]) v[lg(e.first ^ last) + 1].push_back(e);
    v[i].clear();
  }
  pair<Key, T> top() { return pull(), v[0][ptr]; }
  void pop() { pull(), --sz, ++ptr; }
  bool empty() const { return sz == 0; }
};

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  array<int, 3> p{2, 3, 5};
  int tt;
  cin >> tt;
  while (tt--) {
    long long n, a[3], d;
    cin >> n >> a[0] >> a[1] >> a[2] >> d;
    map<long long, long long> dist;
    radix_heap<long long, long long> rh;
    rh.emplace(dist[n] = 0, n);
    while (true) {
      auto [dv, v] = rh.top();
      rh.pop();
      if (v == 0) {
        cout << dv << '\n';
        break;
      }
      if (dv != dist[v]) continue;
      for (int k = 0; k < 3; ++k) {
        auto r = v % p[k];
        {
          auto to = v / p[k];
          auto dto = dv + r * d;
          if (to) {
            dto += a[k];
          }
          if ((double)abs(v - to) * d < 9e18) {
            dto = min(dto, dv + abs(v - to) * d);
          }
          if (not dist.count(to) or dto < dist[to]) {
            rh.emplace(dist[to] = dto, to);
          }
        }
        {
          auto to = (v + p[k] - 1) / p[k];
          auto dto = dv + abs(to * p[k] - v) * d;
          if (to) {
            dto += a[k];
          }
          if ((double)abs(v - to) * d < 9e18) {
            dto = min(dto, dv + abs(v - to) * d);
          }
          if (not dist.count(to) or dto < dist[to]) {
            rh.emplace(dist[to] = dto, to);
          }
        }
      }
    }
  }
}


Measured memory_bytes: 4564
#include<iostream>
using namespace std;
typedef long long int ll;
const ll INF=(ll)1e18;
 
int main(){
  ll N;
 
  cin >> N;
 
  ll ans = INF;
  for(ll i = 1; i * i <= N; i++){
    if(N%i!=0)continue;
    ans = min(ans, i + (N/i) - 2);
  }
 
  cout << ans;
}

Measured memory_bytes: 256
N, C = map(int, input().split())
xs = []
vs = []
for i in range(N):
    x, v = map(int, input().split())
    xs += [x]
    vs += [v]


fAs = [0] * N
fAs[0] = vs[0]
for A in range(1, N):
    fAs[A] = fAs[A - 1] + vs[A]
for A in range(N):
    fAs[A] -= xs[A]

gAs = [0] * N
gAs[0] = 0
for A in range(1, N):
    gAs[A] = max(gAs[A - 1], fAs[A - 1])


fBs = [0] * N
fBs[N - 1] = vs[N - 1]
for B in range(0, N - 1)[::-1]:
    fBs[B] = fBs[B + 1] + vs[B]

for B in range(N):
    fBs[B] -= C - xs[B]

gBs = [0] * N
gBs[N - 1] = 0
for B in range(0, N - 1)[::-1]:
    gBs[B] = max(gBs[B + 1], fBs[B + 1])


ans = 0

# 初手：時計回り
for A in range(N):
    ans1 = fAs[A]

    # 2手目：反時計回り
    ans2 = max(0, gBs[A] - xs[A])

    ans = max(ans, ans1 + ans2)


# 初手：反時計回り
for B in range(N):
    ans1 = fBs[B]

    # 2手目：時計回り
    ans2 = max(0, gAs[B] - (C - xs[B]))

    ans = max(ans, ans1 + ans2)

print(ans)


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n+1];
		int b[] = new int[n+1];
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.fill(b, 0);
		int sum = 0;
		for (int i = n ; i >=1 ; i--) {
			for (int o = i; o <= n; o = o + i) {
				if (b[o] == 1) {
					sum++;
				}
			}
			b[i] = Math.abs((sum % 2) - a[i]);
			sum = 0;

		}

		int hai = haisum(b);
		System.out.println(hai);
		for (int i = 1; i <= n; i++) {
			if (b[i] == 1) {
				System.out.print(i + " ");
			}
		}
		System.out.println();

	}

	static int haisum(int a[]) {
		int n = a.length;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += a[i];
		}
		return ans;
	}

}

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

int main() {

#ifdef LOCAL_DEFINE
	freopen("input.txt", "rt", stdin);
#endif

	string s;
	int k;

	cin >> s >> k;

	int pos = -1, tmp;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') pos = i + 1;
		else {
			tmp = s[i] - '0';
			break;
		}
	}

	if (pos >= k) cout << 1 << endl;
	else cout << tmp << endl;

#ifdef LOCAL_DEFINE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s. \n";
#endif

	return 0;
}

Measured memory_bytes: 256
#include<math.h>
#include<cstdio>

bool check(int num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sr = sqrt((double)num);
    for (int i = 3; i <= sr; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n, x;
    int c = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        if (check(x)) c++;
    }
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 2712
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int k,n;
	cin >> k >> n;
	vi a(n);
	rep(i,n) cin >> a[i];
	sort(all(a));
	int d = k-(a[n-1]-a[0]);
	for(int i = 1; i < n; i++){
		d = max(d,a[i]-a[i-1]);
	}
	cout << k-d << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
static const int fast_io = [](){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);return 0;}();
static const int precise_doubles = [](){cout<<fixed<<setprecision(20);return 0;}();
typedef pair<int, int> PII;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(k) - iterator to kth largest, order_of_key(k) - #things < k
typedef long double LD;
typedef long long LL;
#define EVAL(x) x
#define NEWL EVAL({cout << '\n';})
#define SPA(x) EVAL({cout << #x" = " << x << ' ';})
#define SPAR(a, b) EVAL({cout<<#a" = ";for(auto it=a;it!=b;)cout<<*(it++)<<" ";cout<<'\n';})
#define SPAV(v) EVAL({cout<<#v" = ";for(auto it=v.begin();it!=v.end();)cout<<*(it++)<<" ";cout<<'\n';})
const int INF = 0x3f3f3f3f; // 1.0e9
const LL LINF = 0x3f3f3f3f3f3f3f3fll; // 4.5e18
const LD eps = 1e-20;
const int mod = 1e9 + 7;
inline int msum(int x, int y) {return (x+y<mod ? x+y : x+y-mod);}
inline int mdif(int x, int y) {return (x>=y ? x-y : x-y+mod);}
inline int mprod(int x, int y) { return (1ll*x*y) % mod; }
inline int mpow(int x, LL y) {LL r=1;while(y){if(y&1)r=mprod(r,x);x=mprod(x,x);y>>=1;}return r;}
inline int minv(int x) { return mpow(x, mod-2); }
//------------------------------------------------------------------------------------------------------

void die() {
    cout << -1 << endl;
    exit(0);
}

int main() {
    int m, k; cin >> m >> k;
    if (k >= (1 << m)) {
        die();
    }
    if (m == 1 and k == 1) {
        die();
    }
    if (m == 1 and k == 0) {
        cout << "0 0 1 1\n";
        return 0;
    }
    for (int i = (1<<m)-1; i >= 0; i--) {
        if (i != k) {
            cout << i << ' ';
        }
    }
    cout << k << ' ';
    for (int i = 0; i < (1<<m); i++) {
        if (i != k) {
            cout << i << ' ';
        }
    }
    cout << k << '\n';
}






























Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[2005];
int main(){
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            int pos=lower_bound(a+1,a+1+n,a[i]+a[j])-a-j-1;
            ans+=max(0,pos);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
?????????: Getting Started - Insertion Sort
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A&lang=jp
?????°
7/5
14:23 ?????£????????????part3
14:29 ????????????
*/
#include <iostream>
using namespace std;

void print(int* A, int N)
{
	cout << A[0];
	for(int i=1;i<N;i++){
		cout << " ";
		cout << A[i];
	}
	cout << endl;
}

void insertionSort(int* A, int N)
{
	for(int i=1; i<N; i++){
		int v = A[i];
		int j = i-1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		print(A,N);
	}
}



int a[100];

int main()
{
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	print(a,N);
	insertionSort(a,N);

}

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


int main() {
    int N;
    cin >> N;
    double cnt1 = 0;
    int cnt2 = 0;
    for (int i = 1; i <= N; ++i) {
        cnt1++;
        if (i%2 != 0){
            cnt2++;
        }
    }
    double ans = cnt2 / cnt1;
    cout << ans << endl;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
void print() {}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail){ cout << head << " \n"[sizeof...(tail) == 0]; print(forward<Tail>(tail)...);}
struct Integer{
public:

    ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;} //最大公約数

    ll lcm(ll a,ll b){return a / gcd(a, b) * b;} //最小公倍数

    bool isPrime(ll x){
        if(x < 2) return false;
        if(x == 2) return true;
        if(x % 2 == 0) return false;
        for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
        return true;
    }

    bool isSquare(ll x){
        ll lv = 0, rv = x+1;
        while(rv - lv > 1){
            ll mid = (lv + rv) / 2;
            if(mid * mid >= x){
                rv = mid;
            }else{
                lv = mid;
            }
        }
        if(rv * rv == x){
            return true;
        }else{
            return false;
        }
    }

    vector<ll> divisor(ll M){ //約数の全列挙
        vector<ll> dd;
        for(ll i = 1; i * i <= M; i++){
            if(M % i == 0){
                dd.push_back(i);
                if(i * i != M){
                    dd.push_back(M / i);
                }
            }
        }
        sort(dd.begin(), dd.end());
        return dd;
    }

    vector<ll> factor(ll M){ //素因数分解
        vector<ll> dd;
        if(M == 1){
            dd.push_back(1);
            return dd;
        }
        for(ll i = 2; i*i <= M; i++){
            while(M % i == 0){
                dd.push_back(i);
                M /= i;
            }
        }
        if(M != 1) dd.push_back(M);
        sort(dd.begin(), dd.end());
        return dd;
    }
};
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    Integer it;
    vector<ll> da = it.divisor(A);
    vector<ll> db = it.divisor(B);

    map<ll,ll> mp;
    for(auto &e: da) mp[e]++;
    for(auto &e: db) mp[e]++;
    ll ans = 0;
    for(auto &e: mp){
        if(it.isPrime(e.first) || e.first == 1){
            if(e.second >= 2){
                ans++;
            }
        }
    }
    print(ans);


    
}

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

int main() {
  int n;
  int l;
  char str[2000];

  scanf("%s %d", str, &n);

  l = strlen(str);

  int x = 0;
  while (x < l) {
    printf("%c", str[x]);
    x += n;
  }
  
  putchar('\n');

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


ll x[MAX], par[MAX];
vll edge[MAX];


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



  cin >> n >> m;
  rep(i, n + m - 1) {
    ll a, b;
    cin >> a >> b;
    edge[a].pb(b);
    x[b]++;
  }
  queue<ll> q;
  FOR(i, 1, n + 1) if (!x[i]) q.push(i);
  while (!q.empty()) {
    ll cur = q.front();
    q.pop();
    rep(i, edge[cur].size()) {
      ll to = edge[cur][i];
      x[to]--;
      if (!x[to]) {
        par[to] = cur;
        q.push(to);
      }
    }
  }
  FOR(i, 1, n + 1) cout << par[i] << endl;



  return 0;
}

Measured memory_bytes: 12160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n,cnt; 
int a[100050];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read();
	for (int i=1;i<=n;i++)
	  a[i]=read();
	for (int i=1;i<=n;i++)
	  if (a[i]%2==0) {
	  	while (true) {
	  	  if (a[i]%2==0) cnt++,a[i]/=2;
	  	  else break;
	    }
	}
	out(cnt);
}
	

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::{HashSet,HashMap};
#[allow(unused_imports)]
use std::cmp::{min,max};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input!(s:String);
    let s = s.chars().collect::<Vec<char>>();
    println!("{}{}{}", s[0], s.len() - 2, s[s.len() - 1]);
}


Measured memory_bytes: 4352
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
  	string s,a="",b="";
  int q,w=0;
  cin>>s>>q;
  while(q--){
   int t;
    cin>>t;
    if(t==1){
      w^=1;
    }else{
      int f;string c;
      cin>>f>>c;
      if(f==1){
        if(!w)a+=c;
        else b+=c;
      }else{
        if(!w)b+=c;
        else a+=c;
      }
    }
  }
  if(!w){
    reverse(all(a));
    cout<<a<<s<<b<<endl;
  }else{
    reverse(all(s));
    reverse(all(b));
    cout<<b<<s<<a<<endl;
  }
}







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

int main()
{
	int i, j;
	int ans;
	
	for(i = 1; i < 10; i++)
	{
		for(j = 1; j < 10; j++)
		{
			ans = i * j;
			cout << i << "x" << j << "=" << ans << endl;
		}
	}
	return 0;
	
}

Measured memory_bytes: 1116
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mod 1000000007
#define n 50
void add(int&x,int y){
	x=(x+y)%mod;
}
struct mat{
	int a[n][n];
};
mat operator*(mat a,mat b){
	mat c;for(int i=0;i<n;i++) for(int j=0;j<n;j++){
		c.a[i][j]=0;for(int k=0;k<n;k++) add(c.a[i][j],a.a[i][k]*b.a[k][j]);
	}
	return c;
}
mat qp[40];
mat qpow(mat x,int y){
	mat res;for(int i=0;i<n;i++) for(int j=0;j<n;j++) res.a[i][j]=(i==j);
	for(int i=0;i<31;i++) if((1ll<<i)&y) res=res*qp[i];
	return res;
}
int qpow(int x,int y){
	int res=1;
	while(y){
		if(y&1) res=res*x%mod;
		x=x*x%mod;y=y/2;
	}
	return res;
}

int id(int a,int b){
	if(a==10) return n-1;if(a==11) return -1;
	return a*2+b;
}mat base;
void up(int x,int y){
	if(x>=0 and y>=0)
	base.a[x][y]++;
}
signed main(){
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) base.a[i][j]=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<2;j++){
			int now=id(i,j);
			if(i%2==0){
				up(now,id(i,j^1));
				if(j==0) up(now,id(i+1,0)),up(now,id(i+1,1));
			}
			if(i%2==1){
				up(now,id(i,j));
				if(j==0) up(now,id(i,1));
				if(j==1) up(now,id(i+1,1));
				if(j==1) up(now,id(i+2,0));
				if(j==1) up(now,id(i+2,1));
			}
		}
	}
	
	base.a[n-1][n-1]++;
	qp[0]=base;for(int i=1;i<35;i++) qp[i]=qp[i-1]*qp[i-1];
	
	int t,y;scanf("%lld",&t);
	while(t--){
		scanf("%lld",&y);
		printf("%lld\n",qpow(base,y+1).a[id(0,0)][n-1]%mod);
	}	
	
	
	return 0;
}

Measured memory_bytes: 4636
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int N;
    scanf("%d",&N);
    long long a[N+10];
    for(int i=0; i<N; i++)
        scanf("%lld",&a[i]);
    sort(a,a+N);
    long long c=0,n,m;
    for(int i=N-1; i>0; i--)
    {
        if(a[i]==a[i-1])
        {
            c++,i--;
            if(c==1)
                n=a[i];
            if(c==2)
            {
                m=a[i];
                break;
            }
        }
    }
    if(c==2)
        printf("%lld\n",n*m);
    else
        printf("0\n");
}

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

using namespace std;

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

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

//#define int long long

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

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

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

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,C; cin >> A >> B >> C;
    if(A % 2 == 1 or B % 2 == 1 or C % 2 == 1){
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    while(1){
        VI tmp;
        tmp.eb(B/2 + C/2);
        tmp.eb(A/2 + C/2);
        tmp.eb(A/2 + B/2);
        sort(tmp.begin(),tmp.end());
        A = tmp[0]; B = tmp[1]; C = tmp[2];
        //cout << A << " " << B << " " << C << endl;
        if(A == B && B == C){
            cout << -1 << endl;
            return 0;
        }

        if(A%2 == 0 && B%2 == 0 && C%2 == 0){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;

}


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

int main(){

    int A, B, K;
    cin >> A >> B >> K;
    vector<int>vec;
    for(int i = 1;i<=min(A, B);i++){
        if(A % i == 0 && B % i == 0){
            vec.push_back(i);
        }
    }
    cout<<vec[vec.size() - K] << endl;
    
    return 0;
}

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

int main() {
    ll N, D;
    cin >> N >> D;
    ll cnt = 0;
    ll X,Y;

    for (ll i=0; i<N; i++){
        cin >> X >> Y;
        if (sqrt(X*X+Y*Y) <= D){
            cnt++;
        }
    }

    cout << cnt << endl;

}


Measured memory_bytes: 3676
import java.io.*;
public class Main {
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		int[] list=new int[10];
		int top=0;
		while(str!=null){
			int num=Integer.parseInt(str);
			if(num==0){
				System.out.println(list[top-1]);
				top--;
			}else{
				list[top]=num;
				top++;
			}
			str=br.readLine();
		}
	}
}

Measured memory_bytes: 24068
N,M=map(int,input().split())
A=[]
B=[]
G=[[]for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)

ans=0
cnt=0
while(1):
    if len(G[cnt])==0:
        cnt+=1
        continue
    m=min(G[cnt])
    break

while(1):
    cnt+=1
    if cnt>=N:
        break
    if cnt==m:
        #print(cnt,m)
        ans+=1
        while(1):
            if cnt==N:
                break
            if len(G[cnt])==0:
                cnt+=1
                continue
            m=min(G[cnt])
            break
    else:
        if len(G[cnt])==0:
            continue
        val=min(G[cnt])
        if val<m:
            m=val

print(ans)

Measured memory_bytes: 55456
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    string S;
    cin >> N >> S;
    map<char, ll> cSet;
    for(auto s : S){
        if(cSet.count(s)==0) cSet[s]=0;
        cSet[s]++;
    }
    ll sum = 1;
    for(auto c : cSet){
        if(c.second==1){
            sum *= 2;
        }else{
            sum *= (c.second+1);
        }
        sum %= 1000000007;
    }
    sum -= 1;
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<pii> v(N);
    REP(i, N) cin >> v[i].first >> v[i].second;
    sort(ALL(v));

    map<pii, int> dist;
    for (int k = 0; k < N; k++) {
        for (int l = k + 1; l < N; l++) {
            dist[{v[k].first - v[l].first, v[k].second - v[l].second}]++;
        }
    }
    int ans = N;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int p = v[i].first - v[j].first;
            int q = v[i].second - v[j].second;
            int cnt = dist[{p, q}];
            ans = min(ans, N - cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384