akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {
				
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		String s = sc.next();
		boolean[] used = new boolean[26];
		String p = "abcdefghijklmnopqrstuvwxyz";
		
		if(s.length() != 26){
			for(int i = 0; i < s.length(); i++){
				used[s.charAt(i)-'a'] = true;
			}
			for(int i = 0; i < 26; i++){
				if(!used[i]){
					System.out.println(s + p.charAt(i));
					return;
				}
			}
		}
		
		if(s.equals("zyxwvutsrqponmlkjihgfedcba")){
			System.out.println(-1);
			return;
		}
		
		int indexSwap1 = 0;
		for(int i = 0; i < s.length()-1; i++){
			if(s.charAt(i) < s.charAt(i+1)) indexSwap1 = i;
		}
		
		char c = 'z';
		for(int i = indexSwap1; i < 26; i++){
			if(s.charAt(i) > s.charAt(indexSwap1) && s.charAt(i) < c){
				c = s.charAt(i);
			}
		}
		
		System.out.println(s.substring(0, indexSwap1) + c);
		
	}//end main
	
}//end Main

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23252
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static int r = int.Parse(input[2]);
static long[,] moveMatrix = new long[n,n];
static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
static List<int> numListOri = Enumerable.Range(0,r).ToList();//0,1,...,n-1のn個入ったリスト。
static List<int> numListEnd = new List<int>(); //生成用のリスト。最初から値が左側に入っていても良い。
static long answer = long.MaxValue;

	static void Main()
	{
    for(int i = 0; i < r; i++) nums[i]--;

    for(int i = 0; i < n; i++)
    {
      for(int j = i+1; j < n; j++)
      {
        moveMatrix[i,j] = 9999999999999;
        moveMatrix[j,i] = 9999999999999;
      }
    }
    
    for(long i = 0; i < m; i++)
    {
      long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      moveMatrix[numsSub[0]-1,numsSub[1]-1] = numsSub[2];
      moveMatrix[numsSub[1]-1,numsSub[0]-1] = numsSub[2];
    }

    for(int k = 0; k < n; k++)
    {
      for(int i = 0; i < n; i++)
      {
        for(int j = 0; j < n; j++)
        {
          if(moveMatrix[i,j] > moveMatrix[i,k] + moveMatrix[k,j])
            moveMatrix[i,j] = moveMatrix[i,k] + moveMatrix[k,j];//距離の更新
        }
      }
    }

    Permutation(numListOri, numListEnd);//順列の生成関数
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}

  static void Permutation(List<int> numListOri, List<int> numListEnd)//順列の生成関数
    {
      for(int i = 0; i < numListOri.Count(); i++)//numListOriの要素を全通り移していく。
      {
        int x = numListOri[i];//移動する要素
        numListEnd.Add(x);
        numListOri.RemoveAt(i);
        
        if(numListOri.Count() > 0) Permutation(numListOri, numListEnd);//さらに移動
        else
        {
          long memo = 0;
          for(int j = 0; j < numListEnd.Count()-1; j++)
          {
            memo += moveMatrix[nums[numListEnd[j]], nums[numListEnd[j+1]]];
          }
          //Console.WriteLine(memo+" "+nums[numListEnd[0]]+nums[numListEnd[1]]);
          answer = Math.Min(memo, answer);
        }
        
        numListOri.Insert(i, x);//listOriginalに戻す
        numListEnd.RemoveAt(numListEnd.Count()-1);
      }
    }

}

Measured memory_bytes: 13648
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 1000000007
  #define N 1000001
  




int32_t main()
{



    bool ok = 0;

    string s;
    cin >> s;

    char arr[1000001];

    int start = 500000;
    int end = 500000;

    for(int i = 0 ; i < s.length(); i++)
    {
      arr[end++] = s[i];
    }

    int q;
    cin >> q;

    while(q--)
    {
   //   trace4(ok,start,end,0);
      int x;
      cin >> x;
      if(x == 1)
      {
        ok ^= 1;
      }
      else
      {
        int y;
        cin >> y;
        char ch;
        cin >> ch;
      //  trace1(ch);
        if(y == 1)
        {
          if(ok)
          {
            arr[end++] = ch;
          }
          else
          {
            arr[--start] = ch;
          }
        }
        else
        {
          if(ok)
          {

            arr[--start] = ch;
          }
          else
          {
            arr[end++] = ch;
          } 
        }
      }
      // trace4(ok,start,end,1);
    }

    if(ok == 1)
    {
      end--;
      while(end >= start)
      {
        char ch = (int)arr[end--] ;
        cout << ch;
      }
    }
    else
    {
      while(start <end)
      {
        //trace2(start,(int)arr[start]);
        char ch = (int)arr[start++] ;
        //trace1(ch);
        cout << ch;
      }
    }
 

    return 0;
}

Measured memory_bytes: 1024
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	$ls[$_]?$sum_l[$s[$_]+1]++:$sum_s[$s[$_]]++for 0..$n-1;
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(@sa){
			$sa[$buf[$s[$_-1]]++]=$_-1if$_>=1&&!$ls[$_-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms=grep!$ls[$_-1]&&$ls[$_],1..$n-1;
	my@lms_map=(-1)x($n+1);
	my$m=@lms;
	for(0..$m-1){
		$lms_map[$lms[$_]]=$_;
	}
	@sa=$induce->(@lms);
	if($m){
		my@sorted_lms=grep$lms_map[$_]!=-1,@sa;
		my@rec_s;
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms[$lms_map[$l]+1]//$n;
			my$end_r=$lms[$lms_map[$r]+1]//$n;
			my$different;
			if($end_l-$l!=$end_r-$r){
				$different=1;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$different=$l==$n||$s[$l]!=$s[$r];
			}
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper+=$different;
		}
		my@rec_sa=sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array($){
	my@s=map ord,split"",$_[0];
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array($\@){
	my@s=map ord,split"",$_[0];
	return lcp(@s,@{$_[1]});
}
package main;
my$s=<>;
chomp$s;
my@sa=SuffixArray::suffix_array($s);
my@lcp=LcpArray::lcp_array($s,@sa);
my$ans=@sa*(@sa+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


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

using namespace std;

int main(){
    int a, b, c, x, y, ans = 0;
    cin >> a >> b >> c >> x >> y;
    if(x > y){
        swap(a, b);
        swap(x, y);
    }
    if(a + b > 2 * c){
        ans += 2 * x * c;
        y -= x;
        x = 0;
    }
    ans += x * a  + min(y * b, 2 * y * c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  ul ans = 0;
  cin >> n;
  ul rem = 0;
  bool isrem = false;
  bool is_same = true;
  for (int i=0; i<n; ++i) {
    ul a, b;
    cin >> a >> b;
    ans += a;
    if (a!=b) is_same = false;
    if (a>b) {
      if (isrem) {
        rem = min(rem, b);
      } else {
        isrem = true;
        rem = b;
      }
    }
  }
  if (is_same) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans-rem << endl;
  return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

struct edge {
    int next,to;
};

const int maxn=(int)(1e5)+5;
int fr[maxn];
int b[maxn],vi[maxn];
edge e[maxn<<1];
int tote;

inline void addone(int u,int v) {
    ++tote;
    e[tote].next=fr[u];fr[u]=tote;e[tote].to=v;
}

inline void addedge(int u,int v) {
    addone(u,v);addone(v,u);
}

int main() {
    int n,m;
    read(n);read(m);
    memset(fr,-1,sizeof(fr));
    REP(i,1,m) {
        int u,v;
        read(u);read(v);
        addedge(u,v);
    }
    int x=1,cnt=0;vi[1]=1;
    b[++cnt]=x;
    while(1) {
        int fl=0;
        RAL(i,x) if(!vi[e[i].to]) {
            b[++cnt]=e[i].to;vi[e[i].to]=1;x=e[i].to;fl=1;break;
        } if(!fl) break;
    }
    REP(i,1,cnt/2) swap(b[i],b[cnt-i+1]);
    x=b[cnt];
    while(1) {
        int fl=0;
        RAL(i,x) if(!vi[e[i].to]) {
            b[++cnt]=e[i].to;vi[e[i].to]=1;x=e[i].to;fl=1;break;
        } if(!fl) break;
    }
    printf("%d\n",cnt);
    REP(i,1,cnt) printf("%d ",b[i]);putchar('\n');
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int n, x, y, m;
int a[2000];

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

	for (int i = 1; i < n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (j <= x || i >= y)
				a[j - i]++;
			else {
				m = min(j - i, abs(i - x) + abs(j - y) + 1);
				a[m]++;
			}
		}
	}

	for (int i = 1; i < n; i++)
		cout << a[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> ans(n + 1, 0);
    rep(i, n) {
        if (s[i] == '<') {
            ans[i+1] = ans[i] + 1;
        }
    }
    // rep(i, n + 1) {
    //     cout << ans[i] << " ";
    // }
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == '>') {
            ans[i] = max(ans[i], ans[i+1] + 1);
        }
    }
    // cout << "test2" << endl;
    ll sum =  0;
    rep(i, n + 1) {
        // cout << ans[i] << " ";
        sum += (ll)ans[i];
    }
    // cout << endl;
    cout << sum << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n;
  long long res = 0;
  cin >> n;
  vector<int> fac(n + 1, 1);
  for (int i = 2; i <= n; i++) fac[i] = fac[i - 1] * i;
  int x;
  set<int> m;
  int v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    m.insert(x);
    v = x - distance(m.begin(), m.lower_bound(x)) - 1;
    res += 1LL * v * fac[n - i - 1];
  }
  m.clear();
  for (int i = 0; i < n; i++) {
    cin >> x;
    m.insert(x);
    v = x - distance(m.begin(), m.lower_bound(x)) - 1;
    res -= 1LL * v * fac[n - i - 1];
  }
  cout << abs(res) << '\n';
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    S = [list(input()) for _ in range(N)]

    def bfs(start):
        q = deque([start])
        visited = [-1 for _ in range(N)]
        visited[start] = 0
        prev = [set() for _ in range(N)]
        prev[start].add(-1)

        while q:
            cur = q.popleft()

            for nex in range(N):
                if cur == nex:
                    continue

                if S[cur][nex] == "0":
                    continue

                if nex in prev[cur]:
                    continue

                if visited[nex] == visited[cur] + 1:
                    prev[nex].add(cur)
                    continue

                if visited[nex] > 0:
                    return -1

                visited[nex] = visited[cur] + 1
                prev[nex].add(cur)
                q.append(nex)

        return max(visited) + 1

    # 端を決め打ちして全探索
    ans = -1
    for i in range(N):
        tmp = bfs(i)
        if ans < tmp:
            ans = tmp

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    string n;
    cin >> n;
    int c = n.back() - '0';
    if (c == 3) cout << "bon" << endl;
    else if (c == 0 or c == 1 or c == 6 or c == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}


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

const long long int INF = 1e17;

long long int dis[305][305], g[305][305];

int main(void) {
    long long int n, m, l;
    cin >> n >> m >> l;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            dis[i][j] = INF;
        }
        dis[i][i] = 0;
    }
    for (int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dis[a][b] = dis[b][a] = c;
    }
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (dis[i][k] + dis[k][j] < dis[i][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                }
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            g[i][j] = dis[i][j] <= l ? 1LL : INF;
        }
        g[i][i] = 0;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            for(int k = 1; k <= n; k++) {
                if (g[j][i] + g[i][k] < g[j][k]) {
                    g[j][k] = g[j][i] + g[i][k];
                }
            }
        }
    }
    int q;
    cin >> q;
    for(int i = 1; i <= q; i++) {
        int s, t;
        cin >> s >> t;
        if(g[t][s] < INF) cout << g[t][s] - 1 << "\n";
        else cout << -1 << "\n";
    }
    return 0;
}

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

typedef long long int ll;

ll M = 1000000007;

vector <ll> sum;
vector <ll> diff;


int main()
{
	ll i,j,k,l,m,n,t;

	ll u,v;

  cin >> n;

  for(i=0;i<n;i++)
  {
      cin >> u >> v;
      sum.push_back(u+v);
      diff.push_back(u-v);
  }

  sort(sum.begin(),sum.end());
  sort(diff.begin(),diff.end());

  ll ans = sum[n-1]-sum[0];
  ans = max(ans,diff[n-1]-diff[0]);

  cout << ans << '\n';



	

}

Measured memory_bytes: 6608
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<ll,ll>;
using vi = vector<int>;
int INF = 1e9+7;

int main() {
    string S;
    cin >> S;
    int count = 0;
    for (int i=0; i<3; i++) {
        if (S[i]=='1') count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e10
using namespace std;
struct Card{
	char c;int v;
} A[100000],B[100000];

int partition(int p,int r){
	int x=A[r].v,i=p-1;
	for(int j=p;j<r;j++)
		if(A[j].v<=x) swap(A[++i],A[j]);
	swap(A[i+1],A[r]);
	return i+1;
}
void quickSort(int p,int r){
	if(p<r){
		int q = partition(p,r);
		quickSort(p,q-1);
		quickSort(q+1,r);
	}
}

void merge(int left,int mid,int right){
	int n1=mid-left,n2=right-mid;
	Card L[n1+1],R[n2+1];
	for(int i=0;i<n1;i++) L[i] = B[left+i];
	for(int i=0;i<n2;i++) R[i] = B[mid+i];
	L[n1].v = R[n2].v = INF;
	int i=0,j=0;
	for(int k=left;k<right;k++)
		if(L[i].v<=R[j].v) B[k] = L[i++];
		else B[k] = R[j++];
}
void mergeSort(int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		mergeSort(left,mid);
		mergeSort(mid,right);
		merge(left,mid,right);
	}
}

bool judge(int n){
	for(int i=0;i<n;i++)
		if(A[i].c!=B[i].c) return 0;
	return 1;
}
int main()
{
	int n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i].c>>A[i].v;
		B[i].c = A[i].c;
		B[i].v = A[i].v;
	}
	quickSort(0,n-1);
	mergeSort(0,n);
	if(judge(n)) cout<<"Stable\n";
	else cout<<"Not stable\n";
	for(int i=0;i<n;i++)	
		printf("%c %d\n",A[i].c,A[i].v);
}


Measured memory_bytes: 5480
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int n,k;
struct node{int x,y;}edge[1000010];
int main(){
	n=gi();k=gi();
	int tot=(n-2)*(n-1)/2,m=n-1;
	for(int i=1;i<=m;i++)edge[i].x=n,edge[i].y=i;
	if(k>tot)return puts("-1"),0;int now=2,Q=1;
	n--;
	while(tot!=k){
		tot--;
		edge[++m]=(node){now,(now+Q-1)%n+1};
		now++;now=(now-1)%n+1;
		if(now==2)Q++;
	}
	printf("%d\n",m);
	for(int i=1;i<=m;i++)
		printf("%d %d\n",edge[i].x,edge[i].y);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e6+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int h,n;
	cin>>h>>n;
	int s=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		s+=x;
	}
	if(s>=h)
	{
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N,W;cin>>N>>W;
    ll w[110],v[110];
    vector<vi> dp(110,vi(110000,INF));
    dp[0][0]=0;
    REP(i,N)cin>>w[i]>>v[i];

    REP(i,N){
        FORS(j,0,100000){
            if(j>=v[i]){
                dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            }
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    ll ans=0;
    REPS(j,100000){
        if(dp[N][j]<=W)ans=j;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 98808
#include <iostream>
using namespace std;
#define MAX 100

int main() {
    int n, idx, g_num, a;
    int G[MAX+1][MAX+1];

    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> idx >> g_num;
        for(int j=0; j<=n; j++) {
            G[idx][j] = 0;
        }
        for(int j=0; j<g_num; j++) {
            cin >> a;
            G[idx][a] = 1;
        }   
    }

    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            cout << G[i][j];
            if(j!=n) {
                cout << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

a = [int(input()) for _ in range(5)]
k = int(input())

def f():
    for i in a:
        for j in a:
            if i - j > k:
                return False
    return True

if f():
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

int main() {
  ll N;
  cin >> N;

  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll j = N / i;
    ans += i * j * (j + 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3592
k,a,b = map(int,input().split())

if b-a <= 2:
    print(k+1)
else:
    ans = a
    if (k-a+1)%2 == 0:
        ans += (b-a)*((k-a+1)//2)
        print(ans)
    else:
        ans += (b-a)*((k-a+1)//2)+1
        print(ans)

Measured memory_bytes: 3060
def query(i):
    print(i)
    return input()


n = int(input())
gender = query(0)
if gender == 'Vacant':
    exit()
l = 0
r = n
for _ in range(19):
    mid = (l + r) // 2
    res = query(mid)
    if res == 'Vacant':
        exit()
    cnt = mid - l + 1
    if (cnt % 2 == 0 and res == gender) or (cnt % 2 != 0 and res != gender):
        r = mid
    else:
        l = mid
        gender = res

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    vector<int> a(3);
    rep(0, i, 3)
    {
        cin >> a[i];
    }
    sort(all(a));
    cout << a[0] + a[1] + a[2] * 10 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	System.out.println(Math.min(a + b, Math.min(b + c, c + a)));
    }
}

Measured memory_bytes: 23124
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        int n;
        string s;
        cin >> n >> s;
        ll r = 0, b = 0;
        rep(i, n) {
            if (s[i] == 'R') r++;
            else b++;
        }
        if (r > b) cout << "Yes" << endl;
        else cout << "No" << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    if(n == 1){
        cout << "Hello World" << endl;
    }
    else {
        int A, B; cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}


Measured memory_bytes: 256
use text_io::*;
use std::process::exit;
use im_rc::HashMap;
use std::cmp::min;

fn main(){
    let mut a:usize = read!();
    let mut n:usize = 1;
    for i in 0..a {
        let x:usize = read!();
        if x==n {
            n+=1;
        }
    }
    if n==1 {
        println!("-1");
        exit(0);
    }
    println!("{}",a+1-n);
}

Measured memory_bytes: 2092
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/


int prime[1000000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}

void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}


ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}


ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}


bool comp(const pair<long long,ll> &a , const pair<ll ,ll > &b){
    if(a.first == b.first)  return a.second < b.second;
    return a.first > b.first;

    return false;
}

void solve();

int main() {
    fast();
    customrun();
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


void solve(){
    int n;in(n);

    vector < int > fun(n+1);
    
    int s  = sqrt(2*n) + 1;

    mfor(i,1,n+1,1){
        for(int j = 1; j <= n and j+i <= s ;j++){
            for(int k = 1; k <= n and k+i <= s and k+j <= s ; k++){
                ll temp = i*i + j*j + k*k + i*j + j*k + k*i ;
                if( temp <= n and temp >= 1 ) fun[temp]++; 
            }
        }
    }

    mfor(i,1,n+1,1) on(fun[i]);
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int H,W,M;
    cin >> H >> W >> M;
    vector<int> hcount(H);
    vector<int> wcount(W);
    vector<PII> bomb;
    REP(i,M){
        int h,w;
        cin >> h >> w;
        h--; w--;
        bomb.push_back(MP(h,w));
        hcount[h]++;
        wcount[w]++;
    }

    int ans = 0;
    int HM,WM;
    HM = 0; WM = 0;
    REP(i,H){
        chmax(HM,hcount[i]);
    }
    REP(j,W){
        chmax(WM,wcount[j]);
    }

    ll areabomb = 0;
    ll HMc,WMc;
    HMc = 0; WMc = 0;
    REP(i,H){
        if (HM == hcount[i]) HMc++;
    }
    REP(j,W){
        if (WM == wcount[j]) WMc++;
    }

    REP(i,M){
        int h = bomb[i].first;
        int w = bomb[i].second;
        if ((hcount[h] == HM) and (wcount[w] == WM)) areabomb++;
    }

    ans = HM + WM - 1;
    if (areabomb != HMc * WMc) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 9804
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
	var values = input[1].split(" ").map(val => parseInt(val, 10));
	var costs = input[2].split(" ").map(cost => parseInt(cost, 10));
  	var totalVal = 0;
  	var totalCost = 0;
  
    for (var i = 0; i < n; i++) {
      if (values[i] > costs[i]) {
        totalVal += values[i];
        totalCost += costs[i];
      }
    }
  
	//出力
	console.log(totalVal - totalCost);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

int main(void)
{
  int a,b;

  cin>>a>>b;

  if(a>8 || b>8)
  {
    cout<<":("<<endl;
  }
  else
  {
    cout<<"Yay!"<<endl;
  }
  
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int sum=0;
	char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)){
		sum=(sum<<1)+(sum<<3)+(c^48);
		c=getchar();
	}
	return sum;
}
int const maxn=2e5+5;
int const p=1e9+7;
int n,A,B,mn_all,c[maxn],w[maxn],father[maxn],mn[maxn],id[maxn];
int frac[maxn],inv[maxn],debug[maxn];
int sum[maxn],tag[maxn],size[maxn];
int find(int x){
	if(father[x]!=x) father[x]=find(father[x]);
	return father[x];
}
inline void merge(int a,int b){
	int r1=find(a),r2=find(b);
	if(r1!=r2) father[r1]=r2;
}
inline bool cmp(int a,int b){
	return father[a]<father[b];
}
inline int ksm(int a,int b){
	int res=1;
	while(b>0){
		if(b&1) res=res*a%p;
		b>>=1;
		a=a*a%p;
	}
	return res;
}
signed main(){
	n=read(),A=read(),B=read();
	for(int i=1;i<=n;i++)
	  c[i]=read(),w[i]=read(),id[i]=i,debug[c[i]]++;
	w[0]=100000000000;
    int mn_all=0,mn_second=0;
	for(int i=1;i<=n;i++)
	  if(w[i]<w[mn[c[i]]]) mn[c[i]]=i;
	for(int i=1;i<maxn;i++)
	  if(mn[i]){
	  	  if(w[mn[i]]<w[mn_all]) mn_second=mn_all,mn_all=mn[i];
	  	  else if(w[mn[i]]<w[mn_second]) mn_second=mn[i];
	  }
	int temp=0;
	for(int i=1;i<=n;i++)
	  father[i]=i;
	for(int i=1;i<=n;i++){
		if(w[i]+w[mn[c[i]]]<=A) merge(i,mn[c[i]]);
		if(c[i]==c[mn_all] && w[i]+w[mn_second]<=B) merge(i,mn_second);
		if(c[i]!=c[mn_all] && w[i]+w[mn_all]<=B) merge(i,mn_all);
	}
	for(int i=1;i<=n;i++)
	  father[i]=find(father[i]);
	temp=0;
	for(int i=1;i<=n;i++)
	  if(father[i]!=i || father[i]==i && i==10) temp++;
	sort(id+1,id+n+1,cmp);
	int ans=1;
	frac[0]=1;
	for(int i=1;i<=n;i++)
	  frac[i]=frac[i-1]*i%p;
    inv[n]=ksm(frac[n],p-2);
    for(int i=n-1;i>=0;i--)
	  inv[i]=inv[i+1]*(i+1)%p;
	for(int i=1;i<=n;i++)
	  size[father[i]]++;
	for(int i=1;i<=n;i++)
	  if(father[i]==i) ans=ans*frac[size[i]]%p;
	temp=0;
	for(int i=1;i<=n;i++){
		if(tag[c[id[i]]]!=father[id[i]]){
			ans=ans*inv[sum[c[id[i]]]]%p;
			if(tag[c[id[i]]]==10) temp+=sum[c[id[i]]]; 
			sum[c[id[i]]]=0;
			tag[c[id[i]]]=father[id[i]];
		}
		sum[c[id[i]]]++;
	}
	for(int i=1;i<maxn;i++)
	  ans=ans*inv[sum[i]]%p;
	printf("%lld\n",ans);
	return 0;
}

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

int main()
{
     int num[10], v1, v2;
     while (scanf("%d,", &num[0]) != EOF) {
          for (int i = 1; i < 10; i++) scanf("%d,", &num[i]);
          scanf("%d,%d", &v1, &v2);

          int sum = 0;
          for (int i = 0; i < 10; i++) sum += num[i];
          double dis;
          dis = (double)sum / (double)(v1 + v2);
          dis *= (double)v1;
          sum = 0;
          int i = 0;
          do {
               sum += num[i];
               i++;
          }while(sum < dis);
          cout << i << endl;
     }

     return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
int n;
vector<int> v[N];
int f[N];
void dfs(int x){
	int t;
	vector<int> tmp;
	for(int i=0;i<v[x].size();i++){
		dfs(t = v[x][i]);
		tmp.push_back(f[t]);
	}
	sort(tmp.begin(),tmp.end());
	int mx = 0;
	int len = tmp.size();
	for(int i=0;i<tmp.size();i++){
		mx = max(mx,tmp[i]+len-i);
	}
	f[x] =mx;
}
int main(){
	scanf("%d",&n);
	int x;
	for(int i=2;i<=n;i++)scanf("%d",&x),v[x].push_back(i);
	dfs(1);
	cout<<f[1]<<endl;
	return 0;
}

Measured memory_bytes: 13952
// 選択ソート
// O(n^2) 安定でない

#include <stdio.h>

#define MAX 100

void swap(int *a, int *b) {
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void disp(int A[], int N){
    int i;

    // 表示
    for(i = 0; i < N; i++){
        if (i == 0) printf("%d", A[i]);
        else printf(" %d", A[i]);
    }
    // 改行を出力
    printf("\n");
}

int selectionSort(int A[], int N) {
    int i, j, tmp, cnt = 0;
    int minj;

    for (i = 0; i < N; i++) {
        minj = i;
        for (j = i; j < N; j++) {
            if (A[j] < A[minj]) {
	            minj = j;
            }
        }

        if (i != minj) {
            swap(&A[i], &A[minj]);
            cnt++;
        }
    }
    return cnt;
}

int main(){
  int i, N;
  int A[MAX];
  int count;

  scanf("%d", &N);

  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  count = selectionSort(A, N);

  disp(A, N);

  printf("%d\n", count);


  return 0;
}


Measured memory_bytes: 2004
#include<bits/stdc++.h>
using namespace std;
vector<vector<char>> v;

int ans,k,n,m;

int main()
{
    cin>>n>>m>>k;
    int i,j;
    for(i=0;i<n;i++)
    {
        v.push_back(vector<char>(m));
        for(j=0;j<m;j++)
        {
            cin>>v[i][j];
        }
    }
    for(i=0;i<pow(2,n);i++)
    {
        for(j=0;j<pow(2,m);j++)
        {
            int row[n]={0},col[m]={0},ct=0;
            int t=i,l=0;
            while(t)
            {
                row[l]=t%2;
                l++;
                t/=2;
            }
            l=0;
            t=j;
            while(t)
            {
                col[l]=t%2;
                l++;
                t/=2;
            }
            for(int a=0;a<n;a++) 
                for(int b=0;b<m;b++) 
                    if(row[a] && col[b] && v[a][b]=='#') 
                        ct++;
            if(ct==k) ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 1000  //check the limits, man
const ll INF = 1e12;
int main()
{
    int i,n,k,x;
    in(n);
    in(k);
    vi v(n);
    vi ar(n);
    read(v,i,n);
    k=0;
    for(i=n-1;i>=0;i--)
        k=max(k,v[i]),ar[i]=k;
    k=0;
    rep(i,n)
        k=max(k,ar[i]-v[i]);
    x=0;
    rep(i,n)
        if(ar[i]-v[i]==k)x++;
    out(x);
}







Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int A, B;
  string S;
  cin >> A >> B;
  cin >> S;
  if( S.size() != A+B+1 ){
    cout << "No" << endl;
    return 0;
  }
  for( int i=0; i<A+B+1; i++ ){
    if( i == A ){
      if( S[i] != '-' ){
        cout << "No" << endl;
        return 0;
      }
    } else {
      if( S[i] < '0' || '9' < S[i] ){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,d;
	cin>>n>>d;
	if(n%(2*d+1)==0)
	{
		cout<<n/(2*d+1);
	}
	else
	{
		cout<<(n/(2*d +1))+1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

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

    bool ans = false;
    for (int i = 0; i <= N / 4; i++) {
        for (int j = 0; j <= N / 7 ; j++) {
            if (i * 4 + j * 7 == N)
                ans = true;
        }
    }

    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;


int main(){
   int n  ;
   cin >> n  ;
  
  int p[20010],a[20010],b[20010];
  
  for(int i=1;i<=n;i++)
    cin >> p[i];
  
  for(int i=1;i<=n;i++)
		a[i]=1+30000*(i-1),b[i]=1+30000*(n-i);
  
  for(int i=1;i<=n;i++){
    a[p[i]] += i;
  }
  
  for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	cout<<endl;
  
	for(int i=1;i<=n;i++)
		cout<<b[i]<<" ";
	cout<<endl;
}
  
  
  


Measured memory_bytes: 896
n = int(input())

ans_b = []
ans_n = ['a']

s = ['a','b','c','d','e','f','g','h','i','j']

for i in range(1,n):
    ans_b = ans_n.copy()
    ans_n = []
    for j in ans_b:
        plus = 1
        ans_n.append(j+'a')
        while( j.count(s[plus-1]) > 0):
            ans_n.append(j+ s[plus])
            plus += 1

ans = sorted(ans_n)

for i in ans:
    print(i)

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      n: usize,
      w: usize,
      wvs: [(usize, usize); n]
    }
    let mut dp = vec![vec![0; w+1]; n+1];
    for i in 0..n {
        let (iw, iv) = wvs[i];
        for cw in 0..w {
            dp[i+1][cw] = max(dp[i+1][cw], dp[i][cw]);

            let nw = cw + iw;
            if nw <= w  {
                dp[i+1][nw] = max(dp[i+1][nw], dp[i][cw] + iv);
            }
        }
    }
    let ans = dp[n].iter().max().unwrap();
    puts!("{}\n", ans);
}


Measured memory_bytes: 106748