akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
def update(A,keta,count):
    for k in xrange(keta):
        if count > (2**(keta - k - 1)):
            A[2*k] = 'A'
            count -= 2**(keta - k - 1)
    return A

S = raw_input()
if len(S) > 9:
    print 'NO'
elif S == 'AKIHABARA':
    print 'YES'
else:
    count = 0
    while(count < 2**(len(S)+1)):
        A = ['' for i in xrange(len(S)*2+1)]
        for i in xrange(len(S)):
            A[2*i+1] = S[i]
        A = update(A,len(S)+1,count)
        tmp = ''
        for a in A:
            tmp += a
        #print tmp
        if tmp == 'AKIHABARA':
            print 'YES'
            quit(0)
        count += 1
        #print count
    print 'NO'


Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
constexpr ll mod = 1e9 + 7;
using namespace std;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;


int main() {
	cin >> N >> X;
	int ans = 1;
	int dist = 0;
	ll L;
	for (int i = 0; i < N; i++) {
		cin >> L;
		dist += L;
		if (dist <= X) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))

ans = 0

for i in range(N-1):
    if p[i] == i+1:
        # swap
        temp = p[i]
        p[i] = p[i+1]
        p[i+1] = temp
        ans += 1
if p[-1] == N:
    ans += 1
print(ans)

Measured memory_bytes: 14008
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int a=s.nextInt(),b=s.nextInt();
		for(int i=0,q=s.nextInt();i<q;++i) {
			if(i%2==0)
				b+=a/=2;
			else
				a+=b/=2;
		}
		System.out.println(a+" "+b);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
using namespace std;
const int maxn=4e6+10;
int n,m,head[maxn*2],cnt,vis[maxn*2],dis[maxn*2],tot=200010;
struct edge
{
    int next,to,quan;
} e[maxn*2];
priority_queue<pair<int,int> >q;
map<pair<int,int>,int>mp;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
	if(ch=='-')
	    f=-1;
	ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
	x=(x<<1)+(x<<3)+(ch^48);
	ch=getchar();
    }
    return x*f;
}
inline void add(int from,int to,int quan)
{
    e[++cnt].next=head[from];
    e[cnt].quan=quan;
    e[cnt].to=to;
    head[from]=cnt;
}
int bianhao(int x,int y)
{
    if(mp.find(make_pair(x,y))!=mp.end())
	return mp[make_pair(x,y)];
    return mp[make_pair(x,y)]=++tot;
}
int main()
{
    n=read(),m=read();
    memset(dis,0x3f,sizeof(dis));
    for(int i=1; i<=m; i++)
    {
	int p=read(),q=read(),c=read();
	int t1=bianhao(p,c),t2=bianhao(q,c);
	add(p,t1,1),add(t1,t2,0),add(t2,q,1);
	add(t1,p,1),add(t2,t1,0),add(q,t2,1);
    }
    dis[1]=0;
    q.push(make_pair(0,1));
    while(!q.empty())
    {
	int now=q.top().second;
	q.pop();
	if(vis[now])
	    continue;
	vis[now]=1;
	for(int i=head[now]; i; i=e[i].next)
	{
	    int to=e[i].to;
	    if(dis[to]>dis[now]+e[i].quan)
	    {
		dis[to]=dis[now]+e[i].quan;
		q.push(make_pair(-dis[to],to));
	    }
	}
    }
    if(dis[n]>1e9+10)dis[n]=-2;
    printf("%d",dis[n]/2);
    return 0;
}


Measured memory_bytes: 81660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static final String EOL = System.getProperty("line.separator");
    public void exec() throws IOException {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	PrintWriter out = new PrintWriter(System.out);
    	char[] cbuf = new char[1200];
    	int len = br.read(cbuf);
    	for (int i=0; i<len; i++){
    		char c = cbuf[i];
    		if('A' <= c && c <= 'Z') {
    			c -= 'A';
    			c += 'a';
    			cbuf[i] = c;
    		}else if ('a' <= c && c <= 'z') {
    			c -= 'a';
    			c += 'A';
    			cbuf[i] = c;
    		}
    	}
    	out.print(new String(cbuf,0,len));
        out.flush();
    }
 
    public static void main(String[] args) throws IOException {
    	new Main().exec();
    }
}

Measured memory_bytes: 24180
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b,c,d;
cin >> a >> b >> c >> d;
if(a+b>c+d) {
  cout << "Left" << endl;
} else if(a+b==c+d) {
  cout << "Balanced" << endl;
} else {
  cout << "Right" << endl;
}
return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int a=in(),b=in();
	double c=(a+b)/2.0;

	out((int)ceil(c));

	return 0;
}

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

using namespace std;

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

char grid[101][101];
bool eraseX[101];
bool eraseY[101];

int main()
{
	memset(grid, 0, sizeof(grid));
	memset(eraseX, false, sizeof(eraseX));
	memset(eraseY, false, sizeof(eraseY));
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int H, W; cin >> H >> W;
	rep (i, H){
		rep (j, W){
			cin >> grid[i][j];
		} // end rep
	} // end rep

	bool update = false;
	while(true){
		update = false;
		rep (i, H){
			if (eraseY[i]) continue;
			int cnt = 0;
			int total = 0;
			rep (j, W){
				if (eraseX[j]) continue;
				++total;
				cnt += (int)(grid[i][j] == '.');
			} // end rep
			if (total == cnt){
				eraseY[i] |= true;
				update|= true;
			} // end if
		} // end rep

		rep (j, W){
			if (eraseX[j]) continue;
			int cnt = 0;
			int total = 0;
			rep (i, H){
				if (eraseY[i]) continue;
				++total;
				cnt += (int)(grid[i][j] == '.');
			} // end rep
			if (total == cnt){
				eraseX[j] |= true;
				update |= true;
			} // end if
		} // end rep
		if (!update){
			break;
		} // end if
	} // end while

	rep (i, H){
		if (eraseY[i]) continue;
		rep (j, W){
			if (eraseX[j]) continue;
			cout << grid[i][j];
		} // end rep
		cout << endl;
	} // end rep
		
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var n,t int
	fmt.Scan(&n,&t)

	ans := 1001
	for i := 0; i < n; i++{
		var c,ti int
		fmt.Scan(&c,&ti)

		if ti <= t {
			ans = int(math.Min(float64(ans),float64(c)))
		}
	}
	if ans > 1000 {
		fmt.Println("TLE")
	} else {
		fmt.Println(ans)
	}
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	const long INFL = 4011686018427387913L;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var a = G;
		var dp = new long[N + 1, N + 1];
		var sum = new long[N + 1];
		for (var i = 0; i < N; i++) sum[i + 1] = sum[i] + a[i];
		for (var l = 2; l <= N; l++)
		{
			for (var i = 0; i + l <= N; i++)
			{
				dp[i, i + l] = INFL;
				for (var j = i + 1; j < i + l; j++) dp[i, i + l] = Min(dp[i, i + l], dp[i, j] + dp[j, i + l]);
				dp[i, i + l] += sum[i + l] - sum[i];
			}
		}
		WriteLine(dp[0, N]);
	}
}


Measured memory_bytes: 14432
#include <bits/stdc++.h>
using namespace std;
#define INF (1 <<29)
// const int INF = int(1e5 + 1);
int N, M, R;
int d[201][201];
int r[8];
// int min_cost = 7 * INF;
int min_cost = INF;

void dfs(int from_idx, int dist, int used) {

    if (used == (1 << R) - 1) {
        min_cost = min(min_cost, dist);
        return;
    }

    for (int to_idx = 0; to_idx < R; ++to_idx) if (!(used >> to_idx & 1)) {
        if (dist == -1) {
            dfs(to_idx, 0, used | 1 << to_idx);
        } else {
            dfs(to_idx, dist + d[r[from_idx]][r[to_idx]], used | 1 << to_idx);
        }
    }
}


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

    cin >> N >> M >> R;

    for (int i = 1; i <= N; ++i) {
        fill(d[i] + 1, d[i] + N + 1, INF);
        d[i][i] = 0;
    }
    for (int i = 0; i < R; ++i) {
        cin >> r[i];
    }
    int a, b, c;
    for (int i = 0; i < M; ++i) {
        cin >> a >> b >> c;
        if (d[a][b] > c) d[a][b] = d[b][a] = c;
    }
    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    dfs(0, -1, 0);

    cout << min_cost << '\n';

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define int long long

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

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<int> p(a);
    for (int i = 0; i < a; i++) cin >> p[i];
    vector<int> q(b);
    for (int i = 0; i < b; i++) cin >> q[i];
    vector<int> r(c);
    for (int i = 0; i < c; i++) cin >> r[i];

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());

    int wealth = 0;
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int i = 0; i < x; i++) {
        wealth += p[i];
        pq.push(p[i]);
    }
    for (int i = 0; i < y; i++) {
        wealth += q[i];
        pq.push(q[i]);
    }

    for (int i = 0; i < c && !pq.empty(); i++) {
        if (r[i] > pq.top()) {
            wealth -= pq.top();
            pq.pop();
            wealth += r[i];
        } else
            break;
    }

    cout << wealth << endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		String[] heightstr = new String[10];
		int[] heightint = new int[10];

		for (int i = 0; i <= 9; i++) {
			str = br.readLine();
			heightstr[i] = str;
			heightint[i] = Integer.parseInt(heightstr[i]);
		}
		for (int j = 0; j <= 8; j++) {
			for (int k = j + 1; k <= 9; k++) {
				Boolean isBig = heightint[j] < heightint[k];
				if (isBig) {
					int temporary = heightint[j];
					heightint[j] = heightint[k];
					heightint[k] = temporary;
				}
			}
		}
		System.out.println(heightint[0]);
		System.out.println(heightint[1]);
		System.out.println(heightint[2]);
	}

}

Measured memory_bytes: 24196
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;
int A[200010];
int a[200010];
int b[200010];
int main() {
  int N,M; cin >> N >> M;
  for ( int i = 0; i < M; i++ ) {
    cin >> a[i] >> b[i];
    A[a[i]] = b[i];
  }

  for ( int i = 0; i < M; i++ ) {
    if ( a[i] == 1 && A[b[i]] == N ) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

signed main()
{
    vi a;
    a.resize(5);
    REP(i, 5)
    cin >> a[i];
    sort(ALL(a));
    int k;
    cin >> k;
    if (a[4] - a[0] > k)
        cout << ":(" << endl;
    else
        cout << "Yay!" << endl;
    // system("pause");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    if(S.size()==2){
        cout << S << endl;
    }else{
        cout << S[2] << S[1] << S[0] << endl;
    }

    return 0;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1e9
using namespace std;
typedef long long ll;

int n,m;
vector <string> s, t;

int main(){
  std::cin >> n;
  rep(i,0,n){
    string tmp;
    std::cin >> tmp;
    s.push_back(tmp);
  }
  std::cin >> m;
  rep(i,0,m){
    string tmp;
    std::cin >> tmp;
    t.push_back(tmp);
  }
  int res = 0;
  rep(i,0,n){
    int tmp = 0;
    rep(j,0,n){
      if(s[j] == s[i])tmp++;
    }
    rep(j,0,m){
      if(t[j] == s[i])tmp--;
    }
    res = max(tmp, res);
  }
  std::cout << res << '\n';
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			int t[][][]=new int[24][60][60];
			int ans=0;
			for(int i=0;i<n;i++)
			{
				String st1[]=in.next().split(":");
				String st2[]=in.next().split(":");
				int h1=Integer.valueOf(st1[0]);
				int m1=Integer.valueOf(st1[1]);
				int s1=Integer.valueOf(st1[2]);
				int h2=Integer.valueOf(st2[0]);
				int m2=Integer.valueOf(st2[1]);
				int s2=Integer.valueOf(st2[2]);
				for(;;)
				{
					t[h1][m1][s1]++;
					s1++;
					if(s1==60)
					{
						m1++;
						s1=0;
					}
					if(m1==60)
					{
						h1++;
						m1=0;
					}	
					if(h1==h2&&m1==m2&&s1==s2)
						break;
				}
			}
			for(int i=0;i<24;i++)
				for(int j=0;j<60;j++)
					for(int k=0;k<60;k++)
						ans=Math.max(ans, t[i][j][k]);
			System.out.println(ans);
		}
	}
	
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 70764
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, A: int, B: int):
    if (B-A) % 2 == 0:
        print('Alice')
    else:
        print('Borys')
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5304
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		String str=input.readLine();
		String[] str2=str.split(" ");
		int a=Integer.parseInt(str2[0]);
		int b=Integer.parseInt(str2[1]);
		int c=Integer.parseInt(str2[2]);
		if(a<b&&b<c){
			System.out.println("Yes");
		}else{
			System.out.println("No");			
		}
		
		
	}
}

Measured memory_bytes: 24072
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int A[100000]={0,};
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    A[x]++;
  }

  int ans=0;
  for(int i=0;i<=100000;i++){
    int cnt=0;
    if(i==0) cnt=A[1]+A[0];
    else if(i==100000) cnt=A[100000-1]+A[100000];
    else cnt=A[i-1]+A[i]+A[i+1];
    if(cnt>ans) ans=cnt;
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main {
	
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int dp[][] = new int[301][18];
		int ans[]  = new int[301];
		for(int i=0; i<18; i++)
			dp[0][i] = 1;
		for(int i=1; i<=300; i++){
			for(int j=1; j*j<=i; j++){
				for(int k=j*j; k<=i; k+=j*j){
					dp[i][j] += dp[i-k][j-1];
				}
			}
			for(int j=1; j<=17; j++){
				dp[i][j] += dp[i][j-1];
			}
		}
		for(int i=0; i<=300; i++)
			for(int j=0; j<=17; j++)
				ans[i] += dp[i][j];
		while(true){
			int n = in.nextInt();
			if(n==0) return ;
			System.out.println(dp[n][17]);
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)

#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, K;
const ll MAX_N = 200000;
ll a[MAX_N];

// bit O(log n) for a query
// 1. set n
// 2. init bit[0] ... bit[n + 1]
// 3. use add(i, x) and sum(i)


ll bit[MAX_N + 1], n;

int sum(int i) {
  ll s = 0;
  while(i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, ll x) {
  while(i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}

int main(){
  cin >> N >> K;
  REP(i, N) cin >> a[i];

  REP(i, N) a[i] -= K;
  ll s[N];
  ll su = 0;
  REP(i, N) {
    su += a[i];
    s[i] = su;
  }

  vll sorts;
  REP(i, N) sorts.pb(s[i]);
  sort(ALL(sorts));

  ll compress_s[N];
  REP(i, N) {
    compress_s[i] = lower_bound(ALL(sorts), s[i]) - sorts.begin();
  }

  // REP(i, N) cout << compress_s[i] << ", ";
  // cout << endl;

  n = N;
  REP(i, N + 1) bit[i] = 0;

  ll ans = 0;
  add(lower_bound(ALL(sorts), 0) - sorts.begin() + 1, 1);
  REP(i, N) {
    
    ans += sum(compress_s[i] + 1);
    add(compress_s[i] + 1, 1);
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8176
#coding:utf-8
x = int(input())
ans = 1
i = 2
minv = 100000
while i ** 2 <= x:
    n = 2
    while i ** n <= x:
        if minv > x - i ** n:
            minv = min(minv, x - i ** n)
            ans = i ** n
        n += 1
    i += 1
print(ans)


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

int n,a[310];
int sum[310][310],dp[310][310];

const int inf=1<<26;

inline int cost(int a,int b){
	int c=0,res=0;
	while(a||b){
		int x=a%10,y=b%10;
		res+=x*y;
		c=(x+y+c>=10)?1:0;
		res+=c;
		a/=10,b/=10;
	}
	return res;
}

int main(void){
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n+1)rep(j,n+1){
		sum[i][j]=0;
		dp[i][j]=inf;
	}
	rep(i,n){
		sum[i][i+1]=a[i];
		dp[i][i+1]=0;
	}
	for(int d=2;d<=n;d++){
		for(int i=0;i+d<=n;++i){
			for(int j=i+1;j<i+d;++j){
				sum[i][i+d]=sum[i][j]+sum[j][i+d];
				dp[i][i+d]=min(dp[i][i+d],dp[i][j]+dp[j][i+d]+cost(sum[i][j],sum[j][i+d]));
			}
		}
	}
	cout << dp[0][n] << endl;
}

Measured memory_bytes: 1896
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    int n, m, k, i, j;
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;

    return 0;
}


Measured memory_bytes: 3592
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	set := make(map[int]bool)
	for i := 0; i < N; i++ {
		a := sc.nextInt()
		if set[a] {
			set[a] = false
		} else {
			set[a] = true
		}
	}
	ans := 0
	for _, b := range set {
		if b {
			ans++
		}
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
string s;
int n, low, high, mid;
inline int ask(int x)
{
	cout << x << endl;
	fflush(stdout);
	cin >> s;
	if (s == "Vacant")exit(0);
	else return (s == "Male");
}
int main()
{
	cin >> n;
	low = 0;
	high = n-1;
	int s = ask(0);
	while (high - low > 1){
		mid = low + high >> 1;
		int a = ask(mid);
		if (mid % 2 == low % 2){
			if (a == s)low = mid;
			else high = mid;
		}
		else{
			if (a != s)low = mid, s = a;
			else high = mid;
		}
	}
	for (int i = low; i <= high; ++i)ask(i);
	return 0;
} 

Measured memory_bytes: 852
X=int(input())
DP=[0 for i in range(X+1)]
DP[0]=1
L=[100,101,102,103,104,105]

for s in range(6):
  for x in range(X+1):
    if DP[x]==1 and x+L[s]<=X:
      DP[x+L[s]]=1
print(DP[X])

Measured memory_bytes: 3864
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
#include<bitset> 
using namespace std;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int mod = 1000000007;
const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
}


int main(){
	int a,p;cin >> a >> p;
	pl((3*a+p)/2)
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

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

    ll N; cin >> N;

    REP(i, 9) {
        REP(j, 9) {
            if ((i+1)*(j+1)==N) {
                cout << "Yes" << '\n';
                return 0;
            }
        }
    }
    cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
const ll INF = 200000000000000;

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  
  ll a[3*N];
  for(int i = 0; i < 3*N; i++) cin >> a[i];

  priority_queue<int, vector<int>, greater<int> > pq_f;
  priority_queue<int> pq_b;

  ll sum_f[N+1];
  ll sum_b[N+1];
  fill(sum_f, sum_f + N + 1, 0);
  fill(sum_b, sum_b + N + 1, 0);

  // Forward
  for(ll i = 0; i < N; i++) {
    pq_f.push(a[i]);
    sum_f[0] += a[i];
  }

  for(ll k = 1; k <= N; k++) {
    ll top = pq_f.top();
    if(top < a[N - 1 + k]) {
      pq_f.pop();
      pq_f.push(a[N - 1 + k]);
      sum_f[k] = sum_f[k-1] - top + a[N - 1 + k];
    }
    else sum_f[k] = sum_f[k-1];
  }

  // backward
  for(ll i = 0; i < N; i++) {
    pq_b.push(a[3*N - 1 - i]);
    sum_b[0] += a[3*N - 1 - i];
  }

  for(ll k = 1; k <= N; k++) {
    ll top = pq_b.top();
    if(top > a[2*N - k]) {
      pq_b.pop();
      pq_b.push(a[2*N - k]);
      sum_b[k] = sum_b[k-1] - top + a[2*N - k];
    }
    else sum_b[k] = sum_b[k-1];
  }

  ll ans = -INF;
  for(ll k = 0; k <= N; k++) ans = max(ans, sum_f[k] - sum_b[N - k]);
  cout << ans << endl;
  
  return 0;
}


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

namespace ConsoleApp15
{
    class Class109
    {
        static void Main()
        {
            string w = Console.ReadLine();
            Dictionary<char, bool> Table = new Dictionary<char, bool>();
            for(int i = 0; i < w.Length; i++)
            {
                if (!Table.ContainsKey(w[i]))
                    Table.Add(w[i], false);
                else
                    Table[w[i]] = !Table[w[i]];
            }
            Console.WriteLine(Table.ContainsValue(false) ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 13152
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}/*swap 交換*/
ll max2(ll a,ll b){return a>=b?a:b;}/*2つのうち大きい数を返す*/ 
ll min2(ll a,ll b){return a>=b?b:a;}/*2つのうち小さい数を返す*/ 
ll ABS(ll a){return a>=0?a:(-a);}/*絶対値*/ 
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[27],max[27]="zyxwvutsrqponmlkjihgfedcba";
    scanf("%s",s);
    if(strcmp(s,max)==0){
        printf("-1\n");
        return 0;
    }
    ll n=strlen(s);
    ll chara[26];
    rep(i,0,26){
        chara[i]=0;
    }
    rep(i,0,n){
        chara[(int)s[i]-97]=1;
    }
    if(n<26){
        rep(i,0,26){
            if(chara[i]==0){
                printf("%s%c\n",s,(char)(i+97));
                return 0;
            }
        }
    }
    ll t;
    rep(i,1,n){
        t=(int)s[n-1-i]+1;
        rep(j,0,i){
            // printf("%c %c? ",s[n-1-j],(char)t);
            if((int)s[n-1-j]>=t){
                rep(k,0,n-i-1){
                    printf("%c",s[k]);
                }
                printf("%c",s[n-1-j]);
                printf("\n");
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include<cmath>
#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<cstring>
#include<math.h>
#include<stack>
#include<algorithm>
#include<queue>
#include<bitset>
#include<sstream>
#define  ll long long int
const ll mod=20123;
using namespace std;
ll n,m;
string s;
ll a[200010];
map<ll,ll>p1,p2;
int main()
{
    ios::sync_with_stdio(false);
    ll i=0,j,flat1=0,flat2=0,x,k,y,z,t;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        p1[a[i]+i]++;
        p2[i-a[i]]++;
    }
    map<ll,ll>::iterator it;
    ll sum=0;
    for(it=p1.begin();it!=p1.end();it++)
    {
        sum+=(it->second)*p2[it->first];
    }
    cout<<sum;
      return 0;
}


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


if N>=0:
  k=0
  while N>2**k:
    k+=2
else:
  k=1
  while N<-2*(2**(k-1)):
    k+=2

S=[0]*(k+1)
for i in range(k+1):
  if N%(-2)==-1:
    S[i]=1
    N-=1
  N//=-2
print(int("".join(reversed(list(map(str,S))))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main (){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int count = 0, i = 0;
  if (K <= A)
    count += K;
  else if(A < K && K <= A + B)
    count += A;
  else if (A + B + C >= K && K > A + B){
    count += A;
    i = K - A - B;
    count -= i;
  }
  cout << count << endl;
}
    
  

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

ans = [-1]*n
a = 0
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        a = -1
    elif ans[s-1] not in [-1, c]:
        a = -1
    else:
        ans[s-1] = c

if a == -1:
    print(a)
else:
    b = ""
    if ans[0] == -1 and n != 1:
        ans[0] = 1
    for x in ans:
        if x == -1:
            b += "0"
        else:
            b += str(x)
    print(b)


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

ll MOD = 1E+9 + 7;

int main() {
    ll H, W, K;
    cin >> H >> W >> K;

    ll A[H+1][W+1] = {};
    A[0][1] = 1;
    ll c[8] = {1, 1, 2, 3, 5, 8, 13, 21};
    for (ll h=0; h<H; h++) {
        for (ll w=1; w<=W; w++) {
            if (w>=2) A[h+1][w-1] = (A[h+1][w-1] + A[h][w] * c[w-2] * c[W-w]) % MOD;
            A[h+1][w] = (A[h+1][w] + A[h][w] * c[w-1] * c[W-w]) % MOD;
            if (w<W) A[h+1][w+1] = (A[h+1][w+1] + A[h][w] * c[w-1] * c[W-(w+1)]) % MOD;
        }
    }

    cout << A[H][K] << endl;

    return 0;
}

 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <queue>
#include <climits>
#include<cmath>
#include <sstream>
#include <iomanip>

bool sort_pair( std::pair< int64_t, std::pair< int64_t, int64_t > > origin, std::pair< int64_t, std::pair< int64_t, int64_t > > another )
{
    return origin.second.first < another.second.first;
}

int main()
{

    int64_t a;
    std::string b;
    
    std::cin>> a;
    std::cin>> b;

    int64_t count = 0;
    int64_t c = 1;
    char d = b[0];

    for( int i = 1; i < a; i++ )
    {
        if( d == b[i] )
        {
            c = 1;
        }
        else
        {
            count += c;
            d = b[i];
        }
    }

    count += c;
    
    std::cout<< count;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+5;

int main()
{
	int k; cin>>k;
	int cnt = 1, cur = 7 % k;
	while (cnt < 1e6+2 && cur) {
		cnt++;
		cur = (cur*10 % k+7) % k;
	}
	if (cnt == 1e6+2) puts("-1"); 
	else printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 3712
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int m = in.nextInt();
        final int x = in.nextInt();
        in.nextLine();
        final int[][] books = new int[n][m + 1];
        final int[] max = new int[m];
        for (int i = 0; i < n; i++) {
            final int[] book = new int[m + 1];
            for (int z = 0; z < m + 1; z++) {
                book[z] = in.nextInt();
                if (z > 0) {
                    max[z - 1] += book[z];
                }
            }
            in.nextLine();
            books[i] = book;
        }
        if (Arrays.stream(max).anyMatch(skill -> skill < x)) {
            System.out.println(-1);
            return;
        }
        final int[] res = { (int) 1e9 };
        knapsack(books, new int[m], x, 0, 0, res);
        System.out.println(res[0]);
    }

    private static void knapsack(int[][] books, int[] pick, int x, int i, int cost, int[] res) {
        if (i == books.length) {
            if (Arrays.stream(pick).noneMatch(skill -> skill < x)) {
                res[0] = Math.min(res[0], cost);
            }
            return;
        }
        for (int z = 1; z < books[i].length; z++) {
            pick[z - 1] += books[i][z];
        }
        knapsack(books, pick, x, i + 1, cost + books[i][0], res);
        for (int z = 1; z < books[i].length; z++) {
            pick[z - 1] -= books[i][z];
        }
        knapsack(books, pick, x, i + 1, cost, res);
    }
}


Measured memory_bytes: 42188
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

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

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<int> qtype(q);
    vector<bool> isrev(q + 1, false);
    int revnum = 0;

    map<int, char> addchar;
    map<int, bool> addfront;
    rep(i, q)
    {
        int t;
        cin >> t;
        qtype[i] = t;
        if (t == 1)
        {
            revnum++;
        }
        if (t == 2)
        {
            int f;
            char c;
            cin >> f >> c;
            addchar[i] = c;
            addfront[i] = (f == 1);
        }
    }

    int cur = 0;
    rep(i, q)
    {
        if (qtype[i] == 1)
            cur++;

        isrev[i] = (revnum - cur) % 2;
    }
    if (isrev[0])
    {
        reverse(ALL(s));
    }
    deque<char> que;
    rep(i, s.size())
    {
        que.push_back(s[i]);
    }
    rep(i, q)
    {
        if (qtype[i] == 2)
        {
            if (addfront[i] ^ isrev[i])
            {
                que.push_front(addchar[i]);
            }
            else
            {
                que.push_back(addchar[i]);
            }
        }
    }
    while (!que.empty())
    {
        cout << que.front();
        que.pop_front();
    }
    cout << endl;
    return 0;
}


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

typedef long long ll;

int main(){
    ll s = 0;
    ll n, tmp;
    ll a[100001] = {0};
    cin >> n;
    for(ll i = 1; i <= n; ++i){
        cin >> tmp;
        ++a[tmp];
        s += tmp;
    }

    ll q;
    cin >> q;
    ll b, c;
    for(ll i = 0; i < q; ++i){
        cin >> b >> c;
        s = s - a[b]*b + a[b]*c;
        a[c] += a[b];
        a[b] = 0;
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 4380
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

//sort(ALL(v),greater<int>());
//priority_queue<int, vector<int>, greater<int>>Q;

int N;
int A[100001];
vector<set<int>>win;

int solve(const int p) {
	//選手pが負けるところから見ての深さの最小値
	if (win[p].empty())return 1;
	vector<int>depth;
	ITR(x, win[p]) {
		depth.push_back(solve(*x)+1);
	}
	sort(ALL(depth));
	rep(i, depth.size())depth[i] += int(depth.size())-1-i;
	return Max(depth);


}

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

	cin >> N;
	win = vector<set<int>>(N);
	REP(i, 1, N) {
		cin >> A[i];
		A[i]--;
		win[A[i]].insert(i);
	}

	
	cout<<solve(0)-1<<endl;




	return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,x,y;
    for(i=0;i<3000;i++){
        cin>>x>>y;
        if(x==0 && y==0){break;}
        else if(x>y){cout<<y<<" "<<x<<endl;}
        else if(x<y){cout<<x<<" "<<y<<endl;}
        else{cout<<x<<" "<<y<<endl;}
    }
    return 0;
}


Measured memory_bytes: 3060
# C
n, m = map(int, input().split())
ab = [[int(i) for i in input().split()] for i in range(n)]

ab.sort(key=lambda x:x[0])

cost = 0
for i in range(n):
    value = ab[i][0]
    num = ab[i][1]
    if num > m:
        cost += value * m
        break
    else:
        cost += value * num
        m -= num
print(cost)

Measured memory_bytes: 22756
while True:
    H, W = list(map(int, input().split()))
    if (H == 0) & (W == 0):
        break
        
    print(W * "#")
    for _ in range(H-2):
        print("#", end="")
        print((W-2) * ".", end="")
        print("#")
    print(W * "#")
    
    print("")

Measured memory_bytes: 7580
#include<bits/stdc++.h>
#include <cstdio>
#include <algorithm>

#define maxn 1000010

using namespace std;
int a[maxn],prime[maxn],not_prime[maxn],tot,vis[maxn];
void linear_shaker(int x){
	int i,j;
	for(i=2;i<=x;i++){
		if(!not_prime[i])prime[++tot]=i;
		for(j=1;prime[j]*i<=x;j++){
			not_prime[i*prime[j]]=prime[j];
			if(i%prime[j]==0)break;
		}
	}
}
int main(){
	int n,i,m=0,b,c,cnt=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]),m=max(m,a[i]);
	linear_shaker(m);
	for(i=1;i<=n;i++){
		b=a[i];
		while(not_prime[b]){
			c=not_prime[b];
			vis[c]++,cnt=max(cnt,vis[c]);		
          while(b%c==0)b/=c;
		}
		if(b!=1)vis[b]++,cnt=max(cnt,vis[b]);
	}

  if(cnt<=1)printf("pairwise coprime\n");
	
  else if(cnt<n)printf("setwise coprime\n");
	
  else printf("not coprime\n");//cnt>=n
	
  return 0;
}


Measured memory_bytes: 15540
#include<stdio.h>
#include<string.h>
int main(){
  char s[7][4]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  char a[4];
  int i;
  scanf("%s",a);
  for(i=0;i<7;i++)
    if(strcmp(s[i],a)==0)
      printf("%d\n",7-i);
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }

  ll ans = 0;
  for(int i = 0; i < n-1; i++){
    sum -= a[i];
    ll modSum = sum % 1000000007;
    ll tmp = ( a[i] * modSum) % 1000000007;
    ans = (ans + tmp) % 1000000007;
  }
  cout << ans  << endl;
}


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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    vector<ll> v = {0, 1, 2, 3, 4};
    vector<ll> a(5);
    for(auto &e: a) cin >> e;

    ll r = 1e9;
    do {
        ll t = 0;
        for(auto &i: v) {
            t = (t + 9) / 10 * 10;
            t += a[i];
        }
        r = min(r, t);
    } while(next_permutation(v.begin(), v.end()));
    cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


int main(){
    ll n,m,tmp,ans=0;
    cin>>n>>m;
    rep(i,0,m){cin>>tmp;ans+=tmp;}
    if(n>=ans)cout<<n-ans;
    else cout<<-1;
    
}


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

ll X[50];
ll Y[50];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N, K;
	cin >> N >> K;

	vector<ll> xs, ys;
	for(int i = 0; i < N; i++){
		cin >> X[i] >> Y[i];
		xs.push_back(X[i]);
		ys.push_back(Y[i]);
	}
	sort(xs.begin(), xs.end());
	xs.erase(unique(xs.begin(), xs.end()), xs.end());
	sort(ys.begin(), ys.end());
	ys.erase(unique(ys.begin(), ys.end()), ys.end());

	ll ans = 1LL << 62;
	for(int i = 0; i < xs.size(); i++){
		for(int j = i + 1; j < xs.size(); j++){
			for(int k = 0; k < ys.size(); k++){
				for(int l = k + 1; l < ys.size(); l++){
					int sum = 0;
					for(int m = 0; m < N; m++){
						if(xs[i] <= X[m] && X[m] <= xs[j] && ys[k] <= Y[m] && Y[m] <= ys[l]){
							sum++;
						}
					}
					if(sum >= K){
						ans = min(ans, (ys[l] - ys[k]) * (xs[j] - xs[i]));
					}
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B,K;
    cin >>K>>A>>B;
    string ans="NG";
    for(int i=A;i<=B;i++){
        if(i%K==0) ans="OK";
    }
    cout << ans << endl;



}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define nl ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()

using namespace std;

int main() {
    nl // youtu.be/QosiU0JR_h8  
    string s;
    cin >> s;
    for(int i=1; i<=s.size(); ++i) {
        if(i&1) cout << s[i-1];
    }
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N, A;
  int m1 = 10000, m2;
  
  for (int i = 0; i < N; i++){
    cin >> A;
    m2 = 0;
    
    while (A % 2 == 0){
      A = A /2;
      m2 ++;
    }
    
    m1 = min (m1, m2);
  }
  
  cout << m1 <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <regex>
using namespace std;

int main() {
	int p, q, r;
	cin >> p >> q >> r;
	if (p >= q and p >= r) {
		std::cout << q + r << endl;
	}else if(q >= p and q >= r) {
		std::cout << p + r << endl;
	}
	else if (r >= p and r >= q) {
		std::cout << p + q << endl;
	}

}

Measured memory_bytes: 256