akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

int main()
{
    string S, T;
    cin >> S >> T;

    string ans;
    if (S.length() == T.length() - 1 && S == T.substr(0, S.length()))
    {
        ans = "Yes";
    }
    else
    {
        ans = "No";
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
  int dists[3];
  std::cin >> dists[0] >> dists[1] >> dists[2];

  int min = INT_MAX;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if( i != j ){
        if( min > dists[i] + dists[j] ){
          min = dists[i] + dists[j];
        }
      }
    }
  }
  std::cout << min << '\n';
  return 0;
}


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

#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/

using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

map<string, int> memo;
int main() {
	//sort(a.begin(),a.end());
	long long int h;
	cin >> h ;
	//vector<int> a(n);
	long long int count = 1,ans=1;
	while (h > 1) {
		h /= 2;
		count *= 2;
		ans += count;
	}
	cout << ans;
	
	return 0;
}









Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string str;
	int con=0,c;
	bool dig=true;
	cin >>str;
	if(str[0]!='A'){
		dig=false;
	}
	for(int i=1;i<str.length();i++){
		if(str[i]=='C'){
			if(i>=2&&i<str.length()-1) con++;
		}else if('a'>str[i]||str[i]>'z'){
			dig=false;
		}
	}
	if(con!=1){
		dig=false;
	}
	if(dig) cout <<"AC\n";
	else cout <<"WA\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

string str;
const char *p;

int parse() {

  p ++;
  
  switch(*p) {
  case '[':
    {
      vector<int> v;
      while(*p == '[') {
	v.push_back( parse() );
	p ++;
      }
      
      sort(v.begin(), v.end());

      int sum = 0;
      for(int i=0; i<v.size()/2+1; i++) {
	sum += v[i];
      }

      return sum;
    }

  default:
    if(isdigit(*p)) {
      char *e;
      int num = strtol(p, &e, 10);
      p = e;
      return num/2+1;
    }
  }
}

int main() {
  int n;
  
  cin >> n; cin.ignore();
  for(int i=0; i<n; i++) {
    getline(cin, str);
    p = &str[0];

    cout << parse() << endl;
  }
  
  return 0;
}

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

int main() {
    int n, h, w, ita = 0;
    cin >> n >> h >> w;
    int a[n], b[n];
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        if(a[i] >= h && b[i] >= w) ita++;
    }

    cout << ita << '\n';
}

Measured memory_bytes: 256
S = input()
n = len(S)+1
a = [0] * n
for i in range(n-1):
	if(S[i] == '<'):
		if(a[i+1] < a[i]+1):
			a[i+1] = a[i]+1
for i in reversed(range(n-1)):
	if(S[i] == '>'):
		if(a[i] < a[i+1]+1):
			a[i] = a[i+1]+1
print(sum(a))

Measured memory_bytes: 46664
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0195

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        am, pm = map(int, input().split())
        if am == 0 and pm == 0:
            break
        totals = [0] * 5
        totals[0] = am + pm
        for i in range(1, 5):
            am, pm = map(int, input().split())
            totals[i] = am + pm

        top = max(totals)
        shop = totals.index(top)

        print('{} {}'.format(chr(ord('A')+shop), top))



if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],ans[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		ans[a[i]]=i;
	}
	for(int i=1;i<=n;i++){
		if(i==1)
			printf("%d",ans[i]);
		else
			printf(" %d",ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def primeFact(n):
    """
    nの素因数をlistで返す
    """
    factors = []
    i = 2
    while i*i <= n:
        if n % i == 0:
            n //= i
            factors.append(i)
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors


n = int(input())
print(str(n)+": "+" ".join(map(str, primeFact(n))))



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

int main(){
  int N;
  string format;
  double money, sum = 0.0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> money >> format;
    if (format == "JPY") sum += money;
    else sum += money * 380000.0;
  }
  cout << sum;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b;
  cin>>a>>b;
  if(a%500<=b)cout<<"Yes";
  else cout<<"No";
}


Measured memory_bytes: 256
#include <cstdio>
 
int main() {
  bool first = true;
  while (true) {
    int p;
    scanf("%d", &p);
    if (p == 0) break;
    int n10, n50, n100, n500;
    scanf("%d %d %d %d", &n10, &n50, &n100, &n500);
    int rest = n10*10+n50*50+n100*100+n500*500-p;
    n500 -= rest/500;
    rest %= 500;
    n100 -= rest/100;
    rest %= 100;
    n50 -= rest/50;
    rest %= 50;
    n10 -= rest/10;
    if (!first) putchar('\n');
    first = false;
    if (n10 > 0) printf("%d %d\n", 10, n10);
    if (n50 > 0) printf("%d %d\n", 50, n50);
    if (n100 > 0) printf("%d %d\n", 100, n100);
    if (n500 > 0) printf("%d %d\n", 500, n500);
  }
  return 0;
}


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

string ans;
bool get(int a, int b) {
	cout << "? " << a << " " << b << endl;
	cin >> ans;
	if (ans[0] == 'Y') return 1;
	else return 0;
}

int main()
{
	int n, a, b;

	cin >> a >> b;
	n = a + b;

	if (a <= b) {
		cout << "Impossible" << endl;
		return 0;
	}

	stack<int> s;
	for (int i = 0; i < n; i++) {
		if (s.empty() || get(s.top(), i))
			s.push(i);
		else
			s.pop();
	}

	vector<bool> ans(n, false);
	for (int i = 0; i < n; i++) {
		if (s.top() == i || get(s.top(), i))
			ans[i] = true;
		else
			ans[i] = 0;
	}

	cout << "! ";
	for (bool p : ans) cout << p;
	cout << endl;

	return 0;
}

Measured memory_bytes: 724
N = int(input())
H = list(map(int, input().split()))

mcount = 0
count = 0
val = H[0]
for i in range(1, N):
    if H[i] <= val:
        val = H[i]
        count += 1
    else:
        val = H[i]
        mcount = max(count, mcount)
        count = 0

print(max(mcount, count))

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

#ifdef LOCAL
        #include "debug.h"
        #define input freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
        #else
        #define debug(...) 4
        #define input ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

using ll = long long;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int main() {
    input;
        
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    set<pair<int, int>> s;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        v.push_back({x - y, x + y});
        s.insert({x - y, x + y});
    }
    sort(v.begin(), v.end(), [](auto x, auto y) {
        return x.second < y.second;
    });
    // debug(v);
    int last = -INT_MAX;
    int cnt = 0;
    for (auto p : v) {
        if (last <= p.first) {
            cnt++;
            last = p.second;
        }
    }
    cout << cnt;
    

}   

Measured memory_bytes: 5748
require 'set'

H, W = gets.chomp.split(" ").map(&:to_i)
A = []
H.times{A << gets.chomp.split(" ").map(&:to_i)}
B = []
H.times{B << gets.chomp.split(" ").map(&:to_i)}

Z = 80 * (H + W)
bef = Set.new
now = Set.new
bef.add([0, 0])
now.add([0, 1])
now.add([1, 0])
D = Hash.new{|h, k| h[k] = 0}
D[[0, 0]] = 1 << (Z + A[0][0] - B[0][0])
begin
  nxt = Set.new
  now.each{|n|
    y, x = n
    c = A[y][x] - B[y][x]
    if y > 0 then
      t = [y - 1, x]
      D[n] |= D[t] << c
      D[n] |= D[t] >> c
    end
    if x > 0 then
      l = [y, x - 1]
      D[n] |= D[l] << c
      D[n] |= D[l] >> c
    end
    nxt.add([y + 1, x]) if y < H - 1
    nxt.add([y, x + 1]) if x < W - 1
  }
  bef.each{|b| D.delete(b)}
  bef = now
  now = nxt
end until(now.empty?)

a = D[[H-1, W-1]]
ans = 0
while(true) do
  break if a[Z - ans] == 1 || a[Z + ans] == 1
  ans += 1
end

puts ans


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

int main(){
  int N,T;
  int minimum = 1000;
  bool inTime = false;
  int c[1001],t[1001];

  cin >> N >> T;

  for(int i=0; i < N; i++){
    cin >> c[i] >> t[i];
  }

  for(int i=0; i < N; i++){
    if(t[i] <= T){
      inTime = true;
      minimum = min(minimum,c[i]);
    }
  }

  if(inTime)
    cout << minimum << endl;
  else
    cout << "TLE" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std;
#define int long long int
int power(int a,int b)
{
	int x=pow(a,b);
	return x;
}
int32_t main()
{
	int n;
	cin>>n;
	int j;
	int len=1;
	int total=0;
	map<int,char> mp;
	char x='a';
	for(j=0;j<=25;j++)
    {
		mp[j]=x;
		x++;
	}
	for(j=1;j<=12;j++)
	{
		total+=power(26,j);
		if(total>n)
		{
			len=j;
			break;
		}
		else
		{
			
			len=j;
			if(total==n)
			  break;
		}
	}
	int arr[len+1]={0};
	for(j=1;j<=len-1;j++)
	{
		int x=power(26,j);
		n-=x;
	}
	for(j=1;j<=len;j++)
	{
		int i;
		for(i=0;i<=25;i++)
	    {
			int here=power(26,len-j);
			if(n>here)
			{
				n-=here;
				arr[j]=i;
			}
			else
			{
				arr[j]=i;
				break;
			}
		}
	}
	for(j=1;j<=len;j++)
	{
		cout<<mp[arr[j]];
	}
	cout<<endl;
}


Measured memory_bytes: 4044
import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		PriorityQueue<Sushi> allQueue = new PriorityQueue<Sushi>(new Comparator<Sushi>() {
		    public int compare(Sushi s1, Sushi s2) {
		        return s2.value - s1.value;
		    }
		});
		for (int i = 0; i < n; i++) {
		    Sushi s = new Sushi(sc.nextInt(), sc.nextInt());
		    allQueue.add(s);
		}
		PriorityQueue<Sushi> changeQueue = new PriorityQueue<Sushi>(new Comparator<Sushi>() {
		    public int compare(Sushi s1, Sushi s2) {
		        return s1.value - s2.value;
		    }
		});
		long value = 0;
		HashSet<Integer> types = new HashSet<>();
		for (int i = 0; i < k; i++) {
		    Sushi s = allQueue.poll();
		    value += s.value;
		    if (types.contains(s.type)) {
		        changeQueue.add(s);
		    } else {
		        types.add(s.type);
		    }
		}
		long max = value + (long)types.size() * (long)types.size();
		while (allQueue.size() > 0) {
		    Sushi s = allQueue.poll();
		    if (!types.contains(s.type) && changeQueue.size() > 0) {
		        Sushi change = changeQueue.poll();
		        value -= change.value;
		        value += s.value;
		        types.add(s.type);
		        max = Math.max(max, value + (long)types.size() * (long)types.size());
		    }
		}
	    System.out.println(max);
   }
   
   static class Sushi {
       int type;
       int value;
       
       public Sushi(int type, int value) {
           this.type = type;
           this.value = value;
       }
   }
}




Measured memory_bytes: 92568
import java.util.*;
public class Main {
	static int H, W;
	static int a[][];
	static int dp[][];
	static long ans;
	static int mod = (int)1e9+7;
	static int DH[] = {0,1}, DW[]= {1,0};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		H = sc.nextInt(); W = sc.nextInt();
		a = new int[H][W];
		for(int i=0;i<H;i++) {
			String s = sc.next();
			for(int j=0;j<W;j++) {
				if(s.charAt(j)=='#') a[i][j] = -1;
			}
		}
		sc.close();
		
		//number of routes from point
		dp = new int[H][W];
		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				dp[i][j]=-1;
			}
		}
		dp[H-1][W-1]=1;
		ans = rec(0, 0);
		
		System.out.println(ans);
		
	}
	static int rec(int h, int w) {
		if(dp[h][w]!=-1) return dp[h][w];
		//if(h==H-1 && w == W-1)return 1;
		long ret = 0;
		for(int i=0;i<2;i++) {
			int nh = h + DH[i], nw= w + DW[i];
			if(0<=nh&&nh<H&&0<=nw&&nw<W) {
				if(a[nh][nw]==-1)continue;
				ret += rec(nh, nw); 
				ret %= mod;
			}
		}
		return dp[h][w] = (int)ret;
	}
}


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

using namespace std;

typedef long long LL;

map<int, LL> dict, dict_q;

LL get_best(int t) {
    LL res = 0;
    for (map<int,LL>::iterator iter = dict.begin(); iter != dict.end(); iter++) {
        int A = iter->first;
        LL B = iter->second;
        if ((A | t) == t) res += B;
    }
    return res;
}

int main() {
    int N, K, A; LL B;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        if (dict.find(A) == dict.end()) {
            dict[A] = B;
        }
        else {
            dict[A] += B;
        }
    }
    int current = 0;
    LL res = get_best(K);
    for (int i = 30; i > 0; i--) {
        if (K & (1 << i)) {
            res = max(res, get_best(current + (1 << i) - 1));
            current = current + (1 << i);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;
import java.math.BigDecimal;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = 2, m = 3;
    double a[][] = new double[n][m];
    while(sc.hasNext()) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          a[i][j] = sc.nextDouble();
        }
      }
      for (int ipv = 0; ipv < n; ipv++) {
        double max = 0.0;
        int row = 0;
        for(int i = ipv; i < n; i++) {
          if(Math.abs(a[i][ipv]) > max) {
            max = a[i][ipv];
            row = i;
          }
        }
        if(max == 0.0) {
          break;
        }
        if(ipv != row) {
          for(int j = 0; j < m; j++) {
            double temp = a[ipv][j];
            a[ipv][j] = a[row][j];
            a[row][j] = temp;
          }
        }
        
        double inv_pv = 1.0/a[ipv][ipv];
        for (int j = 0; j < m; j++) {
          a[ipv][j] *= inv_pv;
        }
        
        for (int i = 0; i < n; i++) {
          if (i != ipv) {
            double temp = a[i][ipv];
            for (int j = 0; j < m; j++) {
              a[i][j] -= temp*a[ipv][j];
            }
          }
        }
      }
      BigDecimal x[] = new BigDecimal[n];
      for (int i = 0; i < n; i++) {
        BigDecimal bda = new BigDecimal(a[i][m-1]);
        x[i] = bda.setScale(3, BigDecimal.ROUND_HALF_UP);
      }
      System.out.println(x[0]+" "+x[1]);
    }
  }
}

Measured memory_bytes: 12000
N, K = list(map(int, input().split()))
if K > (((N-1)*(N-2))/2):
    print(-1)
else:
    loop = (((N-1)*(N-2))//2)-K

    print(N-1 + loop)

    for i in range(2, N+1):
        print(1, i)

    tree = [(i, j) for i in range(2, N+1) for j in range(i+1, N+1)]

    for i, j in tree[:loop]:
        print(i, j)

Measured memory_bytes: 3992
#include<iostream>
 
int main(void){
    bool S[13],H[13],C[13],D[13];
    int i,n;
    char mark;
    int number;
    for(i=0;i<13;i++){
        S[i]=H[i]=C[i]=D[i]=false;
    }
    std::cin>>n;
    for(i=0;i<n;i++){
        std::cin>>mark>>number;
        switch(mark){
            case 'S':
                S[number-1]=true;
                break;
            case 'H':
                H[number-1]=true;
                break;
            case 'C':
                C[number-1]=true;
                break;
             case 'D':
                D[number-1]=true;
                break;
        }
     
    }
    for(i=0;i<13;i++){
        if(!S[i]) std::cout<<'S'<<" "<<i+1<<std::endl;
    }
    for(i=0;i<13;i++){
        if(!H[i]) std::cout<<'H'<<" "<<i+1<<std::endl;
    }
 
    for(i=0;i<13;i++){
        if(!C[i]) std::cout<<'C'<<" "<<i+1<<std::endl;
    }
    for(i=0;i<13;i++){
        if(!D[i]) std::cout<<'D'<<" "<<i+1<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <algorithm>
#include <cstring>
#include<queue>
#include <stack>
#include<map>
#include<vector>
#include <math.h>
using namespace std;
#define ll long long


int main(){
    ll h;
    cin>>h;
    ll count=1;
    ll sum=0;
    while(h>0){
        h/=2;
        sum+=count;
        count*=2;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
r, c = map(int, input().split())

A = []

for i in range(r) :
    A.append([int(a) for a in input().split()])
    A[i].append(sum(A[i]))

S = []

for i in range(c + 1) :
    s = 0
    
    for j in range(r) :
        s += A[j][i]
        
    S.append(s)
        
A.append(S)

for i in range(r + 1) :
    for j in range(c + 1) :
        if j == c :
            print(A[i][j])
        else :
            print(A[i][j], end = " ")
    


Measured memory_bytes: 6192
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
from collections import Counter
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def accumurate(l):
    ret = [0] * len(l)
    ret[0] = l[0]

    for i in range(1, len(l)):
        ret[i] = ret[i - 1] + l[i]

    return ret


def main():
    n, k = geta(int)
    p = [0] + list(geta(int))
    c = [0] + list(geta(int))

    inf = 1 << 32

    used = [False] * (n + 1)

    ans = -inf

    for i in range(1, n + 1):

        if used[i]:
            continue
        else:
            used[i] = True

        c_loop = []
        j = p[i]
        c_loop += [c[j]]

        while j != i:
            used[j] = True
            j = p[j]
            c_loop += [c[j]]

        n_loop = len(c_loop)
        c_loop += c_loop
        cs_loop = accumurate(c_loop)
        tot_loop = cs_loop[n_loop - 1]

        _jmax = k if k < n_loop else n_loop

        _ans = -inf
        _len = 0
        for _i in range(n_loop):
            for _j in range(1, _jmax + 1):
                _tmp = cs_loop[_j + _i] - cs_loop[_i]

                if tot_loop > 0 and k > _j:
                    _tmp += (k - _j) // n_loop * tot_loop

                if _ans < _tmp:
                    _ans = _tmp

        if ans < _ans:
            ans = _ans

    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
    vector<int> vec(3);

    cin >> vec[0] >> vec[1] >> vec[2];
    sort(vec.begin(), vec.end());

    if (vec[0]==5&&vec[1]==5&&vec[2]==7){
        cout << "YES" << endl;
    } else {
        cout << "NO"   << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; 
using block = vector<vector<int>>; 

vector<int> num;
vector<int> seen; 
int groupsize[100001]; 
int group = 1;//グループ番号
void dfs(const Graph &G, int v) { 
    seen[v] = group; // v を訪問済にする 
    groupsize[group]++;
    // v から行ける各頂点 next_v について 
    for (auto next_v : G[v]) {  
        if (seen[next_v]) continue; // next_v が探索済だったらスルー 
        dfs(G, next_v); // 再帰的に探索 
    } 
} 

int main(){
  int n, m, k;
  cin >> n >> m >> k;
  int ans = 0;
  typedef pair<int ,int> pair;
  map<pair, int> mp;

  Graph G(n);
  block bl(n);
  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;a--;b--;
    mp[pair(a,b)]=1;//友達
    mp[pair(b,a)]=1;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(int i=0;i<k;i++){
    int c, d;
    cin >> c >> d;c--;d--;
    mp[pair(c,d)]=2;//ブロック
    mp[pair(d,c)]=2;
    bl[c].push_back(d);
    bl[d].push_back(c);
  }

  // 頂点 0 をスタートとした探索 
  seen.assign(n, 0); // 全頂点を「未訪問」に初期化
  for(int i=0;i<n;i++){
    if(seen[i]==0){
      dfs(G, i); 
      group++;
    }
  }

  num.assign(n, -1);
  for(int i=0;i<n;i++){
    ans=groupsize[seen[i]]-1;
    for(int j=0;j<G[i].size();j++){
      //cout << "[" << bl[i][j] << "]";
      if(seen[i]==seen[G[i][j]])ans--;
    }
    for(int j=0;j<bl[i].size();j++){
      //cout << "[" << bl[i][j] << "]";
      if(seen[i]==seen[bl[i][j]])ans--;
    }
    cout << ans << " ";
    //cout << endl;
  }

  return 0;
}


Measured memory_bytes: 37632
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		String S=next();
		String T=next();
		int min=2000;
		for(int i=0;i<S.length()-T.length()+1;i++){
			String a=S.substring(i,T.length()+i);
			int ans=0;
			for(int j=0;j<T.length();j++){
				if(a.charAt(j)!=T.charAt(j))
					ans++;
			}
			if(ans<min)
				min=ans;
		}
		System.out.println(min);
	}
	public static long lmod(long i, long j) {
	     return (i%j)<0?(i%j)+0+(j<0?-j:j):(i%j+0);
	 }
	static boolean isOK(int index,int key,ArrayList<Integer> a){
		if (a.get(index)>=key) return true;
	    else return false;
	}
	static int binary(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;
	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 33040
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main (String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf);
				int a = Integer.parseInt(st.nextToken());
				int b = Integer.parseInt(st.nextToken());
				int lim = Math.max(a,b);
				int m = 1;
				for (int i=2;i<=lim;i++) {
					if (a%i==0&&b%i==0) m = i;
				}
				System.out.println(m);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 19768
import math
N = int(input())
ans = 0
if N == 0 or N % 2 == 1:
    ans = 0
else:
    # means N >= 2 and even
    digN = round( math.log(N , 5) )

    i = 1
    while i <= digN:
        ans +=  ( N //( 5 ** i * 2 ) )
        i += 1

print(ans)

Measured memory_bytes: 9068
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool cheak(ll x, ll y, ll xMax, ll yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline ll toInt(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1e9 + 9;


int main(){

	ll n;
	cin >> n;

	ll tmp = 1, ans = 0;
	while (tmp <= n){
		tmp *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const int mod = 1e9 + 7;
int h, w;
llong k;

char grid[1000][1001];
bool visited[1000][1000];
int hc, vc;

int dfs(int x, int y) {
    if (x < 0 || x == h || y < 0 || y == w) return 0;
    if (grid[x][y] != '#') return 0;
    if (visited[x][y]) return 0;
    visited[x][y] = 1;
    if (hc) {
        dfs(x - 1, y);
        dfs(x + 1, y);
    }
    if (vc) {
        dfs(x, y - 1);
        dfs(x, y + 1);
    }
    return 1;
}

int ipow(int x, llong p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    int ret = ipow(x, p >> 1);
    ret = (llong)ret * ret % mod;
    if (p & 1) ret = (llong)ret * x % mod;
    return ret;
}

int main() {
    scanf("%d%d%lld", &h, &w, &k);
    if (k-- == 0) {
        printf("1\n");
        return 0;
    }
    int cnt = 0;
    for (int i = 0; i < h; ++i) {
        scanf("%s", grid[i]);
        for (int j = 0; j < w; ++j) {
            if (grid[i][j] == '#') ++cnt;
        }
    }
    
    for (int i = 0; i < h; ++i) {
        if (grid[i][0] == '#' && grid[i][w - 1] == '#') ++vc;
    }
    
    for (int i = 0; i < w; ++i) {
        if (grid[0][i] == '#' && grid[h - 1][i] == '#') ++hc;
    }
    if (hc && vc) {
        printf("1\n");
        return 0;
    }
    if (hc == vc) {
        printf("%d\n", ipow(cnt, k));
        return 0;
    }
    if (vc) {
        for (int i = 0; i < h || i < w; ++i) {
            for (int j = 0; j < h || j < w ; ++j) {
                if (i < j) swap(grid[i][j], grid[j][i]);
            }
        }
        swap(h, w);
        swap(hc, vc);
    }
    
    int cp = 0;
    for (int i = 1; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (grid[i - 1][j] == '#' && grid[i][j] == '#') ++cp;
        }
    }
    
    int ans = cp, a, b;
    if (cnt != hc) {
        a = ipow(cnt - hc, mod - 2);
        b = (ipow(cnt, k) + mod - ipow(hc, k)) % mod;
    }
    else {
        a = 1;
        b = k % mod * ipow(hc, k - 1) % mod;
    }
    ans = (llong)ans * a % mod * b % mod;
    ans = ipow(cnt, k) + mod - ans;
    printf("%d\n", ans % mod);
    
	return 0;
}


Measured memory_bytes: 1280
#[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 ) * } } ; }
#[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" ) } ; }

fn main() {
    input! {
        n: usize, x: u64,
        l:[u64;n]
    }

    let mut cnt = 1;
    let mut d = 0;
    for i in 0..n {
        d += l[i];
        if d <= x {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;
int main(void){
  int n;
  cin >> n;
  ll max_ll =(1LL<<63)-1;
  ll work = 1;
  bool flag = false;
  rep(i,n){
    ll a,pre = work;
    cin >> a;
    if(a == 0){
      cout << 0 << endl;
      return 0;
    }
    work *= a;
    if(1000000000000000000 < work ||  max_ll/a < pre){
      flag = true;
    }

  }

  if(flag){
    cout << -1 << endl;
  }
  else{
    cout << work << endl;
  }
  return 0;
}


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

long long int mod = 1e9 + 7;

long long int powmod(int a, int p, long long int mod) {
    long long int ans = 1;
    long long int mul = a;

    for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
        if ((p & 1) == 1) ans = (ans * mul) % mod;
    }

    return ans;
}

long long int comb(int a, int b, long long int mod) {
    long long int ans = 1;
    if (b > a / 2) return comb(a, a - b, mod);
    long long int div = 1;

    for (int i = 0; i < b; i++) {
        ans *= a - i;
        ans %= mod;

        div *= i + 1;
        div %= mod;
    }

    // Fermat's little theorem
    ans *= powmod(div, mod - 2, mod);

    return ans % mod;
}

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

    for (int i = 1; i <= k; ++i) {
        if (n - k + 1 < i) cout << 0 << endl;
        else {
            long long int x, y;
            x = comb(n-k+1, i, mod);
            y = comb(k-1, k-i, mod);
            cout << x * y % mod << endl;
        }
    }

    return 0;
}

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

int main() {
	int N;
	int const size = 200001;
	int A[size] = {};
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i+1];
	}
	int sum = 0;

	int i = 1, j = 1,k;

	for (i = 0; i <= N; i++)sum += abs(A[i] - A[i + 1]);

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


	return 0;


}

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

int way (int Ax,int Ay,int Bx,int By) {
  int n = max(Ax,Bx)+max(Ay,By)-min(Ax,Bx)-min(Ay,By);
  return n;
}

int main() {
  int N;
  cin >> N;
  vector<int> T(N),X(N),Y(N);
  for(int i=0;i<N;i++) {
    cin >> T.at(i) >> X.at(i) >> Y.at(i);
  }
  vector<int> Tm(N-1),D(N-1);
  for(int i=0;i<N-1;i++) {
    Tm.at(i)=T.at(i+1)-T.at(i);
    D.at(i)=way(X.at(i),Y.at(i),X.at(i+1),Y.at(i+1));
  }
  bool ng = 0;
  for(int i=0;i<N-1;i++) {
    if(((Tm.at(i)%2) != (D.at(i)%2)) ||
       (Tm.at(i) < D.at(i))) {
      ng = 1;
      break;
    }
  }
  if(((T.at(0)%2) != ((X.at(0)+Y.at(0))%2) ||
      (T.at(0) < (X.at(0)+Y.at(0))))) {
    ng = 1;
  }
  if(ng) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 2176
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> M >> N >> K;
	vector<vector<int>>v(N, vector<int>(M));
	for (auto &i : v)for (auto &j : i)cin >> j;
	for (int i = 1; i < N; i++) {
		vector<long long int>dp(100001, -MOD * MOD);
		dp[K] = 0;
		for (int j = 0; j < M; j++) {
			for (int k = 100000; k >= v[i - 1][j]; k--) {
				dp[k - v[i - 1][j]] = max(dp[k - v[i - 1][j]], dp[k] + v[i][j] );
			}
		}
		for (int i = 0; i <= 100000; i++) {
			dp[i] += i;
		}
		K = *max_element(dp.begin(), dp.end());
	}
	cout << K << endl;
}


Measured memory_bytes: 4020
taro = 0
hanako = 0
gets.to_i.times do
  t, h = case gets.split.inject{|a, b| a <=> b}
                 when -1
                   [0, 3]
                 when 0
                   [1, 1]
                 when 1
                   [3, 0]
                 end
  taro += t
  hanako += h
end
puts "#{taro} #{hanako}"

Measured memory_bytes: 6100
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char *argv[]) {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int> sum(n + 1, 0);
	for (int i = 1; i < n; ++i) {
		sum[i] = sum[i - 1];
		sum[i] += (s[i - 1] == 'A' && s[i] == 'C');
	}
	for (int i = 0; i < q; ++i) {
		int l, r;
		cin >> l >> r;
		cout << (sum[r - 1] - sum[l - 1]) << endl;
	}
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if (s == "ABC") cout << "ARC\n";
    if (s == "ARC") cout << "ABC\n";

    return 0;
}


Measured memory_bytes: 3652
#include<cstdio>
#include<algorithm>
long long a[200001];
int main() {
	int n, i;
	long long j, sum = 0;
	scanf("%d", &n);
	a[0] = 0;
	for (i = 1; i <= n; i++)scanf("%lld", &a[i]);
	for (i = 1; i <= n; i++)a[i] += a[i - 1];
	std::sort(a, a + n + 1);
	j = 0;
	for (i = 1; i <= n; i++) {
		if (a[i - 1] == a[i])j++;
		else {
			sum += j*(j + 1) / 2;
			j = 0;
		}
	}
	sum += j*(j + 1) / 2;
	printf("%lld", sum);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	string s; 
	cin >> s ; 
	if(s[0] == s[1] or s[1] == s[2] or s[2] == s[3]){
		cout << "Bad\n" ;
		return;
	}
	cout << "Good\n";	 
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
}



Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    
    edge = [[] for _ in range(N)]
    for i in range(1,N):
        j = I()
        edge[j-1].append(i)
    def dfs(v):
        res = 0
        tmp = []
        for to in edge[v]:
            tmp.append(dfs(to))
        if not tmp:
            return 0

        tmp.sort(reverse=True)
        for i,t in enumerate(tmp,start=1):
            res = max(res, i+t)
        return res

    ans = dfs(0)
    print(ans)


    
if __name__ == '__main__':
    main()

Measured memory_bytes: 147304
import java.util.*;
import java.lang.*;

/**
 * BubbleSort
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            list[i] = Integer.parseInt(sc.next());
        }

        int num = MyBubbleSort(list, n);

        for (int i = 0; i < list.length; i++) {
            if (i == list.length - 1) {
                System.out.print(list[i]);

            } else {
                System.out.print(list[i] + " ");
            }
        }
        System.out.println("");
        System.out.println(num);

    }

    private static int MyBubbleSort(int[] list, int n) {
        int num = 0;
        boolean flag = true; // 逆の隣接要素が存在する
        while (flag) {
            flag = false;

            for (int j = n - 1; j >= 1; j--) {
                if (list[j] < list[j - 1]) {
                    int tmp = list[j];
                    list[j] = list[j - 1];
                    list[j - 1] = tmp;
                    flag = true;
                    num++;
                }
            }
        }

        return num;
    }
}


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

const int SUIT_SIZE = 4;
const int RANK_SIZE = 14;

const char *suits = "SHCD";

bool cards[SUIT_SIZE][RANK_SIZE];

int c2i(char c)
{
    int i = 0;
    for(const char *s = suits; *s != 0; s++, i++)
    {
        if(*s == c)
        {
            return i;
        }
    }
    return -1;
}

const char i2c(int i)
{
    return suits[i];
}

int main()
{
    char s;
    int c, n;

    for(int i = 0; i < SUIT_SIZE; i++)
    {
        for(int j = 1; j < RANK_SIZE; j++)
        {
            cards[i][j] = false;
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++)
    {
        cin >> s >> c;
        cards[c2i(s)][c] = true;
    }

    for(int i = 0; i < SUIT_SIZE; i++)
    {
        for(int j = 1; j < RANK_SIZE; j++)
        {
            if(cards[i][j] == false)
                cout << i2c(i)  << " " << j << endl;
        }
    }

    return 0;
}

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

/* 繰り返し自乗法. */
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合.
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

signed main() {
    int H, A;
    cin >> H >> A;

    int a = 0;
    if ((H%A) != 0) a = 1;

    cout << (H/A) + a << endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 1147483647;

using namespace std;

int dp[101][100001] = {};

int main()
{
  int n, W;
  cin >> n >> W;
  vector<int> v(n), w(n);
  REP(i, n)
  {
    cin >> w[i] >> v[i];
  }

  REP(i, n + 1)
  {
    REP(j, 100001)
    {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  FOR(i, 1, n + 1)
  {
    REP(j, 100001)
    {
      dp[i][j] = dp[i - 1][j];
      if (j - v[i - 1] >= 0)
      {
        dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
      }
    }
  }

  int ans = 0;
  REP(j, 100001)
  {
    if (dp[n][j] <= W)
    {
      ans = max(ans, j);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 39680
function Main(input) {
  var N = parseInt(input.trim(), 10);
  var vec_fX = Array.from({length: N}, () => 1);
  var limit;
  var ans = 0;
  for (var i = 1; i < N; i++){
    limit = N / (i + 1);
    for (var j = 1; j <= limit; j++){
      ans += (i + 1) * j;
    }
  }
  ans += (N * (N + 1)) / 2;
  console.log(ans);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 110044
line = gets()
n = line.chomp.to_i

line = gets()
a = []
line.split(' ').each do |i|
    a.push(i.to_i)
end

max_h = 0
total = 0
a.each do |i|
    if i >= max_h
        max_h = i
        next
    end
    total += max_h - i
end
print(total)


Measured memory_bytes: 28264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String S = in.next();
			if(S.equals("Sunny")) {
				System.out.println("Cloudy");
			}else if(S.equals("Rainy")){
				System.out.println("Sunny");
			} else {
				System.out.println("Rainy");
			}
		}
	}
	
	static boolean permutation_2(String s, String t){
        if(s.length() != t.length()){
            return false;
        }
        
        int[] letters = new int[256]; //文字コードの仮定;
        
        char[] s_array = s.toCharArray();  
        for(char c:s_array){
            letters[c]++;
        }
        
        for(int i=0;i<t.length();i++){
            int c = (int)t.charAt(i);
            if(--letters[c] < 0){
                return false;
            }
        }
        return true;
    }

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 23508