akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    cout << pow(n, 3) << endl;
}

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

int main(void) {

    int x[5];

    for (int i = 0; i < 5; i++) {
        cin >> x[i];
        if (x[i] == 0) {
            cout << (i + 1) << '\n';
            return 0;
        }
    }

    return 0;

}

Measured memory_bytes: 3176
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N;
	long long A[101];
	vector<int>V;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		V.push_back(A[i]);
	}
	sort(V.begin(), V.end());
	cout << V[N - 1] - V[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int k;
  cin>>s>>k;
  set<string> st;
  int j=1;
  for(int l=0;l<k;l++){
    for(int i=0;i<=s.size()-j;i++){
      st.insert(s.substr(i,j));
    }
    j++;
    if(j>s.size()) break;
  }
  if((int)st.size()>=k){
    auto itr=st.begin();
    for(int i=0;i<k-1;i++) ++itr;
    cout<<*itr;
  }
}

Measured memory_bytes: 1664
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        Arrays.sort(ar);
        int sum = 0;
        for (int i = 0; i < n-1; i++) {
            sum += ar[i];
        }
        if (sum > ar[n-1]) {
            System.out.println("Yes"); 
        } else {
            System.out.println("No");
        }

        sc.close();

    }

    public static void intArrayScan(int[] array) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < array.length; i++) {
            array[i] = sc.nextInt();
        }
        sc.close();
    }

    public static void intArrayPrint(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.println(array[i]);
        }
    }

    public static void intSquareArrayScan(int[][] array, int h, int w) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        sc.close();
    }

    public static void intArrayListScan(List<Integer> list, int n) {
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        sc.close();
    }

    public static void intArrayListPrint(List<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));  
        }
    }
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vector<int> A(N+2, 0);
    for(int i = 1; i <= N; i++) cin >> A[i];

    int sum = 0;
     
    for(int i = 0; i < N+1; i++) sum += abs(A[i+1]- A[i]);
    
    for(int i = 1; i <= N; i++){
        int ans = sum - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100005][4];
ll fun(ll a[][4], ll i, ll pos, ll n)
{
    if(i==n)
    return 0;
    if(dp[i][pos]!=-1)
    return dp[i][pos];
    ll ans=0;
    if(pos==0)
    {
        ans=max(ans,a[i][1]+fun(a,i+1,1,n));
        ans=max(ans,a[i][2]+fun(a,i+1,2,n));
        ans=max(ans,a[i][3]+fun(a,i+1,3,n));
    }
    else if(pos==1)
    {
        ans=max(ans,a[i][2]+fun(a,i+1,2,n));
        ans=max(ans,a[i][3]+fun(a,i+1,3,n));
    }
    else if(pos==2)
    {
        ans=max(ans,a[i][1]+fun(a,i+1,1,n));
        ans=max(ans,a[i][3]+fun(a,i+1,3,n));
    }
    else
    {
        ans=max(ans,a[i][1]+fun(a,i+1,1,n));
        ans=max(ans,a[i][2]+fun(a,i+1,2,n));
    }
    return dp[i][pos]=ans;
}
 
int main() {
   
   ll i,n,k,j;
   cin>>n;
   ll a[n+1][4];
   for(i=0;i<n;i++)
   {
       for(j=1;j<=3;j++)
        cin>>a[i][j];
   }
   memset(dp,-1,sizeof(dp));
   cout<<fun(a,0,0,n);
    
}

Measured memory_bytes: 19196
using System;
using static System.Console;

namespace November30
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s1 = ReadLine().Split(' ');
            string[] s2 = ReadLine().Split(' ');

            if(s1[0] == s2[0]) WriteLine(0);
            else WriteLine(1);
        }
    }
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    map<ll, ll> mp;

    mp[A]++;
    mp[B]++;
    mp[C]++;

    if(mp.size() == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
package main

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

var score []int
var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

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

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, q := scanInt(), scanInt()
	g := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := scanInt(), scanInt()
		a--
		b--
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	var p, x int
	score = make([]int, n)
	for i := 0; i < q; i++ {
		p, x = scanInt(), scanInt()
		p--
		score[p] += x
	}

	dfs(g, 0, -1)

	for _, s := range score {
		fmt.Printf("%d ", s)
	}
}

func dfs(g [][]int, v, p int) {
	for _, nv := range g[v] {
		if nv == p {
			continue
		}
		score[nv] += score[v]

		dfs(g, nv, v)
	}
}


Measured memory_bytes: 67584
N = int(input())
A = list(map(int, input().split()))
A.insert(N, 0)
A.insert(0, 0)
sum = 0
for i in range(1, len(A)):
	sum += abs(A[i] - A[i-1])
for i in range(1, len(A) - 1):
	print(sum + abs(A[i+1] - A[i-1]) - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]))

Measured memory_bytes: 14048
import math
S = input().split(" ")
N = int(S[0])
K = int(S[1])
arr = [int(s) for s in input().split(" ")]


def calculate(n, k, arr):
    minsArr = []
    plusArr = []
    for ar in arr:
        if ar < 0:
            minsArr.append(ar)
        else:
            plusArr.append(ar)

    # find start index
    startIndex = -10000

    if len(minsArr) > k:
        startIndex = len(minsArr) - k
    else:
        startIndex = 0

    minValues = []
    while startIndex <= len(minsArr):

        if k == N:
            s1 = arr[0]
            s2 = arr[-1]
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
            minValues.append(minValue)
            break

        if startIndex + k > len(arr):
            break

        s1 = arr[startIndex]
        s2 = arr[startIndex + k - 1]

        minValue = 0

        if s1 * s2 < 0:
            minValue = math.fabs(s2 - s1) + min(math.fabs(s2), math.fabs(s1))
        else:
            # 全部为正数
            if s1 >= 0:
                minValue = math.fabs(s2)
            # 全部为负数
            else:
                minValue = math.fabs(s1)

        minValues.append(minValue)
        startIndex = startIndex + 1

    return int(min(minValues))


result = calculate(N, K, arr)
print(result)


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

// Aliases
#define enable_fast_io()  	ios_base::sync_with_stdio(false); 	\
			  				cin.tie(nullptr); 					\
							cout.tie(nullptr)  

#define N 300010LL
#define round(n) int64_t(n+0.5)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pi;

int main(){
	enable_fast_io();

	int64_t n, m, k;
	cin >> n >> m >> k;

	deque<int64_t> books1(n+1, 0), books2(m+1, 0);
	for(int i=1; i<=n; ++i){ cin >> books1[i]; books1[i] += books1[i-1];}
	for(int i=1; i<=m; ++i){ cin >> books2[i]; books2[i] += books2[i-1];}

	int64_t ans = 0, j = m;
	for(int i=0; i<=n; ++i){
		if(books1[i] > k) break;
		while (books2[j] > k - books1[i]) --j;
		ans = max(ans, i+j);
	}	
	
	cout << ans << "\n";
	
	return 0;
}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    sort(A.rbegin(), A.rend());
    queue<ll> q;
    q.push(A[0]);


    ll ans = 0;

    for (int i = 1; i<N;i++) {
        ans += q.front();
        q.pop();

        q.push(A[i]);
        q.push(A[i]);
    }

    cout << ans << endl;

}


Measured memory_bytes: 6424
def main():
    n = int(input())
    a = list(map(int, input().split()))
    xor = 0
    for i in range(2, n):
        xor ^= a[i]
    s = a[0] + a[1]
    dp = [[[-1 for k in range(2)] for j in range(2)] for i in range(45)]
    p = a[0]
    dp[0][0][0] = 0
    for i in range(44):
        crrx = xor&1
        crrs = s&1
        crrp = p&1
        for j in range(2):
            for k in range(2):
                if dp[i][j][k] == -1:
                    continue
                for nxtp in range(2):
                    for nxtq in range(2):
                        nxti = i+1
                        nxtj = 0
                        nxtk = k
                        if (nxtp ^ nxtq) != crrx:
                            continue
                        nxts = nxtp+nxtq+j
                        if nxts%2 != crrs:
                            continue
                        if nxts >= 2:
                            nxtj = 1
                        if crrp < nxtp:
                            nxtk = 1
                        elif crrp == nxtp:
                            nxtk = k
                        else:
                            nxtk = 0
                        dp[nxti][nxtj][nxtk] = max(dp[nxti][nxtj][nxtk], dp[i][j][k]+(1<<i)*nxtp)
        xor //= 2
        s //= 2
        p //= 2
    if dp[-1][0][0] > 0:
        print(a[0] - dp[-1][0][0])
    else:
        print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9316
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define f first
#define s second
#define ub  upper_bound
#define lb  lower_bound
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) cout << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " << endl

using ld = long double;
using ll = long long;
using pii = pair <int,int>;
using pll = pair <ll,ll>;
using vi = vector <int>;
using vll = vector <ll>;
using vpii = vector <pii>;
using vpll = vector<pll>;
using vs = vector <string>;


int main(){
  fastio;

  string a;
  cin >> a;
  if(a.back() == 's')
    cout << a << "es" << endl;
  else
    cout << a << "s" << endl;

  return 0;
}

Measured memory_bytes: 3620
n,a,b = map(int, input().split())

center = abs(a-b) // 2
# restore
if abs(a-b) % 2 == 0:
    print(center)
else:
    leftside = a - 1
    rightside = n - b
    
    print(min(leftside,rightside) + 1 + (b-a-1)//2)



Measured memory_bytes: 3064
n = int(input())
lst = []
for i in range(n):
    lst.append(input().split())

ans = 0.0
for i in lst:
    if i[1] == 'JPY':
        ans += float(i[0])
    else:
        mon = float(i[0]) * 380000.0
        ans += mon
print(ans)

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

int main(){
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  int A,B,C,D;
  A=a-'0',B=b-'0',C=c-'0',D=d-'0';
  int F,S;
  F=A*10+B,S=C*10+D;
  if(F==0){
    if(S==0||12<S)
      cout << "NA" << endl;
    else
      cout << "YYMM" << endl;
  }
  else if(F<13){
    if(S!=0&&S<13)
      cout << "AMBIGUOUS" << endl;
    else
      cout << "MMYY" << endl;
  }
  else{
    if(S!=0&&S<13)
      cout << "YYMM" << endl;
    else
      cout << "NA" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  for(int i = 0; i < N; i++) cin >> W[i];

  int ans = INT_MAX;
  int sum1 = 0, sum2 = 0;
  for(int i = 0; i < N - 1; i++) {
    sum1 += W[i];
    sum2 = 0;
    for(int j = i + 1; j < N; j++) {
      sum2 += W[j];
    }
    ans = min(abs(sum1 - sum2), ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  std::string S; std::cin >> S;

  int count = 0;
  for (int i = 0; i < N-2; ++i) {
    if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') ++count;
  }
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;


int main()
{
    string a,b;
    int maxn=-100;
    cin>>a>>b;
    for(int i=0;i<=a.size()-b.size();i++){
        int s=0;
        for(int j=0;j<b.size();j++){
            if((a[i+j]==b[j])){
                s++;
            }
        }
        maxn=max(maxn,s);
    }
    cout<<b.size()-maxn<<endl;
}


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

int main() {
  long A, B, C;
  cin >> A >> B >> C;
  long ans = 0, A2, B2, C2;
  set<tuple<int, int, int>> T;
  T.insert(make_tuple(A, B, C));
  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
    A2 = (B + C) / 2;
    B2 = (A + C) / 2;
    C2 = (A + B) / 2;
    A = A2; B = B2; C = C2;
    auto t = make_tuple(A, B, C);
    if (T.count(t)) {
      cout << -1 << endl;
      return 0;
    }
    T.insert(t);
    ans++;
  }
  cout << ans << endl;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);
    ll N;
    string S;
    cin >> N >> S;

    if( N % 2 != 0 ){
        cout << "No" << endl;
        return 0;
    }

    string S1 = S.substr(0, S.size()/2);
    if( S == (S1+S1) ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

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

	var aIndex = strings.Index(s, "A")
	var zIndex = strings.LastIndex(s, "Z")

	var answer = zIndex - aIndex + 1
	fmt.Println(answer)
}


Measured memory_bytes: 2048
#coding utf-8
N,M=map(int,input().split())
S =[[int(i) for i in input().split()] for i in range(M)]
p =list(map(int,input().split())) 
ans=0
for i in range(2**N):
  x=bin(i)[2:]
  x="0"*(N-len(x))+x
  for j in range(M):
    tmp=0
    for k in range(1,S[j][0]+1):
      tmp+=int(x[N-S[j][k]:N-S[j][k]+1])
    if tmp%2 != p[j]:
      break
    if j==M-1:
      ans+=1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    std::vector<vector<char>> vec(h,vector<char>(w));
    std::vector<vector<int>> ans(h,vector<int>(w));
    char c;
    for (int i=0;i<h;i++) {
        for (int j=0;j<w;j++) {
            cin>>c;
            vec.at(i).at(j)=c;
        }
    }
    for (int k=0;k<h;k++) {
        int flag=0;
        for (int l=0;l<w;l++) {
            if (vec.at(k).at(l)=='c') {
                flag=1;
                ans.at(k).at(l)=0;
                int tmp=l,count=0;
                while (tmp+1<w) {
                    count++;
                    if (vec.at(k).at(tmp+1)=='.') {
                        ans.at(k).at(tmp+1)=count;
                    } else {
                        break;
                    }
                    tmp++;
                }
            } else {
                if (flag==0) {
                    ans.at(k).at(l)=-1;
                }
            }
        }
    }
    for (int m=0;m<h;m++) {
        for (int n=0;n<w;n++) {
            cout<<ans.at(m).at(n);
            if (n!=w-1) {
                cout<<" ";
            }
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3228
#include<stdio.h>
int main()
{
    int a,b,d,r;
    double f;
    scanf("%d%d",&a,&b);
    d=a/b;
    r=a%b;
    f=1.0*a/b;
    printf("%d %d %.8lf\n",d,r,f);
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001

typedef struct _n {
  int deg;
  int right;
  int left;
  int r;
  int parent;
  int sib;
  int depth;
  int height;
} node;

node tree[100000];
int n;
void setDepth(int);
int setHeight(int);
int main() {
  int i;
  int  j, k, l, r;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    tree[i].parent = -1;
    tree[i].sib = -1;
    tree[i].depth = 0;
    tree[i].height = 0;
    tree[i].deg = 0;
  }

  for(k = 0; k < n; k++) {
    scanf("%d", &i);
    scanf("%d %d", &tree[i].left, &tree[i].right);
    if(tree[i].left != -1) tree[tree[i].left].sib = tree[i].right;
    if(tree[i].right != -1) tree[tree[i].right].sib = tree[i].left;
    if(tree[i].left != -1)tree[tree[i].left].parent = i;
    if(tree[i].right != -1) tree[tree[i].right].parent = i;
    if(tree[i].left != -1) tree[i].deg++;
    if(tree[i].right != -1) tree[i].deg++;
  }

  for(i = 0; i < n; i++) {
    if(tree[i].parent == -1) {k = i;}
  }
  setDepth(k);
  setHeight(k);

  for(i = 0; i < n; i++) {
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
	   i, tree[i].parent, tree[i].sib, tree[i].deg, tree[i].depth, tree[i].height);
    if(tree[i].parent == -1) {printf("root\n");}
    else if(tree[i].deg == 0) {  printf("leaf\n");}
    else {  printf("internal node\n");}
  }
  return 0;
}

void setDepth(int r) {
  if(tree[r].right != -1 )tree[tree[r].right].depth += 1 + tree[r].depth;
  if(tree[r].left != -1) tree[tree[r].left].depth += 1 + tree[r].depth;
  if(tree[r].left != -1) setDepth(tree[r].left);
  if(tree[r].right != -1) setDepth(tree[r].right);
}

int setHeight(int r) {
  int i, h, x, y, n;
  h=0;
  if(tree[r].deg == 0) {
    tree[r].height = 0;
    return 0;
  }
  if(tree[r].left != -1) {x = setHeight(tree[r].left);}
  else {x = 0;}
  if(tree[r].right != -1) {y = setHeight(tree[r].right);}
  else {y = 0;}
  h = (x < y)? y: x;
  h++;
  tree[r].height = h;
  return h;
}



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

int main(){
	int n,i,j,k;
	int money,temp,check=0;

	cin >>n >>money;
	temp=money/1000;
	for(i=0;i<=n;i++){
		for(j=0;j<=n-i;j++){
			for(k=0;k<=n-i-j;k++){
				if(temp==i*10+j*5+k&&i+j+k==n){
					check=1;
					break;
				}
			}
			if(check==1)break;
		}
		if(check==1)break;
	}
	if(i==n+1)cout<<-1<<" "<<-1<<" "<<-1<<endl;
	else cout<<i<<" "<<j<<" "<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		String strN = String.valueOf(n);

		char[] arrN = new char[3];
		arrN[0] = strN.charAt(0);
		arrN[1] = strN.charAt(1);
		arrN[2] = strN.charAt(2);

		for(int i = 0; i < 3;i++) {
			if(arrN[i] == '1') {
				arrN[i] = '9';
			}else if(arrN[i] == '9') {
				arrN[i] = '1';
			}
		}

		System.out.println(String.valueOf(arrN[0])
				+ String.valueOf(arrN[1])
				+ String.valueOf(arrN[2])
						);
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

int main() {
	int n,q;cin>>n>>q;
	stack<int> st[1010];

	while(q--){
		int query,t;cin>>query>>t;
		if(query==0){
			int x;cin>>x;
			st[t].push(x);
		}else if(query==1){
			if(st[t].empty()) continue;
			cout<<st[t].top()<<endl;
		}else{
			if(st[t].empty()) continue;
			st[t].pop();
		}
	}
	
  return 0;
}



Measured memory_bytes: 4288
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
int n,t,tot;
LL nowx,nowy,dx,dy;
int x[1010],y[1010],len[33];
char s[40];
int jue(int x){return x>0?x:-x;}
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d%d",&x[i],&y[i]);
	t=jue(x[1]+y[1])&1;
	for(int i=1;i<=n;++i)
		if((jue(x[i]+y[i])&1)!=t)return puts("-1")==2333;
	cout<<32-t<<endl;
	len[tot=1]=1;printf("%d ",1);
	for(int i=t;i<=30;++i)printf("%d ",len[++tot]=1<<i);puts("");
	for(int i=1;i<=n;++i)
	{
		nowx=0;nowy=0;
		for(int j=tot;j>=1;--j)
		{
			dx=x[i]-nowx;dy=y[i]-nowy;
			if(jue(dx)>jue(dy))
			{
				if(dx>0)nowx+=len[j],s[j]='R';
				else nowx-=len[j],s[j]='L';
			}
			else
			{
				if(dy>0)nowy+=len[j],s[j]='U';
				else nowy-=len[j],s[j]='D';
			}
		}
		printf("%s\n",s+1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 0

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define NMAX (200*1000)
#define QMAX (200*1000)

int N;
int Q;
int A[NMAX+5];
int B[NMAX+5];
vector<int> X[QMAX+5];
int x[QMAX+5];

vector<int> edges[NMAX+5];
int counter[NMAX+5];

void dfs(int u, int v)
{
	DOUT << "X["<<u<<"].size()="<<X[u].size()<<endl;

	vector<int>::iterator it_x = X[u].begin();
	for(;it_x!=X[u].end();it_x++) {
		DOUT << "> (*it_x)=="<<*it_x<<endl;
		v += (*it_x);
	}
	DOUT << "** counter["<<u<<"]="<<v<<endl;
	counter[u] = v;

	DOUT << "edges["<<u<<"].size()="<<edges[u].size()<<endl;
	vector<int>::iterator it_e = edges[u].begin();
	for(;it_e!=edges[u].end();it_e++) {
		dfs(*it_e, v);
	}
}

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

	cin >> N >> Q;
	FOR(i,N-1) {
		int a,b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
	}
	FOR(j,Q) {
		int p, x;
		cin >> p >> x;
		p--;
		X[p].push_back(x);
	}

	dfs(0, 0);

	ll ans = 0;
	FOR(n,N){
		cout << counter[n] << " ";
	}
	cout << endl;

	return 0;
}




Measured memory_bytes: 33280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

int main()
{
    int n,k;
    cin >> n >> k;
    char d[k];
    for(int i = 0; i < k; i++){
        cin >> d[i];
    }
    for(int i = n; i < 100000; i++){
        bool ans = true;
        string s = to_string(i);
        for(int j = 0; j < k; j++){
            for(int l = 0; l < s.size(); l++){
                if(d[j] == s[l]){
                    ans = false;
                }
            }
        }
        if(ans){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N,T = map(int,(input().split()))
tt = list(map(int,(input().split())))

start = -10
stop = -10
ans = 0
flag = False

for t in tt:
	if stop < t:
		ans += stop-start
		start = t
		stop = t + T
	else:
		stop = t + T

ans += stop-start

print(ans)

Measured memory_bytes: 25716
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)
#define pb push_back
#define eb emplace_back

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<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;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int n,m;
    cin >> n >>m;
    vector<int> a(m);
    vector<int> c(m,0);
    rep(i,m){
        int b;
        cin >> a[i] >> b;
        vector<int> x(b);
        rep(j,b) cin >> x[j];
        rep(j,b){
            c[i] += pow(2,x[j]-1);
        }
    }
    vector<vector<int>> dp(m+1,vector<int>(pow(2,n),INF));
    dp[0][0] = 0;
    rep(i,m){
        rep(j,pow(2,n)){
            chmin(dp[i+1][j],dp[i][j]);
            if(dp[i][j]==INF) continue;
            chmin(dp[i+1][j|c[i]],dp[i][j]+a[i]);
        }
    }
    if(dp[m][pow(2,n)-1]==INF) cout << -1 << endl;
    else{
        cout << dp[m][pow(2,n)-1] << endl;
    }
}

Measured memory_bytes: 16384
#include <iostream>
using namespace std;
string s, t;
int main() {
	int n, i;
	cin>>n>>s>>t;
	for(i=0; i<n; i++) if(s.substr(i,n-i)==t.substr(0,n-i)) break;
	cout<<n+i;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, m;
    boolean[] prime;
    int[] sum;
    
    void run(){
	prime = new boolean[1000000];
	setP();
	while(sc.hasNext()){
	    n = sc.nextInt();
	    m = sc.nextInt();
	    if(n==-1 && m==-1) break;
	 
	    int p = 0;
	    sum = new int[100000];
	    Arrays.fill(sum, Integer.MAX_VALUE);
	    for(int i=n+1; i<n+300&&p<sum.length; i++)
		for(int k=i; k<n+300&&p<sum.length; k++){
		    if(prime[i]&&prime[k]){
			sum[p] = i+k;
			p++;
		    }
		}
	    Arrays.sort(sum);
	    System.out.println(sum[m-1]);
	}
    }

    void setP(){
	Arrays.fill(prime, true);
	prime[0] = prime[1] = false;
	for(int i=2; i<prime.length; i++)
	    if(prime[i])
		for(int k=i+i; k<prime.length; k+=i)
		    prime[k] = false;
    }
}

Measured memory_bytes: 157624
# -*- coding: utf-8 -*-
import numpy as np
from operator import itemgetter
def solve():
    Z = sorted([tuple(map(int,input().split())) for _ in range(int(input()))], key=itemgetter(2,0,1) , reverse=True)
    x0, y0, h0 = Z[0]
    H = h0 + np.abs(np.arange(101, dtype=int).reshape(101,1)-x0) + np.abs(np.arange(101, dtype=int).reshape(1,101)-y0)
    for (i,j), h in np.ndenumerate(H):
        if all(h == max(H[i,j]-abs(x-i)-abs(y-j), 0) for x,y,h in Z):
            return ' '.join(map(str, [i,j,h]))

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 12652
#include<iostream>
using namespace std;
int main() {
  int K;
  cin >> K;
  int sum = 0;
  for (int a = 1; a <= K; a++) {
    for (int b = 1; b <= K; b++) {
      for (int c = 1; c <= K; c++) {
        for (int i = 0; i < min(min(a, b), c); i++) {
          if (a%(min(min(a, b), c) - i) == 0 && b%(min(min(a, b), c) - i) == 0 && c%(min(min(a, b), c) - i) == 0) {
            sum += (min(min(a, b), c) - i);
            break;
          }
          else {
            continue;
          }
        }
      }
    }
  }
  cout << sum << endl;
}





Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  vector<long long> B(n+1,0);
  long ans = 0;
  for(int i= 0;i<n;i++){
    cin >> A[i];
    B[i+1] = B[i]+A[i];
  }
 for(int i = 0;i<n;i++){
  long long sum = (B[n]-B[i+1])%M;
   ans += A[i]*sum;
   ans %=M;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 5624
S = input()
kouho = []

for i in range(len(S) + 1):
  for j in range(1, len(S) + 1):
    s = S[i : j]
    if len(s) == s.count("A") + s.count("C") + s.count("G") + s.count("T"):
      kouho.append(len(s))
print(max(kouho))

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(int argc, const char * argv[]) {
    char W[11], T[1001];
    int count = 0;
    scanf("%s", W);
    for(int i=0; W[i]!='\0'; i++){
        W[i] = tolower(W[i]);
    }
    while(1){
        scanf("%s", T);
        if(strcmp(T, "END_OF_TEXT") == 0) break;
        for(int i=0; T[i]!='\0'; i++){
            T[i] = tolower(T[i]);
        }
        if(strcmp(W, T) == 0){
            count += 1;
        }
    }
    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 2056
n,k = map(int,input().split())
l = list(map(int,input().split()))
p1 = 0
for i in range(k):
	p1 += l[i]
for i in range(k,n):
	p2 = p1
	p2 += l[i]
	p2 -= l[i-k]
	#print(p1,p2)
	print('Yes' if p2 > p1 else 'No')
	p1 = p2

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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2e5+5,inf=1e9+5,D=1e9+7;
s64 mi(s64 x,int y=D-2)
{
	s64 ans=1;
	while(y)
	{
		if(y&1)ans=ans*x%D;
		x=x*x%D;y>>=1;
	}
	return ans;
}
int n,X,Y;
int c[N],w[N],mn[N];
vector<int>lk[N];bool vis[N];
void add_e(int x,int y)
{
	lk[x].push_back(y);
	lk[y].push_back(x);
}
void check(int x,int y)
{
	if(y&&c[x]!=c[y]&&w[x]+w[y]<=Y)add_e(x,y);
}

s64 jie[N];
s64 ans;
int q[N],tail,cnt[N];
void bfs(int x)
{
	tail=1;
	q[1]=x;
	vis[x]=1;
	rep(head,1,tail)
	{
		int x=q[head];
		for(auto y:lk[x])
		if(!vis[y])vis[q[++tail]=y]=1;
	}
	ans=ans*jie[tail]%D;
	rep(head,1,tail)
	{
		int x=q[head];
		ans=ans*mi(++cnt[c[x]])%D;
	}
	rep(head,1,tail)
	{
		int x=q[head];
		cnt[c[x]]=0;
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	cin>>n>>X>>Y;
	w[0]=inf;
	rep(i,1,n)
	{
		scanf("%d%d",c+i,w+i);
		if(w[mn[c[i]]]>w[i])mn[c[i]]=i;
	}
	
	rep(i,1,n)
	if(w[i]+w[mn[c[i]]]<=X)add_e(i,mn[c[i]]);
	
	int a1=0,a2=0;
	rep(i,1,n)
	if(w[mn[i]]<w[a1]){a2=a1;a1=mn[i];} else
	if(w[mn[i]]<w[a2])a2=mn[i];
	
	rep(i,1,n)
	{
		check(i,a1);
		check(i,a2);
	}
	
	jie[0]=1;
	rep(i,1,n)jie[i]=jie[i-1]*i%D;
	ans=1;
	rep(x,1,n)
	if(!vis[x])bfs(x);
	cout<<ans;
}

Measured memory_bytes: 19304
n,m = map(int,input().split())
l=[0]*m
r=[0]*m
for x in range(m):
    l[x],r[x] = map(int,input().split())
lm=max(l)
rm=min(r)
#print(lm)
#print(rm)
if (rm-lm)<0:
    print("0")
else:
    print(rm-lm+1)


Measured memory_bytes: 10868
#include<stdio.h>

int main(void) {
	
	int a,b,ans=0;
	char op;

	while(1){
	scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			ans=a+b;
		}
		else if(op=='-'){
			ans=a-b;
		}
		else if(op=='/'){
			ans=a/b;
		}
		else if(op=='*'){
			ans=a*b;
		}
		else if(op=='?'){
			break;
		}
		
	printf("%d\n",ans);
	}
  
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  int mini;
  int maxi = -2000000000;
  
  rep(i, 0, n) {
    int r; cin >> r;
    if(i == 0) mini = r;
    else {
      maxi = max(maxi, r -mini);
      mini = min(mini, r);
    }
  }
  
  cout << maxi << "\n";
  
}



Measured memory_bytes: 3216
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<random>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<vector<pair<int,int> > > vvp;
#define INF (1<<29)

int main(){
    string s;
    int a=0;
    cin>>s;
    int i=0, j=s.size()-1;



    while(1){
        //cout<<i<<":"<<j<<endl;


        if(i>=j){
            cout<<a<<endl;
            break;
        }


        if(s[i]==s[j]){
            i++; j--;
        }else if(s[i]=='x'){
            a++;
            i++;
        }else if(s[j]=='x'){
            a++;
            j--;
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }



    return 0;
}

Measured memory_bytes: 512
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

constexpr int cm = 1<<17;
char cn[cm], *ci = cn + cm, ct;

inline char readchar() {
	if (ci - cn == cm) {
    fread_unlocked(cn, 1, cm, stdin); 
    ci = cn;
  }
	return *ci++;
}
inline int readint() {
	int ret = 0;
	if (ci - cn + 16 > cm) {
    while ((ct = readchar()) >= '0') {
      ret = (ret<<3) + (ret<<1) + ct - '0';
    }
  } else {
    while ((ct = *ci++) >= '0') {
      ret = (ret<<3) + (ret<<1) + ct - '0';
    }
  }
	return ret;
}

int cnt[202020];
template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar_unlocked(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar_unlocked('0');
  putchar_unlocked('\n');
}
int main(){;
  int n = readint(); int k = readint();
  
  for (int i = 0; i < n; ++i) {
    int x = readint();
    ++cnt[x];
  }

  sort(cnt, cnt + n + 1 , greater<int>());

  n -= accumulate(cnt, cnt + k, int());

  fastout(n);

  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
int main(void)
{
	int s[4] = { 6000,4000,3000,2000 }, i,a,b,t[4];
	for (i = 0; i < 4; i++) {
		scanf("%d %d", &a, &b);
		a--;
		t[i] = s[a] * b;
	}
	for (i = 0; i < 4; i++) {
		printf("%d\n", t[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
string a;
char d;
int len,tt,vis[10005];
int main(){
	cin>>a;
	len=a.length();
	scanf("%d",&tt);
	for(int i=1;i<=5;i++){
		d='z'+1;
		set<string>s;
		for(int j=0;j<len;j++){
			if(vis[a[j]-'a'+1]==0&&d>a[j])d=a[j];
		}
		vis[d-'a'+1]=1; 
		for(int j=0;j<len;j++){
			if(d==a[j]){
				string b;
				for(int k=j;k<len;k++){
					if(b.length()>tt)break;
			        b+=a[k];
					s.insert(b);
				}
			}
		}
		if(s.size()>=tt){
			int t=0;
			set<string>::iterator iter;  
			for(iter=s.begin();iter!=s.end();iter++){
				t++;
				if(t==tt){
					cout<<*iter;
					break;
				} 
			}
			break;
		}
		else tt-=s.size();
	}
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
#define YesNo(a) cout<<TO((a),"Yes","No")<<endl;



int main(){
  ll N;
  cin >> N;
  vector<ll> pl,mi,ansx,ansy;
  FOR(i,0,N){
    ll a;
    cin >> a;
    if(a>=0){
      pl.push_back(a);
    }else{
      mi.push_back(a);
    }
  }
  SORT(pl);
  SORT(mi);
  queue<ll> pq,mq;
  if(pl.size() == N){
    FOR(i,1,N-1) pq.push(pl[i]);
    mq.push(pl[0]-pl[N-1]);
    ansx.push_back(pl[0]);
    ansy.push_back(pl[N-1]);
  }else if(mi.size()==N){
    FOR(i,1,N-1) mq.push(mi[i]);
    pq.push(mi[N-1]-mi[0]);
    ansx.push_back(mi[N-1]);
    ansy.push_back(mi[0]);
  }else{
    FOR(i,0,pl.size()) pq.push(pl[i]);
    FOR(i,0,mi.size()) mq.push(mi[i]);
  }

  while(pq.size()+mq.size() > 1){
    int p = pq.front();
    int m = mq.front();
    pq.pop();
    mq.pop();
    if(pq.size()==0){
      pq.push(p-m);
      ansx.push_back(p);
      ansy.push_back(m);
    }else{
      mq.push(m-p);
      ansx.push_back(m);
      ansy.push_back(p);
    }
  }
  cout << pq.front() << endl;
  FOR(i,0,ansx.size()){
    cout << ansx[i] << " " << ansy[i] << endl;
  }
}

Measured memory_bytes: 6004
#include <bits/stdc++.h>
#include<set>
#include <algorithm>
#define ll long long 
#include <string.h>
#define pb push_back
#define mp make_pair
# define pi 3.14159265358979323846
using namespace std;
int main()
{
	string s;
	ll int n;
	cin>>n;
	cin>>s;
	ll int i;
	vector<ll int > r,w;
	for(i=0;i<n;i++)
	{
		if (s[i]=='R')
		r.pb(i);
		else
		w.pb(i);
	}
	ll int ans=0;
	sort(r.begin(),r.end(),greater<ll int>());
	sort(w.begin(),w.end());
ll int l=min(r.size(),w.size());
	for(i=0;i<l;i++)
	{
		if (w[i]<r[i])
		ans++;
		
	}
	cout<<ans<<endl;
	
}

    
	
		

	
			

		


 






Measured memory_bytes: 5800
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		String s = in.next();
		boolean f = true;
		for(int i = 0; i < s.length(); i++){
			for(int j = 0; j < s.length(); j++){
				if(i == j) continue;
				if(s.charAt(i) == s.charAt(j)){
					f = false;
					break;
				}
			}
		}
		System.out.println(f ? "yes" : "no");
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
int main(void){
  int N;
  while(cin>>N,N){
    vector<pair<int,int> > v(N);
    rep(i,N)cin>>v[i].second>>v[i].first;
    sort(v.begin(),v.end());
    int M = 0;
    bool is = true;
    rep(i,N){
      M += v[i].second;
      if(v[i].first < M){
        is = false;
        break;
      }
    }
    cout<<(is?"Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a < b){
		printf("a < b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else {
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>

using namespace std;

int main() {
	string n;
	while (cin >> n) {
		if (n == "0")break;
		int ans = 0;
		for (int i = 0; i < n.size(); i++)ans += n[i] - '0';
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define LL long long
#define N 200100
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x7fffffff
#define pb push_back
#define X first
#define Y second
using namespace std;
int main(){
	int w,a,b;
	scanf("%d%d%d",&w,&a,&b);
	if (a < b) swap(a,b);
	int l1 = a,r1 = a + w,l2 = b,r2 = b + w;
	int ans = max(l1 - r2,0);
	printf("%d\n",ans);
}

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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    for(int i = min(a, b); i >= 1; i--) {
        if(a % i == 0 && b % i == 0) {
            if(++count == k) {
                cout << i << endl;
                break;
            }
        }
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

signed main(){
	IOS;
	int n;
	cin >> n;
	vec<ll> p(n);
	REP(i,n)cin >> p[i];
	sort(ALL(p),greater<ll>());
	p[0] /= 2;
	ll sum = 0;
	REP(i,n)sum += p[i];
	dump(sum);
}	

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

int main()
{
    char c;
    cin >> c;
    set<char> st = {'a', 'i', 'u', 'e', 'o'};
    auto it = st.find(c);
    if (it != st.end()) cout << "vowel" << endl;
    else cout << "consonant" << endl;

    return 0;
}


Measured memory_bytes: 256
def fib():
    a = 1
    b = 0
    while 1:
        c = a + b
        yield c
        a = b
        b = c


def main():
    h, w, k = map(int, input().split())

    dp = [[0] * (w + 2) for _ in range(h + 1)]
    dp[0][1] = 1
    f = fib()
    c = [f.__next__() for _ in range(w + 1)]

    for i in range(1, h + 1):
        for j in range(1, w + 1):
            dp[i][j] = c[j - 1] * c[w - j] * dp[i - 1][j] + c[j - 1] * c[w - j - 1] * dp[i - 1][j + 1] + c[j - 2] * c[w - j] * dp[i - 1][j - 1]

    print(dp[h][k] % (10 ** 9 + 7))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<pii> v[410][410];

int main() {
    int h,w;cin>>h>>w;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    ll ans = 0;
    vector<vector<bool> > check(h,vector<bool>(w,false));
    rep(i,h)rep(j,w){
        if(s[i][j]=='.')continue;
        if(check[i][j])continue;
        queue<pii> q;
        check[i][j] = true;
        q.push(pii(i,j));
        ll cnt = 0,blacks = 0;
        while(!q.empty()){
            pii now = q.front();q.pop();
            if (s[now.first][now.second]=='.')cnt++;
            else blacks++;
            rep(i,4){
                int x = now.second + x_pos[i],y = now.first + y_pos[i];
                if(0 > x || x >= w || 0 > y || y >= h)continue;
                if(s[now.first][now.second] == s[y][x] || check[y][x])continue;
                q.push(pii(y,x));
                check[y][x] = true;
            }
        }
        ans += cnt*blacks;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4480