akhauriyash/Code-Regression huggingface dataset:
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_9_A
# Complete Binary Tree
# Result:
import sys

nary = int(sys.stdin.readline())
ary = [int(x) for x in sys.stdin.readline().rstrip().split(' ')]
assert nary == len(ary)

for (i, x) in enumerate(ary):
    id_ = i + 1
    key = x
    parent = id_ / 2
    left = id_ * 2
    right = id_ * 2 + 1
    str_ = 'node %d: key = %d, ' % (id_, key)
    if parent > 0:
        str_ += 'parent key = %d, ' % (ary[parent - 1])
    if left <= nary:
        str_ += 'left key = %d, ' % (ary[left - 1])
    if right <= nary:
        str_ += 'right key = %d, ' % (ary[right - 1])
    print str_

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

int main(){
  int a=0,b=0,n,m,k;
  cin >> k;
  while(k--){
    cin >> n >> m;
    if(n>a){
      a=n;b=m;
    }
  }
  cout << a+b<<endl;
}

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


void solve(){
    int x; cin >> x;
    cout << (x >= 30 ? "Yes\n" : "No\n");
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    bool multitest = false;
   // multitest = true;
    if(multitest){
        int t; cin >> t;
        while(t--)
            solve();
    }
    else
        solve();
}






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

e = [[int(i) for i in input().split()] for i in range(n)] 

marray = [0] * m
count = 0

for i in e:
    for j in i[1:]:
        marray[j-1] += 1

for i in marray:
    if i == n:
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

ll cnt(int n){
  if(n%2) return n-1+cnt(n-1);
  else return (n/2)*(n/2-1)*2; //4/2=2
}
void solve(int n){
  if(n%2){
    REP(i,1,n) cout<<i<<" "<<n<<'\n';
    solve(n-1);
  }else{
    vector<P> v;
    REP(i,1,n/2+1) v.eb(make_pair(i,n+1-i));
    rep(i,n/2-1)REP(j,i+1,n/2){
      cout<<v[i].fi<<" "<<v[j].fi<<'\n';
      cout<<v[i].fi<<" "<<v[j].se<<'\n';
      cout<<v[i].se<<" "<<v[j].fi<<'\n';
      cout<<v[i].se<<" "<<v[j].se<<'\n';
    }
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  out(cnt(n));
  solve(n);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n%1000==0){
        printf("0");
        return 0;
    }
    printf("%d",1000-n%1000);
    return 0;
}

Measured memory_bytes: 1736
while True:
    try:
        n = int(input())
        a = list(map(int,input().split()))
        s = sum(a)
        ave = s/n
    
        i = 0
        x = []
        while i <= n-1:
            if a[i] <= ave:
                x.append(a[i])
            i += 1

        print(len(x))
    
    except:
        if n == 0:
            break


Measured memory_bytes: 6616
H,W=map(int,input().split())
N=10
c=[[int(i) for i in input().split()] for i in range(N)]
A=[[int(i) for i in input().split()] for i in range(H)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            if c[i][j]>c[i][k]+c[k][j]:
                c[i][j]=c[i][k]+c[k][j]
ans=0
for i in range(H):
    for j in range(W):
        if A[i][j]!=-1:
            ans+=c[A[i][j]][1]
print(ans)


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

using namespace std;
using ll = long long;


int main()
{
	int n;
	cin >> n;
	int A[n];
	for (int i = 0; i < n; ++i)
		cin >> A[i];
	ll s = 0;
	for (int i = 1; i < n; ++i)
	{
		if (A[i] >= A[i -1])
			continue;
		else
		{
			s += A[i-1] - A[i];
			A[i] = A[i-1];
		}
	}
	cout << s << endl;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
typedef long long ll;

ll nCr(ll n){
    ll result;
    result = ( n * (n - 1) ) / 2;
    return result;
}

int main() {
    fast_io();
    ll former = 0;
    ll latter = 0;
    ll n; cin >> n;
    unordered_map<ll,ll> nums;
    vector<ll> A(n);
    ll k;
    rep(i,n){
        cin >> k;
        nums[k] += 1;
        A[i] = k;
    }
    for (auto it : nums) {
        former += nCr(it.second);
    }
    rep(i,n){
        k = A[i];
        latter = nums[k] - 1;
        cout << former - latter << '\n';
    }
    return 0;
}


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

int main() {
	long long int N;
	while( cin >> N, N ) {
		long long int ans = 0;
		vector<vector<long long int>>d( N + 1, vector<long long int>( 5 ) );
		for( size_t i = 1; i <= N; i++ ) {
			for( size_t j = 0; j < 5; j++ ) {
				cin >> d[i][j];
				ans += d[i][j];
			}
		}
		bool f = true;
		while( f ) {
			f = false;
			for( size_t i = 1; i <= N; i++ ) {
				if( d[i][2] ) {
					int now = d[i][2];
					int count = 1;
					int j = 3, k = 1;
					while( j < 5 && now == d[i][j] ) j++;
					while( k >= 0 && now == d[i][k] ) k--;
					if( j - k >3 ) {
						f = true;
						for( size_t l = k + 1; l < j; l++ ) {
							d[i][l] = 0;
						}
					}
				}
			}
			for( int i = N; i >= 1; i-- ) {
				for( size_t j = 0; j < 5; j++ ) {
					if( !d[i][j] ) {
						int k = i;
						while( k > 0 && !d[k][j] ) k--;
						if( k != 0 ) swap( d[i][j], d[k][j] );
					}
				}
			}
		}
		for( size_t i = 0; i <= N; i++ ) {
			for( size_t j = 0; j < 5; j++ ) {
				ans -= d[i][j];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;
// mp::cpp_int
// mp::cpp_dec_float_100
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll s, w;
  cin >> s >> w;
  
  //vector<ll> a(n);  rep(i, 0, n) cin >> a[i];
  
 // cout <<  << "\n";
  
  cout << ( s <= w ?"unsafe" :"safe") << "\n";
  
  //cout << fixed << setprecision(15) << n << "\n";

}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
using ll = long long;
int MOD = 1e9 + 7;
using namespace std;
ll GCD(ll x,ll y){
    if(y==0){
        return x;
    }else{
        return GCD(y, x % y);
    }
}
ll LCM(ll x,ll y){
    return x / GCD(x, y) * y;
}
struct UnionFind
{
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N)
    { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    int root(int x)
    { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y)
    {                     // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry)
            return;   //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y)
    { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n;i++){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end());
    if (n % 2 == 1)
    {
        if(vec[0]!=0){
            cout << 0 << endl;
            return 0;
        }
        for (int i = 1; i <= n / 2;i++){
            if(vec[i*2]!=i*2||vec[i*2-1]!=i*2){
                cout << 0 << endl;
                return 0;
            }
        }
    }else{
        for (int i = 0; i < n / 2;i++){
            if(vec[i*2]!=1+i*2||vec[i*2+1]!=1+i*2){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    ll sum = 1;
    for (int i = 0; i < n / 2;i++){
        sum *= 2;
        sum %= MOD;
    }
    cout << sum << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
main()
{
  int a,b,i,c=0;
  while(scanf("%d %d",&a,&b)!=EOF){
  

    a=a+b;
    if(a==0){
      a=1;
    }
    c=(int)log10(a);
 
 
    printf("%d\n",c+1);
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }
template<class T>
inline T upper(T a, T b) {return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int a[51][26];

int main() {

	int n;
	cin >> n;

	memset(a, 0, sizeof(a));
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;

		for (int j = 0; j < s.size(); ++j) {
			a[i][s[j] - 97]++;
		}
	}

	string ans;
	for (int i = 0; i < 26; ++i) {
		int mn = inf;

		for (int j = 0; j < n; ++j) {
			mn = min(mn, a[j][i]);
		}

		for (int j = 0; j < mn; ++j) {
			ans += char(i + 97);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
const int N=1e5;
using namespace std;
int main()
{
	int n,k;
	int a[N],b[N];
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	int t=0;
	for(int i=0;i<n-k+1;i++){
		int m=abs(a[i+k-1]-a[i]);
		b[i]=m;
		t++;
	}
	sort(b,b+t);
	cout<<b[0]<<endl;
	return 0;
 } 

Measured memory_bytes: 1024
#include <stdio.h>
#define maxn 100010
struct node{
	int to,next;
}e[maxn<<1];
int h[maxn],head[maxn],tot,cnt;
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
int main(){
	int n,m,u,v,i,b,flag1,flag2;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",&h[i]);
	for(i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
	for(i=1;i<=n;i++){
		flag1=0,flag2=0;
		for(b=head[i];b;b=e[b].next){
			flag1=1,v=e[b].to;
			if(h[i]<=h[v]){flag2=1;break;}
		}
		if(!flag1)cnt++;
		else if(!flag2)cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        ll l=1,r=0;
        while(s[i+1]=='R'){i++;l++;}
        while(s[i+1]=='L'&&i<s.size()-1){i++;r++;}
        ll fir=(l+r)/2,sec=fir;
        if((l+r)&1){
            ll len=max(l-1,r-1);
            if(len&1&&l<r||len%2==0&&r<l)fir++;
            else sec++;
        }
        //cout<<l<<" "<<r<<" "<<fir<<" "<<sec<<"\n";
        for(int j=i-l-r+1;j<=i;j++){
            if(s[j]=='R'&&s[j+1]=='L'){cout<<fir<<" "<<sec<<" ";j++;}
            else cout<<"0 ";
        }
    }
}


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

int main(){
  int cards[4][14], limit, number, index;
  char mark;

  cin >> limit;

  for(int j = 0; j < 4; j++){
    for(int k = 1; k < 14; k++){
      cards[j][k] = false;
    }
  }

  for(int i = 0; i < limit; i++){
    cin >> mark >> number;

    if( mark == 'S') cards[0][number] = true;
    if( mark == 'H') cards[1][number] = true;
    if( mark == 'C') cards[2][number] = true;
    if( mark == 'D') cards[3][number] = true;
  }

  for(int j = 0; j < 4; j++){
    for(int k = 1; k < 14; k++){
      if(cards[j][k]) continue;
      if(j == 0) cout << 'S' << ' ' << k << endl;
      if(j == 1) cout << 'H' << ' ' << k << endl;
      if(j == 2) cout << 'C' << ' ' << k << endl;
      if(j == 3) cout << 'D' << ' ' << k << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var h = new int[4].Select(_ => int.Parse(Console.ReadLine())).ToArray();
		var r = 0;
		for (int i = 500 * h[0]; i >= 0; i -= 500)
			for (int j = 100 * h[1]; j >= 0; j -= 100)
			{
				var k = (h[3] - i - j) / 50;
				if (0 <= k && k <= h[2]) r++;
			}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 13268
while 1:
	H, W = map(int, input().split())
	if (H == 0 and W == 0) : break
	for i in range(H):
		if (i == 0 or i == H - 1):
			print("#" * W)
		else: 
			print("#" + "." * (W - 2) + "#")
	print("")

Measured memory_bytes: 7468
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <string.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <functional>
#include <map>
#include <typeinfo>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<double, double> pd;
typedef pair<ll, ll> pl;

int adj[200001];
int co[200001];
int hp[200001];
vector<int> sorted;

int main()
{
  int n, d, a;
  scanf("%d %d %d", &n, &d, &a);
  
  for(int i = 0; i < n; i++)
  {
    scanf("%d %d", &co[i], &hp[i]);
    sorted.push_back(i);
    hp[i] = ceil((double)hp[i]/a);
  }
  
  sort(sorted.begin(), sorted.end(), [](int a, int b) -> bool {
    return co[a] < co[b];
  });
  
  ll res = 0;
  
  int num = 0;
  queue<pi> q;
  
  for(int i = 0; i < n; i++)
  {
    int idx = sorted[i];
    while(!q.empty() && q.front().first < co[idx])
    {
      num -= q.front().second;
      q.pop();
    }
    
    hp[idx] -= num;
    
    if(hp[idx] < 0)
      continue;
    
    num += hp[idx];
    q.push(make_pair(co[idx]+d*2, hp[idx]));
    res += hp[idx];
    //printf("%daa\n", hp[i]);
  }
  
  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 3444
class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n)]
    def root(self, x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.root(self.par[x])
            return self.par[x]
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def unite(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x!=y:
            self.par[x]=y

n, m=map(int, input().split())
p=[int(s)-1 for s in input().split()]
pair=[[int(s)-1 for s in input().split()] for _ in range(m)]

uf=UnionFind(n)
for pi in pair:
    uf.unite(pi[0],pi[1])

cnt=0
for i, pi in enumerate(p):
    if uf.same(i,pi):
        cnt+=1
print(cnt)



Measured memory_bytes: 29412
import java.io.*;
import java.util.*;

public class Main {

    void run() {
        while (true) {
            int R = readInt();
            int C = readInt();
            if(R == 0 && C == 0) break;
            boolean[][] osenbei = new boolean[R][C];
            for (int i = 0; i < R; i++) {
                for (int j = 0; j < C; j++) {
                    int x = readInt();
                    osenbei[i][j] = x == 1;
                }
            }
            int ans = 0;
            for (int S = 0; S < 1 << R; S++) {
                int tmp = 0;
                for (int j = 0; j < C; j++) {
                    int k = 0;
                    for (int i = 0; i < R; i++) {
                        if(osenbei[i][j] ^ (((S >> i) & 1) != 0)) k++;
                    }
                    tmp += Math.max(k, R - k);
                }
                ans = Math.max(ans, tmp);
            }
            sysout.println(ans);
        }
    }

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

    // flush automatically iff you call `println` or `printf` or `format`.
    PrintWriter sysout = new PrintWriter(System.out, true);

    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer buffer = new StringTokenizer("");

    String read() {
        if (!buffer.hasMoreTokens()) {
            try {
                buffer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return buffer.nextToken();
    }

    int readInt() {
        return Integer.parseInt(read());
    }

    long readLong() {
        return Long.parseLong(read());
    }

    double readDouble() {
        return Double.parseDouble(read());
    }

    String readLine() {
        buffer = new StringTokenizer("");
        try {
            return in.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Measured memory_bytes: 28900
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

string lshift(string &msg) {
  string front{msg[0]};
  return msg.substr(1, msg.size() - 1) + front;
}

string rshift(string &msg) {
  string back{msg[msg.size() - 1]};
  return back + msg.substr(0, msg.size() - 1);
}

void add_num(string &msg, int32_t num) {
  for (uint32_t i = 0; i < msg.size(); i++) {
    if ('0' <= msg[i] && msg[i] <= '9') {
      msg[i] += num;
      if (msg[i] < '0') msg[i] = '9';
      if ('9' < msg[i]) msg[i] = '0';
    }
  }
}

string swap(string &msg) {
  string front = msg.substr(0, msg.size() / 2);
  if (msg.size() % 2 == 0) {
    string back = msg.substr(msg.size() / 2, msg.size() - msg.size() / 2);
    return back + front;
  } else {
    string center{msg[msg.size() / 2]};
    string back =
        msg.substr(msg.size() / 2 + 1, msg.size() - (msg.size() / 2 + 1));
    return back + center + front;
  }
}

int32_t main() {
  uint32_t n;
  cin >> n;
  for (uint32_t _ = 0; _ < n; _++) {
    string mem;
    cin >> mem;
    string msg;
    cin >> msg;

    for (int32_t i = mem.size() - 1; i >= 0; i--) {
      switch (mem[i]) {
        case 'A':
          reverse(msg.begin(), msg.end());
          break;
        case 'P':
          add_num(msg, -1);
          break;
        case 'M':
          add_num(msg, +1);
          break;
        case 'J':
          msg = rshift(msg);
          break;
        case 'C':
          msg = lshift(msg);
          break;
        case 'E':
          msg = swap(msg);
          break;
      }
    }

    cout << msg << endl;
  }

  return 0;
}

Measured memory_bytes: 3172
/**
 *  author: mahfuzz
 *  created: 06.07.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define trace(x) cout << #x << ':' << x << "\n"
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    char c; cin >> c;
    
    if(c >= 'A' && c <= 'Z')
        cout << "A\n";
    else
        cout << "a\n";
        
    return 0;
}


Measured memory_bytes: 3564
N,W = map(int,input().split())
w,v=[0]*N,[0]*N

for i in range(N):
  w[i],v[i]=map(int,input().split())

dp=[[0]*(W+1) for _ in range(N+1)]

for i in range(N):
  for j in range(W+1):
    if j-w[i]>=0:
      dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i])
    dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

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

int main(){
    int n,ans=1000500;cin>>n;vector<int> w(n);
    for(int i=0;i<n;i++) cin>>w.at(i);
    for(int i=0;i<n;i++){
        int sum1=0,sum2=0;
        for(int j=0;j<=i;j++) sum1+=w.at(j);
        for(int j=i+1;j<n;j++) sum2+=w.at(j);
        ans=min(ans,max(sum1-sum2,sum2-sum1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <set>
#include <cstdio>
#include <queue>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  while(int n = getInt()){
    vector<vector<int> > v(n);
    REP(i,n){
      int m = getInt();
      REP(j,m) v[i].push_back(getInt());
    }

    int k = getInt();
    REP(i,k){
      int r = getInt();
      for(auto &vv : v){
	auto it = find(vv.begin(), vv.end(), r);
	if(it != vv.end()) *it = -1;
      }
    }

    vector<int> ans;
    REP(i,n) if(count(v[i].begin(), v[i].end(), -1) == k)
      ans.push_back(i + 1);
    printf("%d\n", ans.size() == 1 ? ans[0] : -1);
  }

  return 0;
}

Measured memory_bytes: 1104
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;

int main()
{
	int n,k;
	cin>>n>>k;
	if(n%k==0)
		cout<<0<<endl;
	else
		cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
#define INF 1010001000
#define loop(i, n) for (int i = 0; i < n; i++)
#define mp make_pair
typedef pair<int, int> i_i;

bool dfs(vector<vector<int> > &g);

int sx, sy, gx, gy;
int w, h;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main()
{

    while (cin >> w >> h, (w|h) ) {
        w++;
        h++;
        vector<vector<int> > graph(w, vector<int>(h, 0));
        cin >> sx >> sy >> gx >> gy;
        int blocks;
        cin >> blocks; 
        loop(i, blocks){
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            if (d) {
                for (int j = x; j < x+2; j++) {
                    for (int k = y; k < y+4; k++) {
                        graph[j][k] = c;
                    }
                }
            } else {
                for (int j = x; j < x+4; j++) {
                    for (int k = y; k < y+2; k++) {
                        graph[j][k] = c;
                    }
                }
            }
        }
        cout << ((dfs(graph))?"OK":"NG") << endl;
    }
    return 0;
}

bool dfs(vector<vector<int> > &g)
{
    int cl = g[sx][sy];
    vector<vector<bool> > check(w, vector<bool>(h, false));
    queue<i_i > q;
    q.push(mp(sx,sy));
    while(!q.empty()){
        int x = q.front().first, y = q.front().second;
        q.pop();
        if(x == gx && y == gy){
            return true;
        }
        if(check[x][y]){
            continue;
        } else {
            check[x][y] = true;
        }

        loop(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (0 < nx && nx < w && 0 < ny && ny < h){
                if (g[nx][ny] == cl){
                    q.push(mp(nx,ny));
                }
            }
        }

    }
    return false;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

// t:0or1, i:相手が何枚目を持ってるか
int solve(const vi& a,int t,int i,vvi& memo)
{
	int& res=memo[t][i];
	if(res!=-1) return res;

	int n=a.size();
	res=abs(a[i]-a[n-1]);
	if(t==0)  // 最大化
		repi(j,i+1,n-1)
			chmax(res,solve(a,!t,j,memo));
	else  // 最小化
		repi(j,i+1,n-1)
			chmin(res,solve(a,!t,j,memo));
	return res;
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,z,w;cin>>n>>z>>w&&n|z|w;){
		vi a(n+2);
		a[0]=z,a[1]=w;
		rep(i,n) cin>>a[i+2];
		vvi memo(2,vi(n+2,-1));
		cout<<solve(a,0,1,memo)<<endl;
	}
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
// https://atcoder.jp/contests/abc068/tasks/abc068_b
// 無難に1からNまで全部のチェックをする
// (楽をする場合は1->1,2-3->2,4-7->4..と決め打ち、二進表現など)

int solver(int gavenNumber){
    int result;
    result = 1;
    int defaultTwoDivCounter = 0;
    for(int j=1;j<gavenNumber+1;j++){
        int twodivCounter=0;
        int objectNumber;
        objectNumber = j;
        while(true){
            if(objectNumber%2 == 0){
                twodivCounter = twodivCounter + 1;
                objectNumber = objectNumber / 2;
            }
            else{
                break;
            }
        }
        if(defaultTwoDivCounter < twodivCounter){
            defaultTwoDivCounter = twodivCounter;
            result = j;
        }
    }
    return result;
}

int main(void){
    int N,answer;
    cin >> N ;
    answer = solver(N);
    cout << answer << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;
const ll INF=3e13;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,q;
  cin>>n>>q;
  vector<ll> as(q),bs(q);
  rep(i,q) cin>>as[i]>>bs[i];
  map<ll,ll> mp;
  mp[0]=3e13;
  mp[1]=0;
  rep(i,q){
    ll a=as[i],b=bs[i];
    //cout<<pii(a,b)<<endl;
    auto it=mp.upper_bound(a+1); --it;
    ll orig=it->Y;
    while(b){
      //for(auto p:mp) cout<<p;cout<<endl;
      auto it=mp.upper_bound(a);
      --it;
      // if(it->X == 1,0){
      // 	ll ad=b/a, x=b%a;
      // 	if(x){
      // 	  mp[0]+=ad+1;
      // 	  mp[x]=mp[0]-1;
      // 	}else{
      // 	  mp[0]+=ad;
      // 	}
      // }else{
      ll v=it->Y;
      ll len=a-it->X+1;
      auto ite=it;
      ll lb=ite->X;
      //cout<<pll(v,len)<<*ite<<endl;
      --it;
      if((it->Y-v)>b/len){
	ll ad=b/len, x=b%len;
	//cout<<ad<<","<<x<<endl;
	if(x){
	  if(v+b/len+1==it->Y) mp.erase(ite);
	  else mp[lb]+=ad+1;
	  mp[lb+x]=v+ad;
	}else{
	  mp[lb]+=ad;
	}
	break;
      }else{
	b-=(it->Y-v)*len;
	mp.erase(ite);
      }
    }
    it=mp.upper_bound(a+1);
    --it;
    if(it->Y!=orig) mp[a+1]=orig;
    //for(auto p:mp) cout<<p;cout<<endl;
  }
  ll re=0;
  reps(i,1,n+1){
    if(mp.count(i)) re=mp[i];
    cout<<re<<endl;
  }
  return 0;
}


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

int n, a[120], b, f, r, v;

int main() {
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> b >> f >> r >> v;
        a[30*(b-1)+10*(f-1)+r-1]+=v;
    }
    for (int i=0; i<120; i++) {
        cout << " " << a[i];
        if (i%10 == 9) cout << endl;
        if (i%30 == 29 && i!=119) cout << "####################" << endl;
    }
}


Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int m, k;
    cin >> m >> k;

    if(m == 0) {
        if(k == 0) {
            cout << 0 << " " << 0;
        }
        else {
            cout << -1;
        }
        cout << endl;
        return 0;
    }
    
    if(m == 1) {
        if(k == 0) {
            cout << 0 << " " << 0 << " " << 1 << " " << 1;
        }
        else {
            cout << -1;
        }
        cout << endl;
        return 0;
    }

    int p = 1;
    rep(i, m) {
        p *= 2;
    }
    
    if(k >= p) {
        cout << -1 << endl;
        return 0;
    }

    rep(i, p) {
        if(i != k) {
            cout << i << " ";
        }
    }
    cout << k << " ";
    for(int i = p-1; i >= 0; i--) {
        if(i != k) {
            cout << i << " ";
        }
    }
    cout << k;

    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<double> data(N);
  double sum = 0;
  for(int i = 0; i < N; i++){
    cin >> data.at(i);
    sum += data.at(i);
  }
  sum /= N;
  double sub = 10000, a;
  for(int i = 0; i < N; i++){
    if(abs(sum - data.at(i)) < sub){
      a = i;
      sub = abs(sum - data.at(i));
    }
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int height = 0;
        for (int i = 0; i < b - a; i++) {
            height += i;
        }
        System.out.println(height - a);
    }
}


Measured memory_bytes: 21076
n = int(input())
w = [input() for i in range(n)]
for i in range(n-1):
   if w[i][-1] != w[i+1][0]:
      print('No')
      exit()
   else:
    for j in range(i+1,n):
      if w[i] == w[j]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 998244353;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int ddx = tx - sx;
    int ddy = ty - sy;
    string ans;
    rep(i, ddx) {
        ans += 'R';
    }
    rep(i, ddy) {
        ans += 'U';
    }
    ans += 'R';
    rep(i, ddy + 1) {
        ans += 'D';
    }
    rep(i, ddx + 1) {
        ans += 'L';
    }
    ans +='U';
    ans += 'L';
    rep(i, ddy + 1) {
        ans += 'U';
    }
    rep(i, ddx + 1) {
        ans += 'R';
    }
    ans += 'D';
    rep(i, ddx) {
        ans += 'L';
    }
    rep(i, ddy) {
        ans += 'D';
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b,c;
  cin >> a >> b >> b >> b >> b >> c;
  if (b-a>c){
    cout << ":(";
  }else{
    cout << "Yay!";
  }
}
  /*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

template<typename T>
class CumulativeSum{
public:
  int n;
  vector<T> sum;
  vector<T> A;
  int added;
  CumulativeSum():n(-1),added(0){}
  CumulativeSum(int n):n(n), sum(n+1), A(n+1),added(0){}
  CumulativeSum(const vector<T> &B):n(B.size()), sum(n+1), A(n+1),added(0){
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + B[i-1];
  }

  void apply(){
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) A[i] = A[i] + A[i-1];
    for(int i=1;i<=n;i++) sum[i] = sum[i] + A[i-1];
    added = 0; A.clear(); A.resize(n+1);
  }

  //[l, r)にxを加算
  void add(int l, int r, T x){
    added = 1;
    assert(l <= r && 0 <= l && r <= n);
    A[l] = A[l] + x;
    A[r] = A[r] - x;
  }

  //[l, r)の和を得る
  T get(int l,int r){
    assert(l<=r && 0<=l && r<=n);
    if(added) apply();
    return sum[r] - sum[l];
  }
};


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  string s;
  cin>>s;
  N = s.size();

  vector<int> A(N), B(N);
  for(int i=0;i<N;i++) A[i] = s[i] =='.';
  for(int i=0;i<N;i++) B[i] = s[i] =='#';

  CumulativeSum <int> sum1(A), sum2(B);
  int ans = 1000000000;
  for(int i=0;i<=N;i++){
    int a = sum2.get(0, i);
    int b = sum1.get(i, N);
    int cost = a + b;
    Min(ans, cost);
  };
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 5268
import math
def main():
  n = int(input())
  a=list(map(int,input().split()))
  max=a[0]
  min=a[0]
  
  for i in range(1,n):
    if a[i]>max:
      max=a[i]
    if a[i] < min:
      min=a[i]
  print(max-min)
main()


Measured memory_bytes: 9188
#include <deque>
#include <iostream>
#include <queue>
#include <vector>
#define INF 0x3f3f3f3f

using namespace std;

const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int h, w, sx, sy, ex, ey;

int main() {
  cin >> h >> w >> sx >> sy >> ex >> ey;
  sx--, sy--, ex--, ey--;
  vector<string> a(h);
  for (int i = 0; i < h; ++i)
    cin >> a[i];
  vector<vector<int>> dist(h, vector<int>(w, INF));
  vector<vector<bool>> vis(h, vector<bool>(w, false));
  deque<pair<int, int>> q;
  q.push_back({sx, sy});
  dist[sx][sy] = 0;
  while (!q.empty()) {
    auto f = q.front();
    q.pop_front();
    int ci = f.first, cj = f.second;
    if (ci == ex && cj == ey) {
      cout << dist[ci][cj];
      return 0;
    }
    if (vis[ci][cj])
      continue;
    vis[ci][cj] = true;

    for (int k = 0; k < 4; ++k) {
      int ni = ci + dy[k], nj = cj + dx[k];
      if (ni < 0 || ni >= h || nj < 0 || nj >= w ||
          dist[ni][nj] <= dist[ci][cj] || a[ni][nj] == '#')
        continue;
      dist[ni][nj] = dist[ci][cj];
      q.push_front({ni, nj});
    }
    
    for (int ni = ci - 2; ni <= ci + 2; ++ni)
      for (int nj = cj - 2; nj <= cj + 2; ++nj) {
        if (ni < 0 || ni >= h || nj < 0 || nj >= w || a[ni][nj] == '#' ||
            dist[ni][nj] <= dist[ci][cj] + 1)
          continue;
        dist[ni][nj] = dist[ci][cj] + 1;
        q.push_back({ni, nj});
      }
  }
  cout << -1;
}


Measured memory_bytes: 9632
mod = int(1e9) + 7
x, y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
    exit()

n = (x+y)//3
a = x - n
b = y - n
r = min(a, b)
if r < 0:
    print(0)
    exit()
val1 = 1
for i in range(a+b):
    val1 = (val1 * ((a+b) - i)) % mod
val2 = 1
for i in range(r):
    val2 = (val2 * (r-i)) % mod
for i in range(a+b-r):
    val2 = ((val2% mod) * ((a+b-r)-i)) % mod
# val1 = factorial(a+b) % mod
# val2 = (factorial(r) % mod * factorial((a+b)-r) % mod) % mod
print((val1 * pow(val2,mod-2,mod)) % mod)

Measured memory_bytes: 41900
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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 before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int N;
    cin>>N;
    vector<int> ans;
    REP(i,N+1) {
        if(i*(i+1)/2>=N) {
            RREP(j,i) {
                if(j==0) break;
                if(N>=j) {
                    N-=j;
                    cout<<j<<endl;
                }
            }
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;

int a[maxn],n;
string s;

int main()
{
	cin>>n;
	a[1]=0;a[2]=0;a[3]=0;a[4]=0;
	for(int i=1;i<=n;++i)
	{
		cin>>s;
		if(s[0]=='A') a[1]++;
		if(s[0]=='W') a[2]++;
		if(s[0]=='T') a[3]++;
		if(s[0]=='R') a[4]++;
	}
	cout<<"AC x "<<a[1]<<endl;
    cout<<"WA x "<<a[2]<<endl;
    cout<<"TLE x "<<a[3]<<endl;
    cout<<"RE x "<<a[4]<<endl;
}


Measured memory_bytes: 3620
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
	int n,c;
	String b;
	Scanner scan=new Scanner(System.in);
	n=scan.nextInt();
	int a[][]=new int[4][13];
	for(int i=0;i<n;i++)
	    {
		b=scan.next();
		c=scan.nextInt();
		if(b.equals("S"))a[0][c-1]=1;
		else if(b.equals("H"))a[1][c-1]=1;
		else if(b.equals("C"))a[2][c-1]=1;
		else if(b.equals("D"))a[3][c-1]=1;
	    }
	
	for(int i=0;i<4;i++)
	    {
		for(int j=0;j<13;j++)
		    {
			if(a[i][j]==0 && i==0)
			    {
				System.out.println("S "+(j+1));
			    }
			else if(a[i][j]==0 && i==1)
			    {
				System.out.println("H "+(j+1));
			    }
			else if(a[i][j]==0 && i==2)
			    {
				System.out.println("C "+(j+1));
			    }
			else if(a[i][j]==0 && i==3)
			    {
				System.out.println("D "+(j+1));
			    }
		    }
	    }
    }
}

Measured memory_bytes: 18052
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VL a(n);
    REP(i,n) a[i] = in();
    VL dp(n, 1e18);
    dp[0] = 0;
    FOR(i,1,n-1){
        dp[i] = dp[i-1] + abs(a[i] - a[i - 1]);
        if (i > 1) dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n , l; cin >> n >> l;
  string arr[n];
  for(int i=0; i<n; i++) cin >> arr[i];
  sort(arr, arr+n);
  for(int i=0; i<n; i++) cout << arr[i];
  cout << endl;
}

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

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

	int r = 0;
	for (int i = 0; i < n; i++) {
		if (stones.at(i) == 'R') r++;
	}

	int ans = 0;
	for (int i = 0; i < r; i++) {
		if (stones.at(i) == 'W') ans++;
	}

	cout << ans << endl;
}

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int S;
  cin >> S;

  if((S%100>0&&S%100<=12)&&(S/100>0&&S/100<=12)){
    cout << "AMBIGUOUS" << endl;
  }else if((S%100>0&&S%100<=12)&&(S/100>12||S/100==0)){
    cout << "YYMM" << endl;
  }else if((S%100==0||S%100>12)&&(S/100>0&&S/100<=12)){
    cout << "MMYY" << endl;
  }else{
    cout << "NA" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	long long n, m;
	cin >> n >> m;

	vector<bool> p(n);
	vector<long long> s(n);

	for(long long i=0;i<m;i++){
		long long pp;
		string ss;
		cin >> pp >> ss;
		if(p.at(pp-1)==0){
			if(ss=="WA")
				s.at(pp-1) += 1;
			else if(ss=="AC")
				p.at(pp-1) = 1;
		}
	}

	long long ac = 0, wa = 0;
	for(long long i=0;i<n;i++){
		ac += p.at(i);
		if(p.at(i)==1)
			wa += s.at(i);
	}

	cout << ac << ' ' << wa << endl;
}

Measured memory_bytes: 1024
//「合成抵抗」(https://beta.atcoder.jp/contests/cf16-relay-open/tasks/relay_a)

#include<iostream>


int main(){
	//標準入力
	int r[2];
	std::cin>>r[0]>>r[1];

	//処理
	//1/R3=1/R1+1/R2
	//これを加工してR3=R1R2/(R1+R2)
	double ans=r[0]*r[1];//計算誤差を抑えるため、計算結果の途中経過をdoubleにしておく
	ans=ans/(r[0]+r[1]);

	//出力
	//std::cout<<ans<<std::endl;//桁数の指定がめんどいのでprintfに
	printf("%.8f",ans);

	return 0;
}


Measured memory_bytes: 256