akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
 
#define comMAX 2000000
#define comLEN 7

void heapify(int s[],int h,int i){
    int l,r,max,tmp;
    l=i<<1;
    r=(i<<1)+1;
    max=i;
 
    if(l<=h&&s[l-1]>s[max-1])max=l;
    if(r<=h&&s[r-1]>s[max-1])max=r;
     
    if(max!=i){
        tmp=s[max-1];
        s[max-1]=s[i-1];
        s[i-1]=tmp;
         
        heapify(s,h,max);
    }
     
    return;
}
void makeHeap(int s[],int h){
    int l,r,max,tmp,i=h/2;
    while(i>0){
        l=i<<1;
        r=(i<<1)+1;
        max=i;
        if(l<=h&&s[l-1]>s[max-1])max=l;
        if(r<=h&&s[r-1]>s[max-1])max=r;
        if(max==i)break;
        tmp=s[i-1];
        s[i-1]=s[max-1];
        s[max-1]=tmp;
        i>>=1;
    }
}
void output(int s[],int h){
    int i;
    for(i=0;i<h;i++)printf("%d ",s[i]);
    printf("\n");
}
 
int main(void){
    int s[comMAX];
    int l=0;
    char com[comLEN+1];
    int x;
    while(1){
        scanf("%s \n",com);
        if(com[0]=='i'){
            scanf("%d\n",&x);
            s[l++]=x;
            makeHeap(s,l);
        }else if(com[1]=='x'){
            printf("%d\n",s[0]);
            s[0]=s[--l];
            heapify(s,l,1);
        }else if(com[1]=='n')break;
        else break;
    }
     
//    output(l);
     
    return 0;    
}


Measured memory_bytes: 5652
N, K = map(int,input().split())
R, S, P = map(int,input().split())
T = input()
 
def EarnScore(rsp, t):
    if t == 'r':
        return rsp[2]
    elif t == 's':
        return rsp[0]
    elif t == 'p':
        return rsp[1]
    else:
        return 0
 
RSP = [R, S, P]
Answer = 0
ListT = list(T)
for i in range(N):
    Answer = EarnScore(RSP, ListT[i]) + Answer
    if i + K < N:
        if ListT[i] == ListT[i+K]:
            ListT[i+K] = 'x'
 
print(Answer)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 90000000000000000
signed main(void){
    int n,t;cin>>n>>t;
    P V[n];
    rep(i,n){
        int x,y;cin>>x>>y;
        V[i]=make_pair(x,y);
    }
    sort(V,V+n);
    int A[n],B[n];
    rep(i,n){
        A[i]=V[i].F;B[i]=V[i].S;
    }
    vector<vector<int>>dp(3010,vector<int>(6010,0));
    rep(i,n)rep(j,t){
        dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
        dp[i+1][j+A[i]]=max(dp[i+1][j+A[i]],dp[i][j]+B[i]);
    }
    int ans=0;
    rep(i,3010)rep(j,6010)ans=max(ans,dp[i][j]);
   // rep(i,n){
    //    rep(j,t)cout<<dp[i][j]<<' ';
//cout<<endl;
   // }
    cout<<ans<<endl;
    
}
        

Measured memory_bytes: 141824
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

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

	vector<int> t(n);

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

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

	int ans = 0;

	int index = 0;
	int cnt = 1;
	for (; index < n;) {
		int first = t[index++];

		while (index<n && t[index] <= first + k && cnt < c) {
			++cnt;
			++index;
		}

		++ans;
		cnt = 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    private class NodeWithCost {
        public int id;
        public long cost;

        public NodeWithCost(int id, long cost) {
            this.id = id;
            this.cost = cost;
        }
    }

    private Map<Integer, Long> buildCostData(int root, Map<Integer, List<NodeWithCost>> tree) {
        Map<Integer, Long> result = new HashMap<>();
        Queue<NodeWithCost> q = new LinkedList<>();
        Map<Integer, Object> visited = new HashMap<>();
        q.add(new NodeWithCost(root, 0));
        while (!q.isEmpty()) {
            NodeWithCost toSearch = q.poll();
            long costSoFar = toSearch.cost;
            visited.put(toSearch.id, new Object());

            for (NodeWithCost neighbor : tree.get(toSearch.id)) {
                if (!visited.containsKey(neighbor.id)) {
                    long costFromRootToNeighbor = costSoFar + neighbor.cost;
                    result.put(neighbor.id, costFromRootToNeighbor);
                    q.add(new NodeWithCost(neighbor.id, costFromRootToNeighbor));
                }
            }
        }
        return result;
    }

    private void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Integer, List<NodeWithCost>> tree = new HashMap<>();
        for (int i = 0; i < (n - 1); i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int cost = sc.nextInt();
            if (!tree.containsKey(a)) {
                tree.put(a, new ArrayList<>());
            }
            if (!tree.containsKey(b)) {
                tree.put(b, new ArrayList<>());
            }
            tree.get(a).add(new NodeWithCost(b, cost));
            tree.get(b).add(new NodeWithCost(a, cost));
        }
        int q = sc.nextInt();
        int k = sc.nextInt();
        Map<Integer, Long> costDataFromK = buildCostData(k, tree);

        for (int i = 0; i < q; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            System.out.println(costDataFromK.get(x) + costDataFromK.get(y));
        }
    }

    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
}


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

int main(){

	int a[101],n;
	cin >>n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = n-1; i > 0; i--){
		cout << a[i] << " ";
	}
	cout << a[0];
	cout << "\n";

	return 0;
}

Measured memory_bytes: 1164
# は？なんやこれ無限にわからん
# 半分全列挙的な気持ちでやる？
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ab = []
for av in a:
    for bv in b:
        ab.append(av + bv)
ab = sorted(ab, reverse=True)[:k]
abc = []
for abv in ab:
    for cv in c:
        abc.append(abv + cv)
abc = sorted(abc, reverse=True)[:k]
for ans in abc:
    print(ans)


Measured memory_bytes: 150780
//author: zekigurbuz (Zeki Gurbuz) 2020
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;

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

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define all(x) begin(x),end(x)

const int N = 1e5 + 10;
const int M = 1e9 + 7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

template<class T>void ckmin(T&a,T b){a=min(a,b);}
template<class T>void ckmax(T&a,T b){a=max(a,b);}

void precomp() {

}


void solve() {
	int n; cin >> n;
	ll a, b, c; cin >> a >> b >> c;
	ll ab = a + b, ac = a + c, bc = b + c;
	vector<string> v(n);
	for (int i = 0; i < n; i++) cin >> v[i];
	set<int> ab1, ac1, bc1;
	for (int i = 0; i < n; i++) {
		if (v[i] == "AB") ab1.insert(i);
		else if (v[i] == "BC") bc1.insert(i);
		else ac1.insert(i);
	}
	ab1.insert(INT_MAX);
	ac1.insert(INT_MAX);
	bc1.insert(INT_MAX);
	char ans[n];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] == "AB") {
			if (ab == 0) {
				cout << "No" << endl;
				return;
			}
			if (ac < bc) {
				ac++;
				bc--;
				ans[i] = 'A';
			}
			else if (ac > bc) {
				ac--;
				bc++;
				ans[i] = 'B';
			}
			else if (*ac1.lb(cnt) < *bc1.lb(cnt)) {
				ac++;
				bc--;
				ans[i] = 'A';
			}
			else {
				ac--;
				bc++;
				ans[i] = 'B';
			}
		}
		else if (v[i] == "AC") {
			if (ac == 0) {
				cout << "No" << endl;
				return;
			}
			if (ab < bc) {
				ab++;
				bc--;
				ans[i] = 'A';
			}
			else if (ab > bc) {
				ab--;
				bc++;
				ans[i] = 'C';
			}
			else if (*ab1.lb(cnt) < *bc1.lb(cnt)) {
				ab++;
				bc--;
				ans[i] = 'A';
			}
			else {
				ab--;
				bc++;
				ans[i] = 'C';
			}
		}
		else {
			if (bc == 0) {
				cout << "No" << endl;
				return;
			}
			if (ab < ac) {
				ab++;
				ac--;
				ans[i] = 'B';
			}
			else if (ab > ac) {
				ab--;
				ac++;
				ans[i] = 'C';
			}
			else if (*ab1.lb(cnt) < *ac1.lb(cnt)) {
				ab++;
				ac--;
				ans[i] = 'B';
			}
			else {
				ab--;
				ac++;
				ans[i] = 'C';
			}
		}
		if (ab > a + b + c || ac > a + b + c || bc > a + b + c) {
			cout << "No" << endl;
			return;
		}
		cnt++;
	}
	cout << "Yes" << endl;
	for (int i = 0; i < n; i++) cout << ans[i] << '\n';
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	precomp();
	int t = 1; // cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N, X, Y; cin >> N >> X >> Y;
	vint cnt(N, 0);
	for (int i = 1; i <= N; i++) {
		for (int j = i+1; j <= N; j++) {
			cnt[min({j-i, abs(i-X) + abs(j-Y) + 1, abs(j-X) + abs(i-Y) + 1})]++;
		}
	}
	for (int i = 1; i < N; i++) {
		cout << cnt[i] << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}

Measured memory_bytes: 256
# ABC099C - Strange Bank
def main():
    n = int(input())
    # initialize dp table with using only ¥1
    dp = [i for i in range(n + 1)]
    cand = (6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049)
    for i in range(n + 1):
        for j in cand:
            if j > n:
                break
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + 1)
    print(dp[-1])


if __name__ == "__main__":
    main()

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

const int mxN = 1e2 + 2, mxV = 1e5 + 4;
long long n, w, weights[mxN], values[mxN], dp[mxV];
const int INF = 1e9 + 7;

int main()
{
    cin >> n >> w;
    for (int i = 0; i < n; i++)
        cin >> weights[i] >> values[i];

    memset(dp, INF, sizeof(dp));
    dp[0] = 0;

    for (int j = 0; j < n; j++)
    {
        for (int i = mxV - 1; i >= 0; i--)
        {
            if (i - values[j] >= 0)
                dp[i] = min(dp[i], dp[i - values[j]] + weights[j]);
            if (dp[i] > w)
                dp[i] = w + 1;
        }
    }

    long long ret = 0;
    for (int i = 0; i < mxV; i++)
    {
        if (dp[i] <= w)
            ret = i;
    }
    cout << ret << endl;
}

Measured memory_bytes: 4420
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [i64; n]);
    let mut dp = vec![0i64; n + 1];
    dp[0] = 1000;
    for i in 0..n {
        dp[i + 1] = dp[i];
        for j in 1..=i {
            let mut m = dp[j];
            let c = m / a[j - 1];
            m -= a[j - 1] * c;
            m += a[i] * c;
            dp[i + 1] = max(dp[i + 1], m);
        }
    }
    println!("{}", dp[n]);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, w, sum = 0, t, minimum;
  vector<int> W;
  cin >> N;
  REP(i, N)
  {
    cin >> w;
    sum += w;
    W.push_back(sum);
  }

  minimum = sum;
  REP(i, N)
  {
    minimum = min(minimum, abs(sum - W[i] * 2));
  }
  cout << minimum << '\n';

  return 0;
}

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

typedef long long ll;
const ll MOD=1e9+7;

ll mod_pow(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%MOD;
}

int main(){
    int N,K; cin >> N >> K;
    ll ans=0;
    map<int,ll> ma;
    for(int i=K;i>=1;i--){
        int tmp=K/i;
        ll res=mod_pow(tmp,N);
        for(int j=2;j<=tmp;j++){
            ll k=i*j;
            res=(res-ma[k]+MOD)%MOD;
        }
        ma[i]=res;
        ans+=(res*i)%MOD;
        ans%=MOD;
    }
    cout << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    int m=753;
    for(int i=0;i<s.size()-2;i++){
        m=min(m,abs(753-stoi(s.substr(i,3))));
    }
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
  {
    long int k,i,su=0;
    scanf("%ld",&k);
        for( i=1;i<=k;i++){
            su=(su*10+7)%k;
            
            if(su%k==0){
                printf("%ld\n",i);
                return 0;
            }
        }
    printf("-1\n");
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<char> v(N);
  REP(i,N) cin >> v.at(i);
  if(v.at(K-1)=='A') {
    v.at(K-1)='a';
  }
  else if(v.at(K-1)=='B') {
    v.at(K-1)='b';
  }
  else if(v.at(K-1)=='C') {
    v.at(K-1)='c';
  }
  REP(i,N) cout << v.at(i);
}
  

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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

const int msz=3003;
int a[msz];
int n;

int f(int m)
{
	int val=0;
	for(int i=0;i<n;i++)
	{
		val+=m%a[i];
	}
	return val;
}

int main()
{
	fio;
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=a[i]-1;
	}
	cout<<ans<<endl;
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <queue>
#pragma comment (linker,"/STACK:102400000,102400000")
#define maxn 105
#define MAXN 200005
#define mod 1000000007
#define INF 0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-6
typedef long long ll;
using namespace std;

int n,m,ans,cnt,flag;
char mp[maxn][maxn];
bool vis[maxn][maxn];
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};

void dfs(int x,int y,char c)
{
    int i,j,tx,ty;
    for(i=0;i<4;i++)
    {
        tx=x+dx[i];
        ty=y+dy[i];
        if(tx<0||tx>=n||ty<0||ty>=m||vis[tx][ty]||mp[tx][ty]!=c) continue ;
        vis[tx][ty]=1;
        dfs(tx,ty,c);
    }
}
int main()
{
    int i,j,t;
    while(scanf("%d%d",&n,&m),n||m)
    {
        for(i=0;i<n;i++)
        {
            scanf("%s",mp[i]);
        }
        ans=0;
        memset(vis,0,sizeof(vis));
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                if(!vis[i][j])
                {
                    ans++;
                    vis[i][j]=1;
                    dfs(i,j,mp[i][j]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
/*
10 10
####*****@
@#@@@@#*#*
@##***@@@*
#****#*@**
##@*#@@*##
*@@@@*@@@#
***#@*@##*
*@@@*@@##@
*@*#*@##**
@****#@@#@
0 0
*/

Measured memory_bytes: 1684
N = int(input())
cnt = 0

for i in range(len(str(N))-1):
  if (i+1) % 2 == 1:
    cnt += 9*10**(i)

if len(str(N)) % 2 == 1:
  cnt += N - 10**(len(str(N))-1) + 1
print(cnt)

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

int main(void) {
    int a;
    int an,cnt = 0;
    
    cin >> a;
    an = a;
    unordered_set<int> mp;
    for(int i=1;;i++) {
        if(mp.find(an) == mp.end()) {
            mp.insert(an);
        } else {
            cout << i << endl;
            break;
        }
        if(an%2) {
            an = 3*an + 1;
        } else {
            an = an / 2;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, C = lr()
D = np.array([lr() for _ in range(C)])

grid = [lr() for _ in range(N)]
three = [[0] * C for _ in range(3)]
for i in range(N):
    for j in range(N):
        remain = (i+j) % 3
        three[remain][grid[i][j]-1] += 1

three = np.array(three)
answer = 10 ** 10
for x, y, z in itertools.permutations(range(C), 3):
    # three[0]をxの色にする
    result = 0
    for i in range(3):
        s = [x, y, z][i]
        result += (three[i] * D[:, s]).sum()
    if result < answer:
        answer = result

print(answer)
# 35

Measured memory_bytes: 14972
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

import sys
input = sys.stdin.readline
N, M, K = map(int, input().split())
uf = UnionFind(N)
ans = [0]*N
not_friend_candidates = [1]*N #自分自身
nfc = not_friend_candidates
for _ in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)
    nfc[A-1] += 1
    nfc[B-1] += 1
for _ in range(K):
    C, D = map(int, input().split())
    if uf.same(C-1, D-1):
        nfc[C-1] += 1
        nfc[D-1] += 1
ans = [uf.size(i)-nfc[i] for i in range(N)]
print(*ans)


Measured memory_bytes: 14136
#include<stdio.h>
#define N 501

int main()
{
  int i,j,n,u,k,v,data[N][N];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      data[i][j] = 0;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      v--;
      data[u][v] = 1;
    }
  }

  for(i=0; i<n; i++){
    for(j=0; j<n-1; j++){
      printf("%d ", data[i][j]);
    }
    printf("%d\n",data[i][n-1]);
  }

  return 0;
}


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


int main(){
    string S;
    int K;
    cin >> K;
    cin >> S;
    int s = S.size();
    if(s <= K) cout << S;
    else{
        string new_s = S.erase(K);
        new_s += "...";
        cout << new_s << endl;
    }
}

Measured memory_bytes: 3596
#!/usr/bin/env ruby

n = gets.chomp!.to_i

n.times do
  tris = gets.chomp!.split(" ").map(&:to_i)

  tris.sort!.map!{|elem| elem = elem ** 2}
  puts (tris.pop) == tris.reduce(:+) ? "YES" : "NO"
end

Measured memory_bytes: 8716
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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)*}
    };
}

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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut c = 1;
    for i in 0..n - 1 {
        if a[i] >= a[i + 1] {
            c += 1;
        }
    }
    puts!("{}\n{}\n", c, n);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



Measured memory_bytes: 1968
#include "stdio.h"

typedef struct {
    int flag;
    int check[100];
    long long int W;
} bigint;

void clear_A(int*A){for (size_t i = 0; i < 100; i++) {A[i]=0;}}

void  dainyuu_A(int*A,int*B) {for (size_t i = 0; i < 100; i++) {A[i]=B[i];}}

int main(int argc, char const *argv[]) {

  int N,i,j;
  long long int W;
  scanf("%d%lld", &N,&W);
  int V[N];
  long long int w[N];
  int ans=0;
  for (i = 0; i < N; i++) {scanf("%lld%d",&w[i],&V[i]);}

  int ans_max=0;
  for (i = 0; i <N; i++) {ans_max=ans_max+V[i];}
  bigint A[ans_max+1];
  for (i = 0; i <= ans_max; i++) {A[i].flag=0;A[i].W=W+1;clear_A(A[i].check);}

  for (i = 0; i <= ans_max; i++) {
    for (j = 0; j < N; j++) {
      if (i==V[j] && A[i].W > w[j]) {
        A[i].flag=1;
        A[i].W=w[j];
        clear_A(A[i].check);
        A[i].check[j]=1;
      }
      if (i-V[j]>0 && A[i-V[j]].flag==1 && A[i].W>A[i-V[j]].W+w[j] && A[i-V[j]].check[j]==0) {
        A[i].flag=1;
        A[i].W=A[i-V[j]].W+w[j];
        dainyuu_A(A[i].check,A[i-V[j]].check);
        A[i].check[j]=1;
      }
    }
  }

  for (i = 0; i <= ans_max; i++) {if (A[i].W<=W) {ans=i;}}
  printf("%d", ans);
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}
	
	int ans = 0, tmp = 0;
	for (int i = 0; i < n; ++i)
	{
		if (tmp >= h[i])
		{
			tmp = h[i];
		}
		else
		{
			ans += h[i] - tmp;
			tmp = h[i];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  vector<vector<int> > bingo(3, vector<int>(3));
  rep(i, 3)rep(j, 3)cin>>bingo[i][j];
  int n;cin>>n;
  vector<int> vec(n);
  rep(i, n)cin>>vec[i];
  bool ans = false;
  rep(i, 3){
    bool tmp = true;
    rep(j, 3){
      if(find(vec.begin(), vec.end(), bingo[i][j])==vec.end())tmp = false;
    }
    if(tmp)ans = true;
    tmp = true;
    rep(j, 3){
      if(find(vec.begin(), vec.end(), bingo[j][i])==vec.end())tmp = false;
    }
    if(tmp)ans = true;
  }
  bool tmp = true;
  rep(i, 3){
    if(find(vec.begin(), vec.end(), bingo[i][i])==vec.end())tmp = false;
  }
  if(tmp)ans = true;
  tmp = true;
  rep(i, 3){
    if(find(vec.begin(), vec.end(), bingo[2-i][i])==vec.end())tmp = false;
  }
  if(tmp)ans = true;
  cout<<(ans?"Yes":"No")<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3632
/*
©³©·¡¡¡¡¡¡©³©·
*©³©¿©ß©¥©¥©¥©¿©ß©·
*©§¡¡¡¡¡¡¡¡¡¡¡¡¡¡©§ ¡¡
*©§¡¡¡¡¡¡©¥¡¡¡¡¡¡©§
*©§¡¡©×©¿¡¡©»©×¡¡©§
*©§¡¡¡¡¡¡¡¡¡¡¡¡¡¡©§
*©§¡¡¡¡¡¡©ß¡¡¡¡¡¡©§
*©§¡¡¡¡¡¡¡¡¡¡¡¡¡¡©§
*©»©¥©·¡¡¡¡¡¡©³©¥©¿
*¡¡¡¡©§¡¡¡¡¡¡©§ÉñÊÞ±£ÓÓ
*¡¡¡¡©§¡¡¡¡¡¡©§´úÂëÎÞBUG£¡
*¡¡¡¡©§¡¡¡¡¡¡©»©¥©¥©¥©·
*¡¡¡¡©§¡¡¡¡¡¡¡¡¡¡¡¡¡¡©Ç©·
*¡¡¡¡©§¡¡¡¡¡¡¡¡¡¡¡¡¡¡©³©¿
*¡¡¡¡©»©·©·©³©¥©×©·©³©¿
*¡¡¡¡¡¡©§©Ï©Ï¡¡©§©Ï©Ï
*¡¡¡¡¡¡©»©ß©¿¡¡©»©ß©¿
*¡¡¡¡¡¡
*/
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int N = 2e5+10;
const ll mod = 1000000007;
const ll inf = 10000000000000000;

int random(int n){return (ll)rand()*rand()%n;}

inline int read(){
    char ch=getchar();int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch =getchar();}
    while('0'<=ch&&ch<='9'){x=x*10+ch-'0';ch=getchar();
    }return x*f;
}

int a[N];
int vis[N];

int main(){
    //srand((unsigned)time(0));
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin >> s;
    if(s == "ABC"){
        cout<<"ARC\n";
    }else {
        cout<<"ABC\n";
    }
    return 0;
}


Measured memory_bytes: 3604
"""
sheep oXo xXx ⇨ True
wolf  oXx xXo ⇨ True 
２点決める

s[i] == "o" and a[i] == "W"  a[i+1] != a[i-1]
s[i] == "o" and a[i] == "S"  a[i+1] == a[i-1]
s[i] == "x" and a[i] == "W"  a[i+1] == a[i-1]
s[i] == "x" and a[i] == "S"  a[i+1] != a[i-1]
"""
n = int(input())
s = input()
# S -> 0, W -> 1
ds = [(0,0),(0,1),(1,0),(1,1)]

for d0,d1 in ds:
    a = [d0,d1]
    for i in range(1,n):
        if s[i] == "o" and a[i] == 0:
            a.append(a[i-1])
        elif s[i] == "x" and a[i] == 0:
            a.append(a[i-1]^1)
        elif s[i] == "o" and a[i] == 1:
            a.append(a[i-1]^1)
        else:
            a.append(a[i-1])
    # 帳尻があっているかどうか
    X = ["S","W"]
    # print(a)
    if a[0] != a[-1]:continue
    a = a[:-1]
    if a[0] == 0 and s[0] == "x":
        if a[1] != a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[0] == 0 and s[0] == "o":
        if a[1] == a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[0] == 1 and s[0] == "x":
        if a[1] == a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
    if a[-0] == 1 and s[0] == "o":
        if a[1] != a[-1]:
            a = "".join([X[i] for i in a])
            print(a)
            exit()
print(-1)

Measured memory_bytes: 4948
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 62;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	vector<int> p(N);
	for (int i = 0; i < N; ++i) cin >> p[i], --p[i];
	vector<long long> dp(N);
	for (int i = 0; i < N; ++i) {
		long long nxt = inf;
		for (int j = 0; j <= p[i]; ++j) {
			nxt = min(nxt, dp[j]);
		}
		for (int j = 0; j < N; ++j) {
			if (j < p[i]) dp[j] += A;
			else dp[j] += B;
		}
		dp[p[i]] = min(dp[p[i]], nxt);
	}
	cout << *min_element(dp.begin(), dp.end()) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    int A;
    double ans[N];
    double cnt = 0;
    cin >> N;
    REP(i,N){
        cin >> A;
      //cout << A[i] << endl;
        ans[i] = 1.0 / (double)A; 
        cnt += ans[i];
    }
  double K = 1.0/cnt;
    cout << 1.0/cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

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

int main(){
  stack< int > st;
  int a,b;
  string s;
  while( cin >> s ){
    if( s[0] == '+' ){
      b = st.top(); st.pop();
      a = st.top(); st.pop();
      st.push(a + b);
    }else if( s[0] == '-' ){
      b = st.top(); st.pop();
      a = st.top(); st.pop();
      st.push(a - b);
    }else if( s[0] == '*'){
      b = st.top(); st.pop();
      a = st.top(); st.pop();
      st.push(a * b);
    }else{
      st.push( atoi(s.c_str()) );
    }
  }
  cout << st.top() << "\n";
  return 0;
}


Measured memory_bytes: 3180
package main 

import (
        "fmt"
        "sort"
)

func main () {
        var a, b, c, k int
        fmt.Scan(&a,&b,&c)
        fmt.Scan(&k)
        s :=[]int{a, b, c}
        sort.Sort(sort.IntSlice(s))
        x :=s[2]
        for i := 0 ; i < k ; i++ {
                x = x * 2
        }
        z := s[0]
        y := s[1]
        fmt.Println(x+z+y)
}


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

#define n_l '\n'
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)),  __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += n_l; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cout << to_string(H) << " | "; dbgm(T...); }
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl


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

   int n;
   cin >> n;
   vector <vector <int>> abc(n, vector <int> (3, 0)), dp(n, vector <int> (3, 0));
   for (int i = 0; i < n; i++) {
      for (int j = 0; j < 3; j++) {
         cin >> abc[i][j];
      }
   }

   for (int i = 0; i < 3; i++) {
      dp[0][i] = abc[0][i];
   }
   for (int i = 1; i < n; i++) {
      for (int j = 0; j < 3; j++) {
         for (int k = 0; k < 3; k++) {
            if (j != k) {
               dp[i][j] = max(dp[i - 1][k] + abc[i][j], dp[i][j]);
            }
         }
      }
   }

   cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << '\n';

   return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,c;
	string s="Odd";
	cin>>a>>b;
	c=(a*b)%2;
	if(c==0){
		s="Even";
	}
	cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
g = Array.new(n){ [] }

(n-1).times do |i|
  a, b = gets.to_s.split.map{|t| t.to_i - 1 }
  g[a] << [b, i]
  g[b] << [a, i]
end

q = [[0,-1,-1]]

ans = Array.new(n-1)
while q[0]
  v, parent, parent_color = q.shift
  
  # 小さい順に色を割り当てていく
  color = 0
  g[v].each do |(u, i)|
    next if u == parent
    color += 1
    color += 1 if color == parent_color
    ans[i] = color
    q << [u, v, color]
  end
end

puts ans.max, ans

Measured memory_bytes: 28284
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}


int main(){
	int n,m;
	cin >> n >> m;
	int sum=0,a[n+5];
	FOR0(i, n) cin>>a[i],sum+=a[i];
	int cnt=0;
	double target = ((1.0*sum)/(4*m));
	FOR0(i, n) 
	{
		if(a[i]>=target) cnt++;
	}
	if(cnt>=m)
		cout << "Yes"<<endl;
	
	else
		cout<<"No"<<endl;
	

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_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>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

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

	int n;
	cin >> n;

	vector<set<int>> win(n);

	for (int i = 1; i < n; i++) {
		int a;
		cin >> a; a--;
		win[a].insert(i);
	}

	vector<int> dp(n, -1);

	function<int(int)> dfs = [&](int i) {
		if (dp[i] != -1)return dp[i];
		if (win[i].size() == 0)return 0ll;

		vector<int> ranks;
		each(j, win[i]) {
			ranks.push_back(dfs(j));
		}
		sort(all(ranks));
		reverse(all(ranks));

		int ret = 0;
		rep(j, ranks.size()) {
			ret = max(ret, ranks[j] + j);
		}
		return dp[i] = ret + 1;
	};

	cout << dfs(0) << endl;

	return 0;
}

Measured memory_bytes: 21376
#include <stdio.h>
#include <ctype.h>

void print_int(int n)
{
    printf("%d\n",n);
}

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

void sort(int a[], int n)
{
    for(int i = 1; i < n; i++)
    {
        int j = i-1;
        while(j >= 0 && a[j+1] > a[j])
        {
            swap(&a[j+1],&a[j]);
            j--;
        }
        
    }
    
}

int main(int argc, char * argv[])
{
    int button[2];
    int coin[3];
    scanf("%d %d",&button[0], &button[1]);

    coin[0] = button[0] + button[1];
    coin[1] = button[0] + button[0] - 1;
    coin[2] = button[1] + button[1] - 1;

    sort(coin, 3);

    print_int(coin[0]);
    return 0;
}



Measured memory_bytes: 128
#147C
n=int(input())
a_li=[]
xy_li=[]
for i in range(n):
  a_li.append(int(input()))
  xy_li_i=[list(map(int,input().split())) for j in range(a_li[i])]
  xy_li.append(xy_li_i)
  
proof=[]  
for i in range(2**n):
  li=[0]*n
  for j in range(n):
    if (i>>j)&1==1:
      li[j]=1
  proof.append(li)

ans=0  
for i in proof:
  flag=True
  for j in range(n):
    if i[j]==1:
      for k in range(a_li[j]):
        x=xy_li[j][k][0]
        y=xy_li[j][k][1]
        if i[x-1]!=y:
          flag=False
          break
  if flag:
    count=(sum(i))
    if ans<=count:
      ans=count
    
print(ans)

Measured memory_bytes: 11508
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int , int>
#define psi pair <string , int >
#define pll pair <ll , ll>
#define pi 3.14159
using namespace std;
int main()
{
    double r;
    cin >> r;
    cout << 2 * pi * r << endl;
    ///code here
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x; cin >> n >> m >> x;
  int bef = 0, aft = 0;
  for (auto i = 0; i < m; i++) {
    int a; cin >> a;
    if (a < x) bef++;
    else aft++;
  }
  cout << min(bef, aft) << endl;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, K; cin >> n >> K;
  vector<ll> a(n); cin >> a;
  vector<ll> ans;
  auto use = [&](ll pos) {
    assert(a[pos] > 0);
    a[pos]--;
    ans.pb(pos);
  };
  ll prv = -1;
  while (K >= 0) {
    ll mn = -1;
    rep(i, n) {
      if (i == prv) continue;
      if (mn < 0 || a[i] < a[mn]) {
        mn = i;
      }
    }
    rep(i, n) {
      if (i != mn && i != prv) {
        if (a[i] == 0) {
          cout << -1 << endl;
          return;
        }
        use(i);
      }
    }
    if (a[mn] == 0) {
      cout << -1 << endl;
      return;
    }
    use(mn);
    prv = mn;
    --K;
  }
  each(a, ans) ++a;
  cout << ans.size() << endl;
  cout << ans << endl;
}


Measured memory_bytes: 384
unittest
{
	assert( [ "3", "1 3 2", "3 1 2" ].parse.expand.solve == 3 );
	assert( [ "8", "7 3 5 4 2 1 6 8", "3 8 2 5 4 6 7 1" ].parse.expand.solve == 17517 );
	assert( [ "3", "1 2 3", "1 2 3" ].parse.expand.solve == 0 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	input.popFront;
	auto qs = input.front.split.to!( long[] );
	return tuple( ps, qs );
}

auto solve( long[] ps, long[] qs )
{
	auto pi = -1L;
	auto qi = -1L;
	auto as = iota( 1L, ps.length.signed + 1 ).array;
	for( auto i = 0L; as.nextPermutation; i++ )
	{
		if( as == ps ) pi = i;
		if( as == qs ) qi = i;
	}
	return ( qi - pi ).abs;
}


Measured memory_bytes: 256
n=int(input())
i=1
while i<=n:
    ball=list(map(int,input().split()))
    left=[0]
    right=[0]
    m=0
    while True:
        #終了条件
        if m==10:
            print("YES")
            #print("left",left,"right",right)
            break
        #noの条件
        if ball[m]<left[len(left)-1] and ball[m]<right[len(right)-1]:
            print("NO")
            #print("left",left,"right",right,"ball",ball[m])
            break

        #左側に入れるか右側に入れるかの条件
        if ball[m]>left[len(left)-1] and ball[m]>right[len(right)-1]:
            if left[len(left)-1]>right[len(right)-1]:
                left.append(ball[m])
            else:
                right.append(ball[m])
        elif ball[m]>left[len(left)-1]:
            left.append(ball[m])
        else:
            right.append(ball[m])
        m+=1
    i+=1
        
        
            


Measured memory_bytes: 5608
#include<bits/stdc++.h>
 
using namespace std;
 
int n, a[100000];
int two, four, none;
 
int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(a[i] % 4 == 0) four++;
		else if(a[i] % 2 == 0) two++;
		else none++;
	}
	if(four+1 >= none && two == 0) cout << "Yes" << endl;
	else if(four >= none) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
  string S;
  cin>>S;
  for (int i=0;i<S.length();i++){
    if(!((i+1)%2==0)){
      cout<<S.at(i);
    }
  }
  cout<<endl;
  return 0;
}

  

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

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=0;

string S;

int main() {
	cin >> S;
	if(S.length() >= 4 && S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256