akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;

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

    LL n;
    cin >> n;
    LL a[n];
    for( int i = 0; i < n; ++i ) {
         cin >> a[i];

    }

    bool flg = true;
    sort( a, a + n, greater<LL>() );

    set< LL > st;
    for( int i = 0; i < n - 1; i += 2 ) {
        int s = st.size();
        if( a[i] != a[i + 1] ) flg = false;
        else {
            st.insert( a[i] );
            int ss = st.size();
            if( s == ss ) flg = false;

        }
    }
    if( n % 2 ) {
        int s = st.size();
        st.insert( a[n - 1] );
        int ss = st.size();
        if( s == ss ) flg = false;
    }

    LL res = 1;
    if( !flg ) cout << 0;
    else {
        for( int i = 0; i < n / 2; ++i ) {
            res = ( res * 2 ) % MOD;

        }
        cout << res;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

int main(){
    long long int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    std::cout << std::max({a * c, a * d, b * c, b * d}) << std::endl;

    return 0;
}

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

int main() {
  int n, count=0;
  cin >> n;
  int a[n];
  if(3<=n && n<=20){
    for(int i=0; i<n; i++){
      cin >> a[i];
      if(i>1){
        if(a[i-2]<a[i-1] && a[i-1]<=a[i]){
          count++;
        } else if(a[i]<a[i-1] && a[i-1]<=a[i-2]){
          count++;
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h> 
 
 using namespace std;
 
 double dDistance(const double &x0, const double &y0, const double &x1, const double &y1){
     return sqrt( (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0) );
 }
 
 int main(){
     const double dTolerance = 1.0e-10;
     double c1x,c1y,c1r,c2x,c2y,c2r;
     scanf("%lf %lf %lf", &c1x, &c1y, &c1r);
     scanf("%lf %lf %lf", &c2x, &c2y, &c2r);
     
     double dDist = dDistance(c1x, c1y, c2x, c2y);
     if ( dDist > c1r + c2r + dTolerance ) {
         printf("4\n");
     } else if ( fabs( dDist - (c1r + c2r) ) < dTolerance ) {
         printf("3\n");
     } else if ( dDist - fabs(c1r - c2r) < -dTolerance ) {
         printf("0\n");
     } else if ( fabs( dDist - fabs(c1r - c2r) ) < dTolerance ) {
         printf("1\n");
     } else {
         printf("2\n");
     }
     return 0;
 }


Measured memory_bytes: 2760
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
    string s;
    s=to_string(i);
    int sum=0;
    for(int w=0;w<s.size();w++){
      sum+=stoi(s.substr(w,1));
    }
    if(a<=sum and sum <= b){
      ans+=i;
    }
  }
  cout<<ans<<endl;


}


Measured memory_bytes: 256
using System;

namespace abc158_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            char sago = s[0];

            for(int i = 1;i < 3;i++)
            {
                char si = s[i];
                if(sago != si)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }
    }
}


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

vector<int> A;

int main() {
    long int s, t, d;
    cin >> d >> t >> s;

    if(d <= t * s) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    

    return 0;
}

Measured memory_bytes: 3100
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))

    if A[0] != 0:
        print(-1)
        exit()
    res = 0
    for i in range(1, n):
        if A[i] != 0:
            if A[i] - A[i - 1] <= 0:
                res += A[i]
            elif A[i] - A[i - 1] == 1:
                res += 1
            else:
                print(-1)
                exit()

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 16972
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		String inStr = scn.nextLine();
		char[] charList = new char[inStr.length()];
		for(int i=0 ; i<charList.length ; i++) {
			charList[i] = inStr.charAt(i);
		}

		int cnt = 0;
		while(true){
			boolean isCnt = false;
			outside: for(int i= 0 ; i<charList.length ; i++) {
				if('K'==charList[i]) {
					charList[i] = 'A';
					for(int j=0 ; j<charList.length ; j++) {
						if('U'==charList[j]) {
							charList[j] = 'A';
							for(int k=0 ; k<charList.length ; k++) {
								if('P'==charList[k]) {
									charList[k] = 'A';
									for(int l=0 ; l<charList.length ; l++) {
										if('C'==charList[l]) {
											charList[l] = 'A';
											cnt++;
											isCnt = true;
											break outside;
										}
									}
								}
							}
						}
					}
				}
			}
			if(!isCnt)
				break;
		}
		System.out.println(cnt);
	}

}

Measured memory_bytes: 19220
def main():
    """
    1<=H,W<=50

    # or ## がない場合塗り方として無理
    #
    """
    H, W = map(int, input().split())

    s = [
        input()
        for _ in range(H)
    ]

    f(H, W, s)


def f(H, W, s):
    d = list(zip(
        (0, 0, 1, -1),
        (1, -1, 0, 0)
    ))
    for h in range(H):
        for w in range(W):
            if s[h][w] == ".":
                continue

            ok = False
            for dy, dx in d:
                ny, nx = h+dy, w+dx
                if 0 <= ny < H and 0 <= nx < W and s[ny][nx] == "#":
                    ok = True
            if not ok:
                print("No")
                return

    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let h = v[0];
    let w = v[1];
    let a: Vec<String> = read_col(h);

    for _ in 0..(w + 2) {
        print!("#");
    }
    println!("");
    for tmp in a {
        print!("#");
        print!("{}", tmp);
        println!("#");
    }
    for _ in 0..(w + 2) {
        print!("#");
    }
    println!("");
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int n,s[15],t[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
int f(int m){
    int ans=0;
    for(int i=0;i<15;i++){
        if(s[i]>=m){
            ans++;
        }
    }
    return ans;
}
int main(void){
    cin>>n;
    for(int i=2;i<=n;i++){
        for(int j=0;j<15;j++){
            int cur=i;
            while(cur%t[j]==0){
                s[j]++;
                cur/=t[j];
            }
        }
    }
    cout<<(f(2)-2)*f(4)*(f(4)-1)/2+(f(4)-1)*f(14)+(f(2)-1)*f(24)+f(74)<<endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()

	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(slice)))

	total := 0
	for i := 0; i < k; i++ {
		total += slice[i]
	}

	fmt.Println(total)

}


Measured memory_bytes: 640
import Data.Char

main = do
  ds <- map digitToInt <$> getLine
  putStr $ solve "" id ds

solve str f [d] = if f d == 7 then reverse ("7="++intToDigit d:str) else ""
solve str f (d:ds)
  = max (solve ('+':intToDigit d:str) (f d+) ds) (solve ('-':intToDigit d:str) (f d-) ds)

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

namespace ConsoleApplication1
{
    class Program
    {
        static int cnt = 0;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] S = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            MergeSort(S, 0, n);

            Console.WriteLine(string.Join(" ", Array.ConvertAll(S, s => s.ToString())));
            Console.WriteLine(cnt);
        }

        static void MergeSort(int[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                int mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }

        static void Merge(int[] A,int left,int mid,int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;

            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];

            for (int i = 0; i < n1; i++) L[i] = A[left + i];
            for (int i = 0; i < n2; i++) R[i] = A[mid + i];

            L[n1] = int.MaxValue;
            R[n2] = int.MaxValue;

            int x = 0, y = 0;

            for(int i = left; i < right; i++)
            {
                if (L[x] <= R[y])
                {
                    A[i] = L[x];
                    x++;
                }
                else
                {
                    A[i] = R[y];
                    y++;
                }

                cnt++;
            }
        }
    }
}

Measured memory_bytes: 93320
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int[] a=new int[n];
		int[] b=new int[n];
		int[] c=new int[n-1];
		for(int i=0;i<n;i++){
			a[i]=scanner.nextInt()-1;
		}
		for(int i=0;i<n;i++){
			b[i]=scanner.nextInt();
		}
		for(int i=0;i<n-1;i++){
			c[i]=scanner.nextInt();
		}
		int pre = a[0];
		int ans = b[a[0]];
		for(int i=1;i<n;i++){
			int tmp = a[i];
			ans+=b[a[i]];
			if(pre == tmp - 1) ans += c[pre];
			pre = tmp;
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    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: 21332
#include<iostream>
#include<string>
using namespace std;

int lcs(string a,string b){
    int la=a.size();
    int lb=b.size();

    int array[la+1][lb+1];
    for(int i=0;i<=la;i++){
        array[i][0]=0;
    }
    for(int i=0;i<=lb;i++){
        array[0][i]=0;
    }
    for(int i=1;i<=lb;i++){
        for(int j=1;j<=la;j++){
            if(a[j-1]==b[i-1]){
                array[j][i]=array[j-1][i-1]+1;
            }
            else{
                if(array[j-1][i]>array[j][i-1]){
                    array[j][i]=array[j-1][i];
                }
                else{
                    array[j][i]=array[j][i-1];
                }
            }
        }
    }
    return array[la][lb];
}

int main(){
    string a,b;
    int d;
    cin>>d;
    int c[d];
    for(int i=0;i<d;i++){
        cin>>a>>b;
        c[i]=lcs(a,b);  
    }
    for(int i=0;i<d;i++){
        cout<<c[i]<<endl;
    }
    return 0;
}


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

vector<int> edge[100005];
int dfn[100005], dfnn, X, Y;

int dfs(int x, int p, int c) {
	int ret = 0;
	dfn[x] = ++dfnn;
	if (x == Y) c = 1;
	for (auto i : edge[x]) {
		if (i == p) continue;
		if (dfn[i]) {
			if (i == X && c) ret++;
			continue;
		}
		ret += dfs(i, x, c);
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N, M; cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int x, y; cin >> x >> y;
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	int flag = 0;
	vector<int> vec;
	for (int i = 1; i <= N; ++i) {
		if (edge[i].size() & 1) return !puts("No");
		if (edge[i].size() >= 6) flag = 1;
		if (edge[i].size() == 4) vec.push_back(i);
	}
	if (flag || vec.size() > 2) puts("Yes");
	else {
		if (vec.size() == 2) {
			X = vec[0];
			Y = vec[1];
		}
		if (vec.size() == 2 && dfs(vec[0], 0, 0) == 1) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  int H, W;
  std::cin >> H >> W;
  std::string s[50], ss[50];
  for (int i = 0; i < H; ++i) {
    std::cin >> s[i];
    ss[i] = s[i];
  }

  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      if (s[y][x] == '#') {
        continue;
      }
      const int minY = std::max(y - 1, 0);
      const int maxY = std::min(y + 1, H - 1);
      const int minX = std::max(x - 1, 0);
      const int maxX = std::min(x + 1, W - 1);
      int bombs = 0;
      for (int yy = minY; yy <= maxY; ++yy) {
        for (int xx = minX; xx <= maxX; ++xx) {
          if (s[yy][xx] == '#') {
            ++bombs;
          }
        }
      }
      ss[y][x] = '0' + bombs;
    }
  }
  for (int i = 0; i < H; ++i) {
    std::cout << ss[i] << std::endl;
  }
}

Measured memory_bytes: 3640
A, B, C, X, Y = map(int, input().split())

ans = float('inf')
for ab in range(0, max(X, Y)*2+1, 2):
    a = max(0, X - ab//2)
    b = max(0, Y - ab//2)
    ans = min(ans, A * a + B * b + C * ab)

print(ans)


Measured memory_bytes: 40304
#include <stdio.h>

int cou = 1;
int oya[500010];
int kodo[2][500010];
int ata[500010];

int ks(int x,int y){
  if(y==0)printf(" %d",ata[x]);
  if(kodo[0][x])ks(kodo[0][x],y);
  if(y==1)printf(" %d",ata[x]);
  if(kodo[1][x])ks(kodo[1][x],y);
  if(y==2)printf(" %d",ata[x]);
}

void pull(int x, int xa){
  if(cou==1){
    ata[cou]=xa;
    cou++;
    return;
  }
  if(kodo[ata[x]<xa][x])pull(kodo[ata[x]<xa][x],xa);
  else{
    kodo[ata[x]<xa][x] = cou;
    oya[cou]=x;
    ata[cou]=xa;
    cou++;
  }
}

int main(){
  int p;
  scanf("%d",&p);
  while(p--){
    char s[10];
    scanf("%s",s);
    if(s[0]=='p'){
      ks(1,1);
      puts("");
      ks(1,0);
      puts("");
    }else{
      int t;
      scanf("%d",&t);
      pull(1,t);
    }
  }
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <cstdio>
#include<stdio.h>
#include<string.h>

int Fans (int n){
    int sum = 0;
    while(n>0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(void){

    int n, a, b;
    int i, ans;
    int sum = 0;
    scanf("%d%d%d", &n, &a, &b);

    for (i = 1; i <= n;i++){
        ans = Fans(i);
        if ((a <= ans) && (ans <= b))
        {
            sum += i;
        }
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(),A.end())
#define vecmax(A) *max_element(A.begin(),A.end())
typedef long long ll;

int main(){
  vector<int> v(3);
  rep(i,3) cin >> v[i];
  sort(v);
  if(v[0] == 5 && v[1] == 5 && v[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    double r,S,L;
    scanf("%lf\n",&r);
    S=r*r*3.141592653589;
    L=2*3.141592653589*r;
    printf("%.5f %.5f\n",S,L);
    
    return 0;
    
}



Measured memory_bytes: 2088
import java.util.Scanner;

public class Main {

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = scan.nextInt();
		int B = scan.nextInt();

		scan.close();
		
		int r = 0;
		if(A<B) {
			r=B;
			if(A<B-1) {
				r=r+B-1;
			} else {
				r=r+A;
			}
		} else {
			r=A;
			if(B<A-1) {
				r=r+A-1;
			} else {
				r=r+B;
			}
		}
		System.out.println(r);

	}

}


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


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

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

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    ll a,b,c; cin >> a >> b >> c;
    if(c-a-b<0){
        cout << "No" << endl;
        return 0;
    }
    ll r=(c-a-b)*(c-a-b);
    ll l=4*a*b;
    if(l<r) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 262144
int main() {
	string s;
	cin >> s;
	if (s.length() >= 4&&s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I') {
		cout << "Yes" << endl;
		return 0;
	}
	else cout << "No" << endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[222222][4];

void chMax(ll &a, ll b){
	a = max(a, b);
}

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

	ll n;cin >> n;
	vector<ll> v(n);REP(i, n)cin >> v[i];

	REP(i, 222222)REP(j, 4)dp[i][j] = -LLINF;
	dp[0][0] = 0;

	REP(i, n){
		REP(j, 4){
			chMax(dp[i+1][min(3LL, j+1)], dp[i][j]);
			if(n % 2 && i == n-1 && j == 0)continue;
			chMax(dp[min(n, i+2)][j], dp[i][j] + v[i]);
		}
	}

	if(n % 2){
		cout << max(dp[n][1], dp[n][2]) << endl;
	}
	else{
		cout << max(dp[n][0], dp[n][1]) << endl;
	}

	return 0;
}


Measured memory_bytes: 11220
n = gets.to_i

require 'prime'
def divisor_list x
  return [1] if x == 1
  Prime.prime_division(x).map do |e|
    Array.new(e[1]+1).map.with_index do |element, i|
      e[0]**i
    end
  end.inject{|p,q| p.product(q)}.map do |a|
    [a].flatten.inject(&:*)
  end.sort
end

divisors = divisor_list(n-1) + divisor_list(n)
results = [2, n , *divisors].uniq

def is_result? n, x
  return false if x < 2
  nn = n
  while(nn % x == 0) do
    nn = nn / x
  end
  nn = nn % x
  if nn == 1
    true
  else
    false
  end
end
puts results.find_all{|z| is_result?(n, z) }.size

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7;

using namespace std;
using pii = pair<int,int>;

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

  string s;
  int k;
  cin >> s >> k;
  int x = s.size();
  rep( i , min(x , k ) ){
    if( s[i] != '1' ){
      cout << s[i] << '\n';
      return 0;
    }
  }
  cout << s[k - 1] << '\n';
  return 0;
}


Measured memory_bytes: 256
program main
	implicit none
	character(100010) :: S
	integer :: counter_0, counter_1, i
	read(*, *) S
	counter_0 = 0
	counter_1 = 0
	do i = 1, len_trim(S)
		if(S(i:i) == '0') then
			counter_0 = counter_0 + 1
		else
			counter_1 = counter_1 + 1
		end if
	end do
	write(*, *) min(counter_0, counter_1)*2
end program main

Measured memory_bytes: 1084
N, M = [int(e) for e in input().split()]
A = sorted([int(e) for e in input().split()])
A.reverse()

base =float(sum(A)) / 4.0/M
cond = all([float(e) >= base for e in A[:M]])
ans = 'Yes' if cond  else 'No'
print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    bool flag = true;
    for(int i = 0; i < n; i++){
        if(a[i]&1){
            flag = false;
        }
    }

    if(flag){
        cout << "second" << endl;
    }else{
        cout << "first" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;

int main()
{
	FAST;
	int n;
	cin >> n;
	int gem[21];
	int cost[21];

	for(int i=0 ; i<n ; i++)
		cin >> gem[i];
	for(int i=0 ; i<n ; i++)
		cin >> cost[i];

    int ans = 0;
    for(int i=0 ; i<n ; i++)
    {
        if(gem[i]-cost[i] > 0)
            ans += gem[i]-cost[i];
    }

	cout << ans;
	return 0;
}

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

L = 0
R = N

for _ in range(M):
    preL, preR = map(int, input().split())
    if preL > L:
        L = preL
    if preR < R:
        R = preR

res = 0
if R-L >= 0:
    res= R - L + 1
print(res)

Measured memory_bytes: 3188
#include  <bits/stdc++.h>
using namespace std;
int main()
{
	long int x,c,d,n,a,b;
	cin>>n>>a>>b;
	c=n%(a+b);
	x=n/(a+b);
	if(c>a)
	{
	d=(x*a)+a;
	}
	else
	{
		d=(x*a)+c;
	}
	cout<<d<<endl;
}

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

int main() {
  ll n,k;
  cin >> n >> k;
  double ans=0;
  rep(i,n){
    ll s=i+1;
    double p=1.0/n;
    while(s<k){
      s *= 2;
      p *= 0.5;
    }
    ans += p;
  }
  
  cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 3716
H, W = map(int, input().split())

grid = []

for h in range(H):
    inputs = input()
    _w = []
    for w in range(W):
        _w.append(inputs[w])
    grid.append(_w)

dy = [-1, -1, -1, 0, 0, +1, +1, +1]
dx = [-1, 0, +1, -1, +1, -1, 0, +1]

for i in range(H):
    for j in range(W):

        if grid[i][j] == '#': continue

        num = 0
        for k in range(8):
            ci = i + dy[k]
            cj = j + dx[k]

            if ci < 0 or H <= ci: continue
            if cj < 0 or W <= cj: continue
            if grid[ci][cj] == "#": num += 1
        
        grid[i][j] = "{}".format(num)

for g in range(len(grid)):
    print(''.join(grid[g]))

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int s;
	cin>>s;
	int a[1000]={0},len=0;
	while(len<999){
		a[len++]=s; 
		if(s%2==0){
			s=s/2;
		}else{
			s=s*3+1;
		}
	}
	int b[10000]={0};
	int i;
	for(i=0;i<len;i++){
		b[a[i]]++;
		if(b[a[i]]>1){
			break;
		}	
	}
	cout<<i+1<<endl;
}

Measured memory_bytes: 256
n,y = map(int,input().split())
d=y//1000-n
a=(d*7)%9 # 7=4^-1
b=(d-a*4)//9
c=n-a-b
if c>=0 and b>=0:
    print(b,a,c)
else:
    print(-1,-1,-1)

Measured memory_bytes: 3060
#include <stdio.h>
int a[200010],sum;
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]),sum^=a[i];
	for(i=1;i<=n;i++)printf("%d ",sum^a[i]);
	return 0;
}

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

using namespace std;

int main() {

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int turn = 1;
    while(A > 0 && C > 0){
        if(turn & 1){
            C -= B;
//            cout << "Taka attacks: " << C << endl;
            turn = 0;
        } else{
            A -= D;
//            cout << "Aoki attacks: " << A << endl;
            turn = 1;
        }
    }
    if(A > 0)
        cout << "Yes";
    else
        cout << "No";
    cout << endl;

    return 0;
}

Measured memory_bytes: 3620
# https://atcoder.jp/contests/abc054/tasks/abc054_c
# なんか水パフォだけど全探索するだけ

import sys
read = sys.stdin.readline


from itertools import permutations


def read_ints():
    return list(map(int, read().split()))


N, M = read_ints()
from collections import defaultdict
graph = defaultdict(lambda: [])
for m in range(M):
    a, b = read_ints()
    graph[a].append(b)
    graph[b].append(a)


def is_ok(p):  # 順序pにしたがってグラフがつながっているか
    for now, nx in zip(p, p[1:]):
        if nx not in graph[now]:
            return 0
    return 1


def main():
    ans = 0
    for perm in permutations(range(2, N + 1)):
        perm = [1] + list(perm)
        ans += is_ok(perm)

    print(ans)


if __name__ == "__main__":
    main()


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

int n;
long a[100010], b, c, t;

int main(){
	cin >> n;
	for (int i = 0; i < n+1; ++i) cin >> a[i];
	c = 0;
	for (int i = 0; i < n; ++i){
		cin >> b;
		t = min(b, a[i] + a[i+1]);
		c += t;
		a[i+1] -= t - min(b, a[i]);
	}
	cout << c;
}


Measured memory_bytes: 1024
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    var ans = 1L
    readLongList()
        .sorted()
        .reduce { acc, i ->
            if (acc * 2 >= i) ans++ else ans = 1
            acc + i
        }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 63200
n=int(input())
a=list(map(int,input().split()))
b=[0]*100009
c=[0]*100009
for i in range(n//2):
  b[a[i*2]]+=1
  c[a[i*2+1]]+=1
t=max(b)
r=max(c)
s=b.index(t)
p=c.index(r)
if s==p:
  b[s]=0
  k=max(b)
  c[p]=0
  j=max(c)
  f=max(k+r,t+j)
else:
  f=t+r
print(n-f)


Measured memory_bytes: 14404
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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

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

const ll mod = 1000000007;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr operator u64() const { return a; }
};


int main() {
	ll s;
	cin >> s;
	modint sum = 0;
	Factorial f(2 * s);
	for (int i = 1; i < s / 3 + 2; i++) {
		ll r = s - i * 3;
		if (r < 0) continue;
		modint c = f.cmb(r + i - 1, i - 1);
		sum += c;
	}
	cout << sum.a << endl;
	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
#define vi vector<ll>
#define pi pair<ll,ll>
#define TC int t;cin>>t;while(t--)
#define in(n) ll n;cin>>n;
#define inarr(n) ll n;cin>>n;ll arr[n];
int main(void){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    in(x);inarr(n);
    set<int>s;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        s.insert(arr[i]);
    }
    vector<pair<int,int>>diff;
    for(int i=0;i<=102;i++){
        if(s.find(i)==s.end()){
            diff.push_back({int(fabs(i-x)),i});
        }
    }
    sort(diff.begin(),diff.end());
    ll ans = diff.begin()->second;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int >PII;

vector< PII >edg[27];

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

    int n = 20, m = 0;
    for (int i = 2; i <= 20; i++) {
        edg[i-1].emplace_back(i, 0);
        m++;
    }

    int msb = 31-__builtin_clz(L);
    for (int i = 0; i < msb; i++) {
        edg[20-i-1].emplace_back(20-i, 1<<i);
        m++;
    }

    int now = 1<<msb;
    for (int i = msb-1; i >= 0; i--) {
        if (L&(1<<i)) {
            edg[1].emplace_back(20-i, now);
            now |= 1<<i;
            m++;
        }
    }

    cout << n << " " << m << endl;
    for (int i = 1; i < 20; i++) {
        for (PII p : edg[i]) {
            cout << i << " " << p.first << " " << p.second << endl;
        }
    }

    return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll X, Y, Z;
    cin >> X >> Y >> Z;
    cout << (X - Z) / (Z + Y) << endl;
    return 0;
}

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

        if(A==B&&A!=C||B==C&&B!=A||C==A&&C!=B){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 H, W;
  cin >> H >> W;
  if(H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  i64 ans = (H / 2) * (W / 2) * 2;
  if(H % 2 + W % 2 == 2) {
    ans += H / 2 + W / 2 + 1;
  }
  else if(H % 2 == 1) {
    ans += W / 2;
  }
  else if(W % 2 == 1) {
    ans += H / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int K = sc.nextInt();
            int N = sc.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }

            int max = (K + A[0]) - A[N - 1];
            for (int i = 1; i < N; i++) {
                max = Math.max(max, A[i] - A[i - 1]);
            }

            System.out.println(K - max);
        }
    }
}


Measured memory_bytes: 50628
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int N=0,W=0;
int w[110]={0};
int v[110]={0};
long long dp[110][100000]={0};
int main(void){
	cin>>N>>W;
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<=W;j++)
		{
			if(j-w[i]>=0)
			{
				dp[i+1][j]=max(dp[i+1][j-w[i]]+v[i],dp[i][j]);
			}
			else
			{
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;
}
/*
<配列>
要素を一列に並べて管理する
最初から固定の要素数でメモリを確保する
用意した要素数が連続した領域にメモリとして確保される
添え字を使ってメモリアドレスを直接指定できるので要素へのアクセスが速い
途中に要素を挿入したり追加したりするには元にあった要素をズラす必要があり大変
<リスト>
要素を一列に並べて管理する
要素数が可変できる
前後にポインタが付与されポインタで接続されながらあいているメモリ領域に要素が格納されていく
要素にアクセスするには先頭からポインタを辿っていく必要があり時間がかかる
途中に要素を挿入したり、削除したりするにはポインタの接続を変えるだけなので速い
*/


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

int main(){
	int a,b;
	cin >> a >> b;

	int ans = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 0; j <= 9; j++){
			for(int k = 0; k <= 9; k++){
				int sum = 10001*i + 1010*j + 100*k;
				if(a <= sum && sum <= b) ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    if (s=="SUN") cout << 7 << endl;
    if (s=="MON") cout << 6 << endl;
    if (s=="TUE") cout << 5 << endl;
    if (s=="WED") cout << 4 << endl;
    if (s=="THU") cout << 3 << endl;
    if (s=="FRI") cout << 2 << endl;
    if (s=="SAT") cout << 1 << endl;
    return 0;
}


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

struct {
  int id;
  int num;
  int *list_c;
  int pare;
  int depth;
  int flag;
} typedef Tree;

int main(){
  Tree *k;
  int n, id, num, p, i, j;

  scanf("%d", &n);
  k = (Tree *)malloc(sizeof(Tree) * n);

  if(k == NULL){
    printf("error!\n");
    exit(-1);
  }

  for(i = 0; i < n; i++){
    scanf("%d %d", &id, &num);
    k[id].id = id;
    k[id].num = num;
    if(num != 0){
      k[id].list_c = (int *)malloc(sizeof(int) * num);
      if( k[id].list_c == NULL){
	printf("error!\n");
	free(k);
	exit(-1);
      }
      for(j = 0; j < num; j++) scanf("%d", &k[id].list_c[j]); 
    }
  }
  
  for(i = 0; i < n; i++){
    k[i].pare = -1;
    k[i].depth = 0;
    k[i].flag = 0;
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < k[i].num; j++){
      if( i == 0) k[ k[i].list_c[j] ].flag = 1; 
      k[ k[i].list_c[j] ].pare = k[i].id;  
      k[ k[i].list_c[j] ].depth += 1; 

      p = k[i].pare;
      while(p != -1){
	k[ k[i].list_c[j] ].depth += 1; 
	p = k[p].pare;
      }
      
    }
  }
  
  for(i = 0; i < n; i++){
    if(k[i].flag == 1) k[i].depth += k[k[i].pare].depth;
  }

  for(i = 0; i < n; i++){
    printf("node %d: parent = %d, depth = %d, ", k[i].id, k[i].pare, k[i].depth);
    if(k[i].pare == -1) printf("root, [");
    else if(k[i].num != 0) printf("internal node, [");
    else printf("leaf, [");
    if(k[i].num != 0){
      for(j = 0; j < k[i].num - 1; j++) printf("%d, ", k[i].list_c[j]);
      printf("%d]\n", k[i].list_c[j]);
    }
    else printf("]\n");
  }

  return 0;
}

Measured memory_bytes: 4208
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		
		for(int i=0; i<n; i++) {
		    a[i] = Integer.parseInt(sc.next());
		}
		
		int[][] c = new int[h][w];
		int nowi = 0;
		int nowj = 0;
		for(int k=0; k<n; k++) {
		    int count = a[k];
		    while(count > 0) {
    	        if(nowi % 2 == 0) {
                    for(int j=nowj; j<w; j++) {
                        if(count == 0) break;
                        c[nowi][nowj] = k+1;
                        count--;
                        nowj++;
                    }
                    if(nowj == w) {nowi++; nowj--;}
                    if(count == 0) break;
    	        }
    	        if(nowi % 2 == 1) {
    	            for(int j=nowj; j>=0; j--) {
                        if(count == 0) break;
                        c[nowi][nowj] = k+1;
                        count--;
                        nowj--;
                    }
                    if(nowj == -1) {nowi++; nowj++;}
                    if(count == 0) break;
    	        }
		    }
		}
		
		for(int i=0; i<h; i++) {
		    for(int j=0; j<w; j++) {
		        System.out.print(c[i][j]+" ");
		    }
		    System.out.println();
		}
		
	}
}

Measured memory_bytes: 30760
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

template <class T>
inline void relax(T &a, const T &b)
{
	if (b > a)
		a = b;
}

const int MaxN = 100000;

int n;
vector<int> adj[MaxN + 1];

int dfs(const int &u)
{
	vector<int> sub;
	for (int v : adj[u])
		sub.push_back(dfs(v) + 1);

	sort(sub.begin(), sub.end());

	int l = sub.size() - 1, ret = 0;
	for (int w : sub)
		relax(ret, w + l--);

	return ret;
}

int main()
{
	cin >> n;
	for (int v = 2; v <= n; ++v)
	{
		int u = getint();
		adj[u].push_back(v);
	}

	cout << dfs(1) << endl;

	return 0;
}

Measured memory_bytes: 13568
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);

my @c1 = (); $#c1 = $n - 1;
my @c2 = (); $#c2 = $n - 1;

my @xy=();
for(my $i=0;$i<$n;$i++){
  my @xy1 = map { $_ - 0 } split(/\s+/,<STDIN>);
  push(@xy,\@xy1);
  $c1[$i] = $xy1[1] - $xy1[0];
  $c2[$i] = $xy1[1] + $xy1[0];
}

my @sc1 = sort { $a <=> $b } @c1;
my @sc2 = sort { $a <=> $b } @c2;

my $v1 = abs($sc1[0] - $sc1[$#sc1]);
my $v2 = abs($sc2[0] - $sc2[$#sc2]);

$v1 = $v2 if( $v2 > $v1 );

print "$v1\n";



Measured memory_bytes: 70872
#include<bits/stdc++.h>
using namespace std;
#define lps(i,j,n) for(int i=j;i<n;i++)
#define lp(i,n) lps(i,0,n)
#define DEKAI 1000000007
#define INF (1<<28)
#define int long long
int x,y,rotates,ans=0,stat=0;
char a[100][100];

int movex(int x){
  if(x==1) return 1;
  if(x==3) return -1;
  else return 0;
}

int movey(int x){
  if(x==0) return -1;
  if(x==2) return 1;
  else return 0;
}

bool ifcheck(string s){
  char c;
  if(s[1]=='~') c=s[2];
  else c=s[1];
  bool ret;
  if(c=='N'){
    if(rotates==0) ret=true;
    else ret=false;
  }
  if(c=='E'){
    if(rotates==1) ret=true;
    else ret=false;
  }
  if(c=='S'){
    if(rotates==2) ret=true;
    else ret=false;
  }
  if(c=='W'){
    if(rotates==3) ret=true;
    else ret=false;
  }
  if(c=='C'){
    if(a[y+movey(rotates)][x+movex(rotates)]=='#') ret=true;
    else ret=false;
  }
  if(c=='T'){
    ret=true;
  }
  if(s[1]=='~') return !ret;
  else return ret;
}

void move(string s){
  lp(it,s.size()){
    /*cout<<x<<" "<<y<<" "<<s[it]<<" "<<s<<endl;
      int hogehoge;cin>>hogehoge;*/
    if(stat==1) return;
    if(ans>5000000){
      stat=1;
      return;
    }
    if(a[y][x]=='g'){
      stat=1;
      return;
    }
    if(s[it]=='<'){
      rotates--;
      if(rotates==-1) rotates=3;
      ans++;
    }
    if(s[it]=='>'){
      rotates++;
      if(rotates==4) rotates=0;
      ans++;
    }
    if(s[it]=='^'){
      if(a[y+movey(rotates)][x+movex(rotates)]!='#'){
	x+=movex(rotates);
	y+=movey(rotates);
      }
      ans++;
    }
    if(s[it]=='v'){
      if(a[y-movey(rotates)][x-movex(rotates)]!='#'){
	x-=movex(rotates);
	y-=movey(rotates);
      }
      ans++;
    }
    else if(s[it]=='{'){
      int count=0,dotc=1;
      int i=it+1;
      while(dotc!=0){
	if(s[i]=='{') dotc++;
	if(s[i]=='}') dotc--;
	i++;
	count++;
      }
      string center=s.substr(it,count+1);
      
      /*cout<<center.substr(2,center.size()-3)<<endl;
      int hogehoge;
      cin>>hogehoge;*/
      
      it+=count;
      int kick=0;
      while(ifcheck(center)){
	kick++;
	if(kick>1000000){
	  stat=1;
	  ans=INF;
	  return;
	}
	if(stat==1) return;
	if(center[1]=='~') move(center.substr(3,center.size()-4));
	else move(center.substr(2,center.size()-3));
      }
    }
    else if(s[it]=='['){
      int count=0,dotc=1;
      int i=it+1;
      while(dotc!=0){
	if(s[i]=='[') dotc++;
	if(s[i]==']') dotc--;
	i++;
	count++;
      }
      string center=s.substr(it,count+1);
      it+=count;
      if(ifcheck(center)){
	if(center[1]=='~') move(center.substr(3,center.size()-4));
	else move(center.substr(2,center.size()-3));
      }
    }
    if(a[y][x]=='g'){
      stat=1;
      return;
    }
  }
  return;
}

signed main(){
  int h,w;
  cin>>h>>w;
  lp(i,h){
    lp(j,w){
      cin>>a[i][j];
      if(a[i][j]=='s'){
	x=j;
	y=i;
      }
    }
  }
  string s;
  cin>>s;
  rotates=0;
  //0 N 1 E 2 S 3 W
  move(s);
  if(stat==0||ans>5000000) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3420