akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long dp[51][51][2501] = {};

int main() {
    int N, K;
    cin >> N >> K;
    dp[0][0][0] = 1;
    for(int i=1; i<=N; ++i) {
        for(int j=0; j<=i; ++j) {
            for(int k=0; k<=N*N; ++k) {
                if(k < 2 * j) continue;
                dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j][k - 2 * j] * (2 * j + 1)) % MOD;
                if(j + 1 < i) dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j + 1][k - 2 * j] * (j + 1) * (j + 1)) % MOD;
                if(j > 0) dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j - 1][k - 2 * j]) % MOD;
            }
        }
    }
    cout << dp[N][0][K] << endl;
}

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

int main() {
	int N;
	int D1, D2;
	int count = 0;
	string ok ="No";

	cin >> N;

	for (int i = 0; i < N; i++) {

		cin >> D1 >> D2;

		if (D1 == D2) {
			count++;
		}
		else {
			count = 0;
		}
		if (count > 2) {
			ok = "Yes";
			count = 0;
		}
	}

	cout << ok << endl;

	

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    char buf[200];
    while(fgets(buf, sizeof(buf), stdin), buf[0] != '.'){
        stack<char> s;

        for(int i = 0; i < strlen(buf); i++){
            if(not s.empty()){
                if(s.top() == '(' && buf[i] == ')'){
                    s.pop();
                    continue;
                } else if(s.top() == '[' && buf[i] == ']'){
                    s.pop();
                    continue;
                }
            }

            if(buf[i] == '(' || buf[i] == ')' || buf[i] == '[' || buf[i] == ']') s.push(buf[i]);

        }
        if(s.empty()) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 3052
#include <iostream>
#include <math.h>

using namespace std;
int main () {
    int d ,n;
    cin >> d >> n;
    if (n == 100) {
        printf("%.0f\n", pow(100, d)*101);
    } else {
        printf("%.0f\n", pow(100, d)*n);
    }

} 

Measured memory_bytes: 256
class Node:
    key = None
    parent = None
    left = None
    right = None

    def __init__(self, key):
        self.key = key


def insert(key):
    global T
    global root

    new_node = Node(key)
    T.append(new_node)

    if root is None:
        root = new_node

    else:
        y = None  # 親
        x = root  # 子

        while x is not None:
            y = x
            if key < x.key:
                x = x.left
            else:
                x = x.right

        new_node.parent = y
        if new_node.key < y.key:
            y.left = new_node
        else:
            y.right = new_node


def in_order(node, order):
    if node is None:
        return

    in_order(node.left, order)
    order.append(node.key)
    in_order(node.right, order)


def pre_order(node, order):
    if node is None:
        return

    order.append(node.key)
    pre_order(node.left, order)
    pre_order(node.right, order)


m = int(input())
T = []
root = None

for i in range(m):
    order = input()

    if order.startswith('print'):
        output = []
        in_order(root, output)
        # print(output)
        print(' ' + ' '.join(map(str, output)))

        output = []
        pre_order(root, output)
        # print(output)
        print(' ' + ' '.join(map(str, output)))

    else:
        order, value = order.split()
        value = int(value)
        insert(value)



Measured memory_bytes: 211444
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define ll long long

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> ans_flag(n, 0);
    vector<int> p(m);
    vector<string> s(m);
    for(int i = 0;i < m;++i)    cin >> p[i] >> s[i];

    const string ac = "AC", wa = "WA";

    int ac_num = 0, wa_num = 0;
    vector<int> wa_buf(n, 0);

    for(int i = 0;i < m;++i){
        if(ans_flag[p[i]-1] != 1){
            if(s[i] == ac){
                ans_flag[p[i]-1] = 1;
                ac_num++;
                wa_num += wa_buf[p[i]-1];
            }else{
                wa_buf[p[i] -1]++;
            }
        }
    }

    cout << ac_num << " " << wa_num << endl;

    return 0;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	ll a, b;
	cin >> a >> b;
	a -= 2;
	b -= 2;
	if (a == -1) {a = 1;}
	if (b == -1) {b = 1;}
	cout << a*b;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)
typedef long long ll;

int main() {
    ll N, M;
    cin >> N >> M;
    if (N > M / 2) cout << M / 2 << endl;
    else cout << N + (M - 2 * N) / 4 << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll powmod(ll a, ll b, const ll mod = MOD) {
    a %= mod;
    ll res = 1;
    while (b > 0) {
        if (b % 2 == 1)res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res;
}

ll f[2110000];
void cominit(ll n = 210000, const ll mod = MOD) {
    f[0] = 1;
    REP(i, n)f[i + 1] = f[i] * (i + 1) % mod;
}

ll nCr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * powmod(f[r] * f[n - r], mod - 2, mod) % mod;
}

ll nPr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return f[n] * powmod(f[n - r], mod - 2, mod) % mod;
}

ll nHr(ll n, ll r, const ll mod = MOD) {
    if (n < r)return 0;
    if (n < 0 or r < 0)return 0;
    return nCr(n + r - 1, r, mod);
}

ll k, ans;
string s;
int main() {
    cominit(2100000);
    cin >> k >> s;
    ll sz = s.size();
    ll n = k + sz;
    ans = powmod(26, n);
    REP(i, sz){
        ans -= nCr(n, i) * powmod(25, n - i) % MOD;
        ans = (ans + MOD * 2) % MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 21684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 510000;
const int MOD = 1000000007;

/*long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}*/
int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }

    int dp[1000000];

    for (int i = 0; i < 1000000; i++)
    {
        dp[i] = 0;
    }
    dp[2] = abs(h[1] - h[0]);
    for (int i = 3; i <= N; i++)
    {
        dp[i] = min(dp[i - 1] + abs(h[i - 2] - h[i - 1]), dp[i - 2] + abs(h[i - 3] - h[i - 1]));
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll dp[50][200010]={};

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  V<ll> a(n+1,0),b(n+1,0);rep(i,0,n)cin>>dp[0][i];

  rep(j,0,k){
    rep(i,0,n){
      dp[j+1][max(0ll,i-dp[j][i])]++;
      dp[j+1][min(n,i+dp[j][i]+1)]--;
    }

    bool up=false;
    rep(i,0,n){
      dp[j+1][i+1]+=dp[j+1][i];
      if(dp[j+1][i]<n)up=true;
    }

    if(!up){
      cerr<<j<<ENDL;
      rep(i,0,n){
        cout<<dp[j+1][i]<<" ";
      }
      cout<<ENDL;
      return 0;
    }
  }

  rep(i,0,n){
    cout<<dp[k][i]<<" ";
  }
  cout<<ENDL;

}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 72044
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];

    long long ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j++) {
            ans += d[i]*d[j];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map( int, input().split() )
p = 10 ** 9 + 7

inv = [ 0, 1 ]      # iの逆元
fact = [ 1, 1 ]     # iの階乗
factinv = [ 1, 1 ]  # iの階乗の逆元
for i in range( 2, 2001 ):
    fact = fact + [ fact[-1] * i % p ]
    inv = inv + [ - inv[p%i] * (p//i) % p ]
    factinv = factinv + [ factinv[-1] * inv[-1] % p ]

numerator = fact[ k-1 ] * fact[ n-k+1 ] % p
for i in range( 1, k+1 ):
    if n-k-i+1 >= 0:
        ans = numerator * factinv[ k-i ] % p
        ans = ans * factinv[ i-1 ] % p
        ans = ans * factinv[ n-k-i+1 ] % p
        ans = ans * factinv[ i ] % p
        print( ans )
    else:
        print( "0" )

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
int main() {
  int n;
  cin >> n;
  FOR(i, 1, 10) {
    FOR(j, 1, 10) {
      if (n == i*j) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <iomanip>
#include <sstream>
#include <list>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define sz(x) (int)(x).size()
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

template <typename A, typename B> 
ostream& operator<<(ostream& os, pair<A,B> &p) {
	return os << "(" << p.first << "," << p.second << ")";
} 

template <typename A> 
ostream& operator<<(ostream& os, vector<A> &p) {
	for (auto &x : p) {
		os << x << " ";
	}
	os << endl;
	return os;
} 

vector<int> primes;

void siv(int n) {
	vector<bool> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
	    if (is_prime[i] && (long long)i * i <= n) {
	    	primes.push_back(i);
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
}

template <typename T>
T gcd(T a, T b) {
	if (a < 0) a *= -1;
	if (b < 0) b *= -1;
	
	while (b != 0) {
		T temp = a;
		a = b;
		b = temp % b;
	}

	return a;
}


// cout << setfill('0') << setw(5) << number < endl;
// while(getline(cin, s)) { .. } | `s` is a string


void solve() {
	string s, t;
	cin >> s >> t;
	int count = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != t[i])
			count++;
	}

	cout << count;
}


int main(){
	IOS;
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    (void)freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    (void)freopen("output.txt", "w", stdout);
	#endif

	int t = 1;
	// cin >> t;
	while(t--) 
		solve();

	// return 0;
}



























 

Measured memory_bytes: 3804
program ABC_088_B_CardGameforTwo
   implicit none 
   integer i, m, N, am, countA, countB
   integer(8), allocatable :: a(:)
   read(*, *) N
   allocate (a(1:2*N))
   a(:) = 0
   read(*, *) a(1:N)
   do i = 1, N - 1
      am = maxval(a(i+1:N))
	  m  = maxloc(a(i+1:N), 1) + i
	  if (a(i) < am) then
	      a(m) = a(i)
		  a(i) = am
	  end if
   end do
   countA = 0
   countB = 0
   do i = 1, N
      countA = countA + a(2 * i -1 )
	  countB = countB + a(2 * i)
   end do
   write(*, *)countA-countB
end program ABC_088_B_CardGameforTwo  

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAX 10000000

long count = 0;

void Merge(long *A, long left, long mid, long right) {
  long n1,n2,*L,*R,i,j,k;
  n1 = mid -left;
  n2 = right - mid;
  L = (long*)malloc(sizeof(long) * (n1+1));
  R = (long*)malloc(sizeof(long) * (n2+1));
  for (i = 0; i< n1; i++) {
    L[i] = A[left+i];
  }
  for (i = 0; i < n2; i++) {
    R[i] = A[mid+i];
  }
  L[n1] = LONG_MAX; R[n2] = LONG_MAX;
  i = 0;j = 0;
  for(k = left; k < right; k++) {
    if (L[i] < R[j]) {
      A[k] = L[i];
      i++;
    }else {
      A[k] = R[j];
      j++;
    }
    count++;
  }
  free(L);
  free(R);
}

void Merge_Sort(long *A, long left, long right) {
  if(left+1 < right) {
    long mid = (left + right)/2;
    Merge_Sort(A,left,mid);
    Merge_Sort(A,mid,right);
    Merge(A,left,mid,right);
  }
}

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++)count++;
}

int main()
{
  int a=100;
  long i,n,*S;
  scanf("%ld", &n);
  S = (long*)malloc(sizeof(long) * n);
  for (i = 0; i < n; i++) {
    scanf("%ld", S+i);
  }
  Merge_Sort(S,0,n);
  for (i = 0; i < n-1; i++) {
    printf("%ld ", S[i]);
  }
  printf("%ld\n", S[i]);
  printf("%ld\n", count);
  aaaaa(a);
  return 0;
}



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

char s[1010];

int main(){
	int n;
	scanf("%s%d", s, &n);
	int x, y;
	char order[10], str[1010];
	for(int i = 0; i < n; i++) {
		scanf("%s%d%d", order, &x, &y);
		if(strcmp(order, "replace") == 0) {
			scanf("%s", str);
			int len = strlen(str);
			for(int i = y; i >= x; i--)
				s[i] = str[--len];
		}else if(strcmp(order, "reverse") == 0) {
			for(int i = x; i <= (x + y) / 2; i++)
				swap(s[i], s[x+y-i]);
		}else{
			string ans = "";
			for(int i = x; i <= y; i++)
				ans += s[i];
			cout << ans << endl;
		}
	}
}



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

signed main(void)
{
	long long k, n, ans, sum, tmp;

	cin >> k >> n;
	long long a[n], dis[n];
	rep(i, n) cin >> a[i];
	rep(i, n - 1) dis[i] = a[i + 1] - a[i];
	dis[n - 1] = k - a[n - 1] + a[0];
	sum = 0;
	rep(i, n) sum += dis[i];
	tmp = sum;
	ans = INF;
	rep(i, n)
	{
		sum = tmp;
		sum -= dis[i];
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

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

    string s; cin >> s;
    for(int i=0;i<3;i++){
        if(s[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
from itertools import permutations as pm
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
i = 0

for l in pm([i+1 for i in range(n)],n):
    if l == p:
        a = i
    if l == q:
        b = i
    i += 1
print(abs(a-b))


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    static private node t = null;
    final static private StringBuilder sb = new StringBuilder();
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        String in;
        for(int i = 0; i<n; i++){
            in = br.readLine();
            if(in.charAt(0)=='p'){
                inorder(t);
                sb.append('\n');
                preorder(t);
                sb.append('\n');
            }else if(in.charAt(0)=='i'){
                insert(new node(Integer.parseInt(in.substring(7))));
            }else{
                sb.append(find(Integer.parseInt(in.substring(5))) ? "yes\n" : "no\n");
            }
        }
        System.out.print(sb);
    }
    static void insert(node z){
        node y = null;
        node x = t;
        while(x!=null){
            y = x;
            if(z.key<x.key){
                x = x.left;
            }else{
                x = x.right;
            }
        }
        if(y==null){
            t = z;
        }else if(z.key<y.key){
            y.left = z;
        }else{
            y.right = z;
        }
    }
    static boolean find(int key){
        node x;
        for(x = t; x!=null&&x.key!=key; x = key<x.key ? x.left : x.right);
        return x!=null&&x.key==key;
    }
    static void inorder(node t){
        if(t==null) return;
        inorder(t.left);
        sb.append(' ').append(t.key);
        inorder(t.right);
    }
    static void preorder(node t){
        if(t==null) return;
        sb.append(' ').append(t.key);
        preorder(t.left);
        preorder(t.right);
    }
}
class node{
    final public int key;
    public node left;
    public node right;
    node(int key){
        this.key = key;
        left = right = null;
    }
}

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

#define SENTINEL (1<<30)

int Merge(int *A, int left, int mid, int right) {
  int cnt = 0;
  int i,j,k;
  int n1, n2;
  int *L, *R;
  n1 = mid - left;
  n2 = right - mid;
  L = malloc(sizeof(int)*(n1+1));
  R = malloc(sizeof(int)*(n2+1));
  for(i = 0; i < n1; ++i)
    L[i] = A[left+i];
  for(i = 0; i < n2; ++i)
    R[i] = A[mid+i];
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  i = 0;
  j = 0;
  for(k = left; k < right; ++k) {
    ++cnt;
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i = i + 1;
    } else {
      A[k] = R[j];
      j = j + 1;
    }
  }
  free(L);
  free(R);
  return cnt;
}

int Merge_Sort(int *A, int left, int right) {
  int cnt = 0;
  int mid;
  if(left+1 < right) {
    mid = (left + right)/2;
    cnt += Merge_Sort(A, left, mid);
    cnt += Merge_Sort(A, mid, right);
    cnt += Merge(A, left, mid, right);
  }
  return cnt;
}

int main() {
  int i;
  int n, A[500000], cnt;
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%d", A+i);
  }
  cnt = Merge_Sort(A,0,n);
  for(i = 0; i < n; ++i) {
    printf(i ? " %d" : "%d", A[i]);
  }
  printf("\n%d\n", cnt);
  return 0;
}


Measured memory_bytes: 5416
from functools import reduce
import math

orientation = math.cos(math.pi/3) + 1j * math.sin(math.pi/3)


def main():
    n = int(input())
    results = [(0.0, 0.0), (100.0, 0.0)]
    results = koch_curve(results, 0, n)
    for r in results:
        print(r[0], r[1])


def f(a, b):
    c = ((2*a[0]+b[0])/3, (2*a[1]+b[1])/3)
    d = ((a[0]+2*b[0])/3, (a[1]+2*b[1])/3)
    vec = d[0] + d[1]*1j - (c[0] + 1j*c[1])
    e = vec * orientation
    e += (c[0] + 1j*c[1])
    e = (e.real, e.imag)
    return [a, c, e, d]


def koch_curve(lst, i, maximum):
    if i == maximum:
        return lst
    else:
        results = []
        l = len(lst)
        for j in range(l-1):
            results += f(lst[j], lst[j+1])
        results += [lst[j+1]]
        return koch_curve(results, i+1, maximum)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6860
A,B,K = list(map(int,input().split(' ')))
yaku = []
for i in range(1,(min(A,B)+1)):
  if (A%i ==0) and (B%i ==0):
    yaku.append(i)

yaku.sort(reverse=True)
print(yaku[K-1]) 
#print(yaku)

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

int main(){ 
	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];

	for(int i = 0;i < 5;i++){
		if(a[i] == 0)
			cout << i+1;
	}
}

Measured memory_bytes: 3596
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
fn main() {
    let n = get!(i32);
    let mut ans = 0;
    for i in 1..n+1 {
        if i.to_string().len() % 2 ==1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>

using namespace std;

int main(void) {
  string s;
  cin >> s;

  int flag = 0;
  for(int i = s.length() - 1; i >= 2; i--) {
    int half = i / 2;
    for(int j = 0; j < half; j++) {
      if(i % 2 != 0) {
	break;
      }
      if(s[j] != s[j + half]) {
	flag = 0;
	break;
      }
      flag = 1;
    }
    if(flag == 1) {
      cout << i << endl;
      return 0;
    }
  }
      
}

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

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

  int a, b;
  if (k % 2 == 0) {
    cout << (k / 2) * (k / 2) << endl;
  } else {
    cout << ((k / 2) + 1) * (k / 2) << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define N 300009
#define inf 1e18
//int mod=1e9+7;
int mod=998244353;
#define ll int
#define P pair<int,int>

int MOD(int n){
    if(n>=mod)
    n-=mod;
    return mod;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    set<string>st;
    while(n--){
        string s;cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<"\n";
    return 0;
}

Measured memory_bytes: 19236
#include <iostream>
#include <string>
#include <algorithm>
#include<vector>

using namespace std;

int main(){
	int x;
	cin >> x;
	int ans = 0;
	ans += 1000 * (x / 500);
	x %= 500;
	ans += 5 * (x / 5);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, T = li_input()
    Ts = li_input()

    L = []

    i = 0
    while i < len(Ts):
        l = [Ts[i]]

        while i + 1 < len(Ts) and Ts[i + 1] - Ts[i] <= T:
            i += 1

        l.append(Ts[i] + T)
        i += 1
        L.append(l)

    ans = 0

    for l in L:
        ans += (l[1] - l[0])

    print(ans)



main()


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

using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()

int main(){
  int N;cin>>N;
  vi A(N);
  vi B(N);
  for(int i=0; i<N; i++){
    cin>>A[i];
    cin>>B[i];
  }

  sort(all(A));
  sort(all(B));

  int L,R;
  if(N%2==1){
    L = A[N/2];
    R = B[N/2];
    cout<<( R-L+1 )<<endl;
  }else{
    L = A[N/2] + A[N/2-1];
    R = B[N/2] + B[N/2-1];
    cout<<( (R-L)+1 )<<endl;
  }
}

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

using namespace std;

long long n, a, b;

long long solve(long long a, long long b) {
    if (a > b) {
        swap(a, b);
    }
    long long res = a;
    b -= a;
    a = 1;
    res += (b - a) / 2;
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    if ((b - a) % 2 == 0) {
        cout << (b - a) / 2 << endl;
    } else {
        cout << min(solve(a, b), solve(n - a + 1, n - b + 1)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[1010];
int S,N,E,W;
int main() {
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++){
        if(s[i]=='N')N=1;
        if(s[i]=='S')S=1;
        if(s[i]=='E')E=1;
        if(s[i]=='W')W=1;
    }
    if(N==S&&E==W)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [[0] * w for i in range(h)]

for i in range(h):
    line = input()
    for j in range(w):
        a[i][j] = line[j]

delete_row = []
for i in range(h):
    chk = True
    for j in range(w):
        if a[i][j] == '#':
            chk = False
            break
    if chk:
        delete_row.append(i)

for row in delete_row[::-1]:
    a.pop(row)

delete_col = []
for i in range(w):
    chk = True
    for j in range(h-len(delete_row)):
        if a[j][i] == '#':
            chk = False
            break
    if chk:
        delete_col.append(i)

for row in a:
    for col in delete_col[::-1]:
        row.pop(col)

for i in a:
    for j in i:
        print(j, end='')
    print()

Measured memory_bytes: 4596
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] arr1 = new String[4];
    arr1[0]="AC";
    arr1[1]="WA";
    arr1[2]="TLE";
    arr1[3]="RE";
    int[] arr = new int[4];
    for(int i=0;i<n;i++){
      String a = sc.next();
      if(a.equals("AC")){
        arr[0]++;
      }
      else if(a.equals("WA")){
        arr[1]++;
      }
      else if(a.equals("TLE")){
        arr[2]++;
      }
      else if(a.equals("RE")){
        arr[3]++;
      }
    }
    for(int i=0;i<4;i++){
      System.out.println(arr1[i]+" "+"x"+" "+arr[i]);
    }
  }
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    return 0;
}

Measured memory_bytes: 3624
N = int(input())
B = [0]*N
for i in range(N-1):
    x, y, a = map(int, input().split())
    B[x] ^= a
    B[y] ^= a
D = {}
for b in B:
    D[b] = D.get(b, 0) + 1
D[0] = 0
ans = 0
first = 0
for b in D:
    ans += D[b]//2
    if D[b]%2:
        first |= 1 << b

A = [0]*(1 << 16)
for i in range(1, 1<<16):
    bit = i & -i
    l = len(bin(bit))-3
    A[i] = A[i ^ bit] ^ l

memo = {0: 0}
def dfs(state):
    if state in memo:
        return memo[state]
    cur = state
    res = 10**9+7
    while cur:
        if A[cur] == 0:
            res = min(res, dfs(state ^ cur) + bin(cur).count('1')-1)
        cur -= 1
        cur &= state
    memo[state] = res
    return res
ans += dfs(first)
print(ans)


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

int main() {
	string S;
	cin >> S;
	int a = 0;
	if (S == "RSS") a = 1;
	if (S == "SRS") a = 1;
	if (S == "SSR") a = 1;
	if (S == "RSR") a = 1;
	if (S == "RRS") a = 2;
	if (S == "SRR") a = 2;
	if (S == "RRR") a = 3;
	std::cout << a << '\n';
}


Measured memory_bytes: 3620
#include <stdio.h>

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


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
char n[maxn],m[maxn];
bool cmp(char a,char b){return a>b;}
int main(){
	scanf("%s%s",n,m);
	int ln=strlen(n),lm=strlen(m);
	sort(n+0,n+ln);
	sort(m+0,m+lm,cmp);
	FOR(i,0,min(ln,lm)-1){
		if(n[i]<m[i]){
			outy;
			return 0;
		}
		if(n[i]>m[i]){
			outn;
			return 0;
		}
	}
	ln<lm?outy:outn;;
} 

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

long long yu(long long a, long long b) {
  if(a==0||b==0) return 0;
  long long big=max(a,b);
  long long small=min(a,b);
  long long mod=big%small;
  while(mod!=0) {
    big=small;
    small=mod;
    mod=big%small;
  }
  return small;
}

int main()
{
  long long n,m;
  cin >> n >> m;
  vector<long long> a(n);
  for(long long i=0;i<n;i++) {
    long long temp;
    cin >> temp;
    a.at(i)=temp/2;
  }
  long long mod;
  long long ans=a.at(0);
  
  for(long long i=1;i<n;i++) {
    if(ans==0) {
      break;
    }
    mod=yu(ans,a.at(i));
    if(mod==0) {
      ans=0;
      break;
    }
    if(ans/mod%2==0||a.at(i)/mod%2==0) {
      ans=0;
    }
    ans=ans*a.at(i)/mod;
  }
  
  if(ans==0) {
    cout << 0 << endl;
  }
  else {
    cout << (m/ans+1)/2 << endl;
  }
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	sc    = bufio.NewScanner(os.Stdin)
	words = [4]string{"dream", "dreamer", "erase", "eraser"}
)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func solve(target string) bool {

	if len(target) == 0 {
		return true
	}

	for _, v := range words {
		if strings.HasPrefix(target, v) {
			res := solve(target[len(v):])
			if res {
				return res
			}
		}
	}

	return false
}

func main() {
	var input string
	fmt.Scan(&input)

	if res := solve(input); res {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
typedef pair<ll, ll> pint;

const int MOD = 1000000007;
void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }
}

int main(){
    string S;
    cin >> S;
    if(S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }
}


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

#define ll   long long

int main() {

    int N, up, down;
    cin >> N;

    up = N / 100;
    down = N % 100;

    if(up >= 1 && up <= 12){
        if(down >= 1 && down <= 12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(down >= 1 && down <= 12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }

    return 0;
}

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

using namespace std;

#define all(v)          v.begin(), v.end()
#define pb              push_back
#define sz(x)          (int) (x.size())
#define endl            "\n"
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))


typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


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

    int r, g, b, k; cin >> r >> g >> b >> k;
    int c = 0;
    while(g <= r) g *= 2, c++;
    while(b <= g) b *= 2, c++;
    if(c <= k) cout << "Yes";
    else cout << "No";
    return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> x(n);
    for (int i = 0; i < n; i++) cin >> x[i].first >> x[i].second;
    sort(x.begin(), x.end());
    priority_queue<int> pq;
    int now = 0;
    long long ans = 0;
    for (int i = 1; i <= m; i++){
        while (1){
            if (x[now].first > i) break;
            pq.push(x[now].second);
            now++;
        }
        if (pq.size()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1660
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;


class Program {

	const long mod = 1000000007;
	//public static int[] max;

	static void Main(string[] args) {

		char[] cs = new char[] { ' ', ',' };
		//int val = int.Parse(Console.ReadLine());
		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//string str = Console.ReadLine();
		//string[] strs = Console.ReadLine().Split(cs);

		//int[] vals = parseAry(Console.ReadLine().Split(cs));
		//int n = vals[0];
		//string res="";

		//int y = vals[0];
		//int x = vals[1];

		int[] vals = parseAry(Console.ReadLine().Split(cs));
		int[] nums = new int[vals[0]];
		int has = vals[1];
		for(int i=0;i<vals[0];i++){
			nums[i] = int.Parse(Console.ReadLine());
		}

		int totoal = nums.Sum();
		int res = nums.Length;
		has -= totoal;
		res += has / nums.Min();
			//deug
			Console.WriteLine(res);

		return;
	}


	//　String[]  ----->  int[]
	static int[] parseAry(string[] str) {
		int[] nums = new int[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}
	//　String[]  ----->  long[]
	static long[] parseAryl(string[] str) {
		long[] nums = new long[str.Length];
		for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
		return nums;
	}



	//文字列を1文字ずつString[]に入れる
	static string[] strAry(String str) {
		string[] re = new string[str.Length];
		for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
		return re;
	}

}

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<ll,ll>

using namespace std;
typedef long long ll;



int main(void) {
	int a, b; cin >> a >> b;
	rep(i, max(a, b)) {
		cout << min(a, b);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<string>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)

bool check(string line){
  stack<char> S;
  char ch;
  for ( int i = 0; i < line.size()-1; i++ ){
    if ( line[i] == '(' ){
      S.push('(');
    } else if ( line[i] == '[' ){
      S.push('[');
    } else if ( line[i] == ')' ){
      if ( S.size() == 0) return false;
      ch = S.top(); S.pop();
      if ( ch != '(' ) return false;
    } else if ( line[i] == ']' ){
      if ( S.size() == 0) return false;
      ch = S.top(); S.pop();
      if ( ch != '[' ) return false;
    } 
  }
  return S.size() == 0;
}

main(){
  string line;
  while(1){
    getline(cin, line);
    if ( line == "." ) break;
    if ( check(line) ) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   string s;
   cin >> s;
   int n = s.size();
   int ans = 0;
   rep(i, 0, n) {
      int j = n - i - 1;
      if (i >= j) break;
      if (s[i] != s[j]) ans++;
   }
   cout << ans << endl;
   return 0;
}

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

int main(void) {
  int a[10], i;
  for(i = 0; i < 10; ++i)scanf("%d", &a[i]);
  std::sort(a, a + 10);
  for(i = 9; i >6; --i) printf("%d\n", a[i]);
  return 0;
}


Measured memory_bytes: 2768
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
using namespace std;
#define N 100010
int a[N],b[N],c[N];
long long s[N],t[N];
int main()
{
    int n,i,j,k,p1,p2,flag;
    long long ans=0,s1,s2;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    scanf("%d",&b[i]);
    for(i=1;i<=n;i++)
    scanf("%d",&c[i]);
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    p1=n;
    p2=n;
    s1=0;
    for(i=n;i>=1;i--)
    {
        while(b[p1]>a[i]&&p1>=1)
        {
            s1=s[p1+1]+(n-p2);
            while(c[p2]>b[p1]&&p2>=1)
            {
                s1++;
                t[p2]=s1;
                p2--;
            }
            s[p1]=s1;
            p1--;
        }
        ans=ans+s1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    
    if(S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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

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

    int cnt = 1, ans = n - 1;
    for(int i = 1; i < n; ++i) {
        if(p[i - 1] < p[i]) {
            cnt += 1;
        } else {
            cnt = 1;
        }
        ans = min(ans, n - cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
firstint = int(input())
inputary = input()
listA= inputary.split()
numlist =[ int(x) for x in listA]
numlist.sort(reverse=True)
Alice = 0
Bob = 0
for index,elm in enumerate(numlist):
    if index % 2 == 0:
        Alice += int(numlist[index])
    else:
        Bob += int(numlist[index])

print(Alice - Bob)

Measured memory_bytes: 3064
a = gets.chomp
b = a.slice(0,2).to_i
c = a.slice(2,2).to_i

if (b == 0 || b >=13) && (c == 0 || c >=13) 
  puts "NA"
elsif (b == 0 || b >=13) 
  puts "YYMM"
elsif (c == 0 || c >=13)
  puts "MMYY"
else
  puts "AMBIGUOUS"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 string s;
 cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
  else if(s=="MON"){
    cout<<6<<endl;
  }
  else if(s=="TUE"){
    cout<<5<<endl;
  }
  else if(s=="WED"){
    cout<<4<<endl;
  }
  else if(s=="THU"){
    cout<<3<<endl;
  }
  else if(s=="FRI"){
    cout<<2<<endl;
  }
  else{
    cout<<1<<endl;
  }
}
  

Measured memory_bytes: 3604
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;

namespace AtCoder
{
    class AtCoderrrrrr
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            string s = ReadLine();
            int ans = 0;
            int x = 0;
            for (int i = 0; i < N; i++)
            {
                if (s[i] == 'I')
                {
                    x++;
                }
                else
                {
                    x--;
                }
                if (x>ans)
                {
                    ans = x;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;



int n, n1, cnt, tmp;


int main(){

	cin >> n;
	n1 = n;

	while (n1 > 0){
		cnt += n1 % 10;
		n1 /= 10;
	}

	if (n % cnt == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_r
#include <iostream>
#include <vector>
using namespace std;
int const mod = 1e9 + 7;

int mul(int a, int b)
{
    return (long long)a * b % mod;
}
void add_self(int&a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}

class Matrix
{
   
    int size;

public:
    vector<vector<int>> mat;
    Matrix(int n)
    {
        size = n;
        mat.assign(size, vector<int>(size));
    }
    void makeit_identical_matrix()
    {
        for (int x = 0; x < size; ++x)
                mat[x][x] = 1;
    }
    Matrix operator*(Matrix const &obj)
    {
        Matrix answer(size);
        for (int i = 0; i < size; ++i)
            for (int j = 0; j < size; ++j)
                for (int k = 0; k < size; ++k)
                    add_self(answer.mat[i][k], mul(mat[i][j], obj.mat[j][k]));

        return answer;
    }
};

Matrix binary_exponential_mul(Matrix  &mat, long long k, int size)
{
    Matrix answer(size);
    answer.makeit_identical_matrix();
    while (k > 0)
    {
        if (k & 1)
            answer = answer * mat;
            
        mat = mat * mat;
        k = k / 2;
    }
    return answer;
}

int main()
{
    int n;
    long long k;
    cin >> n >>k;
    Matrix m(n);
    for(int i=0; i<n;++i)
      for(int j=0;j<n;++j)
        cin >> m.mat[i][j];
    Matrix result = binary_exponential_mul(m, k, n);
    
    int  answer = 0;
    for(int i=0; i<n;++i)
      for(int j=0;j<n;++j)
        add_self(answer, result.mat[i][j]);
    
    cout << answer <<endl;
        
    return 0;
}

Measured memory_bytes: 256